eslint-plugin-react-hooks-addons
Advanced tools
@@ -15,5 +15,13 @@ /** | ||
| type: 'problem', | ||
| schema: [], | ||
| schema: [{ | ||
| type: 'object', | ||
| properties: { | ||
| customComment: { | ||
| type: 'string' | ||
| } | ||
| }, | ||
| additionalProperties: false | ||
| }], | ||
| messages: { | ||
| unused: 'React Hook {{ hook }} has unused dependencies: {{ unusedDeps }}. They might cause the effect Hook to run unintentionally. Either exclude them or prepend /* effect dep */ comments to make the intention explicit.' | ||
| unused: 'React Hook {{ hook }} has unused dependencies: {{ unusedDeps }}. They might cause the effect Hook to run unintentionally. Either exclude them or prepend /* {{ effectComment }} */ comments to make the intention explicit.' | ||
| } | ||
@@ -25,2 +33,4 @@ }, | ||
| 'ArrowFunctionExpression,FunctionExpression': function (node) { | ||
| var _option$customComment; | ||
| const { | ||
@@ -34,2 +44,4 @@ parent | ||
| const [option] = context.options; | ||
| const effectComment = (_option$customComment = option == null ? void 0 : option.customComment) != null ? _option$customComment : 'effect dep'; | ||
| const through = context.getScope().through.map(r => r.identifier.name); | ||
@@ -48,3 +60,3 @@ const depArray = parent.arguments[1]; | ||
| value | ||
| }) => value.trim().toLowerCase() === 'effect dep')) { | ||
| }) => value.trim() === effectComment)) { | ||
| continue; | ||
@@ -62,3 +74,4 @@ } | ||
| hook: parent.callee.name, | ||
| unusedDeps: unusedDeps.map(dep => `'${dep}'`).join(', ') | ||
| unusedDeps: unusedDeps.map(dep => `'${dep}'`).join(', '), | ||
| effectComment | ||
| } | ||
@@ -65,0 +78,0 @@ }); |
+1
-1
| { | ||
| "name": "eslint-plugin-react-hooks-addons", | ||
| "version": "0.1.2", | ||
| "version": "0.2.0", | ||
| "author": "Zheng Song", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+11
-2
@@ -50,3 +50,3 @@ ## eslint-plugin-react-hooks-addons | ||
| With npm | ||
| with npm | ||
@@ -57,3 +57,3 @@ ```bash | ||
| Or with Yarn | ||
| or with Yarn | ||
@@ -87,2 +87,11 @@ ```bash | ||
| ### Options | ||
| #### `customComment` | ||
| You can use a different comment to mark dependencies as effectful: | ||
| ```json | ||
| "rules": { | ||
| "react-hooks-addons/no-unused-deps": ["warn", { "customComment": "effectful" }] | ||
| } | ||
| ``` | ||
| _Note: this eslint plugin is supposed to work in tandem with [eslint-plugin-react-hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks), as it doesn't check things that have already been reported by that plugin._ | ||
@@ -89,0 +98,0 @@ |
7677
8.69%73
19.67%99
10%