Commit Graph

251 Commits

Author SHA1 Message Date
Andrew Clark
72b7462fe7
Bump local package.json versions for 18.1 release (#24447) 2022-04-26 16:58:44 -04:00
Afzal Sayed
069d23bb74
[eslint-plugin-exhaustive-deps] Fix exhaustive deps check for unstable vars (#24343)
* Fix exhaustive deps for unstable vars

* Fix formatting

* Optimise iterations

* Fix linting
2022-04-11 21:43:16 +01:00
Stephen Cyron
1f7a901d7b
Fix false positive lint error with large number of branches (#24287)
* Switched RulesOfHooks.js to use BigInt. Added test and updated .eslintrc.js to use es2020.

* Added BigInt as readonly global in eslintrc.cjs.js and eslintrc.cjs2015.js

* Added comment to RulesOfHooks.js that gets rid of BigInt eslint error

* Got rid of changes in .eslintrc.js and yarn.lock

* Move global down

Co-authored-by: stephen cyron <stephen.cyron@fdmgroup.com>
Co-authored-by: dan <dan.abramov@gmail.com>
2022-04-08 00:22:47 +01:00
Brian Vaughn
aa05e73150
Add 4.4.0 release to eslint rules CHANGELOG (#24234) 2022-03-31 10:43:08 -04:00
Andrew Clark
34aa5cfe0d Update local package.jsons for 18 2022-03-29 12:07:33 -04:00
Sebastian Markbåge
0dedfcc681
Update the exports field (#23257)
* Add .browser and .node explicit entry points

This can be useful when the automatic selection doesn't work properly.

* Remove react/index

I'm not sure why I added this in the first place. Perhaps due to how our
builds work somehow.

* Remove build-info.json from files field
2022-02-08 21:07:26 -05:00
Dan Abramov
c3f34e4beb eslint-plugin-react-hooks@4.3.0 2021-11-09 13:58:55 +00:00
Dan Abramov
827021c4e3
Changelog for eslint-plugin-react-hooks@4.3.0 2021-11-09 13:55:27 +00:00
Michaël De Boey
0c0d1ddae4
feat(eslint-plugin-react-hooks): support ESLint 8.x (#22248) 2021-09-06 20:17:51 +01:00
Sinan Sonmez (Chaush)
8a37b0ef3f
typos fixed (#21955) 2021-08-03 14:05:20 -04:00
Brian Vaughn
d483463bc8
Updated scripts and config to replace "master" with "main" branch (#21768) 2021-06-29 14:26:24 -04:00
Ricky
a632f7de3b
Flip tuple order of useTransition (#20976) 2021-04-20 12:21:44 -04:00
Sebastian Markbåge
172e89b4bf
Reland Remove redundant initial of isArray (#21188)
* Remove redundant initial of isArray (#21163)

* Reapply prettier

* Type the isArray function with refinement support

This ensures that an argument gets refined just like it does if isArray is
used directly.

I'm not sure how to express with just a direct reference so I added a
function wrapper and confirmed that this does get inlined properly by
closure compiler.

* A few more

* Rename unit test to internal

This is not testing a bundle.

Co-authored-by: Behnam Mohammadi <itten@live.com>
2021-04-07 07:57:43 -07:00
Sebastian Markbage
b4f119cdf1 Revert "Remove redundant initial of isArray (#21163)"
This reverts commit b130a0f5cd.
2021-04-01 15:19:00 -04:00
Sebastian Markbage
c03197063d Revert "apply prettier (#21165)"
This reverts commit 94fd1214d2.
2021-04-01 15:18:56 -04:00
Behnam Mohammadi
94fd1214d2
apply prettier (#21165) 2021-04-01 12:09:16 -07:00
Behnam Mohammadi
b130a0f5cd
Remove redundant initial of isArray (#21163) 2021-04-01 10:50:48 -07:00
Ari Perkkiö
eb58c3909a
react-hooks/exhaustive-deps: Handle optional chained methods as dependency (#20204) (#20247) 2021-03-24 16:45:27 +00:00
Anthony Garritano
c62986cfd8
Add additional messaging for RulesOfHooks lint error (#20692)
* Add additional messaging for RulesOfHooks lint error

* Fix tests and spacing issue

* Prettify ESLintRulesOfHooks-test
2021-02-22 19:17:13 -05:00
Christian Ruigrok
e8eff119e0
Fix ESLint crash on empty react effect hook (#20385)
* Fix ESLint crash on empty react effect hook

* Add layout effect to test

* Improve wording in comment

* Improve lint warning wording

* Reword missing effect callback message
2021-01-11 15:18:45 -05:00
Dan Abramov
40cfe1f486
Update CHANGELOG.md 2020-10-21 01:15:28 +01:00
Dan Abramov
f021a983aa
Bump versions for 17 (#20062) 2020-10-20 21:41:18 +01:00
Dan Abramov
cc581065df eslint-plugin-react-hooks@4.1.2 2020-09-11 13:18:44 +01:00
Dan Abramov
0044805c88
Update CHANGELOG.md 2020-09-11 13:17:55 +01:00
Sebastian Silbermann
0f70d4dd66
Consider components in jsx as missing dependencies in @typescript-eslint/parser@4.x (#19815)
* Run JS tests with TS esling parser

* Add failing test

* fix: Mark JSXIdentifier has missing dependency

* Safe isSameIdentifier
2020-09-11 13:13:43 +01:00
Dan Abramov
ad8a0a8cd0 eslint-plugin-react-hooks@4.1.1 2020-09-10 19:54:42 +01:00
Dan Abramov
77544a0d6f
Update CHANGELOG.md 2020-09-10 19:54:10 +01:00
Sebastian Silbermann
ed4fdfc737
test(eslint-plugin-react-hooks): Run with TS parsers >= 2.x (#19792)
* test(eslint-plugin-react-hooks): Run with TS parsers >= 2.x

* name test suites for each parser
2020-09-10 19:08:47 +01:00
Matthias Schiffer
cd75f93c03
eslint-plugin-react-hooks: fix compatibility with @typescript-eslint/parser@4.0.0+ (#19751)
In addition to `TSTypeQuery`, dependency nodes with a `TSTypeReference`
parent need to be ignored as well. Without this fix, generic type
variables will be listed as missing dependencies.

Example:

    export function useFoo<T>(): (foo: T) => boolean {
        return useCallback((foo: T) => false, []);
    }

This will report the following issue:

    React Hook useCallback has a missing dependency: 'T'. Either include
    it or remove the dependency array

Closes: #19742
2020-09-10 11:30:18 +01:00
Bhumij Gupta
53e622ca7f
Fix instances of function declaration after return (#19733)
* Add ESLint plugin to check for any function declare after return
* Refactor code to move function declarations before return and fix failing lint
2020-09-01 08:55:10 -04:00
Pascal Fong Kye
1396e4a8f5
Fixes eslint warning when node type is ChainExpression (#19680)
* Add babel parser which supports ChainExpression

* Add and fix tests for new babel eslint parser

* extract function to mark node

* refactor for compatibility with eslint v7.7.0+

* Update eslint to v7.7.0
Update hook test since eslint now supports nullish coalescing
2020-08-29 21:03:23 +01:00
Andrew Clark
a8500be893
Add startTransition as a known stable method (#19720)
The `startTransition` method returned from `useTransition` is a stable
method, like `dispatch` or `setState`. You should not have to specify
it as a hook dependency.
2020-08-28 16:44:39 -07:00
Dan Abramov
e4afb2fddf eslint-plugin-react-hooks@4.1.0 2020-08-17 13:31:20 +01:00
Dan Abramov
ced05c46c1
Update CHANGELOG.md 2020-08-17 13:30:16 +01:00
CY Lim
702fad4b1b
refactor fb.me redirect link to reactjs.org/link (#19598)
* refactor fb.me url to reactjs.org/link

* Update ESLintRuleExhaustiveDeps-test.js

* Update ReactDOMServerIntegrationUntrustedURL-test.internal.js

* Update createReactClassIntegration-test.js

* Update ReactDOMServerIntegrationUntrustedURL-test.internal.js

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-08-17 13:25:50 +01:00
Jordan Eldredge
1d5e10f703
[eslint-plugin-react-hooks] Report constant constructions (#19590)
* [eslint-plugin-react-cooks] Report constant constructions

The dependency array passed to a React hook can be thought of as a list of cache keys. On each render, if any dependency is not `===` its previous value, the hook will be rerun. Constructing a new object/array/function/etc directly within your render function means that the value will be referentially unique on each render. If you then use that value as a hook dependency, that hook will get a "cache miss" on every render, making the dependency array useless.

This can be especially dangerous since it can cascade. If a hook such as `useMemo` is rerun on each render, not only are we bypassing the option to avoid potentially expensive work, but the value _returned_ by `useMemo` may end up being referentially unique on each render causing other downstream hooks or memoized components to become deoptimized.

* Fix/remove existing tests

* Don't give an autofix of wrapping object declarations

It may not be safe to just wrap the declaration of an object, since the object may get mutated.

Only offer this autofix for functions which are unlikely to get mutated.

Also, update the message to clarify that the entire construction of the value should get wrapped.

* Handle the long tail of nodes that will be referentially unique

* Catch let/var constant constructions on initial assignment

* Trim trailing whitespace

* Address feedback from @gaearon

* Rename "assignment" to "initialization"

* Add test for a constant construction used in multiple dependency arrays
2020-08-13 20:54:33 +01:00
Dan Abramov
fe19b4247b eslint-plugin-react-hooks@4.0.8 2020-07-13 17:58:49 +01:00
Bianca Del Carretto
84479046f7
reference not add to dependencies if only its type is used as typeof arg (#19316)
* reference not add to dependencies if only its type is used as typeof arg

* Add a few more tests
2020-07-13 17:57:00 +01:00
Dan Abramov
a2b4db05bc eslint-plugin-react-hooks@4.0.7 2020-07-10 19:08:05 +01:00
Dan Abramov
47915fd6e1
[ESLint] Fix a bug causing a too coarse dependency suggestion (#19313)
* Add regression test for ESLint rule

* Fix the issue
2020-07-10 19:02:08 +01:00
Dan Abramov
6fd4321135 eslint-plugin-react-hooks@4.0.6 2020-07-07 22:39:40 +01:00
Dan Abramov
7c35cb20ef
[ESLint] Handle optional member chains (#19275)
* Rename internal variables

This disambiguates "optional"/"required" because that terminology is taken by optional chaining.

* Handle optional member chains

* Update comment

Co-authored-by: Ricky <rickhanlonii@gmail.com>

Co-authored-by: Ricky <rickhanlonii@gmail.com>
2020-07-07 21:34:16 +01:00
Dan Abramov
7ca1d861e8
[ESLint] Consistently treat optional chaining as regular chaining (#19273)
* Revert "Fix ExhaustiveDeps ESLint rule throwing with optional chaining (#19260)"

This reverts commit 0f84b0f02b.

* Re-add a test from #19260

* Remove all code for optional chaining support

* Consistently treat optional chaining as regular chaining

This is not ideal because our suggestions use normal chaining. But it gets rid of all current edge cases.

* Add more tests

* More consistency in treating normal and optional expressions

* Add regression tests for every occurrence of Optional*
2020-07-07 17:38:44 +01:00
Joe Lencioni
0f84b0f02b
Fix ExhaustiveDeps ESLint rule throwing with optional chaining (#19260)
Certain code patterns using optional chaining syntax causes
eslint-plugin-react-hooks to throw an error.

We can avoid the throw by adding some guards. I didn't read through the
code to understand how it works, I just added a guard to every place
where it threw, so maybe there is a better fix closer to the root cause
than what I have here.

In my test case, I noticed that the optional chaining that was used in
the code was not included in the suggestions description or output,
but it seems like it should be. This might make a nice future
improvement on top of this fix, so I left a TODO comment to that effect.

Fixes #19243
2020-07-06 15:52:14 -04:00
Dan Abramov
1887c5d946 eslint-plugin-react-hooks@4.0.5 2020-06-30 12:16:49 +01:00
Fred Vollmer
b0533fe33c
fix(eslint-plugin-react-hooks): Support optional chaining when accessing prototype method inside useCallback and useMemo #19061 (#19062)
* fix(eslint-plugin-react-hooks): Support optional chaining when accessing prototype method #19061

* run prettier

* Add fix for #19043
2020-06-30 12:14:00 +01:00
YeonJuan
090c6ed751
[eslint-plugin-react-hooks]: handling sparse array when no-inline callback (#19145) 2020-06-17 12:29:02 -04:00
Ricky
30b47103d4
Fix spelling errors and typos (#19138) 2020-06-15 19:59:44 -04:00
Aaron Pettengill
9752d31f12
Document additionalHooks option (#19005)
* Document `additionalHooks` option

* Update README.md

Co-authored-by: Aaron Pettengill <aaron.pettengill@echoman.com>
Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-05-27 15:27:43 +01:00
Dan Abramov
b7ff888190 eslint-plugin-react-hooks@4.0.4 2020-05-27 14:38:27 +01:00
Julien Deniau
8abc202c7f
[eslint-plugin-react-hooks] Prefer recommended eslint configuration (#18951)
* [eslint-plugin-react-hooks] Prefer recommended eslint configuration

* Update README.md

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-05-27 01:08:41 +01:00
Yann アウネ Eves
4821d609e9
fix(eslint-plugin-react-hooks): Added matching for nullish coalescing and optional chaining of dependencies, relates to #18985 (#19008) 2020-05-27 01:07:10 +01:00
Dan Abramov
67e130fc68 eslint-plugin-react-hooks@4.0.3 2020-05-26 16:11:08 +01:00
Dan Abramov
bb2239dc90
Revert "Feature: Add support to exhaustive-deps rule for any hook ending with Effect (#18580)" (#19004)
This reverts commit 5ac9ca72df.
2020-05-26 16:08:50 +01:00
Dan Abramov
43063fd844 eslint-plugin-react-hooks@4.0.2 2020-05-13 16:46:26 +01:00
Dan Abramov
f6ff4c43dd
Update changelog 2020-05-13 16:45:50 +01:00
Boris Sergeev
487c693846
[eslint-plugin-react-hooks] useWithoutEffectSuffix fix (#18902) (#18907)
* [eslint-plugin-react-hooks] reproduce bug with a test and fix it (#18902)

Since we only reserve `-Effect` suffix, react-hooks/exhaustive-deps is
expected to succeed without warning on a custom hook which contains -Effect- in
the middle of it's name (but does NOT contain it as a suffix).

* [eslint-plugin-react-hooks] reproduced bug with a test and fix it

Since we only reserve `-Effect` suffix, react-hooks/exhaustive-deps is expected
to succeed without warning on a render helper which contains -use- in the middle
of it's name (but does NOT contain it as a prefix, since that would violate hook
naming convetion).

Co-authored-by: Boris Sergeyev <boris.sergeyev@quolab.com>
2020-05-13 16:44:05 +01:00
Dan Abramov
14e554b310
Add missing changelog item 2020-05-12 19:18:26 +01:00
Dan Abramov
9f396bdd5d eslint-plugin-react-hooks@4.0.1 2020-05-12 17:22:00 +01:00
Dan Abramov
e936034eec
Add item to ESLint Hooks plugin changelog 2020-05-12 17:02:37 +01:00
Michaël De Boey
c3ff21e01b
feat(eslint-plugin-react-hooks): Support ESLint 7.x (#18878) 2020-05-12 17:01:28 +01:00
Rohith Srivathsav
ddcc69c83b
Added clear message for functional component starting with lowercase (#18881) 2020-05-10 01:52:11 +01:00
Kevin Lewis
7992ca10df
eslint-plugin-react-hooks: allow OptionalMemberExpression in deps (#18819) (#18820)
* eslint-plugin-react-hooks: allow OptionalMemberExpression in deps (#18819)

* add test case for #18819

* fix test

* run prettier
2020-05-05 13:53:42 +01:00
Benedikt Franke
333deb707d
Remove hint to post feedback about exhaustive-deps rule (#18712)
The thread is closed and locked.
2020-05-01 19:13:59 +01:00
Dan Abramov
d804f99b9e eslint-plugin-react-hooks@4.0.0 2020-05-01 17:13:56 +01:00
Dan Abramov
4e93b9364c
Add changelog for eslint-plugin-react-hooks (#18801) 2020-05-01 17:12:32 +01:00
Aaron Pettengill
5ac9ca72df
Feature: Add support to exhaustive-deps rule for any hook ending with Effect (#18580)
* Add test cases for support exhaustive deps ending in Effect

* Apply the exhaustive deps lint rule to any hook ending with Effect

* Add another test for supporting linting useXEffect hooks

Co-authored-by: Aaron Pettengill <aaron.pettengill@echoman.com>
2020-05-01 16:57:25 +01:00
Chang Yan
4b02b66111
[ESLint] Extend isHook to recognize those under PascalCase's namespace (#18722)
* Extend Namespace to PascalCase

* Add valid case for jest.useFakeTimer

* format

* format :(

* fix nits
2020-04-24 02:50:52 +01:00
Sophie Alpert
fe2cb52554
[eslint] Consider useRef() as ... as constant (#18496)
Sometimes you need to use casts, eg: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/28884#issuecomment-471341041. This change ignores them and allows you to still omit the ref object from the deps list.

Test Plan: unit tests
2020-04-05 14:13:34 -07:00
Zen
2ff27ec112
[eslint] strip tailing property in assignments (#16784)
* [eslint] strip tailing property in assignments

* inline `stripTailingPropInAssignment`
2020-04-04 14:26:39 +01:00
Gabriel McAdams
3f46844899
[eslint-plugin-react-hooks] Added meta property (including docs) (#16607)
* [eslint-plugin-react-hooks] Added meta property (including docs)

* [eslint-plugin-react-hooks] Fixed typo (`RuleOfHooks` -> `RulesOfHooks`)

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-04-01 21:13:10 +01:00
Dan Abramov
2bf60d9f9c
Fix ESLint rule crash (#18455) 2020-04-01 20:54:42 +01:00
Sebastian Markbåge
3e94bce765
Enable prefer-const lint rules (#18451)
* Enable prefer-const rule

Stylistically I don't like this but Closure Compiler takes advantage of
this information.

* Auto-fix lints

* Manually fix the remaining callsites
2020-04-01 12:35:52 -07:00
Dan Abramov
1960131f11
Add opt-in support for dangerous autofix (#18437) 2020-03-31 11:43:01 +01:00
Dan Abramov
da54641a10
[ESLint] Check deps when callback body is outside the Hook call, too (#18435)
* Refactor: visit CallExpression

Instead of visiting the functions and looking up to see if they're in a Hook call, visit Hook calls and look down to see if there's a callback inside. I will need this refactor so I can visit functions declared outside the call.

* Check deps when callback body is outside the Hook call

* Handle the unknown case
2020-03-31 02:09:32 +01:00
Dan Abramov
5bd1bc29b3 eslint-plugin-react-hooks@3.0.0 2020-03-26 17:59:25 +00:00
Andrew Clark
ad445b127e Update package.jsons for 16.13.1 patch relase 2020-03-19 12:58:31 -07:00
Ian Obermiller
d3368beeec
[eslint-plugin-react-hooks] Disallow hooks in class components (#18341)
Per discussion at Facebook, we think hooks have reached a tipping point where it is more valuable to lint against potential hooks in classes than to worry about false positives.

Test plan:
```
# run from repo root
yarn test --watch RuleOfHooks
```
2020-03-18 19:55:13 +00:00
Simen Bekkhus
79a25125b1
feat: add recommended config eslint rule (#14762)
* feat: add recommended config eslint rule

* add exhaustive-deps to recommended as well
2020-02-28 02:01:17 +00:00
Sebastian Markbåge
549e418830
Move remaining things to named exports (#18165)
* Move remaining things to named exports

The interesting case here is the noop renderers. The wrappers around the
reconciler now changed to use a local export that gets mutated.

ReactNoop and ReactNoopPersistent now have to destructure the object to
list out the names it's going to export. We should probably refactor
ReactNoop away from createReactNoop. Especially since it's also not Flow
typed.

* Switch interactions to star exports

This will have esModule compatibility flag on them. They should ideally
export default instead.
2020-02-27 17:18:55 -08:00
Sunil Pai
c1c5499cc3
update version numbers for 16.13 (#18143)
also includes a bugfix when downloading error codes from circleci.
2020-02-26 20:33:29 +00:00
Moji Izadmehr
bf13d3e3c6
[eslint-plugin-react-hooks] Fix cyclic caching for loops containing a… (#16853)
* [eslint-plugin-react-hooks] Fix cyclic caching for loops containing a condition

* [eslint-plugin-react-hooks] prettier write

* [eslint-plugin-react-hooks] Fix set for tests

* Update packages/eslint-plugin-react-hooks/src/RulesOfHooks.js

Co-Authored-By: Luke Kang <kidkkr@icloud.com>

Co-authored-by: Luke Kang <kidkkr@icloud.com>
2020-02-25 11:38:23 +00:00
Dan Abramov
d533229fba Fix Prettier 2020-02-17 20:36:16 +00:00
Dan Abramov
56a8c35321 eslint-plugin-react-hooks@2.4.0 2020-02-17 20:26:56 +00:00
Will Douglas
93a229bab5
Update eslint rule exhaustive deps to use new suggestions feature (#17385)
This closes #16313
2020-02-17 20:24:27 +00:00
Tao
3ac81a57fb Update create-react-app note for eslint-plugin-react-hooks (#16982)
eslint-plugin-react-hooks was added in react-scripts 3.0.0
2020-01-09 13:47:05 -08:00
Dan Abramov
b979db4e72
Bump Prettier (#17811)
* Bump Prettier

* Reformat

* Use non-deprecated option
2020-01-09 13:54:11 +00:00
Dan Abramov
897976600c
[ESLint] Allow partial matches for custom Effect Hooks (#17663) 2019-12-19 17:04:17 +00:00
David Garner
a807c307c4 [eslint] Check forwardRef callbacks (#17255)
* [eslint] Check forwardRef callbacks (#17220)

* [eslint] Make tests more realistic (#17220)

* [eslint] Check anonymous callback of React.memo for rules-of-hooks (#17220)

* [eslint] Add tests for callbacks not known to be components (#17220)

* [eslint] Correct comments and add another test (#17220)
2019-11-17 13:39:08 +00:00
Luna Ruan
9a5f28dbed update version numbers for 16.12 2019-11-14 16:02:18 -08:00
Andrew Clark
8075c8505b Update local package versions for 16.10 release 2019-10-22 14:30:06 -07:00
Andrew Clark
d256f88ac6 Update local version numbers for 16.10.2 release 2019-10-03 14:14:10 -07:00
Rane Wallin
5943b1da6c Fixing grammatical errors in error message (#16973)
* Fixing grammatical errors in error message

* Fixing grammar error in test file
2019-10-03 18:14:48 +05:30
Andrew Clark
2a264a9dbe Update local version numbers for 16.10.1 release 2019-09-28 21:41:42 -07:00
Andrew Clark
93f5f11b79 Update local version numbers for 16.10 release 2019-09-27 13:31:35 -07:00
Dan Abramov
8a01b50fc3 eslint-plugin-react-hooks@2.0.1 2019-08-21 21:40:20 +01:00
Dan Abramov
0672829053
Bump ESLint plugin to 2.0 (#16528) 2019-08-21 19:14:34 +01:00
Dan Abramov
c433fbb593
Revert "Revert "[ESLint] Forbid top-level use*() calls (#16455)"" (#16525)
* Revert "Revert "[ESLint] Forbid top-level use*() calls (#16455)" (#16522)"

This reverts commit 507f0fb372.

* Update RulesOfHooks.js
2019-08-21 15:43:31 +01:00
Sunil Pai
507f0fb372
Revert "[ESLint] Forbid top-level use*() calls (#16455)" (#16522)
This reverts commit 96eb703bbf.
2019-08-21 10:20:34 +01:00
Dan Abramov
96eb703bbf
[ESLint] Forbid top-level use*() calls (#16455)
* Add a way to skip/only tests to RulesOfHooks test

* [ESLint] Forbid top-level use*() calls

* Add a regression test for logical expressions

This is not a change. Just adding more coverage.
2019-08-19 19:54:06 +01:00
Hristo Kanchev
9e64bf18e1 [eslint-plugin-react-hooks] Fixed crash when referencing arguments in arrow functions. (#16356)
* Fixed issue with def being undefined while referencing arguments.

* Removed todo comment.

* Skip exhaustive deps check if def is null.

* Fixed code formatting in ExhaustiveDeps.

* Removed unneeded comment in ExhaustiveDeps.
2019-08-14 14:44:06 +01:00
Simen Bekkhus
e308a037be chore: make tests compatible with Jest 24 (#15779)
* chore: make tests compatible with Jest 24

* remove fake rafs

* rollback jsdom for localstorage compat

* Apply suggestions from code review

Co-Authored-By: Sunil Pai <threepointone@oculus.com>

* chore: cleanup lockfile
2019-08-14 12:32:26 +01:00
Andrew Clark
85d05b3a4d Bump package.json versions 2019-08-08 14:24:39 -07:00
Min ho Kim
2a0f6390ed Fix typos (#16076) 2019-07-08 11:51:29 +01:00
Dan Abramov
d48db594ec eslint-plugin-react-hooks@1.6.1 2019-06-24 22:31:14 +01:00
Thomas Broyer
7439b48cf4 Add explicit support for ESLint 6.0.0 (#15974)
Preemptively update tests wrt 'parser' requiring an absolute
path rather than a package name, even though the project is
still using ESLint 4.

Fixes #15971
2019-06-24 22:30:12 +01:00
Jordan Rome
a383c46788 [ESLint] don't warn for Flow type variables (#15804)
In Exhaustive Deps check for react-hooks don't warn if the dependency is
a Flow type variable.
2019-06-03 02:20:51 +01:00
Redmond Tran
793ef9b855 test(eslint-plugin-react-hooks): add coverage for unused custom hook (#15130) 2019-04-25 12:15:29 +01:00
Dan Abramov
f33e5790b8 eslint-plugin-react-hooks@1.6.0 2019-03-22 13:56:07 +00:00
Dan Abramov
b1cccd1ed1
Warn about setState directly in dep-less useEffect (#15184) 2019-03-22 13:41:10 +00:00
Dan Abramov
78968bb3d9
Validate useEffect without deps too (#15183) 2019-03-21 20:42:13 +00:00
Dan Abramov
f0621fe232
Use same example code for async effect warning (#15118) 2019-03-15 19:27:55 +00:00
Dan Abramov
f1ff4348c1
Don't suggest a function as its own dep (#15115) 2019-03-15 15:14:01 +00:00
Dan Abramov
935f60083f eslint-plugin-react-hooks@1.5.1 2019-03-14 20:11:22 +00:00
Sophie Alpert
1204c78977 [eslint] Wording tweaks (#15078)
* [eslint] Wording tweaks

I think these are a little clearer.

* fix tests
2019-03-13 18:31:39 +00:00
Dan Abramov
d0289c7e3a eslint-plugin-react-hooks@1.5.0 2019-03-07 19:43:07 +00:00
Dan Abramov
03ad9c73e4
[ESLint] Tweak setState updater message and add useEffect(async) warning (#15055)
* Use first letter in setCount(c => ...) suggestion

In-person testing showed using original variable name confuses people.

* Warn about async effects
2019-03-07 19:40:23 +00:00
Dan Abramov
eb6247a9ab
More concise messages (#15053) 2019-03-07 15:21:44 +00:00
Dan Abramov
197703ecc7
[ESLint] Add more hints to lint messages (#15046)
* A clearer message for props destructuring where applicable

* Add line number to the "move function" message

* Add a hint for how to fix callbacks from props

* Simplify code and harden tests

* Collect all dependency references for better warnings

* Suggest updater or reducer where appropriate
2019-03-07 12:39:15 +00:00
Dan Abramov
6d2666bab1
Fix ESLint rule crash (#15044) 2019-03-07 00:39:39 +00:00
Dan Abramov
9b7e1d1389
[ESLint] Suggest moving inside a Hook or useCallback when bare function is a dependency (#15026)
* Warn about bare function deps and suggest moving or useCallback

* Clearer wording
2019-03-06 23:50:02 +00:00
Dan Abramov
5d49dafac8
Enforce deps array in useMemo and useCallback (#15025) 2019-03-06 18:17:54 +00:00
Dan Abramov
fa5d4ee43b
[ESLint] Treat functions that don't capture anything as static (#14996)
* Treat functions that don't capture anything as static

* Fix comment
2019-03-05 21:07:37 +00:00
Dan Abramov
f16442a106 eslint-plugin-react-hooks@1.4.0 2019-03-01 20:29:06 +00:00
Dan Abramov
e1e45fb367
[ESLint] Suggest to destructure props when they are only used as members (#14993)
* Suggest to destructure props when they are only used as members

* Add more tests

* Fix a bug
2019-03-01 19:48:48 +00:00
Dan Abramov
59ef28437a
Warn about dependencies outside of render scope (#14990) 2019-03-01 18:16:17 +00:00
Dan Abramov
df7b4768c7
[ESLint] Deduplicate suggested dependencies (#14982)
* Deduplicate suggested dependencies

* Tweak test cases
2019-03-01 16:10:22 +00:00
Dan Abramov
3ada82b741
Allow extraneous effect dependencies (#14967)
This makes cases like

  useEffect(() => {
    window.scrollTo(0, 0);
  }, [activeTab]);

not warn.

However, it still warns for unused useCallback/useMemo deps.
2019-02-27 16:59:11 +00:00
Dan Abramov
0b8efb229c
Allow omitting constant primitive deps (#14959) 2019-02-26 16:12:15 +00:00
Dan Abramov
3989c09500 eslint-plugin-react-hooks@1.3.0 2019-02-25 17:27:37 +00:00
Dan Abramov
1bbfbc98d2
[ESLint] Add more cases to exhaustive-deps rule (#14930)
* Add better message for literal dependencies

* Warn about ref.current in cleanup phase

* Fix wrong comment

* Tweak wording
2019-02-25 16:00:29 +00:00
Farhad Yasir
412f882968 fix(eslint-plugin-react-hooks): node engine updated to version 7 because of object.entries (#14951) 2019-02-25 15:37:06 +00:00
Matt Thomson
f99fca3cb2 Fix sample ESLint configuration (#14926)
See [ESLint docs](https://eslint.org/docs/user-guide/configuring#configuring-rules)
2019-02-22 12:22:07 +00:00
Dan Abramov
22bb947642 Release eslint-plugin-react-hooks@1.2.0 2019-02-21 19:41:35 +00:00
Dan Abramov
a77bbf1a1c
[ESLint] Warn against assignments from inside Hooks (#14916)
* [ESLint] Warn against assignments from inside Hooks

* Include variable name

* Add a test for the legit case
2019-02-21 19:23:00 +00:00
Dan Abramov
8c1966590a Release 16.8.3 2019-02-21 18:09:18 +00:00
Dan Abramov
dab2fdbbbd
Add eslint-plugin-react-hooks/exhaustive-deps rule to check stale closure dependencies (#14636)
* Add ESLint rule for useEffect/useCallback/useMemo Hook dependencies

* Fix ReactiveDependencies rule

* fix lint errors

* Support useLayoutEffect

* Add some failing tests and comments

* Gather dependencies in child scopes too

* If we don't find foo.bar.baz in deps, try foo.bar, then foo

* foo is enough for both foo.bar and foo.baz

* Shorter rule name

* Add fixable meta

* Remove a bunch of code and start from scratch

* [WIP] Only report errors from dependency array

This results in nicer editing experience. Also has autofix.

* Fix typo

* [Temp] Skip all tests

* Fix the first test

* Revamp the test suite

* Fix [foo] to include foo.bar

* Don't suggest call expressions

* Special case 'current' for refs

* Don't complain about known static deps

* Support useImperativeHandle

* Better punctuation and formatting

* More uniform message format

* Treat React.useRef/useState/useReducer as static too

* Add special message for ref.current

* Add a TODO case

* Alphabetize the autofix

* Only alphabetize if it already was

* Don't add static deps by default

* Add an undefined variable case

* Tweak wording

* Rename to exhaustive-deps

* Clean up / refactor a little bit
2019-02-20 18:18:58 +00:00
Dan Abramov
3e55560438 Release 16.8.2 2019-02-14 19:13:15 +00:00
zhuoli99
c11015ff4f fix spelling mistakes (#14805) 2019-02-09 16:43:49 -08:00
Brian Vaughn
45fc46bfa0 16.8.1 packages 2019-02-06 18:21:33 +00:00
Brian Vaughn
0975ea3278 eslint-plugin-react-hooks v1.0.0 2019-02-06 10:14:57 +00:00
Dan Abramov
ce6ecd3fbf Add 16.8.0 changelog and update some READMEs (#14692)
* Add 16.8.0 changelog

* Mention ESLint plugin

* Remove experimental notices from the ESLint plugin README

* Update CHANGELOG.md

* Add more details for Hooks

* fix

* Set a date

* Update CHANGELOG.md

Co-Authored-By: gaearon <dan.abramov@gmail.com>

* Update CHANGELOG.md

* useReducer in changelog

* Add to changelog

* Update date

* Add #14119 to changelog

* Add #14744 to changelog

* Fix PR links

* act() method was added to test utils, too

* Updated release date to February 6th
2019-02-06 08:05:18 +00:00
SToneX
e489c3f9c1 Update the version with Hooks proposal in README (#14751) 2019-02-04 09:36:56 +00:00
Yurick
e19c9e1064 Fix issue with multiple code branches in hooks linter (#14661)
* Fix issue with multiple code branches

* Add solution by @calebmer

* Add performance test

* Undo unrelated change
2019-01-25 17:06:33 +00:00
Grey Baker
b66e6e41e6 Add directory details to the package.json of all packages (#14628)
Specifying the directory as part of the `repository` field in a `package.json`
allows third party tools to provide better support when working with monorepos.
For example, it allows them to correctly construct a commit diff for a specific
package.

This format was accepted by npm in https://github.com/npm/rfcs/pull/19.
2019-01-18 20:21:12 +00:00
Sebastian Silbermann
d17d0b99c1 Use public context.report interface in eslint rules (#14623) 2019-01-18 09:26:11 +00:00
Brian Vaughn
686f1060ad
Publish a local release (canary or stable) to NPM (#14260)
New release scripts.

Learn more at https://github.com/facebook/react/blob/master/scripts/release/README.md
2018-11-23 12:37:18 -08:00
Andrew Clark
e3a7b96455 Make react-debug-tools a private package 2018-11-06 18:45:30 -08:00
locknono
2aecbcd6f1 "functional component" -> "function component" (#14123) 2018-11-06 17:33:26 -08:00
Sophie Alpert
3db8b80e15
Don't lint against Hooks after conditional throw (#14040)
Seems like this should be OK. Fixes #14038.

Now when tracking paths, we completely ignore segments that end in a throw.
2018-10-30 17:13:24 -07:00