This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check wheather hooks api is imported from React or not
- Loading branch information
Showing
15 changed files
with
496 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...e_js_analyze/tests/specs/nursery/useExhaustiveDependencies/checkHooksImportedFromReact.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function MyComponent1() { | ||
let a = 1; | ||
React.useEffect(() => { | ||
console.log(a); | ||
}); | ||
|
||
// the rule doesn't show the warnings because the hooks are not imported from react. | ||
useEffect(() => { | ||
console.log(a); | ||
}); | ||
} | ||
|
||
function MyComponent2() { | ||
let a = 1; | ||
const React = { useEffect() {} } | ||
// the rule doesn't show the warnings because `React` is defined by the user. | ||
React.useEffect(() => { | ||
console.log(a); | ||
}); | ||
} |
55 changes: 55 additions & 0 deletions
55
...analyze/tests/specs/nursery/useExhaustiveDependencies/checkHooksImportedFromReact.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
source: crates/rome_js_analyze/tests/spec_tests.rs | ||
expression: checkHooksImportedFromReact.js | ||
--- | ||
# Input | ||
```js | ||
function MyComponent1() { | ||
let a = 1; | ||
React.useEffect(() => { | ||
console.log(a); | ||
}); | ||
|
||
// the rule doesn't show the warnings because the hooks are not imported from react. | ||
useEffect(() => { | ||
console.log(a); | ||
}); | ||
} | ||
|
||
function MyComponent2() { | ||
let a = 1; | ||
const React = { useEffect() {} } | ||
// the rule doesn't show the warnings because `React` is defined by the user. | ||
React.useEffect(() => { | ||
console.log(a); | ||
}); | ||
} | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
checkHooksImportedFromReact.js:3:9 lint/nursery/useExhaustiveDependencies ━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! This hook do not specify all of its dependencies. | ||
1 │ function MyComponent1() { | ||
2 │ let a = 1; | ||
> 3 │ React.useEffect(() => { | ||
│ ^^^^^^^^^ | ||
4 │ console.log(a); | ||
5 │ }); | ||
i This dependency is not specified in the hook dependency list. | ||
2 │ let a = 1; | ||
3 │ React.useEffect(() => { | ||
> 4 │ console.log(a); | ||
│ ^ | ||
5 │ }); | ||
6 │ | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.