eslint-plugin-react-features 1.2.4 → 1.2.6
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/package.json +21 -19
- package/src/index.d.ts +15 -2074
- package/src/index.js +1 -36
- package/src/oxlint.d.ts +17 -20
- package/src/oxlint.js +0 -18
- package/src/rules/component-api/no-arbitrary-token-class.js +0 -11
- package/src/rules/component-api/no-default-test-id.js +0 -7
- package/src/rules/component-api/no-inline-style.js +0 -6
- package/src/rules/component-api/no-is-prefix-prop.js +0 -7
- package/src/rules/component-api/no-kind-prop-discriminator.js +0 -5
- package/src/rules/component-api/no-raw-color-literal.js +0 -8
- package/src/rules/component-api/no-wrapper-sub-component.js +0 -8
- package/src/rules/component-api/require-data-slot.js +0 -5
- package/src/rules/migration/react-class-to-hooks.js +1 -26
- package/src/rules/performance/no-unnecessary-rerenders.js +1 -32
- package/src/rules/performance/react-no-inline-functions.js +2 -29
- package/src/rules/performance/react-render-optimization.js +1 -40
- package/src/rules/react/checked-requires-onchange-or-readonly.js +0 -7
- package/src/rules/react/default-props-match-prop-types.js +2 -23
- package/src/rules/react/display-name.js +1 -33
- package/src/rules/react/hooks-exhaustive-deps.js +1 -90
- package/src/rules/react/jsx-handler-names.js +0 -8
- package/src/rules/react/jsx-key.js +0 -84
- package/src/rules/react/jsx-max-depth.js +0 -10
- package/src/rules/react/jsx-no-bind.js +0 -10
- package/src/rules/react/jsx-no-duplicate-props.js +0 -5
- package/src/rules/react/jsx-no-literals.js +0 -5
- package/src/rules/react/jsx-no-script-url.js +0 -16
- package/src/rules/react/jsx-no-target-blank.js +1 -20
- package/src/rules/react/no-access-state-in-setstate.js +0 -13
- package/src/rules/react/no-adjacent-inline-elements.js +0 -10
- package/src/rules/react/no-arrow-function-lifecycle.js +0 -7
- package/src/rules/react/no-children-prop.js +0 -7
- package/src/rules/react/no-danger-with-children.js +0 -13
- package/src/rules/react/no-danger.js +0 -5
- package/src/rules/react/no-deprecated.js +0 -11
- package/src/rules/react/no-did-mount-set-state.js +0 -6
- package/src/rules/react/no-did-update-set-state.js +0 -10
- package/src/rules/react/no-direct-mutation-state.js +3 -29
- package/src/rules/react/no-find-dom-node.js +0 -7
- package/src/rules/react/no-invalid-html-attribute.js +36 -41
- package/src/rules/react/no-is-mounted.js +0 -7
- package/src/rules/react/no-multi-comp.js +0 -14
- package/src/rules/react/no-namespace.js +0 -5
- package/src/rules/react/no-object-type-as-default-prop.js +0 -9
- package/src/rules/react/no-redundant-should-component-update.js +0 -6
- package/src/rules/react/no-render-return-value.js +1 -9
- package/src/rules/react/no-set-state.js +0 -6
- package/src/rules/react/no-string-refs.js +0 -8
- package/src/rules/react/no-this-in-sfc.js +0 -11
- package/src/rules/react/no-typos.js +1 -9
- package/src/rules/react/no-unescaped-entities.js +0 -7
- package/src/rules/react/no-unknown-property.js +0 -13
- package/src/rules/react/no-unsafe.js +0 -7
- package/src/rules/react/prefer-es6-class.js +0 -7
- package/src/rules/react/prefer-stateless-function.js +0 -13
- package/src/rules/react/prop-types.js +0 -12
- package/src/rules/react/react-in-jsx-scope.js +0 -9
- package/src/rules/react/require-default-props.js +0 -19
- package/src/rules/react/require-optimization.js +6 -44
- package/src/rules/react/require-render-return.js +0 -9
- package/src/rules/react/required-attributes.js +0 -34
- package/src/rules/react/sort-comp.js +1 -19
- package/src/rules/react/state-in-constructor.js +0 -11
- package/src/rules/react/static-property-placement.js +1 -21
- package/src/rules/react/void-dom-elements-no-children.js +0 -7
- package/src/types/index.js +0 -5
- package/CHANGELOG.md +0 -236
- package/src/rules/component-api/no-arbitrary-token-class.d.ts +0 -17
- package/src/rules/component-api/no-default-test-id.d.ts +0 -15
- package/src/rules/component-api/no-inline-style.d.ts +0 -15
- package/src/rules/component-api/no-is-prefix-prop.d.ts +0 -17
- package/src/rules/component-api/no-kind-prop-discriminator.d.ts +0 -25
- package/src/rules/component-api/no-raw-color-literal.d.ts +0 -16
- package/src/rules/component-api/no-wrapper-sub-component.d.ts +0 -23
- package/src/rules/component-api/require-data-slot.d.ts +0 -15
- package/src/rules/migration/react-class-to-hooks.d.ts +0 -22
- package/src/rules/performance/no-unnecessary-rerenders.d.ts +0 -26
- package/src/rules/performance/react-no-inline-functions.d.ts +0 -24
- package/src/rules/performance/react-render-optimization.d.ts +0 -31
- package/src/rules/react/checked-requires-onchange-or-readonly.d.ts +0 -16
- package/src/rules/react/default-props-match-prop-types.d.ts +0 -13
- package/src/rules/react/display-name.d.ts +0 -13
- package/src/rules/react/hooks-exhaustive-deps.d.ts +0 -25
- package/src/rules/react/jsx-handler-names.d.ts +0 -13
- package/src/rules/react/jsx-key.d.ts +0 -20
- package/src/rules/react/jsx-max-depth.d.ts +0 -19
- package/src/rules/react/jsx-no-bind.d.ts +0 -13
- package/src/rules/react/jsx-no-duplicate-props.d.ts +0 -21
- package/src/rules/react/jsx-no-literals.d.ts +0 -20
- package/src/rules/react/jsx-no-script-url.d.ts +0 -25
- package/src/rules/react/jsx-no-target-blank.d.ts +0 -26
- package/src/rules/react/no-access-state-in-setstate.d.ts +0 -13
- package/src/rules/react/no-adjacent-inline-elements.d.ts +0 -13
- package/src/rules/react/no-arrow-function-lifecycle.d.ts +0 -13
- package/src/rules/react/no-children-prop.d.ts +0 -13
- package/src/rules/react/no-danger-with-children.d.ts +0 -16
- package/src/rules/react/no-danger.d.ts +0 -13
- package/src/rules/react/no-deprecated.d.ts +0 -16
- package/src/rules/react/no-did-mount-set-state.d.ts +0 -13
- package/src/rules/react/no-did-update-set-state.d.ts +0 -19
- package/src/rules/react/no-direct-mutation-state.d.ts +0 -20
- package/src/rules/react/no-find-dom-node.d.ts +0 -15
- package/src/rules/react/no-invalid-html-attribute.d.ts +0 -13
- package/src/rules/react/no-is-mounted.d.ts +0 -13
- package/src/rules/react/no-multi-comp.d.ts +0 -18
- package/src/rules/react/no-namespace.d.ts +0 -13
- package/src/rules/react/no-object-type-as-default-prop.d.ts +0 -13
- package/src/rules/react/no-redundant-should-component-update.d.ts +0 -13
- package/src/rules/react/no-render-return-value.d.ts +0 -13
- package/src/rules/react/no-set-state.d.ts +0 -13
- package/src/rules/react/no-string-refs.d.ts +0 -13
- package/src/rules/react/no-this-in-sfc.d.ts +0 -13
- package/src/rules/react/no-typos.d.ts +0 -13
- package/src/rules/react/no-unescaped-entities.d.ts +0 -13
- package/src/rules/react/no-unknown-property.d.ts +0 -13
- package/src/rules/react/no-unsafe.d.ts +0 -20
- package/src/rules/react/prefer-es6-class.d.ts +0 -13
- package/src/rules/react/prefer-stateless-function.d.ts +0 -16
- package/src/rules/react/prop-types.d.ts +0 -18
- package/src/rules/react/react-in-jsx-scope.d.ts +0 -13
- package/src/rules/react/require-default-props.d.ts +0 -16
- package/src/rules/react/require-optimization.d.ts +0 -26
- package/src/rules/react/require-render-return.d.ts +0 -13
- package/src/rules/react/required-attributes.d.ts +0 -28
- package/src/rules/react/sort-comp.d.ts +0 -17
- package/src/rules/react/state-in-constructor.d.ts +0 -13
- package/src/rules/react/static-property-placement.d.ts +0 -20
- package/src/rules/react/void-dom-elements-no-children.d.ts +0 -15
package/src/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.configs = exports.plugin = exports.rules = void 0;
|
|
9
|
-
// React rules
|
|
10
4
|
const required_attributes_1 = require("./rules/react/required-attributes");
|
|
11
5
|
const jsx_key_1 = require("./rules/react/jsx-key");
|
|
12
6
|
const no_direct_mutation_state_1 = require("./rules/react/no-direct-mutation-state");
|
|
@@ -48,23 +42,18 @@ const sort_comp_1 = require("./rules/react/sort-comp");
|
|
|
48
42
|
const state_in_constructor_1 = require("./rules/react/state-in-constructor");
|
|
49
43
|
const static_property_placement_1 = require("./rules/react/static-property-placement");
|
|
50
44
|
const hooks_exhaustive_deps_1 = require("./rules/react/hooks-exhaustive-deps");
|
|
51
|
-
// Security rules
|
|
52
45
|
const jsx_no_target_blank_1 = require("./rules/react/jsx-no-target-blank");
|
|
53
46
|
const jsx_no_script_url_1 = require("./rules/react/jsx-no-script-url");
|
|
54
47
|
const jsx_no_duplicate_props_1 = require("./rules/react/jsx-no-duplicate-props");
|
|
55
48
|
const no_danger_with_children_1 = require("./rules/react/no-danger-with-children");
|
|
56
49
|
const no_deprecated_1 = require("./rules/react/no-deprecated");
|
|
57
|
-
// Deprecated API rules
|
|
58
50
|
const no_find_dom_node_1 = require("./rules/react/no-find-dom-node");
|
|
59
51
|
const no_unsafe_1 = require("./rules/react/no-unsafe");
|
|
60
52
|
const void_dom_elements_no_children_1 = require("./rules/react/void-dom-elements-no-children");
|
|
61
|
-
// Migration rules
|
|
62
53
|
const react_class_to_hooks_1 = require("./rules/migration/react-class-to-hooks");
|
|
63
|
-
// React Performance rules
|
|
64
54
|
const no_unnecessary_rerenders_1 = require("./rules/performance/no-unnecessary-rerenders");
|
|
65
55
|
const react_render_optimization_1 = require("./rules/performance/react-render-optimization");
|
|
66
56
|
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
57
|
const no_default_test_id_1 = require("./rules/component-api/no-default-test-id");
|
|
69
58
|
const require_data_slot_1 = require("./rules/component-api/require-data-slot");
|
|
70
59
|
const no_is_prefix_prop_1 = require("./rules/component-api/no-is-prefix-prop");
|
|
@@ -74,7 +63,6 @@ const no_arbitrary_token_class_1 = require("./rules/component-api/no-arbitrary-t
|
|
|
74
63
|
const no_kind_prop_discriminator_1 = require("./rules/component-api/no-kind-prop-discriminator");
|
|
75
64
|
const no_wrapper_sub_component_1 = require("./rules/component-api/no-wrapper-sub-component");
|
|
76
65
|
exports.rules = {
|
|
77
|
-
// Flat names
|
|
78
66
|
'required-attributes': required_attributes_1.requiredAttributes,
|
|
79
67
|
'jsx-key': jsx_key_1.jsxKey,
|
|
80
68
|
'no-direct-mutation-state': no_direct_mutation_state_1.noDirectMutationState,
|
|
@@ -116,13 +104,11 @@ exports.rules = {
|
|
|
116
104
|
'state-in-constructor': state_in_constructor_1.stateInConstructor,
|
|
117
105
|
'static-property-placement': static_property_placement_1.staticPropertyPlacement,
|
|
118
106
|
'hooks-exhaustive-deps': hooks_exhaustive_deps_1.hooksExhaustiveDeps,
|
|
119
|
-
// Security and bug prevention
|
|
120
107
|
'jsx-no-target-blank': jsx_no_target_blank_1.jsxNoTargetBlank,
|
|
121
108
|
'jsx-no-script-url': jsx_no_script_url_1.jsxNoScriptUrl,
|
|
122
109
|
'jsx-no-duplicate-props': jsx_no_duplicate_props_1.jsxNoDuplicateProps,
|
|
123
110
|
'no-danger-with-children': no_danger_with_children_1.noDangerWithChildren,
|
|
124
111
|
'no-deprecated': no_deprecated_1.noDeprecated,
|
|
125
|
-
// Deprecated API rules
|
|
126
112
|
'no-find-dom-node': no_find_dom_node_1.noFindDomNode,
|
|
127
113
|
'no-unsafe': no_unsafe_1.noUnsafe,
|
|
128
114
|
'void-dom-elements-no-children': void_dom_elements_no_children_1.voidDomElementsNoChildren,
|
|
@@ -130,7 +116,6 @@ exports.rules = {
|
|
|
130
116
|
'no-unnecessary-rerenders': no_unnecessary_rerenders_1.noUnnecessaryRerenders,
|
|
131
117
|
'react-render-optimization': react_render_optimization_1.reactRenderOptimization,
|
|
132
118
|
'react-no-inline-functions': react_no_inline_functions_1.reactNoInlineFunctions,
|
|
133
|
-
// Component-API (flat)
|
|
134
119
|
'no-default-test-id': no_default_test_id_1.noDefaultTestId,
|
|
135
120
|
'require-data-slot': require_data_slot_1.requireDataSlot,
|
|
136
121
|
'no-is-prefix-prop': no_is_prefix_prop_1.noIsPrefixProp,
|
|
@@ -139,7 +124,6 @@ exports.rules = {
|
|
|
139
124
|
'no-arbitrary-token-class': no_arbitrary_token_class_1.noArbitraryTokenClass,
|
|
140
125
|
'no-kind-prop-discriminator': no_kind_prop_discriminator_1.noKindPropDiscriminator,
|
|
141
126
|
'no-wrapper-sub-component': no_wrapper_sub_component_1.noWrapperSubComponent,
|
|
142
|
-
// Categorized names
|
|
143
127
|
'react/required-attributes': required_attributes_1.requiredAttributes,
|
|
144
128
|
'react/jsx-key': jsx_key_1.jsxKey,
|
|
145
129
|
'react/no-direct-mutation-state': no_direct_mutation_state_1.noDirectMutationState,
|
|
@@ -181,13 +165,11 @@ exports.rules = {
|
|
|
181
165
|
'react/state-in-constructor': state_in_constructor_1.stateInConstructor,
|
|
182
166
|
'react/static-property-placement': static_property_placement_1.staticPropertyPlacement,
|
|
183
167
|
'react/hooks-exhaustive-deps': hooks_exhaustive_deps_1.hooksExhaustiveDeps,
|
|
184
|
-
// Security and bug prevention (categorized)
|
|
185
168
|
'react/jsx-no-target-blank': jsx_no_target_blank_1.jsxNoTargetBlank,
|
|
186
169
|
'react/jsx-no-script-url': jsx_no_script_url_1.jsxNoScriptUrl,
|
|
187
170
|
'react/jsx-no-duplicate-props': jsx_no_duplicate_props_1.jsxNoDuplicateProps,
|
|
188
171
|
'react/no-danger-with-children': no_danger_with_children_1.noDangerWithChildren,
|
|
189
172
|
'react/no-deprecated': no_deprecated_1.noDeprecated,
|
|
190
|
-
// Deprecated API rules (categorized)
|
|
191
173
|
'react/no-find-dom-node': no_find_dom_node_1.noFindDomNode,
|
|
192
174
|
'react/no-unsafe': no_unsafe_1.noUnsafe,
|
|
193
175
|
'react/void-dom-elements-no-children': void_dom_elements_no_children_1.voidDomElementsNoChildren,
|
|
@@ -195,7 +177,6 @@ exports.rules = {
|
|
|
195
177
|
'performance/no-unnecessary-rerenders': no_unnecessary_rerenders_1.noUnnecessaryRerenders,
|
|
196
178
|
'performance/react-render-optimization': react_render_optimization_1.reactRenderOptimization,
|
|
197
179
|
'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
180
|
'component-api/no-default-test-id': no_default_test_id_1.noDefaultTestId,
|
|
200
181
|
'component-api/require-data-slot': require_data_slot_1.requireDataSlot,
|
|
201
182
|
'component-api/no-is-prefix-prop': no_is_prefix_prop_1.noIsPrefixProp,
|
|
@@ -208,17 +189,11 @@ exports.rules = {
|
|
|
208
189
|
exports.plugin = {
|
|
209
190
|
meta: {
|
|
210
191
|
name: 'eslint-plugin-react-features',
|
|
211
|
-
version: '1.2.
|
|
192
|
+
version: '1.2.6',
|
|
212
193
|
},
|
|
213
194
|
rules: exports.rules,
|
|
214
195
|
};
|
|
215
196
|
exports.configs = {
|
|
216
|
-
/**
|
|
217
|
-
* Flagship preset — the rule from this plugin in the ecosystem-wide
|
|
218
|
-
* flagship list (`.agent/flagship-rules.md`). Head-to-head with
|
|
219
|
-
* `react-hooks/exhaustive-deps` — same scope, more permissive context
|
|
220
|
-
* detection (catches non-array deps, TS `as const` cast deps).
|
|
221
|
-
*/
|
|
222
197
|
flagship: {
|
|
223
198
|
plugins: {
|
|
224
199
|
'react-features': exports.plugin,
|
|
@@ -238,23 +213,13 @@ exports.configs = {
|
|
|
238
213
|
'react-features/no-string-refs': 'error',
|
|
239
214
|
'react-features/no-unknown-property': 'error',
|
|
240
215
|
'react-features/hooks-exhaustive-deps': 'warn',
|
|
241
|
-
// Security rules
|
|
242
216
|
'react-features/jsx-no-target-blank': 'error',
|
|
243
217
|
'react-features/jsx-no-script-url': 'error',
|
|
244
218
|
'react-features/jsx-no-duplicate-props': 'error',
|
|
245
219
|
'react-features/no-danger-with-children': 'error',
|
|
246
220
|
'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
221
|
},
|
|
251
222
|
},
|
|
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
223
|
componentApi: {
|
|
259
224
|
plugins: {
|
|
260
225
|
'react-features': exports.plugin,
|
package/src/oxlint.d.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
import { plugin } from './index';
|
|
20
|
-
export = plugin;
|
|
1
|
+
// Minimal declaration written by scripts/build-package.ts.
|
|
2
|
+
//
|
|
3
|
+
// tsc's generated entry declaration inlined every inferred rule-option type
|
|
4
|
+
// (up to 166 kB per plugin) for an API no consumer calls directly. This types
|
|
5
|
+
// what a flat config actually touches. Per-rule option types remain available
|
|
6
|
+
// from the "./types" subpath export where a plugin provides one.
|
|
7
|
+
import type { Linter, Rule } from 'eslint';
|
|
8
|
+
|
|
9
|
+
export declare const rules: Record<string, Rule.RuleModule>;
|
|
10
|
+
export declare const configs: Record<string, Linter.Config>;
|
|
11
|
+
export declare const plugin: {
|
|
12
|
+
meta: { name: string; version: string };
|
|
13
|
+
rules: Record<string, Rule.RuleModule>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare const _default: typeof plugin;
|
|
17
|
+
export default _default;
|
package/src/oxlint.js
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
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
|
-
/**
|
|
8
|
-
* oxlint sub-export.
|
|
9
|
-
*
|
|
10
|
-
* Consumers wire oxlint to this entry via:
|
|
11
|
-
* { "jsPlugins": ["eslint-plugin-react-features/oxlint"] }
|
|
12
|
-
*
|
|
13
|
-
* oxlint's JS plugin loader does `require('eslint-plugin-react-features/oxlint')` and reads
|
|
14
|
-
* `.rules` off the result. The compiled output of `export = plugin` is
|
|
15
|
-
* `module.exports = plugin`, which gives oxlint the plugin object directly
|
|
16
|
-
* (`{ meta, rules }`) — no wrapper, no `.default` indirection.
|
|
17
|
-
*
|
|
18
|
-
* Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
|
|
19
|
-
*/
|
|
20
2
|
const index_1 = require("./index");
|
|
21
3
|
module.exports = index_1.plugin;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noArbitraryTokenClass = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -15,10 +10,7 @@ const TOKENIZABLE_PROPS = new Set([
|
|
|
15
10
|
'mx', 'my', 'mt', 'mb', 'ml', 'mr', 'm',
|
|
16
11
|
'gap', 'gap-x', 'gap-y',
|
|
17
12
|
'space-x', 'space-y',
|
|
18
|
-
// Sizing handled separately — only flag when the arbitrary value is a token-able pixel size
|
|
19
13
|
]);
|
|
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
14
|
const ARBITRARY_CLASS_PATTERN = /([\w-]+)-\[([^\]]+)\]/g;
|
|
23
15
|
const TOKENIZABLE_VALUE = /^\d+(?:\.\d+)?(?:px|rem|em)$/;
|
|
24
16
|
exports.noArbitraryTokenClass = (0, eslint_devkit_1.createRule)({
|
|
@@ -58,16 +50,13 @@ exports.noArbitraryTokenClass = (0, eslint_devkit_1.createRule)({
|
|
|
58
50
|
}
|
|
59
51
|
};
|
|
60
52
|
return {
|
|
61
|
-
// className="..." string literal
|
|
62
53
|
'JSXAttribute[name.name="className"] > Literal'(node) {
|
|
63
54
|
if (typeof node.value === 'string')
|
|
64
55
|
scanString(node, node.value);
|
|
65
56
|
},
|
|
66
|
-
// className={`...`} template literal (static parts only)
|
|
67
57
|
'JSXAttribute[name.name="className"] TemplateElement'(node) {
|
|
68
58
|
scanString(node, node.value.cooked);
|
|
69
59
|
},
|
|
70
|
-
// cn("...", "...") / clsx(...) string args
|
|
71
60
|
CallExpression(node) {
|
|
72
61
|
if (node.callee.type !== 'Identifier')
|
|
73
62
|
return;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noDefaultTestId = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -32,7 +27,6 @@ exports.noDefaultTestId = (0, eslint_devkit_1.createRule)({
|
|
|
32
27
|
create(context) {
|
|
33
28
|
return {
|
|
34
29
|
Property(node) {
|
|
35
|
-
// Match `"data-testid": x = "..."` in destructuring patterns
|
|
36
30
|
if (node.key.type !== 'Literal' || node.key.value !== 'data-testid')
|
|
37
31
|
return;
|
|
38
32
|
if (node.value.type !== 'AssignmentPattern')
|
|
@@ -42,7 +36,6 @@ exports.noDefaultTestId = (0, eslint_devkit_1.createRule)({
|
|
|
42
36
|
node: assignment,
|
|
43
37
|
messageId: 'defaultTestId',
|
|
44
38
|
fix(fixer) {
|
|
45
|
-
// Replace `x = "..."` with just `x` — drop the default.
|
|
46
39
|
const bindingText = context.sourceCode.getText(assignment.left);
|
|
47
40
|
return fixer.replaceText(assignment, bindingText);
|
|
48
41
|
},
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noInlineStyle = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -52,7 +47,6 @@ exports.noInlineStyle = (0, eslint_devkit_1.createRule)({
|
|
|
52
47
|
const expr = node.value.expression;
|
|
53
48
|
if (expr.type !== 'ObjectExpression')
|
|
54
49
|
return;
|
|
55
|
-
// Report only when at least one property is a static literal AND not a CSS variable assignment.
|
|
56
50
|
const hasStaticNonVarProp = expr.properties.some((p) => !isCssVariableKey(p) && isStaticLiteralValue(p));
|
|
57
51
|
if (hasStaticNonVarProp) {
|
|
58
52
|
context.report({ node, messageId: 'inlineStyle' });
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noIsPrefixProp = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -48,8 +43,6 @@ exports.noIsPrefixProp = (0, eslint_devkit_1.createRule)({
|
|
|
48
43
|
node: keyNode,
|
|
49
44
|
messageId: 'isPrefix',
|
|
50
45
|
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
46
|
suggest: [
|
|
54
47
|
{
|
|
55
48
|
messageId: 'renameSuggestion',
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noKindPropDiscriminator = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noRawColorLiteral = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -37,15 +32,12 @@ exports.noRawColorLiteral = (0, eslint_devkit_1.createRule)({
|
|
|
37
32
|
defaultOptions: [],
|
|
38
33
|
create(context) {
|
|
39
34
|
return {
|
|
40
|
-
// Color inside JSX attribute string values (className="text-[#fff]", style="...")
|
|
41
35
|
'JSXAttribute > Literal'(node) {
|
|
42
36
|
reportIfColorLiteral(context, node, node.value);
|
|
43
37
|
},
|
|
44
|
-
// Color inside `style={{ color: "#fff" }}` and similar
|
|
45
38
|
'JSXExpressionContainer ObjectExpression > Property > Literal'(node) {
|
|
46
39
|
reportIfColorLiteral(context, node, node.value);
|
|
47
40
|
},
|
|
48
|
-
// Color inside cn()/clsx()/twMerge() args: cn("text-[#fff]")
|
|
49
41
|
CallExpression(node) {
|
|
50
42
|
if (node.callee.type !== 'Identifier')
|
|
51
43
|
return;
|
|
@@ -1,17 +1,10 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noWrapperSubComponent = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
5
|
const isPassthroughBody = (body) => {
|
|
11
|
-
// Arrow function with concise body: () => <X {...props} />
|
|
12
6
|
if (body.type === 'JSXElement')
|
|
13
7
|
return body;
|
|
14
|
-
// Block body with a single return statement
|
|
15
8
|
if (body.type !== 'BlockStatement')
|
|
16
9
|
return null;
|
|
17
10
|
if (body.body.length !== 1)
|
|
@@ -32,7 +25,6 @@ const isSpreadOnlyJsx = (el) => {
|
|
|
32
25
|
return false;
|
|
33
26
|
if (attr.argument.type !== 'Identifier')
|
|
34
27
|
return false;
|
|
35
|
-
// children must be empty (self-closing or empty)
|
|
36
28
|
return el.children.length === 0;
|
|
37
29
|
};
|
|
38
30
|
const isPascalCaseIdentifier = (s) => /^[A-Z]/.test(s);
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.requireDataSlot = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.reactClassToHooks = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -21,7 +16,6 @@ exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
|
21
16
|
fixable: 'code',
|
|
22
17
|
hasSuggestions: true,
|
|
23
18
|
messages: {
|
|
24
|
-
// 🎯 Token optimization: 44% reduction (64→36 tokens) - class to hooks migration simplified
|
|
25
19
|
migrateToHooks: (0, eslint_devkit_1.formatLLMMessage)({
|
|
26
20
|
icon: eslint_devkit_1.MessageIcons.MIGRATION,
|
|
27
21
|
issueName: 'React class component',
|
|
@@ -73,22 +67,15 @@ exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
|
73
67
|
],
|
|
74
68
|
create(context) {
|
|
75
69
|
const options = context.options[0] || {};
|
|
76
|
-
// `options` is always an object here (`|| {}` above), so no second fallback.
|
|
77
70
|
const { allowComplexLifecycle = false } = options;
|
|
78
71
|
const sourceCode = context.sourceCode;
|
|
79
|
-
/**
|
|
80
|
-
* Check if class extends React.Component
|
|
81
|
-
*/
|
|
82
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
83
72
|
const isReactComponent = (node) => {
|
|
84
73
|
if (!node.superClass)
|
|
85
74
|
return false;
|
|
86
|
-
// Check for Identifier (e.g., Component, PureComponent)
|
|
87
75
|
if (node.superClass.type === 'Identifier') {
|
|
88
76
|
return (node.superClass.name === 'Component' ||
|
|
89
77
|
node.superClass.name === 'PureComponent');
|
|
90
78
|
}
|
|
91
|
-
// Check for MemberExpression (e.g., React.Component, React.PureComponent)
|
|
92
79
|
if (node.superClass.type === 'MemberExpression') {
|
|
93
80
|
if (node.superClass.object.type === 'Identifier' &&
|
|
94
81
|
node.superClass.object.name === 'React' &&
|
|
@@ -99,10 +86,6 @@ exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
|
99
86
|
}
|
|
100
87
|
return false;
|
|
101
88
|
};
|
|
102
|
-
/**
|
|
103
|
-
* Analyze lifecycle methods used
|
|
104
|
-
*/
|
|
105
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
106
89
|
const analyzeLifecycleMethods = (node) => {
|
|
107
90
|
const lifecycleMethods = [];
|
|
108
91
|
const classBody = node.body.body;
|
|
@@ -112,7 +95,7 @@ exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
|
112
95
|
componentWillUnmount: 'useEffect cleanup',
|
|
113
96
|
shouldComponentUpdate: 'React.memo',
|
|
114
97
|
getDerivedStateFromProps: 'useState + useEffect',
|
|
115
|
-
getSnapshotBeforeUpdate: 'useEffect',
|
|
98
|
+
getSnapshotBeforeUpdate: 'useEffect',
|
|
116
99
|
};
|
|
117
100
|
for (const member of classBody) {
|
|
118
101
|
if (member.type === 'MethodDefinition' &&
|
|
@@ -141,11 +124,9 @@ exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
|
141
124
|
return;
|
|
142
125
|
const componentName = node.id.name;
|
|
143
126
|
const { complexity, methods: lifecycleMethods } = analyzeLifecycleMethods(node);
|
|
144
|
-
// Check if component has render() method (fixer doesn't handle it properly)
|
|
145
127
|
const hasRenderMethod = node.body.body.some((member) => member.type === 'MethodDefinition' &&
|
|
146
128
|
member.key.type === 'Identifier' &&
|
|
147
129
|
member.key.name === 'render');
|
|
148
|
-
// Skip if too complex and option is set
|
|
149
130
|
if (complexity === 'complex' && allowComplexLifecycle) {
|
|
150
131
|
return;
|
|
151
132
|
}
|
|
@@ -156,19 +137,13 @@ exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
|
156
137
|
componentName,
|
|
157
138
|
complexity,
|
|
158
139
|
},
|
|
159
|
-
// Only provide suggestions for simple components without lifecycle methods or render()
|
|
160
|
-
// The fixer doesn't work properly for components with lifecycle methods or render()
|
|
161
140
|
...(complexity === 'simple' && lifecycleMethods.length === 0 && !hasRenderMethod ? {
|
|
162
141
|
suggest: [
|
|
163
142
|
{
|
|
164
143
|
messageId: 'convertToFunction',
|
|
165
144
|
fix: (fixer) => {
|
|
166
|
-
// Simple auto-fix for basic components
|
|
167
145
|
const classText = sourceCode.getText(node);
|
|
168
|
-
// This is a simplified transformation
|
|
169
|
-
// Real implementation would need more sophisticated AST manipulation
|
|
170
146
|
const funcText = classText
|
|
171
|
-
// Match: class Name extends React.Component or class Name extends Component
|
|
172
147
|
.replace(/class\s+(\w+)\s+extends\s+(\w+\.)?\w+/, 'function $1(props)')
|
|
173
148
|
.replace(/this\.props\./g, 'props.')
|
|
174
149
|
.replace(/this\.state\.(\w+)/g, (_, name) => name);
|
|
@@ -1,20 +1,9 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noUnnecessaryRerenders = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
5
|
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
-
/**
|
|
12
|
-
* Check if a node is in a React component render context
|
|
13
|
-
*/
|
|
14
6
|
function isInReactRenderContext(node) {
|
|
15
|
-
// `current` is `node` on entry and only ever reassigned from `parent` after
|
|
16
|
-
// an explicit `if (!parent) break;`, so it's never null at the loop check
|
|
17
|
-
// (CodeQL: `js/useless-conditional` on the `current &&` test).
|
|
18
7
|
let current = node;
|
|
19
8
|
let depth = 0;
|
|
20
9
|
const maxDepth = 15;
|
|
@@ -22,25 +11,20 @@ function isInReactRenderContext(node) {
|
|
|
22
11
|
const parent = current.parent;
|
|
23
12
|
if (!parent)
|
|
24
13
|
break;
|
|
25
|
-
// Check if we're in JSX
|
|
26
14
|
if (parent.type === 'JSXElement' || parent.type === 'JSXFragment') {
|
|
27
15
|
return true;
|
|
28
16
|
}
|
|
29
|
-
// Check if we're in a JSX attribute
|
|
30
17
|
if (parent.type === 'JSXAttribute') {
|
|
31
18
|
return true;
|
|
32
19
|
}
|
|
33
|
-
// Check if we're in a function that's likely a React component
|
|
34
20
|
if (parent.type === 'FunctionDeclaration' || parent.type === 'FunctionExpression' ||
|
|
35
21
|
parent.type === 'ArrowFunctionExpression') {
|
|
36
|
-
// Check function name patterns (Component, useCallback, etc.)
|
|
37
22
|
if (parent.type === 'FunctionDeclaration' && parent.id) {
|
|
38
23
|
const name = parent.id.name;
|
|
39
|
-
if (name && /^[A-Z]/.test(name)) {
|
|
24
|
+
if (name && /^[A-Z]/.test(name)) {
|
|
40
25
|
return true;
|
|
41
26
|
}
|
|
42
27
|
}
|
|
43
|
-
// Check for JSX return statement
|
|
44
28
|
const body = parent.type === 'FunctionDeclaration' ? parent.body :
|
|
45
29
|
parent.type === 'FunctionExpression' ? parent.body :
|
|
46
30
|
parent.body;
|
|
@@ -58,21 +42,15 @@ function isInReactRenderContext(node) {
|
|
|
58
42
|
}
|
|
59
43
|
return false;
|
|
60
44
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Check if expression should be memoized
|
|
63
|
-
*/
|
|
64
45
|
function shouldBeMemoized(node, minSize = 5) {
|
|
65
|
-
// Check for object literals - only if they have at least minSize properties
|
|
66
46
|
if (node.type === 'ObjectExpression') {
|
|
67
47
|
const properties = node.properties.length;
|
|
68
48
|
return properties >= minSize;
|
|
69
49
|
}
|
|
70
|
-
// Check for array literals - only if they have at least minSize elements
|
|
71
50
|
if (node.type === 'ArrayExpression') {
|
|
72
51
|
const elements = node.elements.filter((el) => el !== null).length;
|
|
73
52
|
return elements >= minSize;
|
|
74
53
|
}
|
|
75
|
-
// Check for function expressions in JSX props (always report, size doesn't matter)
|
|
76
54
|
if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {
|
|
77
55
|
return true;
|
|
78
56
|
}
|
|
@@ -148,16 +126,11 @@ exports.noUnnecessaryRerenders = (0, eslint_devkit_2.createRule)({
|
|
|
148
126
|
create(context, [options = {}]) {
|
|
149
127
|
const { ignoreInTests = true, minSize = 5 } = options || {};
|
|
150
128
|
const filename = context.filename;
|
|
151
|
-
// Only skip if ignoreInTests is true AND filename matches test pattern
|
|
152
|
-
// If ignoreInTests is explicitly false, always run the rule
|
|
153
129
|
const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
154
130
|
if (isTestFile) {
|
|
155
131
|
return {};
|
|
156
132
|
}
|
|
157
133
|
const sourceCode = context.sourceCode;
|
|
158
|
-
/**
|
|
159
|
-
* Check JSX attributes for unnecessary re-renders
|
|
160
|
-
*/
|
|
161
134
|
function checkJSXAttribute(node) {
|
|
162
135
|
try {
|
|
163
136
|
if (!node.value) {
|
|
@@ -169,11 +142,9 @@ exports.noUnnecessaryRerenders = (0, eslint_devkit_2.createRule)({
|
|
|
169
142
|
if (!value) {
|
|
170
143
|
return;
|
|
171
144
|
}
|
|
172
|
-
// Only check if we're in a React render context
|
|
173
145
|
if (!isInReactRenderContext(value)) {
|
|
174
146
|
return;
|
|
175
147
|
}
|
|
176
|
-
// Check if it's an object/array literal or function that should be memoized
|
|
177
148
|
if (shouldBeMemoized(value, minSize)) {
|
|
178
149
|
let expressionText = '';
|
|
179
150
|
try {
|
|
@@ -182,7 +153,6 @@ exports.noUnnecessaryRerenders = (0, eslint_devkit_2.createRule)({
|
|
|
182
153
|
catch {
|
|
183
154
|
expressionText = 'expression';
|
|
184
155
|
}
|
|
185
|
-
// Determine which suggestion to use based on node type
|
|
186
156
|
const isFunction = value.type === 'ArrowFunctionExpression' || value.type === 'FunctionExpression';
|
|
187
157
|
const firstSuggestionMessageId = isFunction ? 'useCallback' : 'useMemo';
|
|
188
158
|
context.report({
|
|
@@ -205,7 +175,6 @@ exports.noUnnecessaryRerenders = (0, eslint_devkit_2.createRule)({
|
|
|
205
175
|
}
|
|
206
176
|
}
|
|
207
177
|
catch {
|
|
208
|
-
// Silently skip if there's an error processing this attribute
|
|
209
178
|
return;
|
|
210
179
|
}
|
|
211
180
|
}
|