@lms5400/eslint-plugin-rsx 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/index.cjs +16 -2
- package/package.json +1 -1
- package/rules/jsx-uses-vars.cjs +38 -0
package/README.md
CHANGED
|
@@ -57,8 +57,6 @@ import reactHooks from "eslint-plugin-react-hooks";
|
|
|
57
57
|
import rsx from "@lms5400/eslint-plugin-rsx";
|
|
58
58
|
|
|
59
59
|
export default [
|
|
60
|
-
js.configs.recommended,
|
|
61
|
-
|
|
62
60
|
// ----------------------------------------
|
|
63
61
|
// React JSX / TSX files
|
|
64
62
|
// ----------------------------------------
|
|
@@ -93,9 +91,10 @@ export default [
|
|
|
93
91
|
},
|
|
94
92
|
},
|
|
95
93
|
rules: {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
// Base JS rules
|
|
95
|
+
...js.configs.recommended,
|
|
96
|
+
// RSX rules
|
|
97
|
+
...rsx.configs.recommended
|
|
99
98
|
},
|
|
100
99
|
},
|
|
101
100
|
];
|
|
@@ -175,6 +174,8 @@ Expected:
|
|
|
175
174
|
| `rsx/no-react-hooks` | Disallow React hooks in RSX |
|
|
176
175
|
| `rsx/no-use-ref` | Disallow `useRef` |
|
|
177
176
|
| `rsx/require-ctx-destructure` | Require RSX context destructuring |
|
|
177
|
+
| `rsx/jsx-uses-vars` | Mark JSX components as used (prevents false-positive `no-unused-vars` errors) |
|
|
178
|
+
|
|
178
179
|
|
|
179
180
|
---
|
|
180
181
|
|
package/index.cjs
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
const plugin = {
|
|
2
2
|
rules: {
|
|
3
|
+
"jsx-uses-vars": require("./rules/jsx-uses-vars.cjs"),
|
|
3
4
|
"no-react-hooks": require("./rules/no-react-hooks.cjs"),
|
|
4
5
|
"no-use-ref": require("./rules/no-use-ref.cjs"),
|
|
5
6
|
"require-ctx-destructure": require("./rules/require-ctx-destructure.cjs"),
|
|
6
7
|
},
|
|
7
|
-
}
|
|
8
|
+
configs: {},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
plugin.configs.recommended = {
|
|
12
|
+
plugins: { rsx: plugin },
|
|
13
|
+
rules: {
|
|
14
|
+
"rsx/jsx-uses-vars": "error",
|
|
15
|
+
"rsx/no-react-hooks": "error",
|
|
16
|
+
"rsx/no-use-ref": "warn",
|
|
17
|
+
"rsx/require-ctx-destructure": "error",
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports = plugin;
|
package/package.json
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "problem",
|
|
4
|
+
docs: {
|
|
5
|
+
description:
|
|
6
|
+
"Mark variables used as JSX component names as used (prevents false-positive no-unused-vars errors)",
|
|
7
|
+
},
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
create(context) {
|
|
11
|
+
return {
|
|
12
|
+
JSXOpeningElement(node) {
|
|
13
|
+
const name = node.name;
|
|
14
|
+
|
|
15
|
+
// Handle simple identifiers like <Badge />
|
|
16
|
+
if (name.type === "JSXIdentifier") {
|
|
17
|
+
const tagName = name.name;
|
|
18
|
+
|
|
19
|
+
// Only mark PascalCase identifiers (components), not intrinsic elements like <div>
|
|
20
|
+
if (tagName[0] === tagName[0].toUpperCase() && tagName[0] !== tagName[0].toLowerCase()) {
|
|
21
|
+
context.markVariableAsUsed(tagName);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Handle member expressions like <Foo.Bar />
|
|
26
|
+
if (name.type === "JSXMemberExpression") {
|
|
27
|
+
let current = name;
|
|
28
|
+
while (current.type === "JSXMemberExpression") {
|
|
29
|
+
current = current.object;
|
|
30
|
+
}
|
|
31
|
+
if (current.type === "JSXIdentifier") {
|
|
32
|
+
context.markVariableAsUsed(current.name);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|