|
| 1 | +--- |
| 2 | +source: crates/biome_cli/tests/snap_test.rs |
| 3 | +expression: redactor(content) |
| 4 | +--- |
| 5 | +## `biome.json` |
| 6 | + |
| 7 | +```json |
| 8 | +{ |
| 9 | + "linter": { |
| 10 | + "domains": { |
| 11 | + "test": "recommended" |
| 12 | + } |
| 13 | + } |
| 14 | +} |
| 15 | +``` |
| 16 | + |
| 17 | +## `package.json` |
| 18 | + |
| 19 | +```json |
| 20 | +{ |
| 21 | + "dependencies": { |
| 22 | + "react": "^18.0.0" |
| 23 | + } |
| 24 | +} |
| 25 | +
|
| 26 | +``` |
| 27 | + |
| 28 | +## `test.jsx` |
| 29 | + |
| 30 | +```jsx |
| 31 | +
|
| 32 | +import { useEffect, useState } from "react"; |
| 33 | +
|
| 34 | +function Component2() { |
| 35 | + const [local, setLocal] = useState(0); |
| 36 | + useEffect(() => { |
| 37 | + console.log(local); |
| 38 | + }, []); |
| 39 | +} |
| 40 | + |
| 41 | +``` |
| 42 | + |
| 43 | +# Termination Message |
| 44 | + |
| 45 | +```block |
| 46 | +lint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 47 | +
|
| 48 | + × Some errors were emitted while running checks. |
| 49 | + |
| 50 | +
|
| 51 | +
|
| 52 | +``` |
| 53 | + |
| 54 | +# Emitted Messages |
| 55 | + |
| 56 | +```block |
| 57 | +test.jsx:4:10 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 58 | +
|
| 59 | + ! This function Component2 is unused. |
| 60 | + |
| 61 | + 2 │ import { useEffect, useState } from "react"; |
| 62 | + 3 │ |
| 63 | + > 4 │ function Component2() { |
| 64 | + │ ^^^^^^^^^^ |
| 65 | + 5 │ const [local, setLocal] = useState(0); |
| 66 | + 6 │ useEffect(() => { |
| 67 | + |
| 68 | + i Unused variables are often the result of typos, incomplete refactors, or other sources of bugs. |
| 69 | + |
| 70 | + i Unsafe fix: If this is intentional, prepend Component2 with an underscore. |
| 71 | + |
| 72 | + 2 2 │ import { useEffect, useState } from "react"; |
| 73 | + 3 3 │ |
| 74 | + 4 │ - function·Component2()·{ |
| 75 | + 4 │ + function·_Component2()·{ |
| 76 | + 5 5 │ const [local, setLocal] = useState(0); |
| 77 | + 6 6 │ useEffect(() => { |
| 78 | + |
| 79 | +
|
| 80 | +``` |
| 81 | +
|
| 82 | +```block |
| 83 | +test.jsx:5:19 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 84 | +
|
| 85 | + ! This variable setLocal is unused. |
| 86 | + |
| 87 | + 4 │ function Component2() { |
| 88 | + > 5 │ const [local, setLocal] = useState(0); |
| 89 | + │ ^^^^^^^^ |
| 90 | + 6 │ useEffect(() => { |
| 91 | + 7 │ console.log(local); |
| 92 | + |
| 93 | + i Unused variables are often the result of typos, incomplete refactors, or other sources of bugs. |
| 94 | + |
| 95 | + i Unsafe fix: If this is intentional, prepend setLocal with an underscore. |
| 96 | + |
| 97 | + 3 3 │ |
| 98 | + 4 4 │ function Component2() { |
| 99 | + 5 │ - ····const·[local,·setLocal]·=·useState(0); |
| 100 | + 5 │ + ····const·[local,·_setLocal]·=·useState(0); |
| 101 | + 6 6 │ useEffect(() => { |
| 102 | + 7 7 │ console.log(local); |
| 103 | + |
| 104 | +
|
| 105 | +``` |
| 106 | +
|
| 107 | +```block |
| 108 | +test.jsx:6:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 109 | +
|
| 110 | + × This hook does not specify its dependency on local. |
| 111 | + |
| 112 | + 4 │ function Component2() { |
| 113 | + 5 │ const [local, setLocal] = useState(0); |
| 114 | + > 6 │ useEffect(() => { |
| 115 | + │ ^^^^^^^^^ |
| 116 | + 7 │ console.log(local); |
| 117 | + 8 │ }, []); |
| 118 | + |
| 119 | + i This dependency is being used here, but is not specified in the hook dependency list. |
| 120 | + |
| 121 | + 5 │ const [local, setLocal] = useState(0); |
| 122 | + 6 │ useEffect(() => { |
| 123 | + > 7 │ console.log(local); |
| 124 | + │ ^^^^^ |
| 125 | + 8 │ }, []); |
| 126 | + 9 │ } |
| 127 | + |
| 128 | + i React relies on hook dependencies to determine when to re-compute Effects. |
| 129 | + Failing to specify dependencies can result in Effects not updating correctly when state changes. |
| 130 | + These "stale closures" are a common source of surprising bugs. |
| 131 | + |
| 132 | + i Either include it or remove the dependency array. |
| 133 | + |
| 134 | + i Unsafe fix: Add the missing dependency to the list. |
| 135 | + |
| 136 | + 8 │ ····},·[local]); |
| 137 | + │ +++++ |
| 138 | +
|
| 139 | +``` |
| 140 | +
|
| 141 | +```block |
| 142 | +Checked 3 files in <TIME>. No fixes applied. |
| 143 | +Found 1 error. |
| 144 | +Found 2 warnings. |
| 145 | +``` |
0 commit comments