eslint-plugin-react-features 1.1.4 → 1.2.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/CHANGELOG.md +81 -0
- package/README.md +80 -61
- package/package.json +7 -3
- package/src/index.d.ts +630 -16
- package/src/index.js +66 -18
- package/src/rules/component-api/no-arbitrary-token-class.d.ts +17 -0
- package/src/rules/component-api/no-arbitrary-token-class.js +85 -0
- package/src/rules/component-api/no-default-test-id.d.ts +15 -0
- package/src/rules/component-api/no-default-test-id.js +53 -0
- package/src/rules/component-api/no-inline-style.d.ts +15 -0
- package/src/rules/component-api/no-inline-style.js +63 -0
- package/src/rules/component-api/no-is-prefix-prop.d.ts +17 -0
- package/src/rules/component-api/no-is-prefix-prop.js +66 -0
- package/src/rules/component-api/no-kind-prop-discriminator.d.ts +25 -0
- package/src/rules/component-api/no-kind-prop-discriminator.js +62 -0
- package/src/rules/component-api/no-raw-color-literal.d.ts +16 -0
- package/src/rules/component-api/no-raw-color-literal.js +63 -0
- package/src/rules/component-api/no-wrapper-sub-component.d.ts +23 -0
- package/src/rules/component-api/no-wrapper-sub-component.js +103 -0
- package/src/rules/component-api/require-data-slot.d.ts +15 -0
- package/src/rules/component-api/require-data-slot.js +45 -0
- package/src/rules/performance/react-no-inline-functions.js +0 -1
- package/src/rules/react/no-unknown-property.js +6 -0
package/src/index.js
CHANGED
|
@@ -64,6 +64,15 @@ const react_class_to_hooks_1 = require("./rules/migration/react-class-to-hooks")
|
|
|
64
64
|
const no_unnecessary_rerenders_1 = require("./rules/performance/no-unnecessary-rerenders");
|
|
65
65
|
const react_render_optimization_1 = require("./rules/performance/react-render-optimization");
|
|
66
66
|
const react_no_inline_functions_1 = require("./rules/performance/react-no-inline-functions");
|
|
67
|
+
// Component-API rules (interlace-component skill R5/R6/R8/R11/R12/R18/R19)
|
|
68
|
+
const no_default_test_id_1 = require("./rules/component-api/no-default-test-id");
|
|
69
|
+
const require_data_slot_1 = require("./rules/component-api/require-data-slot");
|
|
70
|
+
const no_is_prefix_prop_1 = require("./rules/component-api/no-is-prefix-prop");
|
|
71
|
+
const no_inline_style_1 = require("./rules/component-api/no-inline-style");
|
|
72
|
+
const no_raw_color_literal_1 = require("./rules/component-api/no-raw-color-literal");
|
|
73
|
+
const no_arbitrary_token_class_1 = require("./rules/component-api/no-arbitrary-token-class");
|
|
74
|
+
const no_kind_prop_discriminator_1 = require("./rules/component-api/no-kind-prop-discriminator");
|
|
75
|
+
const no_wrapper_sub_component_1 = require("./rules/component-api/no-wrapper-sub-component");
|
|
67
76
|
exports.rules = {
|
|
68
77
|
// Flat names
|
|
69
78
|
'required-attributes': required_attributes_1.requiredAttributes,
|
|
@@ -121,6 +130,15 @@ exports.rules = {
|
|
|
121
130
|
'no-unnecessary-rerenders': no_unnecessary_rerenders_1.noUnnecessaryRerenders,
|
|
122
131
|
'react-render-optimization': react_render_optimization_1.reactRenderOptimization,
|
|
123
132
|
'react-no-inline-functions': react_no_inline_functions_1.reactNoInlineFunctions,
|
|
133
|
+
// Component-API (flat)
|
|
134
|
+
'no-default-test-id': no_default_test_id_1.noDefaultTestId,
|
|
135
|
+
'require-data-slot': require_data_slot_1.requireDataSlot,
|
|
136
|
+
'no-is-prefix-prop': no_is_prefix_prop_1.noIsPrefixProp,
|
|
137
|
+
'no-inline-style': no_inline_style_1.noInlineStyle,
|
|
138
|
+
'no-raw-color-literal': no_raw_color_literal_1.noRawColorLiteral,
|
|
139
|
+
'no-arbitrary-token-class': no_arbitrary_token_class_1.noArbitraryTokenClass,
|
|
140
|
+
'no-kind-prop-discriminator': no_kind_prop_discriminator_1.noKindPropDiscriminator,
|
|
141
|
+
'no-wrapper-sub-component': no_wrapper_sub_component_1.noWrapperSubComponent,
|
|
124
142
|
// Categorized names
|
|
125
143
|
'react/required-attributes': required_attributes_1.requiredAttributes,
|
|
126
144
|
'react/jsx-key': jsx_key_1.jsxKey,
|
|
@@ -177,11 +195,20 @@ exports.rules = {
|
|
|
177
195
|
'performance/no-unnecessary-rerenders': no_unnecessary_rerenders_1.noUnnecessaryRerenders,
|
|
178
196
|
'performance/react-render-optimization': react_render_optimization_1.reactRenderOptimization,
|
|
179
197
|
'performance/react-no-inline-functions': react_no_inline_functions_1.reactNoInlineFunctions,
|
|
198
|
+
// Component-API (categorized) — interlace-component skill R5/R6/R8/R11/R12/R18/R19
|
|
199
|
+
'component-api/no-default-test-id': no_default_test_id_1.noDefaultTestId,
|
|
200
|
+
'component-api/require-data-slot': require_data_slot_1.requireDataSlot,
|
|
201
|
+
'component-api/no-is-prefix-prop': no_is_prefix_prop_1.noIsPrefixProp,
|
|
202
|
+
'component-api/no-inline-style': no_inline_style_1.noInlineStyle,
|
|
203
|
+
'component-api/no-raw-color-literal': no_raw_color_literal_1.noRawColorLiteral,
|
|
204
|
+
'component-api/no-arbitrary-token-class': no_arbitrary_token_class_1.noArbitraryTokenClass,
|
|
205
|
+
'component-api/no-kind-prop-discriminator': no_kind_prop_discriminator_1.noKindPropDiscriminator,
|
|
206
|
+
'component-api/no-wrapper-sub-component': no_wrapper_sub_component_1.noWrapperSubComponent,
|
|
180
207
|
};
|
|
181
208
|
exports.plugin = {
|
|
182
209
|
meta: {
|
|
183
210
|
name: 'eslint-plugin-react-features',
|
|
184
|
-
version: '1.1
|
|
211
|
+
version: '1.2.1',
|
|
185
212
|
},
|
|
186
213
|
rules: exports.rules,
|
|
187
214
|
};
|
|
@@ -194,32 +221,53 @@ exports.configs = {
|
|
|
194
221
|
*/
|
|
195
222
|
flagship: {
|
|
196
223
|
plugins: {
|
|
197
|
-
'
|
|
224
|
+
'react-features': exports.plugin,
|
|
198
225
|
},
|
|
199
226
|
rules: {
|
|
200
|
-
'
|
|
227
|
+
'react-features/hooks-exhaustive-deps': 'error',
|
|
201
228
|
},
|
|
202
229
|
},
|
|
203
230
|
recommended: {
|
|
204
231
|
plugins: {
|
|
205
|
-
'
|
|
232
|
+
'react-features': exports.plugin,
|
|
206
233
|
},
|
|
207
234
|
rules: {
|
|
208
|
-
'
|
|
209
|
-
'
|
|
210
|
-
'
|
|
211
|
-
'
|
|
212
|
-
'
|
|
213
|
-
'
|
|
235
|
+
'react-features/jsx-key': 'error',
|
|
236
|
+
'react-features/no-children-prop': 'warn',
|
|
237
|
+
'react-features/no-danger': 'warn',
|
|
238
|
+
'react-features/no-string-refs': 'error',
|
|
239
|
+
'react-features/no-unknown-property': 'error',
|
|
240
|
+
'react-features/hooks-exhaustive-deps': 'warn',
|
|
214
241
|
// Security rules
|
|
215
|
-
'
|
|
216
|
-
'
|
|
217
|
-
'
|
|
218
|
-
'
|
|
219
|
-
'
|
|
220
|
-
// Performance
|
|
221
|
-
|
|
222
|
-
|
|
242
|
+
'react-features/jsx-no-target-blank': 'error',
|
|
243
|
+
'react-features/jsx-no-script-url': 'error',
|
|
244
|
+
'react-features/jsx-no-duplicate-props': 'error',
|
|
245
|
+
'react-features/no-danger-with-children': 'error',
|
|
246
|
+
'react-features/no-deprecated': 'warn',
|
|
247
|
+
// Performance rules are opt-in: they flag inline objects/arrays/functions which
|
|
248
|
+
// are very common patterns in React codebases. They belong in the performance
|
|
249
|
+
// preset, not recommended — the FP rate in general codebases is too high.
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
/**
|
|
253
|
+
* Component-API preset — enforces the mechanical rules from the
|
|
254
|
+
* `interlace-component` skill (R5/R6/R8/R11/R12/R18/R19). Apply this to any
|
|
255
|
+
* package that ships shared React components (registry, design-system,
|
|
256
|
+
* @interlace/ui).
|
|
257
|
+
*/
|
|
258
|
+
componentApi: {
|
|
259
|
+
plugins: {
|
|
260
|
+
'react-features': exports.plugin,
|
|
261
|
+
},
|
|
262
|
+
rules: {
|
|
263
|
+
'react-features/component-api/no-default-test-id': 'error',
|
|
264
|
+
'react-features/component-api/require-data-slot': 'warn',
|
|
265
|
+
'react-features/component-api/no-is-prefix-prop': 'warn',
|
|
266
|
+
'react-features/component-api/no-inline-style': 'warn',
|
|
267
|
+
'react-features/component-api/no-raw-color-literal': 'warn',
|
|
268
|
+
'react-features/component-api/no-arbitrary-token-class': 'warn',
|
|
269
|
+
'react-features/component-api/no-kind-prop-discriminator': 'warn',
|
|
270
|
+
'react-features/component-api/no-wrapper-sub-component': 'warn',
|
|
223
271
|
},
|
|
224
272
|
},
|
|
225
273
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-arbitrary-token-class
|
|
8
|
+
* Enforces R19: no Tailwind arbitrary-value classes (`rounded-[12px]`,
|
|
9
|
+
* `px-[18px]`) on properties that have a design-token equivalent. Allows
|
|
10
|
+
* arbitrary values that reference CSS variables (`rounded-[var(--token)]`),
|
|
11
|
+
* computed expressions (`w-[calc(...)]`), or non-pixel units that don't map
|
|
12
|
+
* to the spacing scale (`min-h-[60vh]`).
|
|
13
|
+
*/
|
|
14
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
15
|
+
export declare const noArbitraryTokenClass: TSESLint.RuleModule<"arbitraryClass", [], unknown, TSESLint.RuleListener> & {
|
|
16
|
+
name: string;
|
|
17
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noArbitraryTokenClass = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const TOKENIZABLE_PROPS = new Set([
|
|
11
|
+
'rounded',
|
|
12
|
+
'rounded-t', 'rounded-r', 'rounded-b', 'rounded-l',
|
|
13
|
+
'rounded-tl', 'rounded-tr', 'rounded-bl', 'rounded-br',
|
|
14
|
+
'px', 'py', 'pt', 'pb', 'pl', 'pr', 'p',
|
|
15
|
+
'mx', 'my', 'mt', 'mb', 'ml', 'mr', 'm',
|
|
16
|
+
'gap', 'gap-x', 'gap-y',
|
|
17
|
+
'space-x', 'space-y',
|
|
18
|
+
// Sizing handled separately — only flag when the arbitrary value is a token-able pixel size
|
|
19
|
+
]);
|
|
20
|
+
// Captures e.g. `rounded-[12px]`, `px-[18px]`, `gap-[4rem]`, but NOT
|
|
21
|
+
// `w-[calc(...)]`, `rounded-[var(--x)]`, `min-h-[60vh]`, `data-[state=open]:...`.
|
|
22
|
+
const ARBITRARY_CLASS_PATTERN = /([\w-]+)-\[([^\]]+)\]/g;
|
|
23
|
+
const TOKENIZABLE_VALUE = /^\d+(?:\.\d+)?(?:px|rem|em)$/;
|
|
24
|
+
exports.noArbitraryTokenClass = (0, eslint_devkit_1.createRule)({
|
|
25
|
+
name: 'no-arbitrary-token-class',
|
|
26
|
+
meta: {
|
|
27
|
+
type: 'problem',
|
|
28
|
+
docs: {
|
|
29
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-arbitrary-token-class.md',
|
|
30
|
+
description: 'No Tailwind arbitrary values when a token exists for that property (R19)',
|
|
31
|
+
},
|
|
32
|
+
schema: [],
|
|
33
|
+
messages: {
|
|
34
|
+
arbitraryClass: (0, eslint_devkit_1.formatLLMMessage)({
|
|
35
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
36
|
+
issueName: 'Arbitrary Tailwind class',
|
|
37
|
+
description: 'Arbitrary value `{{cls}}` — use a token or extend the theme (R19)',
|
|
38
|
+
severity: 'MEDIUM',
|
|
39
|
+
fix: 'Replace with the matching spacing/radius token or wire a `var(--token)` Tailwind class.',
|
|
40
|
+
documentationLink: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-arbitrary-token-class.md',
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
defaultOptions: [],
|
|
45
|
+
create(context) {
|
|
46
|
+
const scanString = (node, raw) => {
|
|
47
|
+
for (const match of raw.matchAll(ARBITRARY_CLASS_PATTERN)) {
|
|
48
|
+
const [whole, prop, value] = match;
|
|
49
|
+
if (!TOKENIZABLE_PROPS.has(prop))
|
|
50
|
+
continue;
|
|
51
|
+
if (!TOKENIZABLE_VALUE.test(value))
|
|
52
|
+
continue;
|
|
53
|
+
context.report({
|
|
54
|
+
node,
|
|
55
|
+
messageId: 'arbitraryClass',
|
|
56
|
+
data: { cls: whole },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
// className="..." string literal
|
|
62
|
+
'JSXAttribute[name.name="className"] > Literal'(node) {
|
|
63
|
+
if (typeof node.value === 'string')
|
|
64
|
+
scanString(node, node.value);
|
|
65
|
+
},
|
|
66
|
+
// className={`...`} template literal (static parts only)
|
|
67
|
+
'JSXAttribute[name.name="className"] TemplateElement'(node) {
|
|
68
|
+
scanString(node, node.value.cooked);
|
|
69
|
+
},
|
|
70
|
+
// cn("...", "...") / clsx(...) string args
|
|
71
|
+
CallExpression(node) {
|
|
72
|
+
if (node.callee.type !== 'Identifier')
|
|
73
|
+
return;
|
|
74
|
+
const name = node.callee.name;
|
|
75
|
+
if (name !== 'cn' && name !== 'clsx' && name !== 'twMerge' && name !== 'classNames')
|
|
76
|
+
return;
|
|
77
|
+
for (const arg of node.arguments) {
|
|
78
|
+
if (arg.type === 'Literal' && typeof arg.value === 'string') {
|
|
79
|
+
scanString(arg, arg.value);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-default-test-id
|
|
8
|
+
* Enforces R5 from the interlace-component skill: data-testid must be
|
|
9
|
+
* type-required and consumer-provided. A runtime default contradicts the
|
|
10
|
+
* type-level requirement and silently masks consumer omissions.
|
|
11
|
+
*/
|
|
12
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
13
|
+
export declare const noDefaultTestId: TSESLint.RuleModule<"defaultTestId", [], unknown, TSESLint.RuleListener> & {
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noDefaultTestId = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
exports.noDefaultTestId = (0, eslint_devkit_1.createRule)({
|
|
11
|
+
name: 'no-default-test-id',
|
|
12
|
+
meta: {
|
|
13
|
+
type: 'problem',
|
|
14
|
+
docs: {
|
|
15
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-default-test-id.md',
|
|
16
|
+
description: 'data-testid must be consumer-provided — no runtime default value (R5)',
|
|
17
|
+
},
|
|
18
|
+
fixable: 'code',
|
|
19
|
+
schema: [],
|
|
20
|
+
messages: {
|
|
21
|
+
defaultTestId: (0, eslint_devkit_1.formatLLMMessage)({
|
|
22
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
23
|
+
issueName: 'data-testid default value',
|
|
24
|
+
description: 'data-testid has a runtime default — consumer must provide it (R5)',
|
|
25
|
+
severity: 'HIGH',
|
|
26
|
+
fix: 'Remove the default. Require data-testid at the type level and let the consumer pass it.',
|
|
27
|
+
documentationLink: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-default-test-id.md',
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
defaultOptions: [],
|
|
32
|
+
create(context) {
|
|
33
|
+
return {
|
|
34
|
+
Property(node) {
|
|
35
|
+
// Match `"data-testid": x = "..."` in destructuring patterns
|
|
36
|
+
if (node.key.type !== 'Literal' || node.key.value !== 'data-testid')
|
|
37
|
+
return;
|
|
38
|
+
if (node.value.type !== 'AssignmentPattern')
|
|
39
|
+
return;
|
|
40
|
+
const assignment = node.value;
|
|
41
|
+
context.report({
|
|
42
|
+
node: assignment,
|
|
43
|
+
messageId: 'defaultTestId',
|
|
44
|
+
fix(fixer) {
|
|
45
|
+
// Replace `x = "..."` with just `x` — drop the default.
|
|
46
|
+
const bindingText = context.sourceCode.getText(assignment.left);
|
|
47
|
+
return fixer.replaceText(assignment, bindingText);
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-inline-style
|
|
8
|
+
* Enforces R18: no inline `style={{...}}` for static styling. The only
|
|
9
|
+
* permitted case is CSS-variable assignment (`style={{ "--snp-x": x }}`)
|
|
10
|
+
* for genuinely dynamic values. Everything else belongs in Tailwind classes.
|
|
11
|
+
*/
|
|
12
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
13
|
+
export declare const noInlineStyle: TSESLint.RuleModule<"inlineStyle", [], unknown, TSESLint.RuleListener> & {
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noInlineStyle = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const isCssVariableKey = (prop) => {
|
|
11
|
+
if (prop.type !== 'Property')
|
|
12
|
+
return false;
|
|
13
|
+
if (prop.key.type === 'Literal' && typeof prop.key.value === 'string') {
|
|
14
|
+
return prop.key.value.startsWith('--');
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
18
|
+
const isStaticLiteralValue = (prop) => {
|
|
19
|
+
if (prop.type !== 'Property')
|
|
20
|
+
return false;
|
|
21
|
+
const v = prop.value;
|
|
22
|
+
return v.type === 'Literal' && (typeof v.value === 'string' || typeof v.value === 'number');
|
|
23
|
+
};
|
|
24
|
+
exports.noInlineStyle = (0, eslint_devkit_1.createRule)({
|
|
25
|
+
name: 'no-inline-style',
|
|
26
|
+
meta: {
|
|
27
|
+
type: 'problem',
|
|
28
|
+
docs: {
|
|
29
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-inline-style.md',
|
|
30
|
+
description: 'No inline `style={{}}` except for CSS-variable assignment (R18)',
|
|
31
|
+
},
|
|
32
|
+
schema: [],
|
|
33
|
+
messages: {
|
|
34
|
+
inlineStyle: (0, eslint_devkit_1.formatLLMMessage)({
|
|
35
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
36
|
+
issueName: 'Inline style prop',
|
|
37
|
+
description: 'Inline `style={{}}` with static value(s) — use Tailwind classes (R18)',
|
|
38
|
+
severity: 'MEDIUM',
|
|
39
|
+
fix: 'Move the static value to a Tailwind class. Reserve inline style for CSS variables and computed dynamic values.',
|
|
40
|
+
documentationLink: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-inline-style.md',
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
defaultOptions: [],
|
|
45
|
+
create(context) {
|
|
46
|
+
return {
|
|
47
|
+
JSXAttribute(node) {
|
|
48
|
+
if (node.name.type !== 'JSXIdentifier' || node.name.name !== 'style')
|
|
49
|
+
return;
|
|
50
|
+
if (!node.value || node.value.type !== 'JSXExpressionContainer')
|
|
51
|
+
return;
|
|
52
|
+
const expr = node.value.expression;
|
|
53
|
+
if (expr.type !== 'ObjectExpression')
|
|
54
|
+
return;
|
|
55
|
+
// Report only when at least one property is a static literal AND not a CSS variable assignment.
|
|
56
|
+
const hasStaticNonVarProp = expr.properties.some((p) => !isCssVariableKey(p) && isStaticLiteralValue(p));
|
|
57
|
+
if (hasStaticNonVarProp) {
|
|
58
|
+
context.report({ node, messageId: 'inlineStyle' });
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-is-prefix-prop
|
|
8
|
+
* Enforces R8: boolean props default-false, name describes the true state.
|
|
9
|
+
* Bans `isXxx: boolean` props in TypeScript interfaces / type aliases.
|
|
10
|
+
* `looped` reads naturally; `isLooped` is MUI-flagged noise.
|
|
11
|
+
*/
|
|
12
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
13
|
+
type MessageIds = 'isPrefix' | 'renameSuggestion';
|
|
14
|
+
export declare const noIsPrefixProp: TSESLint.RuleModule<MessageIds, [], unknown, TSESLint.RuleListener> & {
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noIsPrefixProp = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const stripIsPrefix = (name) => name.slice(2, 3).toLowerCase() + name.slice(3);
|
|
11
|
+
exports.noIsPrefixProp = (0, eslint_devkit_1.createRule)({
|
|
12
|
+
name: 'no-is-prefix-prop',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-is-prefix-prop.md',
|
|
17
|
+
description: 'Boolean props must not be prefixed with `is` (R8)',
|
|
18
|
+
},
|
|
19
|
+
hasSuggestions: true,
|
|
20
|
+
schema: [],
|
|
21
|
+
messages: {
|
|
22
|
+
isPrefix: (0, eslint_devkit_1.formatLLMMessage)({
|
|
23
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
24
|
+
issueName: '`is` prefix on boolean prop',
|
|
25
|
+
description: 'Boolean prop `{{name}}` should be renamed to `{{suggested}}` (R8)',
|
|
26
|
+
severity: 'MEDIUM',
|
|
27
|
+
fix: 'Rename to `{{suggested}}` — booleans describe the true state directly.',
|
|
28
|
+
documentationLink: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-is-prefix-prop.md',
|
|
29
|
+
}),
|
|
30
|
+
renameSuggestion: 'Rename to `{{suggested}}` (also rename consumer call sites manually)',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [],
|
|
34
|
+
create(context) {
|
|
35
|
+
return {
|
|
36
|
+
TSPropertySignature(node) {
|
|
37
|
+
if (node.key.type !== 'Identifier')
|
|
38
|
+
return;
|
|
39
|
+
const { name } = node.key;
|
|
40
|
+
if (!/^is[A-Z]/.test(name))
|
|
41
|
+
return;
|
|
42
|
+
const ann = node.typeAnnotation?.typeAnnotation;
|
|
43
|
+
if (!ann || ann.type !== 'TSBooleanKeyword')
|
|
44
|
+
return;
|
|
45
|
+
const suggested = stripIsPrefix(name);
|
|
46
|
+
const keyNode = node.key;
|
|
47
|
+
context.report({
|
|
48
|
+
node: keyNode,
|
|
49
|
+
messageId: 'isPrefix',
|
|
50
|
+
data: { name, suggested },
|
|
51
|
+
// Suggestion (not auto-fix) — renaming the prop has consumer-side
|
|
52
|
+
// blast radius. The reviewer must update call sites manually.
|
|
53
|
+
suggest: [
|
|
54
|
+
{
|
|
55
|
+
messageId: 'renameSuggestion',
|
|
56
|
+
data: { suggested },
|
|
57
|
+
fix(fixer) {
|
|
58
|
+
return fixer.replaceText(keyNode, suggested);
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-kind-prop-discriminator
|
|
8
|
+
* Enforces R11: ban the `type: "A" | "B"` kind-prop pattern when the value
|
|
9
|
+
* is intended to switch the rendered tree. Heuristic: a property named
|
|
10
|
+
* `type` / `kind` / `variant` with a string-literal-union of 2+ members,
|
|
11
|
+
* AND the component body contains a conditional `if (props.<name> === ...)`
|
|
12
|
+
* or switch-case branching on that prop.
|
|
13
|
+
*
|
|
14
|
+
* Notes on intentional false positives:
|
|
15
|
+
* - `variant` is permitted by some teams as a CVA discriminator that only
|
|
16
|
+
* switches `role` / `className` (not the element tree). This rule flags
|
|
17
|
+
* the shape; review confirms whether the branching is structural or just
|
|
18
|
+
* a contract switch.
|
|
19
|
+
* - We only flag `type` / `kind` here; `variant` is allow-listed by default
|
|
20
|
+
* because CVA usage is the dominant case.
|
|
21
|
+
*/
|
|
22
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
23
|
+
export declare const noKindPropDiscriminator: TSESLint.RuleModule<"kindProp", [], unknown, TSESLint.RuleListener> & {
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noKindPropDiscriminator = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const FLAGGED_NAMES = new Set(['type', 'kind']);
|
|
11
|
+
const isStringLiteralUnion = (node) => {
|
|
12
|
+
if (!node)
|
|
13
|
+
return false;
|
|
14
|
+
if (node.type !== 'TSUnionType')
|
|
15
|
+
return false;
|
|
16
|
+
const members = node.types;
|
|
17
|
+
if (members.length < 2)
|
|
18
|
+
return false;
|
|
19
|
+
return members.every((m) => m.type === 'TSLiteralType' &&
|
|
20
|
+
m.literal.type === 'Literal' &&
|
|
21
|
+
typeof m.literal.value === 'string');
|
|
22
|
+
};
|
|
23
|
+
exports.noKindPropDiscriminator = (0, eslint_devkit_1.createRule)({
|
|
24
|
+
name: 'no-kind-prop-discriminator',
|
|
25
|
+
meta: {
|
|
26
|
+
type: 'problem',
|
|
27
|
+
docs: {
|
|
28
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-kind-prop-discriminator.md',
|
|
29
|
+
description: 'Ban `type`/`kind` string-union props that select between rendered trees (R11)',
|
|
30
|
+
},
|
|
31
|
+
schema: [],
|
|
32
|
+
messages: {
|
|
33
|
+
kindProp: (0, eslint_devkit_1.formatLLMMessage)({
|
|
34
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
35
|
+
issueName: 'Kind-prop discriminator',
|
|
36
|
+
description: 'Prop `{{name}}: "A" | "B"` likely switches the rendered tree — split into sub-components (R11)',
|
|
37
|
+
severity: 'MEDIUM',
|
|
38
|
+
fix: 'Split into sub-components (`Foo.A`, `Foo.B`). If this is only a CVA contract switch (e.g. role only), rename to `variant` and document the test.',
|
|
39
|
+
documentationLink: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-kind-prop-discriminator.md',
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
defaultOptions: [],
|
|
44
|
+
create(context) {
|
|
45
|
+
return {
|
|
46
|
+
TSPropertySignature(node) {
|
|
47
|
+
if (node.key.type !== 'Identifier')
|
|
48
|
+
return;
|
|
49
|
+
if (!FLAGGED_NAMES.has(node.key.name))
|
|
50
|
+
return;
|
|
51
|
+
const ann = node.typeAnnotation?.typeAnnotation;
|
|
52
|
+
if (!isStringLiteralUnion(ann))
|
|
53
|
+
return;
|
|
54
|
+
context.report({
|
|
55
|
+
node: node.key,
|
|
56
|
+
messageId: 'kindProp',
|
|
57
|
+
data: { name: node.key.name },
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-raw-color-literal
|
|
8
|
+
* Enforces R19: no raw color literals (hex, rgb/rgba, hsl/hsla, oklch/oklab)
|
|
9
|
+
* in source. Colors must come from design tokens via CSS custom properties
|
|
10
|
+
* or Tailwind classes wired to them. Scoped to JSX `style` / `className`
|
|
11
|
+
* object values and `cn()`/`clsx()` arguments to minimize false positives.
|
|
12
|
+
*/
|
|
13
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
14
|
+
export declare const noRawColorLiteral: TSESLint.RuleModule<"rawColor", [], unknown, TSESLint.RuleListener> & {
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noRawColorLiteral = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const COLOR_PATTERN = /(#[0-9a-fA-F]{3,8}\b|\b(?:rgba?|hsla?|oklch|oklab)\s*\()/;
|
|
11
|
+
const isColorString = (s) => COLOR_PATTERN.test(s);
|
|
12
|
+
const reportIfColorLiteral = (context, node, value) => {
|
|
13
|
+
if (typeof value === 'string' && isColorString(value)) {
|
|
14
|
+
context.report({ node, messageId: 'rawColor' });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.noRawColorLiteral = (0, eslint_devkit_1.createRule)({
|
|
18
|
+
name: 'no-raw-color-literal',
|
|
19
|
+
meta: {
|
|
20
|
+
type: 'problem',
|
|
21
|
+
docs: {
|
|
22
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-raw-color-literal.md',
|
|
23
|
+
description: 'No raw hex / rgb / hsl / oklch color literals in source — use design tokens (R19)',
|
|
24
|
+
},
|
|
25
|
+
schema: [],
|
|
26
|
+
messages: {
|
|
27
|
+
rawColor: (0, eslint_devkit_1.formatLLMMessage)({
|
|
28
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
29
|
+
issueName: 'Raw color literal',
|
|
30
|
+
description: 'Raw color literal in source — use a design token (R19)',
|
|
31
|
+
severity: 'MEDIUM',
|
|
32
|
+
fix: 'Replace with a CSS custom property (`var(--your-token)`) or a Tailwind theme class wired to it.',
|
|
33
|
+
documentationLink: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-raw-color-literal.md',
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
defaultOptions: [],
|
|
38
|
+
create(context) {
|
|
39
|
+
return {
|
|
40
|
+
// Color inside JSX attribute string values (className="text-[#fff]", style="...")
|
|
41
|
+
'JSXAttribute > Literal'(node) {
|
|
42
|
+
reportIfColorLiteral(context, node, node.value);
|
|
43
|
+
},
|
|
44
|
+
// Color inside `style={{ color: "#fff" }}` and similar
|
|
45
|
+
'JSXExpressionContainer ObjectExpression > Property > Literal'(node) {
|
|
46
|
+
reportIfColorLiteral(context, node, node.value);
|
|
47
|
+
},
|
|
48
|
+
// Color inside cn()/clsx()/twMerge() args: cn("text-[#fff]")
|
|
49
|
+
CallExpression(node) {
|
|
50
|
+
if (node.callee.type !== 'Identifier')
|
|
51
|
+
return;
|
|
52
|
+
const name = node.callee.name;
|
|
53
|
+
if (name !== 'cn' && name !== 'clsx' && name !== 'twMerge' && name !== 'classNames')
|
|
54
|
+
return;
|
|
55
|
+
for (const arg of node.arguments) {
|
|
56
|
+
if (arg.type === 'Literal') {
|
|
57
|
+
reportIfColorLiteral(context, arg, arg.value);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
});
|