@lms5400/eslint-plugin-rsx 1.0.0 → 1.0.2

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 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
- "rsx/no-react-hooks": "error",
97
- "rsx/no-use-ref": "warn",
98
- "rsx/require-ctx-destructure": "error",
94
+ // Base JS rules
95
+ ...js.configs.recommended,
96
+ // RSX rules
97
+ ...rsx.configs.recommended
99
98
  },
100
99
  },
101
100
  ];
@@ -135,7 +134,6 @@ Add the following to your workspace settings.
135
134
  "eslint.validate": [
136
135
  "javascript",
137
136
  "javascriptreact",
138
- "rsx"
139
137
  ],
140
138
  "files.associations": {
141
139
  "*.rsx": "javascriptreact"
@@ -175,6 +173,8 @@ Expected:
175
173
  | `rsx/no-react-hooks` | Disallow React hooks in RSX |
176
174
  | `rsx/no-use-ref` | Disallow `useRef` |
177
175
  | `rsx/require-ctx-destructure` | Require RSX context destructuring |
176
+ | `rsx/jsx-uses-vars` | Mark JSX components as used (prevents false-positive `no-unused-vars` errors) |
177
+
178
178
 
179
179
  ---
180
180
 
package/index.cjs CHANGED
@@ -1,7 +1,21 @@
1
- module.exports = {
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
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "https://github.com/LMS007/eslint-plugin-rsx.git"
7
7
  },
8
- "version": "1.0.0",
8
+ "version": "1.0.2",
9
9
  "engines": {
10
10
  "node": ">=18"
11
11
  },
@@ -0,0 +1,40 @@
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
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
12
+
13
+ return {
14
+ JSXOpeningElement(node) {
15
+ const name = node.name;
16
+
17
+ // Handle simple identifiers like <Badge />
18
+ if (name.type === "JSXIdentifier") {
19
+ const tagName = name.name;
20
+
21
+ // Only mark PascalCase identifiers (components), not intrinsic elements like <div>
22
+ if (tagName[0] === tagName[0].toUpperCase() && tagName[0] !== tagName[0].toLowerCase()) {
23
+ sourceCode.markVariableAsUsed(tagName, node);
24
+ }
25
+ }
26
+
27
+ // Handle member expressions like <Foo.Bar />
28
+ if (name.type === "JSXMemberExpression") {
29
+ let current = name;
30
+ while (current.type === "JSXMemberExpression") {
31
+ current = current.object;
32
+ }
33
+ if (current.type === "JSXIdentifier") {
34
+ sourceCode.markVariableAsUsed(current.name, node);
35
+ }
36
+ }
37
+ },
38
+ };
39
+ },
40
+ };