Skip to content

Commit

Permalink
fix(analyzer): useExhaustiveDependencies error when useState is on a …
Browse files Browse the repository at this point in the history
…new line #168 (#232)
  • Loading branch information
denbezrukov authored Sep 10, 2023
1 parent cb57b76 commit 5a88220
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
#### Bug fixes

- Fix [#182](https://github.com/biomejs/biome/issues/182), making [useLiteralKeys](https://biomejs.dev/linter/rules/use-literal-keys/) retains optional chaining.
- Fix [#168](https://github.com/biomejs/biome/issues/168), fix [useExhaustiveDependencies](https://biomejs.dev/linter/rules/use-exhaustive-dependencies) false positive case when stable hook is on a new line.

### Parser
### VSCode
Expand Down
3 changes: 2 additions & 1 deletion crates/rome_js_analyze/src/react/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use biome_rowan::AstNode;
use serde::{Deserialize, Serialize};

/// Return result of [react_hook_with_dependency].
#[derive(Debug)]
pub(crate) struct ReactCallWithDependencyResult {
pub(crate) function_name_range: TextRange,
pub(crate) closure_node: Option<AnyJsExpression>,
Expand Down Expand Up @@ -243,7 +244,7 @@ pub fn is_binding_react_stable(
.ok()?
.value_token()
.ok()?
.token_text();
.token_text_trimmed();

let stable = StableReactHookConfiguration {
hook_name: hook_name.to_string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useState, useEffect } from 'react';

export const OtherComponent = () => {
const [stringContent, setString] =
useState('Something');

useEffect(() => {
setString((content) => {
return `${content} other`;
});
}, []);

return stringContent;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
expression: newline.js
---
# Input
```js
import { useState, useEffect } from 'react';

export const OtherComponent = () => {
const [stringContent, setString] =
useState('Something');

useEffect(() => {
setString((content) => {
return `${content} other`;
});
}, []);

return stringContent;
};

```


1 change: 1 addition & 0 deletions website/src/content/docs/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
#### Bug fixes

- Fix [#182](https://github.com/biomejs/biome/issues/182), making [useLiteralKeys](https://biomejs.dev/linter/rules/use-literal-keys/) retains optional chaining.
- Fix [#168](https://github.com/biomejs/biome/issues/168), fix [useExhaustiveDependencies](https://biomejs.dev/linter/rules/use-exhaustive-dependencies) false positive case when stable hook is on a new line.

### Parser
### VSCode
Expand Down

0 comments on commit 5a88220

Please sign in to comment.