Skip to content

Commit 97bba4a

Browse files
update package identity
1 parent 75e5137 commit 97bba4a

File tree

7 files changed

+120
-112
lines changed

7 files changed

+120
-112
lines changed

CHANGELOG.md

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,3 @@
1-
## 4.4.0
2-
3-
* No changes, this was an automated release together with React 18.
4-
5-
## 4.3.0
6-
7-
* Support ESLint 8. ([@MichaelDeBoey](https://github.com/MichaelDeBoey) in [#22248](https://github.com/facebook/react/pull/22248))
8-
* Fix a crash with an empty effect. ([@ChrisRu](https://github.com/ChrisRu) in [#20385](https://github.com/facebook/react/pull/20385))
9-
* Improve the error message. ([@callmetwan](https://github.com/callmetwan) in [#20692](https://github.com/facebook/react/pull/20692))
10-
* Handle optional chained methods as dependency. ([@AriPerkkio](https://github.com/AriPerkkio) in [#20247](https://github.com/facebook/react/pull/20247))
11-
* Assume the new `useTransition` signature in the rule. ([@rickhanlonii](https://github.com/rickhanlonii) in [#20976](https://github.com/facebook/react/pull/20976))
12-
13-
## 4.2.0
14-
15-
* No changes, this was an automated release together with React 17.
16-
17-
## 4.1.2
18-
* Fix a crash with the TypeScript 4.x parser. ([@eps1lon](https://github.com/eps1lon) in [#19815](https://github.com/facebook/react/pull/19815))
19-
20-
## 4.1.1
21-
* Improve support for optional chaining. ([@pfongkye](https://github.com/pfongkye) in [#19680](https://github.com/facebook/react/pull/19680))
22-
* Fix a false positive warning for TypeScript parameters. ([@NeoRaider](https://github.com/NeoRaider) in [#19751](https://github.com/facebook/react/pull/19751))
23-
24-
## 4.1.0
25-
* **New Violations:** Warn when dependencies change on every render. ([@captbaritone](https://github.com/captbaritone) in [#19590](https://github.com/facebook/react/pull/19590))
26-
27-
## 4.0.8
28-
* Fixes TypeScript `typeof` annotation to not be considered a dependency. ([@delca85](https://github.com/delca85) in [#19316](https://github.com/facebook/react/pull/19316))
29-
30-
## 4.0.7
31-
* Fixes an overly coarse dependency suggestion. ([@gaearon](https://github.com/gaearon) in [#19313](https://github.com/facebook/react/pull/19313))
32-
33-
## 4.0.6
34-
* Fix crashes and other bugs related to optional chaining. ([@gaearon](https://github.com/gaearon) in [#19273](https://github.com/facebook/react/pull/19273) and [#19275](https://github.com/facebook/react/pull/19275))
35-
36-
## 4.0.5
37-
* Fix a crash when the dependency array has an empty element. ([@yeonjuan](https://github.com/yeonjuan) in [#19145](https://github.com/facebook/react/pull/19145))
38-
* Fix a false positive warning that occurs with optional chaining. ([@fredvollmer](https://github.com/fredvollmer) in [#19061](https://github.com/facebook/react/pull/19061))
39-
40-
## 4.0.4
41-
* Fix a false positive warning that occurs with optional chaining. ([@fredvollmer](https://github.com/fredvollmer) in [#19061](https://github.com/facebook/react/pull/19061))
42-
* Support nullish coalescing and optional chaining. ([@yanneves](https://github.com/yanneves) in [#19008](https://github.com/facebook/react/pull/19008))
43-
44-
## 4.0.3
45-
* Remove the heuristic that checks all Hooks ending with `Effect` due to too many false positives. ([@gaearon](https://github.com/gaearon) in [#19004](https://github.com/facebook/react/pull/19004))
46-
47-
## 4.0.2
48-
* Prevent Hooks that have `Effect` in the middle from being considered effects. ([@surgeboris](https://github.com/surgeboris) in [#18907](https://github.com/facebook/react/pull/18907))
49-
50-
## 4.0.1
51-
* Declare support for ESLint 7. ([@MichaelDeBoey](https://github.com/MichaelDeBoey) in [#18878](https://github.com/facebook/react/pull/18878))
52-
53-
## 4.0.0
54-
55-
* **New Violations:** Consider `PascalCase.useFoo()` calls as Hooks. ([@cyan33](https://github.com/cyan33) in [#18722](https://github.com/facebook/react/pull/18722))
56-
* **New Violations:** Check callback body when it's not written inline. ([@gaearon](https://github.com/gaearon) in [#18435](https://github.com/facebook/react/pull/18435))
57-
* **New Violations:** Check dependencies for all Hooks ending with `Effect`. ([@airjp73](https://github.com/airjp73) in [#18580](https://github.com/facebook/react/pull/18580))
58-
* Add a way to enable the dangerous autofix. ([@gaearon](https://github.com/gaearon) in [#18437](https://github.com/facebook/react/pull/18437))
59-
* Offer a more sensible suggestion when encountering an assignment. ([@Zzzen](https://github.com/Zzzen) in [#16784](https://github.com/facebook/react/pull/16784))
60-
* Consider TypeScript casts of `useRef` as constant. ([@sophiebits](https://github.com/sophiebits) in [#18496](https://github.com/facebook/react/pull/18496))
61-
* Add documentation. ([@ghmcadams](https://github.com/ghmcadams) in [#16607](https://github.com/facebook/react/pull/16607))
62-
63-
## 3.0.0
64-
65-
* **New Violations:** Forbid calling Hooks from classes. ([@ianobermiller](https://github.com/ianobermiller) in [#18341](https://github.com/facebook/react/pull/18341))
66-
* Add a recommended config. ([@SimenB](https://github.com/SimenB) in [#14762](https://github.com/facebook/react/pull/14762))
67-
68-
## 2.5.0
69-
70-
* Fix a misleading error message in loops. ([@M-Izadmehr](https://github.com/M-Izadmehr) in [#16853](https://github.com/facebook/react/pull/16853))
71-
72-
## 2.4.0
73-
74-
* **New Violations:** Run checks for functions passed to `forwardRef`. ([@dprgarner](https://github.com/dprgarner) in [#17255](https://github.com/facebook/react/pull/17255))
75-
* **New Violations:** Check for ref usage in any Hook containing the word `Effect`. ([@gaearon](https://github.com/gaearon) in [#17663](https://github.com/facebook/react/pull/17663))
76-
* Disable dangerous autofix and use ESLint Suggestions API instead. ([@wdoug](https://github.com/wdoug) in [#17385](https://github.com/facebook/react/pull/17385))
77-
78-
## 2.0.0
79-
80-
* **New Violations:** Forbid calling Hooks at the top level. ([@gaearon](https://github.com/gaearon) in [#16455](https://github.com/facebook/react/pull/16455))
81-
* Fix a crash when referencing arguments in arrow functions. ([@hristo-kanchev](https://github.com/hristo-kanchev) in [#16356](https://github.com/facebook/react/pull/16356))
82-
83-
841
## 1.x
852

86-
The 1.x releases arent noted in this changelog, but you can find them in the [commit history](https://github.com/facebook/react/commits/main/packages/eslint-plugin-react-hooks).
3+
The 1.x releases aren't noted in this changelog, but you can find them in the [commit history](https://github.com/gnowland/eslint-plugin-react-hooks-unreliable-deps/commits/main).

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Facebook, Inc. and its affiliates.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
# `eslint-plugin-react-hooks`
1+
# `eslint-plugin-react-hooks-unreliable-deps`
22

3-
This ESLint plugin enforces the [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html).
4-
5-
It is a part of the [Hooks API](https://reactjs.org/docs/hooks-intro.html) for React.
3+
This is a companion ESLint plugin for [`eslint-plugin-react-hooks`](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks) to warn about potential issues arising from reference equality in [React Hooks API](https://reactjs.org/docs/hooks-intro.html) dependency arrays.
64

75
## Installation
86

9-
**Note: If you're using Create React App, please use `react-scripts` >= 3 instead of adding it directly.**
10-
117
Assuming you already have ESLint installed, run:
128

139
```sh
1410
# npm
15-
npm install eslint-plugin-react-hooks --save-dev
11+
npm install eslint-plugin-react-hooks-unreliable-deps --save-dev
1612

1713
# yarn
18-
yarn add eslint-plugin-react-hooks --dev
14+
yarn add eslint-plugin-react-hooks-unreliable-deps --dev
1915
```
2016

2117
Then extend the recommended eslint config:
@@ -24,7 +20,7 @@ Then extend the recommended eslint config:
2420
{
2521
"extends": [
2622
// ...
27-
"plugin:react-hooks/recommended"
23+
"plugin:react-hooks-unreliable-deps/recommended"
2824
]
2925
}
3026
```
@@ -37,27 +33,26 @@ If you want more fine-grained configuration, you can instead add a snippet like
3733
{
3834
"plugins": [
3935
// ...
40-
"react-hooks"
36+
"react-hooks-unreliable-deps"
4137
],
4238
"rules": {
4339
// ...
44-
"react-hooks/rules-of-hooks": "error",
45-
"react-hooks/exhaustive-deps": "warn"
40+
"react-hooks-unreliable-deps/reference-deps": "warn",
4641
}
4742
}
4843
```
4944

5045

5146
## Advanced Configuration
5247

53-
`exhaustive-deps` can be configured to validate dependencies of custom Hooks with the `additionalHooks` option.
48+
`reference-deps` can be configured to validate dependencies of custom Hooks with the `additionalHooks` option.
5449
This option accepts a regex to match the names of custom Hooks that have dependencies.
5550

5651
```js
5752
{
5853
"rules": {
5954
// ...
60-
"react-hooks/exhaustive-deps": ["warn", {
55+
"react-hooks-unreliable-deps/reference-deps": ["warn", {
6156
"additionalHooks": "(useMyCustomHook|useMyOtherCustomHook)"
6257
}]
6358
}
@@ -66,10 +61,10 @@ This option accepts a regex to match the names of custom Hooks that have depende
6661

6762
We suggest to use this option **very sparingly, if at all**. Generally saying, we recommend most custom Hooks to not use the dependencies argument, and instead provide a higher-level API that is more focused around a specific use case.
6863

69-
## Valid and Invalid Examples
64+
## Explanation
7065

71-
Please refer to the [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html) documentation and the [Hooks FAQ](https://reactjs.org/docs/hooks-faq.html#what-exactly-do-the-lint-rules-enforce) to learn more about this rule.
66+
Please refer to this wonderful treatise [Object & Array Dependencies in the React useEffect Hook](https://www.benmvp.com/blog/object-array-dependencies-react-useEffect-hook/) to learn more about the impetus behind this rule.
7267

7368
## License
7469

75-
MIT
70+
This project was forked from [facebook/react/.../eslint-plugin-react-hooks](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks) and is inherently licensed under MIT.

npm/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// TODO: this doesn't make sense for an ESLint rule.
44
// We need to fix our build process to not create bundles for "raw" packages like this.
55
if (process.env.NODE_ENV === 'production') {
6-
module.exports = require('./cjs/eslint-plugin-react-hooks.production.min.js');
6+
module.exports = require('./cjs/eslint-plugin-react-hooks-unreliable-deps.production.min.js');
77
} else {
8-
module.exports = require('./cjs/eslint-plugin-react-hooks.development.js');
8+
module.exports = require('./cjs/eslint-plugin-react-hooks-unreliable-deps.development.js');
99
}

package.json

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "eslint-plugin-react-hooks",
3-
"description": "ESLint rules for React Hooks",
4-
"version": "4.5.0",
2+
"name": "eslint-plugin-react-hooks-unreliable-deps",
3+
"description": "Extends ESLint rules for React Hooks to check for potential reference equality issues in dependency arrays",
4+
"version": "1.0.0",
55
"repository": {
66
"type": "git",
7-
"url": "https://github.com/facebook/react.git",
8-
"directory": "packages/eslint-plugin-react-hooks"
7+
"url": "https://github.com/gnowland/eslint-plugin-react-hooks-unreliable-deps.git",
8+
"directory": "./"
99
},
1010
"files": [
1111
"LICENSE",
@@ -17,23 +17,59 @@
1717
"eslint",
1818
"eslint-plugin",
1919
"eslintplugin",
20-
"react"
20+
"react",
21+
"objects"
2122
],
2223
"license": "MIT",
2324
"bugs": {
24-
"url": "https://github.com/facebook/react/issues"
25+
"url": "https://github.com/gnowland/eslint-plugin-react-hooks-unreliable-deps/issues"
2526
},
2627
"engines": {
2728
"node": ">=10"
2829
},
29-
"homepage": "https://reactjs.org/",
30+
"homepage": "https://github.com/gnowland/eslint-plugin-react-hooks-unreliable-deps",
3031
"peerDependencies": {
3132
"eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0"
3233
},
34+
"scripts": {
35+
"simlink": "ln -hfs ../ node_modules/${npm_package_name}",
36+
"build": "npm run simlink && node ./scripts/rollup/build.js"
37+
},
3338
"devDependencies": {
39+
"@babel/cli": "^7.10.5",
40+
"@babel/code-frame": "^7.10.4",
41+
"@babel/core": "^7.11.1",
42+
"@babel/plugin-proposal-class-properties": "^7.10.4",
43+
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
44+
"@babel/plugin-transform-arrow-functions": "^7.10.4",
45+
"@babel/plugin-transform-block-scoped-functions": "^7.10.4",
46+
"@babel/plugin-transform-block-scoping": "^7.11.1",
47+
"@babel/plugin-transform-computed-properties": "^7.10.4",
48+
"@babel/plugin-transform-destructuring": "^7.10.4",
49+
"@babel/plugin-transform-for-of": "^7.10.4",
50+
"@babel/plugin-transform-literals": "^7.10.4",
51+
"@babel/plugin-transform-shorthand-properties": "^7.10.4",
52+
"@babel/plugin-transform-spread": "^7.11.0",
53+
"@babel/plugin-transform-template-literals": "^7.10.5",
54+
"@babel/preset-flow": "^7.10.4",
3455
"@typescript-eslint/parser-v2": "npm:@typescript-eslint/parser@^2.26.0",
3556
"@typescript-eslint/parser-v3": "npm:@typescript-eslint/parser@^3.10.0",
3657
"@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@^4.1.0",
37-
"@typescript-eslint/parser-v5": "npm:@typescript-eslint/parser@^5.0.0-0"
58+
"@typescript-eslint/parser-v5": "npm:@typescript-eslint/parser@^5.0.0-0",
59+
"babel-code-frame": "^6.26.0",
60+
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
61+
"cli-table": "^0.3.1",
62+
"filesize": "^6.0.1",
63+
"google-closure-compiler": "^20200517.0.0",
64+
"gzip-size": "^5.1.1",
65+
"ncp": "^2.0.0",
66+
"rollup": "^1.19.4",
67+
"rollup-plugin-babel": "^4.0.1",
68+
"rollup-plugin-commonjs": "^9.3.4",
69+
"rollup-plugin-node-resolve": "^2.1.1",
70+
"rollup-plugin-prettier": "^0.6.0",
71+
"rollup-plugin-replace": "^2.2.0",
72+
"rollup-plugin-strip-banner": "^0.2.0",
73+
"targz": "^1.0.1"
3874
}
3975
}

src/ReferenceDeps.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
/* eslint-disable no-for-of-loops/no-for-of-loops */
9+
10+
'use strict';
11+
12+
export default {
13+
meta: {
14+
type: 'suggestion',
15+
docs: {
16+
description:
17+
'checks the array of dependencies for Hooks like useEffect and similar for the existence of objects',
18+
recommended: true,
19+
url: 'https://www.benmvp.com/blog/object-array-dependencies-react-useEffect-hook/',
20+
},
21+
fixable: 'code',
22+
hasSuggestions: true,
23+
schema: [
24+
{
25+
type: 'object',
26+
additionalProperties: false,
27+
properties: {
28+
additionalHooks: {
29+
type: 'string',
30+
},
31+
},
32+
},
33+
],
34+
},
35+
};

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
'use strict';
99

10+
import ReferenceDeps from './ReferenceDeps';
1011

1112
export const configs = {
1213
recommended: {
14+
plugins: ['react-hooks-unreliable-deps'],
1315
rules: {
16+
'react-hooks-unreliable-deps/reference-deps': 'warn',
1417
},
1518
},
1619
};
1720

1821
export const rules = {
22+
'reference-deps': ReferenceDeps,
1923
};

0 commit comments

Comments
 (0)