-
-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lint/useExhaustiveDependencies): support Preact (#2105)
- Loading branch information
Showing
13 changed files
with
110 additions
and
49 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
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
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
10 changes: 10 additions & 0 deletions
10
crates/biome_js_analyze/tests/specs/correctness/useExhaustiveDependencies/preactHooks.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,10 @@ | ||
import { useCallback } from 'preact/compat'; | ||
import { useState } from 'preact/hooks'; | ||
|
||
function useCounter() { | ||
const [value, setValue] = useState(0); | ||
const increment = useCallback(() => { | ||
setValue(value + 1); | ||
}, []); | ||
return { value, increment }; | ||
} |
45 changes: 45 additions & 0 deletions
45
...es/biome_js_analyze/tests/specs/correctness/useExhaustiveDependencies/preactHooks.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,45 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: preactHooks.js | ||
--- | ||
# Input | ||
```jsx | ||
import { useCallback } from 'preact/compat'; | ||
import { useState } from 'preact/hooks'; | ||
|
||
function useCounter() { | ||
const [value, setValue] = useState(0); | ||
const increment = useCallback(() => { | ||
setValue(value + 1); | ||
}, []); | ||
return { value, increment }; | ||
} | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
preactHooks.js:6:23 lint/correctness/useExhaustiveDependencies ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! This hook does not specify all of its dependencies: value | ||
4 │ function useCounter() { | ||
5 │ const [value, setValue] = useState(0); | ||
> 6 │ const increment = useCallback(() => { | ||
│ ^^^^^^^^^^^ | ||
7 │ setValue(value + 1); | ||
8 │ }, []); | ||
i This dependency is not specified in the hook dependency list. | ||
5 │ const [value, setValue] = useState(0); | ||
6 │ const increment = useCallback(() => { | ||
> 7 │ setValue(value + 1); | ||
│ ^^^^^ | ||
8 │ }, []); | ||
9 │ return { value, increment }; | ||
i Either include it or remove the dependency array | ||
``` |
Oops, something went wrong.