Skip to content

Commit 3ea5d14

Browse files
committed
fix: improve the error marker range of 'hooks-extra/no-unnecessary-use-prefix' rule
1 parent 9298232 commit 3ea5d14

File tree

11 files changed

+244
-269
lines changed

11 files changed

+244
-269
lines changed

.pkgs/configs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"lint:ts": "tsc --noEmit"
2020
},
2121
"dependencies": {
22-
"@eslint/js": "^9.30.0",
22+
"@eslint/js": "^9.30.1",
2323
"@stylistic/eslint-plugin": "^5.1.0",
2424
"eslint-plugin-de-morgan": "^1.3.0",
2525
"eslint-plugin-function": "^0.0.22",

.pkgs/eslint-plugin-local/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@eslint-react/kit": "workspace:*",
2727
"@eslint-react/shared": "workspace:*",
2828
"@eslint-react/var": "workspace:*",
29-
"@eslint/js": "^9.30.0",
29+
"@eslint/js": "^9.30.1",
3030
"@stylistic/eslint-plugin": "^5.1.0",
3131
"@typescript-eslint/scope-manager": "^8.35.1",
3232
"@typescript-eslint/type-utils": "^8.35.1",

apps/website/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@eslint-react/eslint-plugin": "workspace:*",
3434
"@eslint-react/kit": "workspace:*",
3535
"@eslint-react/shared": "workspace:*",
36-
"@eslint/js": "^9.30.0",
36+
"@eslint/js": "^9.30.1",
3737
"@eslint/markdown": "^6.6.0",
3838
"@local/configs": "workspace:*",
3939
"@mdx-js/mdx": "^3.1.0",
@@ -44,12 +44,12 @@
4444
"@tsconfig/strictest": "^2.0.5",
4545
"@types/hast": "^3.0.4",
4646
"@types/mdx": "^2.0.13",
47-
"@types/node": "^24.0.8",
47+
"@types/node": "^24.0.10",
4848
"@types/react": "^19.1.8",
4949
"@types/react-dom": "^19.1.6",
5050
"autoprefixer": "^10.4.21",
5151
"dedent": "^1.6.0",
52-
"eslint": "^9.30.0",
52+
"eslint": "^9.30.1",
5353
"eslint-plugin-de-morgan": "^1.3.0",
5454
"eslint-plugin-import-x": "^4.16.1",
5555
"eslint-plugin-perfectionist": "^4.15.0",

examples/next-app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
"devDependencies": {
1717
"@eslint-react/eslint-plugin": "workspace:*",
1818
"@eslint/config-inspector": "^1.1.0",
19-
"@eslint/js": "^9.30.0",
19+
"@eslint/js": "^9.30.1",
2020
"@next/eslint-plugin-next": "^15.3.4",
2121
"@tsconfig/next": "^2.0.3",
2222
"@tsconfig/node22": "^22.0.2",
2323
"@tsconfig/strictest": "^2.0.5",
24-
"@types/node": "^24.0.8",
24+
"@types/node": "^24.0.10",
2525
"@types/react": "^19.1.8",
2626
"@types/react-dom": "^19.1.6",
27-
"eslint": "^9.30.0",
27+
"eslint": "^9.30.1",
2828
"eslint-config-flat-gitignore": "^2.1.0",
2929
"eslint-plugin-react-hooks": "^5.2.0",
3030
"eslint-plugin-react-refresh": "^0.4.20",

examples/vite-react-dom-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
"devDependencies": {
1818
"@eslint-react/eslint-plugin": "workspace:*",
1919
"@eslint/config-inspector": "^1.1.0",
20-
"@eslint/js": "^9.30.0",
20+
"@eslint/js": "^9.30.1",
2121
"@tsconfig/node22": "^22.0.2",
2222
"@tsconfig/strictest": "^2.0.5",
2323
"@tsconfig/vite-react": "^6.3.6",
2424
"@types/react": "^19.1.8",
2525
"@types/react-dom": "^19.1.6",
2626
"@vitejs/plugin-react": "^4.6.0",
27-
"eslint": "^9.30.0",
27+
"eslint": "^9.30.1",
2828
"eslint-plugin-react-hooks": "^5.2.0",
2929
"eslint-plugin-react-refresh": "^0.4.20",
3030
"typescript": "^5.8.3",

examples/vite-react-dom-js-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"devDependencies": {
1818
"@eslint-react/eslint-plugin": "workspace:*",
1919
"@eslint/config-inspector": "^1.1.0",
20-
"@eslint/js": "^9.30.0",
20+
"@eslint/js": "^9.30.1",
2121
"@types/react": "^19.1.8",
2222
"@types/react-dom": "^19.1.6",
2323
"@vitejs/plugin-react": "^4.6.0",
24-
"eslint": "^9.30.0",
24+
"eslint": "^9.30.1",
2525
"eslint-plugin-react-hooks": "^5.2.0",
2626
"eslint-plugin-react-refresh": "^0.4.20",
2727
"globals": "^16.3.0",

examples/vite-react-dom-js-with-babel-eslint-parser-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
"@babel/preset-env": "^7.27.2",
2121
"@babel/preset-react": "^7.27.1",
2222
"@eslint/config-inspector": "^1.1.0",
23-
"@eslint/js": "^9.30.0",
23+
"@eslint/js": "^9.30.1",
2424
"@types/babel__core": "~7.20.5",
2525
"@types/babel__preset-env": "~7.10.0",
2626
"@types/react": "^19.1.8",
2727
"@types/react-dom": "^19.1.6",
2828
"@vitejs/plugin-react": "^4.6.0",
29-
"eslint": "^9.30.0",
29+
"eslint": "^9.30.1",
3030
"eslint-plugin-react-debug": "workspace:*",
3131
"eslint-plugin-react-dom": "workspace:*",
3232
"eslint-plugin-react-hooks": "^5.2.0",

examples/vite-react-dom-with-ts-blank-eslint-parser-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
"@eslint-react/kit": "workspace:*",
2020
"@eslint-react/shared": "workspace:*",
2121
"@eslint/config-inspector": "^1.1.0",
22-
"@eslint/js": "^9.30.0",
22+
"@eslint/js": "^9.30.1",
2323
"@tsconfig/node22": "^22.0.2",
2424
"@tsconfig/strictest": "^2.0.5",
2525
"@tsconfig/vite-react": "^6.3.6",
2626
"@types/react": "^19.1.8",
2727
"@types/react-dom": "^19.1.6",
2828
"@vitejs/plugin-react": "^4.6.0",
29-
"eslint": "^9.30.0",
29+
"eslint": "^9.30.1",
3030
"eslint-plugin-react-hooks": "^5.2.0",
3131
"eslint-plugin-react-refresh": "^0.4.20",
3232
"globals": "^16.3.0",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"@swc/core": "^1.12.9",
6060
"@tsconfig/node22": "^22.0.2",
6161
"@tsconfig/strictest": "^2.0.5",
62-
"@types/node": "^24.0.8",
62+
"@types/node": "^24.0.10",
6363
"@types/react": "^19.1.8",
6464
"@types/react-dom": "^19.1.6",
6565
"@typescript-eslint/parser": "^8.35.1",
@@ -70,7 +70,7 @@
7070
"dedent": "^1.6.0",
7171
"dprint": "^0.50.1",
7272
"esbuild": "^0.25.5",
73-
"eslint": "^9.30.0",
73+
"eslint": "^9.30.1",
7474
"eslint-config-flat-gitignore": "^2.1.0",
7575
"eslint-plugin-fast-import": "^1.2.0",
7676
"eslint-plugin-vitest": "^0.5.4",

packages/plugins/eslint-plugin-react-hooks-extra/src/rules/no-unnecessary-use-prefix.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,9 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
6464
if (containsUseComments(context, node)) {
6565
continue;
6666
}
67-
if (id != null) {
68-
context.report({
69-
messageId: "noUnnecessaryUsePrefix",
70-
data: {
71-
name,
72-
},
73-
loc: getPreferredLoc(context, id),
74-
});
75-
continue;
76-
}
7767
context.report({
7868
messageId: "noUnnecessaryUsePrefix",
79-
node,
69+
node: id ?? node,
8070
data: {
8171
name,
8272
},
@@ -85,18 +75,3 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
8575
},
8676
};
8777
}
88-
89-
function getPreferredLoc(context: RuleContext, id: TSESTree.Identifier) {
90-
if (AST.isMultiLine(id)) return id.loc;
91-
if (!context.sourceCode.getText(id).startsWith("use")) return id.loc;
92-
return {
93-
end: {
94-
column: id.loc.start.column + 3,
95-
line: id.loc.start.line,
96-
},
97-
start: {
98-
column: id.loc.start.column,
99-
line: id.loc.start.line,
100-
},
101-
};
102-
}

0 commit comments

Comments
 (0)