-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(useExhaustiveDependencies): add option to useExhaustiveDependenc…
…ies to enable errors when the dependencies array is missing (#4149)
- Loading branch information
1 parent
2670095
commit 3baa9fc
Showing
8 changed files
with
109 additions
and
1 deletion.
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
12 changes: 12 additions & 0 deletions
12
...alyze/tests/specs/correctness/useExhaustiveDependencies/reportMissingDependenciesArray.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,12 @@ | ||
import {useEffect} from "react"; | ||
|
||
// should not report errors for the unused `b` when the reportMissingDependenciesArray option is false | ||
function ReportMissingDependenciesArray() { | ||
const [a] = useState(1); | ||
|
||
useEffect(() => { | ||
console.log(a); | ||
}); | ||
|
||
return a; | ||
} |
36 changes: 36 additions & 0 deletions
36
.../tests/specs/correctness/useExhaustiveDependencies/reportMissingDependenciesArray.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,36 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: reportMissingDependenciesArray.js | ||
--- | ||
# Input | ||
```jsx | ||
import {useEffect} from "react"; | ||
|
||
// should not report errors for the unused `b` when the reportMissingDependenciesArray option is false | ||
function ReportMissingDependenciesArray() { | ||
const [a] = useState(1); | ||
|
||
useEffect(() => { | ||
console.log(a); | ||
}); | ||
|
||
return a; | ||
} | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
reportMissingDependenciesArray.js:7:5 lint/correctness/useExhaustiveDependencies ━━━━━━━━━━━━━━━━━━━ | ||
! This hook does not have a dependencies array | ||
5 │ const [a] = useState(1); | ||
6 │ | ||
> 7 │ useEffect(() => { | ||
│ ^^^^^^^^^ | ||
8 │ console.log(a); | ||
9 │ }); | ||
``` |
15 changes: 15 additions & 0 deletions
15
...s/specs/correctness/useExhaustiveDependencies/reportMissingDependenciesArray.options.json
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,15 @@ | ||
{ | ||
"$schema": "../../../../../../packages/@biomejs/biome/configuration_schema.json", | ||
"linter": { | ||
"rules": { | ||
"correctness": { | ||
"useExhaustiveDependencies": { | ||
"level": "error", | ||
"options": { | ||
"reportMissingDependenciesArray": true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.