Skip to content

Commit ece91c5

Browse files
committed
fix(linter/react-hooks): fix diagnostic message for duplicate dependency in array (#14265)
1 parent 013e053 commit ece91c5

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

crates/oxc_linter/src/rules/react/exhaustive_deps.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ fn dependency_array_not_array_literal_diagnostic(hook_name: &str, span: Span) ->
119119
.with_error_code_scope(SCOPE)
120120
}
121121

122-
fn literal_in_dependency_array_diagnostic(span: Span) -> OxcDiagnostic {
123-
OxcDiagnostic::warn("The literal is not a valid dependency because it never changes.")
122+
fn duplicate_dependency_diagnostic(span: Span) -> OxcDiagnostic {
123+
OxcDiagnostic::warn("This dependency is specified more than once in the dependency array.")
124124
.with_label(span)
125-
.with_help("Remove the literal from the array.")
125+
.with_help("Remove the duplicate dependency from the array.")
126126
.with_error_code_scope(SCOPE)
127127
}
128128

@@ -545,7 +545,7 @@ impl Rule for ExhaustiveDeps {
545545
for item in declared_dependencies_iter {
546546
let span = item.span;
547547
if !declared_dependencies.insert(item) {
548-
ctx.diagnostic(literal_in_dependency_array_diagnostic(span));
548+
ctx.diagnostic(duplicate_dependency_diagnostic(span));
549549
}
550550
}
551551

crates/oxc_linter/src/snapshots/react_exhaustive_deps.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,14 @@ source: crates/oxc_linter/src/tester.rs
328328
╰────
329329
help: Either include it or remove the dependency array.
330330

331-
eslint-plugin-react-hooks(exhaustive-deps): The literal is not a valid dependency because it never changes.
331+
eslint-plugin-react-hooks(exhaustive-deps): This dependency is specified more than once in the dependency array.
332332
╭─[exhaustive_deps.tsx:6:22]
333333
5console.log(local);
334334
6 │ }, [local, local]);
335335
· ─────
336336
7 │ }
337337
╰────
338-
help: Remove the literal from the array.
338+
help: Remove the duplicate dependency from the array.
339339

340340
eslint-plugin-react-hooks(exhaustive-deps): React hook useEffect depends on `local`, which changes every render
341341
╭─[exhaustive_deps.tsx:2:17]
@@ -877,14 +877,14 @@ source: crates/oxc_linter/src/tester.rs
877877
╰────
878878
help: Either include it or remove the dependency array.
879879

880-
eslint-plugin-react-hooks(exhaustive-deps): The literal is not a valid dependency because it never changes.
880+
eslint-plugin-react-hooks(exhaustive-deps): This dependency is specified more than once in the dependency array.
881881
╭─[exhaustive_deps.tsx:5:22]
882882
4console.log(local);
883883
5 │ }, [local, local]);
884884
· ─────
885885
6 │ }
886886
╰────
887-
help: Remove the literal from the array.
887+
help: Remove the duplicate dependency from the array.
888888

889889
eslint-plugin-react-hooks(exhaustive-deps): React hook useEffect depends on `local`, which changes every render
890890
╭─[exhaustive_deps.tsx:5:15]

0 commit comments

Comments
 (0)