-
-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lint): implement duplicate dependency error (#2991)
- Loading branch information
1 parent
13811df
commit 9e4feb6
Showing
4 changed files
with
100 additions
and
0 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
14 changes: 14 additions & 0 deletions
14
...ome_js_analyze/tests/specs/correctness/useExhaustiveDependencies/duplicateDependencies.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,14 @@ | ||
import { useCallback } from "react"; | ||
|
||
function Component1({ a }) { | ||
const handle = useCallback(() => { | ||
console.log(a); | ||
}, [a, a]); | ||
} | ||
|
||
function Component2() { | ||
const [local,SetLocal] = useState(0); | ||
const handle = useCallback(() => { | ||
console.log(local); | ||
}, [local, local]); | ||
} |
68 changes: 68 additions & 0 deletions
68
...s_analyze/tests/specs/correctness/useExhaustiveDependencies/duplicateDependencies.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,68 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: duplicateDependencies.js | ||
--- | ||
# Input | ||
```jsx | ||
import { useCallback } from "react"; | ||
|
||
function Component1({ a }) { | ||
const handle = useCallback(() => { | ||
console.log(a); | ||
}, [a, a]); | ||
} | ||
|
||
function Component2() { | ||
const [local,SetLocal] = useState(0); | ||
const handle = useCallback(() => { | ||
console.log(local); | ||
}, [local, local]); | ||
} | ||
``` | ||
|
||
# Diagnostics | ||
``` | ||
duplicateDependencies.js:4:20 lint/correctness/useExhaustiveDependencies ━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! This hook specifies more dependencies than necessary: a | ||
3 │ function Component1({ a }) { | ||
> 4 │ const handle = useCallback(() => { | ||
│ ^^^^^^^^^^^ | ||
5 │ console.log(a); | ||
6 │ }, [a, a]); | ||
i Outer scope values aren't valid dependencies because mutating them doesn't re-render the component. | ||
4 │ const handle = useCallback(() => { | ||
5 │ console.log(a); | ||
> 6 │ }, [a, a]); | ||
│ ^ | ||
7 │ } | ||
8 │ | ||
``` | ||
|
||
``` | ||
duplicateDependencies.js:11:20 lint/correctness/useExhaustiveDependencies ━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! This hook specifies more dependencies than necessary: local | ||
9 │ function Component2() { | ||
10 │ const [local,SetLocal] = useState(0); | ||
> 11 │ const handle = useCallback(() => { | ||
│ ^^^^^^^^^^^ | ||
12 │ console.log(local); | ||
13 │ }, [local, local]); | ||
i This dependency can be removed from the list. | ||
11 │ const handle = useCallback(() => { | ||
12 │ console.log(local); | ||
> 13 │ }, [local, local]); | ||
│ ^^^^^ | ||
14 │ } | ||
``` |