eslint-plugin-react-features 1.7.11 → 1.8.0
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 +25 -0
- package/package.json +5 -2
- package/src/index.js +1 -1
- package/src/rules/component-api/no-arbitrary-token-class.js +1 -1
- package/src/rules/component-api/no-default-test-id.js +1 -1
- package/src/rules/component-api/no-inline-style.js +1 -1
- package/src/rules/component-api/no-is-prefix-prop.js +1 -1
- package/src/rules/component-api/no-kind-prop-discriminator.js +1 -1
- package/src/rules/component-api/no-raw-color-literal.js +1 -1
- package/src/rules/component-api/no-wrapper-sub-component.js +1 -1
- package/src/rules/component-api/require-data-slot.js +1 -1
- package/src/rules/migration/react-class-to-hooks.js +1 -1
- package/src/rules/performance/no-unnecessary-rerenders.js +1 -1
- package/src/rules/performance/react-no-inline-functions.js +1 -1
- package/src/rules/performance/react-render-optimization.js +1 -1
- package/src/rules/react/checked-requires-onchange-or-readonly.js +1 -1
- package/src/rules/react/default-props-match-prop-types.js +1 -1
- package/src/rules/react/display-name.js +1 -1
- package/src/rules/react/hooks-exhaustive-deps.js +1 -1
- package/src/rules/react/jsx-handler-names.js +1 -1
- package/src/rules/react/jsx-key.js +1 -1
- package/src/rules/react/jsx-max-depth.js +1 -1
- package/src/rules/react/jsx-no-bind.js +1 -1
- package/src/rules/react/jsx-no-duplicate-props.js +1 -1
- package/src/rules/react/jsx-no-literals.js +1 -1
- package/src/rules/react/jsx-no-script-url.js +0 -0
- package/src/rules/react/jsx-no-target-blank.js +1 -1
- package/src/rules/react/no-access-state-in-setstate.js +1 -1
- package/src/rules/react/no-adjacent-inline-elements.js +1 -1
- package/src/rules/react/no-arrow-function-lifecycle.js +1 -1
- package/src/rules/react/no-children-prop.js +1 -1
- package/src/rules/react/no-danger-with-children.js +1 -1
- package/src/rules/react/no-danger.js +1 -1
- package/src/rules/react/no-deprecated.js +1 -1
- package/src/rules/react/no-did-mount-set-state.js +1 -1
- package/src/rules/react/no-did-update-set-state.js +1 -1
- package/src/rules/react/no-direct-mutation-state.js +2 -2
- package/src/rules/react/no-find-dom-node.js +1 -1
- package/src/rules/react/no-invalid-html-attribute.js +1 -1
- package/src/rules/react/no-is-mounted.js +1 -1
- package/src/rules/react/no-multi-comp.js +1 -1
- package/src/rules/react/no-namespace.js +1 -1
- package/src/rules/react/no-object-type-as-default-prop.js +1 -1
- package/src/rules/react/no-redundant-should-component-update.js +1 -1
- package/src/rules/react/no-render-return-value.js +1 -1
- package/src/rules/react/no-set-state.js +1 -1
- package/src/rules/react/no-string-refs.js +1 -1
- package/src/rules/react/no-this-in-sfc.js +1 -1
- package/src/rules/react/no-typos.js +1 -1
- package/src/rules/react/no-unescaped-entities.js +1 -1
- package/src/rules/react/no-unknown-property.js +1 -1
- package/src/rules/react/no-unsafe.js +1 -1
- package/src/rules/react/prefer-es6-class.js +1 -1
- package/src/rules/react/prefer-stateless-function.js +1 -1
- package/src/rules/react/prop-types.js +1 -1
- package/src/rules/react/react-in-jsx-scope.js +1 -1
- package/src/rules/react/require-default-props.js +1 -1
- package/src/rules/react/require-optimization.js +1 -1
- package/src/rules/react/require-render-return.js +1 -1
- package/src/rules/react/required-attributes.js +1 -1
- package/src/rules/react/sort-comp.js +1 -1
- package/src/rules/react/state-in-constructor.js +1 -1
- package/src/rules/react/static-property-placement.js +1 -1
- package/src/rules/react/void-dom-elements-no-children.js +1 -1
package/README.md
CHANGED
|
@@ -48,10 +48,34 @@ That trade costs recall, and we measure it:
|
|
|
48
48
|
|
|
49
49
|
- To check out the [guide](https://eslint.interlace.tools/docs/quality/plugin-react-features?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-react-features), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-react-features). 📚
|
|
50
50
|
|
|
51
|
+
<!-- AUTO-GENERATED:INSTALL:START - Do not edit manually -->
|
|
52
|
+
|
|
53
|
+
**oxlint / Vite+** — the same rules under the same `react-features/<rule>` IDs, without ESLint:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install oxlint-plugin-react-features --save-dev
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```jsonc
|
|
60
|
+
// .oxlintrc.json
|
|
61
|
+
{ "jsPlugins": ["oxlint-plugin-react-features"] }
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// vite.config.ts
|
|
66
|
+
import { defineConfig } from 'vite-plus';
|
|
67
|
+
|
|
68
|
+
export default defineConfig({ lint: { jsPlugins: ['oxlint-plugin-react-features'] } });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**ESLint:**
|
|
72
|
+
|
|
51
73
|
```bash
|
|
52
74
|
npm install eslint-plugin-react-features --save-dev
|
|
53
75
|
```
|
|
54
76
|
|
|
77
|
+
<!-- AUTO-GENERATED:INSTALL:END -->
|
|
78
|
+
|
|
55
79
|
## ⚙️ Configuration Presets
|
|
56
80
|
| Preset | Description |
|
|
57
81
|
| :------------ | :----------------------------------------------- |
|
|
@@ -182,6 +206,7 @@ Part of the **Interlace ESLint ecosystem** — AI-native rules with LLM-optimize
|
|
|
182
206
|
|
|
183
207
|
| Plugin | Downloads | Description |
|
|
184
208
|
| :--- | :---: | :--- |
|
|
209
|
+
| [`eslint-plugin-cli-floor`](https://www.npmjs.com/package/eslint-plugin-cli-floor) | [](https://www.npmjs.com/package/eslint-plugin-cli-floor) | CLI floor for commander, yargs and burgee. |
|
|
185
210
|
| [`eslint-plugin-conventions`](https://www.npmjs.com/package/eslint-plugin-conventions) | [](https://www.npmjs.com/package/eslint-plugin-conventions) | Team-specific habits and styles. |
|
|
186
211
|
| [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [](https://www.npmjs.com/package/eslint-plugin-import-next) | Fast cycle + import-graph analysis. |
|
|
187
212
|
| [`eslint-plugin-maintainability`](https://www.npmjs.com/package/eslint-plugin-maintainability) | [](https://www.npmjs.com/package/eslint-plugin-maintainability) | Cognitive load and clean-code patterns. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-features",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "ESLint plugin for React — hooks, prop-types, JSX correctness, render performance, and class-to-hooks migration rules for modern React codebases.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -61,6 +61,9 @@
|
|
|
61
61
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
|
+
"eslint": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
64
67
|
"typescript": {
|
|
65
68
|
"optional": true
|
|
66
69
|
},
|
|
@@ -69,7 +72,7 @@
|
|
|
69
72
|
}
|
|
70
73
|
},
|
|
71
74
|
"dependencies": {
|
|
72
|
-
"@interlace/eslint-devkit": "^1.
|
|
75
|
+
"@interlace/eslint-devkit": "^1.21.0"
|
|
73
76
|
},
|
|
74
77
|
"repository": {
|
|
75
78
|
"type": "git",
|
package/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.rules={get"required-attributes"(){return require("./rules/react/required-attributes").requiredAttributes},get"jsx-key"(){return require("./rules/react/jsx-key").jsxKey},get"no-direct-mutation-state"(){return require("./rules/react/no-direct-mutation-state").noDirectMutationState},get"require-optimization"(){return require("./rules/react/require-optimization").requireOptimization},get"no-set-state"(){return require("./rules/react/no-set-state").noSetState},get"no-this-in-sfc"(){return require("./rules/react/no-this-in-sfc").noThisInSfc},get"no-access-state-in-setstate"(){return require("./rules/react/no-access-state-in-setstate").noAccessStateInSetState},get"no-children-prop"(){return require("./rules/react/no-children-prop").noChildrenProp},get"no-danger"(){return require("./rules/react/no-danger").noDanger},get"no-string-refs"(){return require("./rules/react/no-string-refs").noStringRefs},get"no-unknown-property"(){return require("./rules/react/no-unknown-property").noUnknownProperty},get"checked-requires-onchange-or-readonly"(){return require("./rules/react/checked-requires-onchange-or-readonly").checkedRequiresOnchangeOrReadonly},get"default-props-match-prop-types"(){return require("./rules/react/default-props-match-prop-types").defaultPropsMatchPropTypes},get"display-name"(){return require("./rules/react/display-name").displayName},get"jsx-handler-names"(){return require("./rules/react/jsx-handler-names").jsxHandlerNames},get"jsx-max-depth"(){return require("./rules/react/jsx-max-depth").jsxMaxDepth},get"jsx-no-bind"(){return require("./rules/react/jsx-no-bind").jsxNoBind},get"jsx-no-literals"(){return require("./rules/react/jsx-no-literals").jsxNoLiterals},get"no-adjacent-inline-elements"(){return require("./rules/react/no-adjacent-inline-elements").noAdjacentInlineElements},get"no-arrow-function-lifecycle"(){return require("./rules/react/no-arrow-function-lifecycle").noArrowFunctionLifecycle},get"no-did-mount-set-state"(){return require("./rules/react/no-did-mount-set-state").noDidMountSetState},get"no-did-update-set-state"(){return require("./rules/react/no-did-update-set-state").noDidUpdateSetState},get"no-invalid-html-attribute"(){return require("./rules/react/no-invalid-html-attribute").noInvalidHtmlAttribute},get"no-is-mounted"(){return require("./rules/react/no-is-mounted").noIsMounted},get"no-multi-comp"(){return require("./rules/react/no-multi-comp").noMultiComp},get"no-namespace"(){return require("./rules/react/no-namespace").noNamespace},get"no-object-type-as-default-prop"(){return require("./rules/react/no-object-type-as-default-prop").noObjectTypeAsDefaultProp},get"no-redundant-should-component-update"(){return require("./rules/react/no-redundant-should-component-update").noRedundantShouldComponentUpdate},get"no-render-return-value"(){return require("./rules/react/no-render-return-value").noRenderReturnValue},get"no-typos"(){return require("./rules/react/no-typos").noTypos},get"no-unescaped-entities"(){return require("./rules/react/no-unescaped-entities").noUnescapedEntities},get"prefer-es6-class"(){return require("./rules/react/prefer-es6-class").preferEs6Class},get"prefer-stateless-function"(){return require("./rules/react/prefer-stateless-function").preferStatelessFunction},get"prop-types"(){return require("./rules/react/prop-types").propTypes},get"react-in-jsx-scope"(){return require("./rules/react/react-in-jsx-scope").reactInJsxScope},get"require-default-props"(){return require("./rules/react/require-default-props").requireDefaultProps},get"require-render-return"(){return require("./rules/react/require-render-return").requireRenderReturn},get"sort-comp"(){return require("./rules/react/sort-comp").sortComp},get"state-in-constructor"(){return require("./rules/react/state-in-constructor").stateInConstructor},get"static-property-placement"(){return require("./rules/react/static-property-placement").staticPropertyPlacement},get"hooks-exhaustive-deps"(){return require("./rules/react/hooks-exhaustive-deps").hooksExhaustiveDeps},get"jsx-no-target-blank"(){return require("./rules/react/jsx-no-target-blank").jsxNoTargetBlank},get"jsx-no-script-url"(){return require("./rules/react/jsx-no-script-url").jsxNoScriptUrl},get"jsx-no-duplicate-props"(){return require("./rules/react/jsx-no-duplicate-props").jsxNoDuplicateProps},get"no-danger-with-children"(){return require("./rules/react/no-danger-with-children").noDangerWithChildren},get"no-deprecated"(){return require("./rules/react/no-deprecated").noDeprecated},get"no-find-dom-node"(){return require("./rules/react/no-find-dom-node").noFindDomNode},get"no-unsafe"(){return require("./rules/react/no-unsafe").noUnsafe},get"void-dom-elements-no-children"(){return require("./rules/react/void-dom-elements-no-children").voidDomElementsNoChildren},get"react-class-to-hooks"(){return require("./rules/migration/react-class-to-hooks").reactClassToHooks},get"no-unnecessary-rerenders"(){return require("./rules/performance/no-unnecessary-rerenders").noUnnecessaryRerenders},get"react-render-optimization"(){return require("./rules/performance/react-render-optimization").reactRenderOptimization},get"react-no-inline-functions"(){return require("./rules/performance/react-no-inline-functions").reactNoInlineFunctions},get"no-default-test-id"(){return require("./rules/component-api/no-default-test-id").noDefaultTestId},get"require-data-slot"(){return require("./rules/component-api/require-data-slot").requireDataSlot},get"no-is-prefix-prop"(){return require("./rules/component-api/no-is-prefix-prop").noIsPrefixProp},get"no-inline-style"(){return require("./rules/component-api/no-inline-style").noInlineStyle},get"no-raw-color-literal"(){return require("./rules/component-api/no-raw-color-literal").noRawColorLiteral},get"no-arbitrary-token-class"(){return require("./rules/component-api/no-arbitrary-token-class").noArbitraryTokenClass},get"no-kind-prop-discriminator"(){return require("./rules/component-api/no-kind-prop-discriminator").noKindPropDiscriminator},get"no-wrapper-sub-component"(){return require("./rules/component-api/no-wrapper-sub-component").noWrapperSubComponent},get"react/required-attributes"(){return require("./rules/react/required-attributes").requiredAttributes},get"react/jsx-key"(){return require("./rules/react/jsx-key").jsxKey},get"react/no-direct-mutation-state"(){return require("./rules/react/no-direct-mutation-state").noDirectMutationState},get"react/require-optimization"(){return require("./rules/react/require-optimization").requireOptimization},get"react/no-set-state"(){return require("./rules/react/no-set-state").noSetState},get"react/no-this-in-sfc"(){return require("./rules/react/no-this-in-sfc").noThisInSfc},get"react/no-access-state-in-setstate"(){return require("./rules/react/no-access-state-in-setstate").noAccessStateInSetState},get"react/no-children-prop"(){return require("./rules/react/no-children-prop").noChildrenProp},get"react/no-danger"(){return require("./rules/react/no-danger").noDanger},get"react/no-string-refs"(){return require("./rules/react/no-string-refs").noStringRefs},get"react/no-unknown-property"(){return require("./rules/react/no-unknown-property").noUnknownProperty},get"react/checked-requires-onchange-or-readonly"(){return require("./rules/react/checked-requires-onchange-or-readonly").checkedRequiresOnchangeOrReadonly},get"react/default-props-match-prop-types"(){return require("./rules/react/default-props-match-prop-types").defaultPropsMatchPropTypes},get"react/display-name"(){return require("./rules/react/display-name").displayName},get"react/jsx-handler-names"(){return require("./rules/react/jsx-handler-names").jsxHandlerNames},get"react/jsx-max-depth"(){return require("./rules/react/jsx-max-depth").jsxMaxDepth},get"react/jsx-no-bind"(){return require("./rules/react/jsx-no-bind").jsxNoBind},get"react/jsx-no-literals"(){return require("./rules/react/jsx-no-literals").jsxNoLiterals},get"react/no-adjacent-inline-elements"(){return require("./rules/react/no-adjacent-inline-elements").noAdjacentInlineElements},get"react/no-arrow-function-lifecycle"(){return require("./rules/react/no-arrow-function-lifecycle").noArrowFunctionLifecycle},get"react/no-did-mount-set-state"(){return require("./rules/react/no-did-mount-set-state").noDidMountSetState},get"react/no-did-update-set-state"(){return require("./rules/react/no-did-update-set-state").noDidUpdateSetState},get"react/no-invalid-html-attribute"(){return require("./rules/react/no-invalid-html-attribute").noInvalidHtmlAttribute},get"react/no-is-mounted"(){return require("./rules/react/no-is-mounted").noIsMounted},get"react/no-multi-comp"(){return require("./rules/react/no-multi-comp").noMultiComp},get"react/no-namespace"(){return require("./rules/react/no-namespace").noNamespace},get"react/no-object-type-as-default-prop"(){return require("./rules/react/no-object-type-as-default-prop").noObjectTypeAsDefaultProp},get"react/no-redundant-should-component-update"(){return require("./rules/react/no-redundant-should-component-update").noRedundantShouldComponentUpdate},get"react/no-render-return-value"(){return require("./rules/react/no-render-return-value").noRenderReturnValue},get"react/no-typos"(){return require("./rules/react/no-typos").noTypos},get"react/no-unescaped-entities"(){return require("./rules/react/no-unescaped-entities").noUnescapedEntities},get"react/prefer-es6-class"(){return require("./rules/react/prefer-es6-class").preferEs6Class},get"react/prefer-stateless-function"(){return require("./rules/react/prefer-stateless-function").preferStatelessFunction},get"react/prop-types"(){return require("./rules/react/prop-types").propTypes},get"react/react-in-jsx-scope"(){return require("./rules/react/react-in-jsx-scope").reactInJsxScope},get"react/require-default-props"(){return require("./rules/react/require-default-props").requireDefaultProps},get"react/require-render-return"(){return require("./rules/react/require-render-return").requireRenderReturn},get"react/sort-comp"(){return require("./rules/react/sort-comp").sortComp},get"react/state-in-constructor"(){return require("./rules/react/state-in-constructor").stateInConstructor},get"react/static-property-placement"(){return require("./rules/react/static-property-placement").staticPropertyPlacement},get"react/hooks-exhaustive-deps"(){return require("./rules/react/hooks-exhaustive-deps").hooksExhaustiveDeps},get"react/jsx-no-target-blank"(){return require("./rules/react/jsx-no-target-blank").jsxNoTargetBlank},get"react/jsx-no-script-url"(){return require("./rules/react/jsx-no-script-url").jsxNoScriptUrl},get"react/jsx-no-duplicate-props"(){return require("./rules/react/jsx-no-duplicate-props").jsxNoDuplicateProps},get"react/no-danger-with-children"(){return require("./rules/react/no-danger-with-children").noDangerWithChildren},get"react/no-deprecated"(){return require("./rules/react/no-deprecated").noDeprecated},get"react/no-find-dom-node"(){return require("./rules/react/no-find-dom-node").noFindDomNode},get"react/no-unsafe"(){return require("./rules/react/no-unsafe").noUnsafe},get"react/void-dom-elements-no-children"(){return require("./rules/react/void-dom-elements-no-children").voidDomElementsNoChildren},get"migration/react-class-to-hooks"(){return require("./rules/migration/react-class-to-hooks").reactClassToHooks},get"performance/no-unnecessary-rerenders"(){return require("./rules/performance/no-unnecessary-rerenders").noUnnecessaryRerenders},get"performance/react-render-optimization"(){return require("./rules/performance/react-render-optimization").reactRenderOptimization},get"performance/react-no-inline-functions"(){return require("./rules/performance/react-no-inline-functions").reactNoInlineFunctions},get"component-api/no-default-test-id"(){return require("./rules/component-api/no-default-test-id").noDefaultTestId},get"component-api/require-data-slot"(){return require("./rules/component-api/require-data-slot").requireDataSlot},get"component-api/no-is-prefix-prop"(){return require("./rules/component-api/no-is-prefix-prop").noIsPrefixProp},get"component-api/no-inline-style"(){return require("./rules/component-api/no-inline-style").noInlineStyle},get"component-api/no-raw-color-literal"(){return require("./rules/component-api/no-raw-color-literal").noRawColorLiteral},get"component-api/no-arbitrary-token-class"(){return require("./rules/component-api/no-arbitrary-token-class").noArbitraryTokenClass},get"component-api/no-kind-prop-discriminator"(){return require("./rules/component-api/no-kind-prop-discriminator").noKindPropDiscriminator},get"component-api/no-wrapper-sub-component"(){return require("./rules/component-api/no-wrapper-sub-component").noWrapperSubComponent}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-react-features",exports.rules);exports.plugin={meta:{name:"eslint-plugin-react-features",version:"1.7.11"},rules:exports.rules};exports.configs={flagship:{plugins:{"react-features":exports.plugin},rules:{"react-features/hooks-exhaustive-deps":"error"}},recommended:{plugins:{"react-features":exports.plugin},rules:{"react-features/jsx-key":"error","react-features/no-children-prop":"warn","react-features/no-danger":"warn","react-features/no-string-refs":"error","react-features/no-unknown-property":"error","react-features/hooks-exhaustive-deps":"warn","react-features/jsx-no-target-blank":"error","react-features/jsx-no-script-url":"error","react-features/jsx-no-duplicate-props":"error","react-features/no-danger-with-children":"error","react-features/no-deprecated":"warn"}},componentApi:{plugins:{"react-features":exports.plugin},rules:{"react-features/component-api/no-default-test-id":"error","react-features/component-api/require-data-slot":"warn","react-features/component-api/no-is-prefix-prop":"warn","react-features/component-api/no-inline-style":"warn","react-features/component-api/no-raw-color-literal":"warn","react-features/component-api/no-arbitrary-token-class":"warn","react-features/component-api/no-kind-prop-discriminator":"warn","react-features/component-api/no-wrapper-sub-component":"warn"}}};exports.default=exports.plugin;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.rules={get"required-attributes"(){return require("./rules/react/required-attributes").requiredAttributes},get"jsx-key"(){return require("./rules/react/jsx-key").jsxKey},get"no-direct-mutation-state"(){return require("./rules/react/no-direct-mutation-state").noDirectMutationState},get"require-optimization"(){return require("./rules/react/require-optimization").requireOptimization},get"no-set-state"(){return require("./rules/react/no-set-state").noSetState},get"no-this-in-sfc"(){return require("./rules/react/no-this-in-sfc").noThisInSfc},get"no-access-state-in-setstate"(){return require("./rules/react/no-access-state-in-setstate").noAccessStateInSetState},get"no-children-prop"(){return require("./rules/react/no-children-prop").noChildrenProp},get"no-danger"(){return require("./rules/react/no-danger").noDanger},get"no-string-refs"(){return require("./rules/react/no-string-refs").noStringRefs},get"no-unknown-property"(){return require("./rules/react/no-unknown-property").noUnknownProperty},get"checked-requires-onchange-or-readonly"(){return require("./rules/react/checked-requires-onchange-or-readonly").checkedRequiresOnchangeOrReadonly},get"default-props-match-prop-types"(){return require("./rules/react/default-props-match-prop-types").defaultPropsMatchPropTypes},get"display-name"(){return require("./rules/react/display-name").displayName},get"jsx-handler-names"(){return require("./rules/react/jsx-handler-names").jsxHandlerNames},get"jsx-max-depth"(){return require("./rules/react/jsx-max-depth").jsxMaxDepth},get"jsx-no-bind"(){return require("./rules/react/jsx-no-bind").jsxNoBind},get"jsx-no-literals"(){return require("./rules/react/jsx-no-literals").jsxNoLiterals},get"no-adjacent-inline-elements"(){return require("./rules/react/no-adjacent-inline-elements").noAdjacentInlineElements},get"no-arrow-function-lifecycle"(){return require("./rules/react/no-arrow-function-lifecycle").noArrowFunctionLifecycle},get"no-did-mount-set-state"(){return require("./rules/react/no-did-mount-set-state").noDidMountSetState},get"no-did-update-set-state"(){return require("./rules/react/no-did-update-set-state").noDidUpdateSetState},get"no-invalid-html-attribute"(){return require("./rules/react/no-invalid-html-attribute").noInvalidHtmlAttribute},get"no-is-mounted"(){return require("./rules/react/no-is-mounted").noIsMounted},get"no-multi-comp"(){return require("./rules/react/no-multi-comp").noMultiComp},get"no-namespace"(){return require("./rules/react/no-namespace").noNamespace},get"no-object-type-as-default-prop"(){return require("./rules/react/no-object-type-as-default-prop").noObjectTypeAsDefaultProp},get"no-redundant-should-component-update"(){return require("./rules/react/no-redundant-should-component-update").noRedundantShouldComponentUpdate},get"no-render-return-value"(){return require("./rules/react/no-render-return-value").noRenderReturnValue},get"no-typos"(){return require("./rules/react/no-typos").noTypos},get"no-unescaped-entities"(){return require("./rules/react/no-unescaped-entities").noUnescapedEntities},get"prefer-es6-class"(){return require("./rules/react/prefer-es6-class").preferEs6Class},get"prefer-stateless-function"(){return require("./rules/react/prefer-stateless-function").preferStatelessFunction},get"prop-types"(){return require("./rules/react/prop-types").propTypes},get"react-in-jsx-scope"(){return require("./rules/react/react-in-jsx-scope").reactInJsxScope},get"require-default-props"(){return require("./rules/react/require-default-props").requireDefaultProps},get"require-render-return"(){return require("./rules/react/require-render-return").requireRenderReturn},get"sort-comp"(){return require("./rules/react/sort-comp").sortComp},get"state-in-constructor"(){return require("./rules/react/state-in-constructor").stateInConstructor},get"static-property-placement"(){return require("./rules/react/static-property-placement").staticPropertyPlacement},get"hooks-exhaustive-deps"(){return require("./rules/react/hooks-exhaustive-deps").hooksExhaustiveDeps},get"jsx-no-target-blank"(){return require("./rules/react/jsx-no-target-blank").jsxNoTargetBlank},get"jsx-no-script-url"(){return require("./rules/react/jsx-no-script-url").jsxNoScriptUrl},get"jsx-no-duplicate-props"(){return require("./rules/react/jsx-no-duplicate-props").jsxNoDuplicateProps},get"no-danger-with-children"(){return require("./rules/react/no-danger-with-children").noDangerWithChildren},get"no-deprecated"(){return require("./rules/react/no-deprecated").noDeprecated},get"no-find-dom-node"(){return require("./rules/react/no-find-dom-node").noFindDomNode},get"no-unsafe"(){return require("./rules/react/no-unsafe").noUnsafe},get"void-dom-elements-no-children"(){return require("./rules/react/void-dom-elements-no-children").voidDomElementsNoChildren},get"react-class-to-hooks"(){return require("./rules/migration/react-class-to-hooks").reactClassToHooks},get"no-unnecessary-rerenders"(){return require("./rules/performance/no-unnecessary-rerenders").noUnnecessaryRerenders},get"react-render-optimization"(){return require("./rules/performance/react-render-optimization").reactRenderOptimization},get"react-no-inline-functions"(){return require("./rules/performance/react-no-inline-functions").reactNoInlineFunctions},get"no-default-test-id"(){return require("./rules/component-api/no-default-test-id").noDefaultTestId},get"require-data-slot"(){return require("./rules/component-api/require-data-slot").requireDataSlot},get"no-is-prefix-prop"(){return require("./rules/component-api/no-is-prefix-prop").noIsPrefixProp},get"no-inline-style"(){return require("./rules/component-api/no-inline-style").noInlineStyle},get"no-raw-color-literal"(){return require("./rules/component-api/no-raw-color-literal").noRawColorLiteral},get"no-arbitrary-token-class"(){return require("./rules/component-api/no-arbitrary-token-class").noArbitraryTokenClass},get"no-kind-prop-discriminator"(){return require("./rules/component-api/no-kind-prop-discriminator").noKindPropDiscriminator},get"no-wrapper-sub-component"(){return require("./rules/component-api/no-wrapper-sub-component").noWrapperSubComponent},get"react/required-attributes"(){return require("./rules/react/required-attributes").requiredAttributes},get"react/jsx-key"(){return require("./rules/react/jsx-key").jsxKey},get"react/no-direct-mutation-state"(){return require("./rules/react/no-direct-mutation-state").noDirectMutationState},get"react/require-optimization"(){return require("./rules/react/require-optimization").requireOptimization},get"react/no-set-state"(){return require("./rules/react/no-set-state").noSetState},get"react/no-this-in-sfc"(){return require("./rules/react/no-this-in-sfc").noThisInSfc},get"react/no-access-state-in-setstate"(){return require("./rules/react/no-access-state-in-setstate").noAccessStateInSetState},get"react/no-children-prop"(){return require("./rules/react/no-children-prop").noChildrenProp},get"react/no-danger"(){return require("./rules/react/no-danger").noDanger},get"react/no-string-refs"(){return require("./rules/react/no-string-refs").noStringRefs},get"react/no-unknown-property"(){return require("./rules/react/no-unknown-property").noUnknownProperty},get"react/checked-requires-onchange-or-readonly"(){return require("./rules/react/checked-requires-onchange-or-readonly").checkedRequiresOnchangeOrReadonly},get"react/default-props-match-prop-types"(){return require("./rules/react/default-props-match-prop-types").defaultPropsMatchPropTypes},get"react/display-name"(){return require("./rules/react/display-name").displayName},get"react/jsx-handler-names"(){return require("./rules/react/jsx-handler-names").jsxHandlerNames},get"react/jsx-max-depth"(){return require("./rules/react/jsx-max-depth").jsxMaxDepth},get"react/jsx-no-bind"(){return require("./rules/react/jsx-no-bind").jsxNoBind},get"react/jsx-no-literals"(){return require("./rules/react/jsx-no-literals").jsxNoLiterals},get"react/no-adjacent-inline-elements"(){return require("./rules/react/no-adjacent-inline-elements").noAdjacentInlineElements},get"react/no-arrow-function-lifecycle"(){return require("./rules/react/no-arrow-function-lifecycle").noArrowFunctionLifecycle},get"react/no-did-mount-set-state"(){return require("./rules/react/no-did-mount-set-state").noDidMountSetState},get"react/no-did-update-set-state"(){return require("./rules/react/no-did-update-set-state").noDidUpdateSetState},get"react/no-invalid-html-attribute"(){return require("./rules/react/no-invalid-html-attribute").noInvalidHtmlAttribute},get"react/no-is-mounted"(){return require("./rules/react/no-is-mounted").noIsMounted},get"react/no-multi-comp"(){return require("./rules/react/no-multi-comp").noMultiComp},get"react/no-namespace"(){return require("./rules/react/no-namespace").noNamespace},get"react/no-object-type-as-default-prop"(){return require("./rules/react/no-object-type-as-default-prop").noObjectTypeAsDefaultProp},get"react/no-redundant-should-component-update"(){return require("./rules/react/no-redundant-should-component-update").noRedundantShouldComponentUpdate},get"react/no-render-return-value"(){return require("./rules/react/no-render-return-value").noRenderReturnValue},get"react/no-typos"(){return require("./rules/react/no-typos").noTypos},get"react/no-unescaped-entities"(){return require("./rules/react/no-unescaped-entities").noUnescapedEntities},get"react/prefer-es6-class"(){return require("./rules/react/prefer-es6-class").preferEs6Class},get"react/prefer-stateless-function"(){return require("./rules/react/prefer-stateless-function").preferStatelessFunction},get"react/prop-types"(){return require("./rules/react/prop-types").propTypes},get"react/react-in-jsx-scope"(){return require("./rules/react/react-in-jsx-scope").reactInJsxScope},get"react/require-default-props"(){return require("./rules/react/require-default-props").requireDefaultProps},get"react/require-render-return"(){return require("./rules/react/require-render-return").requireRenderReturn},get"react/sort-comp"(){return require("./rules/react/sort-comp").sortComp},get"react/state-in-constructor"(){return require("./rules/react/state-in-constructor").stateInConstructor},get"react/static-property-placement"(){return require("./rules/react/static-property-placement").staticPropertyPlacement},get"react/hooks-exhaustive-deps"(){return require("./rules/react/hooks-exhaustive-deps").hooksExhaustiveDeps},get"react/jsx-no-target-blank"(){return require("./rules/react/jsx-no-target-blank").jsxNoTargetBlank},get"react/jsx-no-script-url"(){return require("./rules/react/jsx-no-script-url").jsxNoScriptUrl},get"react/jsx-no-duplicate-props"(){return require("./rules/react/jsx-no-duplicate-props").jsxNoDuplicateProps},get"react/no-danger-with-children"(){return require("./rules/react/no-danger-with-children").noDangerWithChildren},get"react/no-deprecated"(){return require("./rules/react/no-deprecated").noDeprecated},get"react/no-find-dom-node"(){return require("./rules/react/no-find-dom-node").noFindDomNode},get"react/no-unsafe"(){return require("./rules/react/no-unsafe").noUnsafe},get"react/void-dom-elements-no-children"(){return require("./rules/react/void-dom-elements-no-children").voidDomElementsNoChildren},get"migration/react-class-to-hooks"(){return require("./rules/migration/react-class-to-hooks").reactClassToHooks},get"performance/no-unnecessary-rerenders"(){return require("./rules/performance/no-unnecessary-rerenders").noUnnecessaryRerenders},get"performance/react-render-optimization"(){return require("./rules/performance/react-render-optimization").reactRenderOptimization},get"performance/react-no-inline-functions"(){return require("./rules/performance/react-no-inline-functions").reactNoInlineFunctions},get"component-api/no-default-test-id"(){return require("./rules/component-api/no-default-test-id").noDefaultTestId},get"component-api/require-data-slot"(){return require("./rules/component-api/require-data-slot").requireDataSlot},get"component-api/no-is-prefix-prop"(){return require("./rules/component-api/no-is-prefix-prop").noIsPrefixProp},get"component-api/no-inline-style"(){return require("./rules/component-api/no-inline-style").noInlineStyle},get"component-api/no-raw-color-literal"(){return require("./rules/component-api/no-raw-color-literal").noRawColorLiteral},get"component-api/no-arbitrary-token-class"(){return require("./rules/component-api/no-arbitrary-token-class").noArbitraryTokenClass},get"component-api/no-kind-prop-discriminator"(){return require("./rules/component-api/no-kind-prop-discriminator").noKindPropDiscriminator},get"component-api/no-wrapper-sub-component"(){return require("./rules/component-api/no-wrapper-sub-component").noWrapperSubComponent}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-react-features",exports.rules);exports.plugin={meta:{name:"eslint-plugin-react-features",version:"1.8.0"},rules:exports.rules};exports.configs={flagship:{plugins:{"react-features":exports.plugin},rules:{"react-features/hooks-exhaustive-deps":"error"}},recommended:{plugins:{"react-features":exports.plugin},rules:{"react-features/jsx-key":"error","react-features/no-children-prop":"warn","react-features/no-danger":"warn","react-features/no-string-refs":"error","react-features/no-unknown-property":"error","react-features/hooks-exhaustive-deps":"warn","react-features/jsx-no-target-blank":"error","react-features/jsx-no-script-url":"error","react-features/jsx-no-duplicate-props":"error","react-features/no-danger-with-children":"error","react-features/no-deprecated":"warn"}},componentApi:{plugins:{"react-features":exports.plugin},rules:{"react-features/component-api/no-default-test-id":"error","react-features/component-api/require-data-slot":"warn","react-features/component-api/no-is-prefix-prop":"warn","react-features/component-api/no-inline-style":"warn","react-features/component-api/no-raw-color-literal":"warn","react-features/component-api/no-arbitrary-token-class":"warn","react-features/component-api/no-kind-prop-discriminator":"warn","react-features/component-api/no-wrapper-sub-component":"warn"}}};exports.default=exports.plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noArbitraryTokenClass=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const TOKENIZABLE_PROPS=new Set(["rounded","rounded-t","rounded-r","rounded-b","rounded-l","rounded-tl","rounded-tr","rounded-bl","rounded-br","px","py","pt","pb","pl","pr","p","mx","my","mt","mb","ml","mr","m","gap","gap-x","gap-y","space-x","space-y"]);const ARBITRARY_CLASS_PATTERN=/([\w-]+)-\[([^\]]+)\]/g;const TOKENIZABLE_VALUE=/^\d+(?:\.\d+)?(?:px|rem|em)$/;exports.noArbitraryTokenClass=(0,eslint_devkit_1.createRule)({name:"no-arbitrary-token-class",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-arbitrary-token-class.md",description:"No Tailwind arbitrary values when a token exists for that property (R19)"},schema:[],messages:{arbitraryClass:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Arbitrary Tailwind class",description:"Arbitrary value `{{cls}}` \u2014 use a token or extend the theme (R19)",severity:"MEDIUM",fix:"Replace with the matching spacing/radius token or wire a `var(--token)` Tailwind class.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-arbitrary-token-class.md"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noArbitraryTokenClass=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const TOKENIZABLE_PROPS=new Set(["rounded","rounded-t","rounded-r","rounded-b","rounded-l","rounded-tl","rounded-tr","rounded-bl","rounded-br","px","py","pt","pb","pl","pr","p","mx","my","mt","mb","ml","mr","m","gap","gap-x","gap-y","space-x","space-y"]);const ARBITRARY_CLASS_PATTERN=/([\w-]+)-\[([^\]]+)\]/g;const TOKENIZABLE_VALUE=/^\d+(?:\.\d+)?(?:px|rem|em)$/;exports.noArbitraryTokenClass=(0,eslint_devkit_1.createRule)({name:"no-arbitrary-token-class",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-arbitrary-token-class.md",description:"No Tailwind arbitrary values when a token exists for that property (R19)"},schema:[],messages:{arbitraryClass:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Arbitrary Tailwind class",description:"Arbitrary value `{{cls}}` \u2014 use a token or extend the theme (R19)",severity:"MEDIUM",fix:"Replace with the matching spacing/radius token or wire a `var(--token)` Tailwind class.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-arbitrary-token-class.md"})}},defaultOptions:[],createOnce(context){const scanString=(node,raw)=>{for(const match of raw.matchAll(ARBITRARY_CLASS_PATTERN)){const[whole,prop,value]=match;if(!TOKENIZABLE_PROPS.has(prop))continue;if(!TOKENIZABLE_VALUE.test(value))continue;context.report({node,messageId:"arbitraryClass",data:{cls:whole}})}};return{'JSXAttribute[name.name="className"] > Literal'(node){if(typeof node.value==="string")scanString(node,node.value)},'JSXAttribute[name.name="className"] TemplateElement'(node){scanString(node,node.value.cooked??node.value.raw)},CallExpression(node){if(node.callee.type!=="Identifier")return;const name=node.callee.name;if(name!=="cn"&&name!=="clsx"&&name!=="twMerge"&&name!=="classNames")return;for(const arg of node.arguments){const staticText=(0,eslint_devkit_1.staticString)(arg);if(staticText!==null){scanString(arg,staticText)}}}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDefaultTestId=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noDefaultTestId=(0,eslint_devkit_1.createRule)({name:"no-default-test-id",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-default-test-id.md",description:"data-testid must be consumer-provided \u2014 no runtime default value (R5)"},fixable:"code",schema:[],messages:{defaultTestId:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"data-testid default value",description:"data-testid has a runtime default \u2014 consumer must provide it (R5)",severity:"HIGH",fix:"Remove the default. Require data-testid at the type level and let the consumer pass it.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-default-test-id.md"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDefaultTestId=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noDefaultTestId=(0,eslint_devkit_1.createRule)({name:"no-default-test-id",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-default-test-id.md",description:"data-testid must be consumer-provided \u2014 no runtime default value (R5)"},fixable:"code",schema:[],messages:{defaultTestId:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"data-testid default value",description:"data-testid has a runtime default \u2014 consumer must provide it (R5)",severity:"HIGH",fix:"Remove the default. Require data-testid at the type level and let the consumer pass it.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-default-test-id.md"})}},defaultOptions:[],createOnce(context){return{Property(node){if(node.key.type!=="Literal"||node.key.value!=="data-testid")return;if(node.value.type!=="AssignmentPattern")return;const assignment=node.value;context.report({node:assignment,messageId:"defaultTestId",fix(fixer){const bindingText=context.sourceCode.getText(assignment.left);return fixer.replaceText(assignment,bindingText)}})}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noInlineStyle=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const isCssVariableKey=prop=>{if(prop.type!=="Property")return false;const staticText=(0,eslint_devkit_1.staticString)(prop.key);if(staticText!==null){return staticText.startsWith("--")}return false};const isStaticLiteralValue=prop=>{if(prop.type!=="Property")return false;const v=prop.value;return v.type==="Literal"&&(typeof v.value==="string"||typeof v.value==="number")};exports.noInlineStyle=(0,eslint_devkit_1.createRule)({name:"no-inline-style",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-inline-style.md",description:"No inline `style={{}}` except for CSS-variable assignment (R18)"},schema:[],messages:{inlineStyle:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Inline style prop",description:"Inline `style={{}}` with static value(s) \u2014 use Tailwind classes (R18)",severity:"MEDIUM",fix:"Move the static value to a Tailwind class. Reserve inline style for CSS variables and computed dynamic values.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-inline-style.md"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noInlineStyle=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const isCssVariableKey=prop=>{if(prop.type!=="Property")return false;const staticText=(0,eslint_devkit_1.staticString)(prop.key);if(staticText!==null){return staticText.startsWith("--")}return false};const isStaticLiteralValue=prop=>{if(prop.type!=="Property")return false;const v=prop.value;return v.type==="Literal"&&(typeof v.value==="string"||typeof v.value==="number")};exports.noInlineStyle=(0,eslint_devkit_1.createRule)({name:"no-inline-style",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-inline-style.md",description:"No inline `style={{}}` except for CSS-variable assignment (R18)"},schema:[],messages:{inlineStyle:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Inline style prop",description:"Inline `style={{}}` with static value(s) \u2014 use Tailwind classes (R18)",severity:"MEDIUM",fix:"Move the static value to a Tailwind class. Reserve inline style for CSS variables and computed dynamic values.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-inline-style.md"})}},defaultOptions:[],createOnce(context){return{JSXAttribute(node){if(node.name.type!=="JSXIdentifier"||node.name.name!=="style")return;if(!node.value||node.value.type!=="JSXExpressionContainer")return;const expr=node.value.expression;if(expr.type!=="ObjectExpression")return;const hasStaticNonVarProp=expr.properties.some(p=>!isCssVariableKey(p)&&isStaticLiteralValue(p));if(hasStaticNonVarProp){context.report({node,messageId:"inlineStyle"})}}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noIsPrefixProp=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const stripIsPrefix=name=>{const rest=name.slice(2);const run=rest.length-rest.replace(/^[A-Z]+/,"").length;const lower=run>1&&/[a-z]/.test(rest[run]??"")?run-1:run;return rest.slice(0,lower).toLowerCase()+rest.slice(lower)};exports.noIsPrefixProp=(0,eslint_devkit_1.createRule)({name:"no-is-prefix-prop",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-is-prefix-prop.md",description:"Boolean props must not be prefixed with `is` (R8)"},hasSuggestions:true,schema:[],messages:{isPrefix:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"`is` prefix on boolean prop",description:"Boolean prop `{{name}}` should be renamed to `{{suggested}}` (R8)",severity:"MEDIUM",fix:"Rename to `{{suggested}}` \u2014 booleans describe the true state directly.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-is-prefix-prop.md"}),renameSuggestion:"Rename to `{{suggested}}` (also rename consumer call sites manually)"}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noIsPrefixProp=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const stripIsPrefix=name=>{const rest=name.slice(2);const run=rest.length-rest.replace(/^[A-Z]+/,"").length;const lower=run>1&&/[a-z]/.test(rest[run]??"")?run-1:run;return rest.slice(0,lower).toLowerCase()+rest.slice(lower)};exports.noIsPrefixProp=(0,eslint_devkit_1.createRule)({name:"no-is-prefix-prop",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-is-prefix-prop.md",description:"Boolean props must not be prefixed with `is` (R8)"},hasSuggestions:true,schema:[],messages:{isPrefix:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"`is` prefix on boolean prop",description:"Boolean prop `{{name}}` should be renamed to `{{suggested}}` (R8)",severity:"MEDIUM",fix:"Rename to `{{suggested}}` \u2014 booleans describe the true state directly.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-is-prefix-prop.md"}),renameSuggestion:"Rename to `{{suggested}}` (also rename consumer call sites manually)"}},defaultOptions:[],createOnce(context){return{TSPropertySignature(node){if(node.key.type!=="Identifier")return;const{name}=node.key;if(!/^is[A-Z]/.test(name))return;const ann=node.typeAnnotation?.typeAnnotation;if(!ann||ann.type!=="TSBooleanKeyword")return;const suggested=stripIsPrefix(name);const keyNode=node.key;context.report({node:keyNode,messageId:"isPrefix",data:{name,suggested},suggest:[{messageId:"renameSuggestion",data:{suggested},fix(fixer){return fixer.replaceText(keyNode,suggested)}}]})}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noKindPropDiscriminator=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const FLAGGED_NAMES=new Set(["type","kind"]);const isStringLiteralUnion=node=>{if(!node)return false;if(node.type!=="TSUnionType")return false;const members=node.types;if(members.length<2)return false;return members.every(m=>m.type==="TSLiteralType"&&m.literal.type==="Literal"&&typeof m.literal.value==="string")};exports.noKindPropDiscriminator=(0,eslint_devkit_1.createRule)({name:"no-kind-prop-discriminator",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-kind-prop-discriminator.md",description:"Ban `type`/`kind` string-union props that select between rendered trees (R11)"},schema:[],messages:{kindProp:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Kind-prop discriminator",description:'Prop `{{name}}: "A" | "B"` likely switches the rendered tree \u2014 split into sub-components (R11)',severity:"MEDIUM",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.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-kind-prop-discriminator.md"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noKindPropDiscriminator=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const FLAGGED_NAMES=new Set(["type","kind"]);const isStringLiteralUnion=node=>{if(!node)return false;if(node.type!=="TSUnionType")return false;const members=node.types;if(members.length<2)return false;return members.every(m=>m.type==="TSLiteralType"&&m.literal.type==="Literal"&&typeof m.literal.value==="string")};exports.noKindPropDiscriminator=(0,eslint_devkit_1.createRule)({name:"no-kind-prop-discriminator",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-kind-prop-discriminator.md",description:"Ban `type`/`kind` string-union props that select between rendered trees (R11)"},schema:[],messages:{kindProp:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Kind-prop discriminator",description:'Prop `{{name}}: "A" | "B"` likely switches the rendered tree \u2014 split into sub-components (R11)',severity:"MEDIUM",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.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-kind-prop-discriminator.md"})}},defaultOptions:[],createOnce(context){return{TSPropertySignature(node){if(node.key.type!=="Identifier")return;if(!FLAGGED_NAMES.has(node.key.name))return;const ann=node.typeAnnotation?.typeAnnotation;if(!isStringLiteralUnion(ann))return;context.report({node:node.key,messageId:"kindProp",data:{name:node.key.name}})}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noRawColorLiteral=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const COLOR_PATTERN=/(#[0-9a-fA-F]{3,8}\b|\b(?:rgba?|hsla?|oklch|oklab)\s*\()/;const isColorString=s=>COLOR_PATTERN.test(s);const reportIfColorLiteral=(context,node,value)=>{if(typeof value==="string"&&isColorString(value)){context.report({node,messageId:"rawColor"})}};exports.noRawColorLiteral=(0,eslint_devkit_1.createRule)({name:"no-raw-color-literal",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-raw-color-literal.md",description:"No raw hex / rgb / hsl / oklch color literals in source \u2014 use design tokens (R19)"},schema:[],messages:{rawColor:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Raw color literal",description:"Raw color literal in source \u2014 use a design token (R19)",severity:"MEDIUM",fix:"Replace with a CSS custom property (`var(--your-token)`) or a Tailwind theme class wired to it.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-raw-color-literal.md"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noRawColorLiteral=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const COLOR_PATTERN=/(#[0-9a-fA-F]{3,8}\b|\b(?:rgba?|hsla?|oklch|oklab)\s*\()/;const isColorString=s=>COLOR_PATTERN.test(s);const reportIfColorLiteral=(context,node,value)=>{if(typeof value==="string"&&isColorString(value)){context.report({node,messageId:"rawColor"})}};exports.noRawColorLiteral=(0,eslint_devkit_1.createRule)({name:"no-raw-color-literal",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-raw-color-literal.md",description:"No raw hex / rgb / hsl / oklch color literals in source \u2014 use design tokens (R19)"},schema:[],messages:{rawColor:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Raw color literal",description:"Raw color literal in source \u2014 use a design token (R19)",severity:"MEDIUM",fix:"Replace with a CSS custom property (`var(--your-token)`) or a Tailwind theme class wired to it.",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-raw-color-literal.md"})}},defaultOptions:[],createOnce(context){return{"JSXAttribute > Literal"(node){reportIfColorLiteral(context,node,node.value)},"JSXExpressionContainer ObjectExpression > Property > Literal"(node){reportIfColorLiteral(context,node,node.value)},CallExpression(node){if(node.callee.type!=="Identifier")return;const name=node.callee.name;if(name!=="cn"&&name!=="clsx"&&name!=="twMerge"&&name!=="classNames")return;for(const arg of node.arguments){if(arg.type==="Literal"){reportIfColorLiteral(context,arg,arg.value)}}}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noWrapperSubComponent=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const isPassthroughBody=body=>{if(body.type==="JSXElement")return body;if(body.type!=="BlockStatement")return null;if(body.body.length!==1)return null;const stmt=body.body[0];if(stmt.type!=="ReturnStatement")return null;if(!stmt.argument||stmt.argument.type!=="JSXElement")return null;return stmt.argument};const isSpreadOnlyJsx=el=>{const attrs=el.openingElement.attributes;if(attrs.length!==1)return false;const attr=attrs[0];if(attr.type!=="JSXSpreadAttribute")return false;if(attr.argument.type!=="Identifier")return false;return el.children.length===0};const isPascalCaseIdentifier=s=>/^[A-Z]/.test(s);const isPascalCaseJsxName=name=>{if(name.type==="JSXIdentifier")return isPascalCaseIdentifier(name.name);if(name.type==="JSXMemberExpression")return true;return false};exports.noWrapperSubComponent=(0,eslint_devkit_1.createRule)({name:"no-wrapper-sub-component",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-wrapper-sub-component.md",description:"Ban pure-passthrough wrapper sub-components \u2014 slot the primitive directly (R12)"},schema:[],messages:{wrapperSubComponent:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Passthrough wrapper component",description:"Component `{{name}}` is a pure passthrough wrapper \u2014 slot the primitive directly (R12)",severity:"MEDIUM",fix:"Delete the wrapper and let consumers import the primitive. If the wrapper must exist, give it structural behavior (a slot, a default prop, or composition logic).",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-wrapper-sub-component.md"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noWrapperSubComponent=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const isPassthroughBody=body=>{if(body.type==="JSXElement")return body;if(body.type!=="BlockStatement")return null;if(body.body.length!==1)return null;const stmt=body.body[0];if(stmt.type!=="ReturnStatement")return null;if(!stmt.argument||stmt.argument.type!=="JSXElement")return null;return stmt.argument};const isSpreadOnlyJsx=el=>{const attrs=el.openingElement.attributes;if(attrs.length!==1)return false;const attr=attrs[0];if(attr.type!=="JSXSpreadAttribute")return false;if(attr.argument.type!=="Identifier")return false;return el.children.length===0};const isPascalCaseIdentifier=s=>/^[A-Z]/.test(s);const isPascalCaseJsxName=name=>{if(name.type==="JSXIdentifier")return isPascalCaseIdentifier(name.name);if(name.type==="JSXMemberExpression")return true;return false};exports.noWrapperSubComponent=(0,eslint_devkit_1.createRule)({name:"no-wrapper-sub-component",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-wrapper-sub-component.md",description:"Ban pure-passthrough wrapper sub-components \u2014 slot the primitive directly (R12)"},schema:[],messages:{wrapperSubComponent:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Passthrough wrapper component",description:"Component `{{name}}` is a pure passthrough wrapper \u2014 slot the primitive directly (R12)",severity:"MEDIUM",fix:"Delete the wrapper and let consumers import the primitive. If the wrapper must exist, give it structural behavior (a slot, a default prop, or composition logic).",documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-wrapper-sub-component.md"})}},defaultOptions:[],createOnce(context){const checkFn=(node,name)=>{if(!isPascalCaseIdentifier(name))return;const jsx=isPassthroughBody(node.body);if(!jsx)return;if(!isSpreadOnlyJsx(jsx))return;if(!isPascalCaseJsxName(jsx.openingElement.name))return;context.report({node,messageId:"wrapperSubComponent",data:{name}})};return{FunctionDeclaration(node){if(!node.id)return;checkFn(node,node.id.name)},VariableDeclarator(node){if(node.id.type!=="Identifier")return;if(!node.init)return;if(node.init.type!=="ArrowFunctionExpression"&&node.init.type!=="FunctionExpression"){return}checkFn(node.init,node.id.name)}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireDataSlot=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const hasNamedAttribute=(node,name)=>node.attributes.some(attr=>attr.type==="JSXAttribute"&&attr.name.type==="JSXIdentifier"&&attr.name.name===name);exports.requireDataSlot=(0,eslint_devkit_1.createRule)({name:"require-data-slot",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/require-data-slot.md",description:"Named composition parts must carry data-slot (R6)"},schema:[],messages:{missingDataSlot:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Missing data-slot",description:"JSX element has data-testid but no data-slot (R6)",severity:"MEDIUM",fix:'Add `data-slot="<part-name>"` so consumers can style by slot.',documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/require-data-slot.md"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireDataSlot=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const hasNamedAttribute=(node,name)=>node.attributes.some(attr=>attr.type==="JSXAttribute"&&attr.name.type==="JSXIdentifier"&&attr.name.name===name);exports.requireDataSlot=(0,eslint_devkit_1.createRule)({name:"require-data-slot",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/require-data-slot.md",description:"Named composition parts must carry data-slot (R6)"},schema:[],messages:{missingDataSlot:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Missing data-slot",description:"JSX element has data-testid but no data-slot (R6)",severity:"MEDIUM",fix:'Add `data-slot="<part-name>"` so consumers can style by slot.',documentationLink:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/require-data-slot.md"})}},defaultOptions:[],createOnce(context){return{JSXOpeningElement(node){if(!hasNamedAttribute(node,"data-testid"))return;if(hasNamedAttribute(node,"data-slot"))return;context.report({node,messageId:"missingDataSlot"})}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.reactClassToHooks=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.reactClassToHooks=(0,eslint_devkit_2.createRule)({name:"react-class-to-hooks",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/react-class-to-hooks.md",description:"Suggest migrating React class components to hooks with detailed migration path",cwe:"CWE-1078",cvss:5},fixable:"code",hasSuggestions:true,messages:{migrateToHooks:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.MIGRATION,issueName:"React class component",cwe:"CWE-1078",description:"React class component detected",severity:"MEDIUM",fix:"Use functional component with useEffect/useState (Complexity: {{complexity}})",documentationLink:"https://react.dev/reference/react/hooks"}),convertToFunction:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Convert to Functional",description:"Convert to functional component with hooks",severity:"LOW",fix:"function Component() { const [state, setState] = useState() }",documentationLink:"https://react.dev/reference/react/hooks"}),viewMigrationGuide:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Migration Guide",description:"View detailed migration guide",severity:"LOW",fix:"Follow React hooks migration guide",documentationLink:"https://react.dev/reference/react/hooks"})},schema:[{type:"object",properties:{ignorePureRenderComponents:{type:"boolean",default:false},allowComplexLifecycle:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{ignorePureRenderComponents:false,allowComplexLifecycle:false}],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.reactClassToHooks=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.reactClassToHooks=(0,eslint_devkit_2.createRule)({name:"react-class-to-hooks",meta:{interop:{runtimes:["eslint","oxlint"]},type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/react-class-to-hooks.md",description:"Suggest migrating React class components to hooks with detailed migration path",cwe:"CWE-1078",cvss:5},fixable:"code",hasSuggestions:true,messages:{migrateToHooks:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.MIGRATION,issueName:"React class component",cwe:"CWE-1078",description:"React class component detected",severity:"MEDIUM",fix:"Use functional component with useEffect/useState (Complexity: {{complexity}})",documentationLink:"https://react.dev/reference/react/hooks"}),convertToFunction:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Convert to Functional",description:"Convert to functional component with hooks",severity:"LOW",fix:"function Component() { const [state, setState] = useState() }",documentationLink:"https://react.dev/reference/react/hooks"}),viewMigrationGuide:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Migration Guide",description:"View detailed migration guide",severity:"LOW",fix:"Follow React hooks migration guide",documentationLink:"https://react.dev/reference/react/hooks"})},schema:[{type:"object",properties:{ignorePureRenderComponents:{type:"boolean",default:false},allowComplexLifecycle:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{ignorePureRenderComponents:false,allowComplexLifecycle:false}],createOnce(context){let allowComplexLifecycle;let sourceCode;const isReactComponent=node=>{if(!node.superClass)return false;if(node.superClass.type===eslint_devkit_2.AST_NODE_TYPES.Identifier){return node.superClass.name==="Component"||node.superClass.name==="PureComponent"}if(node.superClass.type===eslint_devkit_2.AST_NODE_TYPES.MemberExpression){if(node.superClass.object.type===eslint_devkit_2.AST_NODE_TYPES.Identifier&&node.superClass.object.name==="React"){const base=(0,eslint_devkit_2.propertyName)(node.superClass);return base==="Component"||base==="PureComponent"}}return false};const analyzeLifecycleMethods=node=>{const lifecycleMethods=[];const classBody=node.body.body;const lifecycleMap={componentDidMount:"useEffect",componentDidUpdate:"useEffect",componentWillUnmount:"useEffect cleanup",shouldComponentUpdate:"React.memo",getDerivedStateFromProps:"useState + useEffect",getSnapshotBeforeUpdate:"useEffect"};for(const member of classBody){if(member.type===eslint_devkit_2.AST_NODE_TYPES.MethodDefinition&&member.key.type===eslint_devkit_2.AST_NODE_TYPES.Identifier&&lifecycleMap[member.key.name]){lifecycleMethods.push(member.key.name)}}const suggestedHooks=[...new Set(lifecycleMethods.map(m=>lifecycleMap[m]))];let complexity="simple";if(lifecycleMethods.length>2)complexity="medium";if(lifecycleMethods.includes("getDerivedStateFromProps")||lifecycleMethods.includes("getSnapshotBeforeUpdate")){complexity="complex"}return{methods:lifecycleMethods,suggestedHooks,complexity}};return{before(){const options=context.options[0]||{};({allowComplexLifecycle=false}=options);sourceCode=context.sourceCode},ClassDeclaration(node){if(!isReactComponent(node))return;if(!node.id)return;const componentName=node.id.name;const{complexity,methods:lifecycleMethods}=analyzeLifecycleMethods(node);const hasRenderMethod=node.body.body.some(member=>member.type===eslint_devkit_2.AST_NODE_TYPES.MethodDefinition&&(0,eslint_devkit_2.objectKeyName)(member)==="render");if(complexity==="complex"&&allowComplexLifecycle){return}context.report({node,messageId:"migrateToHooks",data:{componentName,complexity},...complexity==="simple"&&lifecycleMethods.length===0&&!hasRenderMethod?{suggest:[{messageId:"convertToFunction",fix:fixer=>{const classText=sourceCode.getText(node);const funcText=classText.replace(/class\s+(\w+)\s+extends\s+\w+(?:\s*\.\s*\w+|\s*\[\s*(['"])[^'"]+\2\s*\])?/,"function $1(props)").replace(/this\.props\./g,"props.").replace(/this\.state\.(\w+)/g,(_,name)=>name);return fixer.replaceText(node,funcText)}}]}:{}})}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnnecessaryRerenders=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function isInReactRenderContext(node){let current=node;let depth=0;const maxDepth=15;while(depth<maxDepth){const parent=current.parent;if(!parent)break;if(parent.type==="JSXElement"||parent.type==="JSXFragment"){return true}if(parent.type==="JSXAttribute"){return true}if(parent.type==="FunctionDeclaration"||parent.type==="FunctionExpression"||parent.type==="ArrowFunctionExpression"){if(parent.type==="FunctionDeclaration"&&parent.id){const name=parent.id.name;if(name&&/^[A-Z]/.test(name)){return true}}const body=parent.type==="FunctionDeclaration"?parent.body:parent.type==="FunctionExpression"?parent.body:parent.body;if(body&&body.type==="BlockStatement"){const hasJSX=body.body.some(stmt=>stmt.type==="ReturnStatement"&&stmt.argument&&(stmt.argument.type==="JSXElement"||stmt.argument.type==="JSXFragment"));if(hasJSX){return true}}}current=parent;depth++}return false}function shouldBeMemoized(node,minSize=5){if(node.type==="ObjectExpression"){const properties=node.properties.length;return properties>=minSize}if(node.type==="ArrayExpression"){const elements=node.elements.filter(el=>el!==null).length;return elements>=minSize}if(node.type==="ArrowFunctionExpression"||node.type==="FunctionExpression"){return true}return false}exports.noUnnecessaryRerenders=(0,eslint_devkit_2.createRule)({name:"no-unnecessary-rerenders",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-unnecessary-rerenders.md",description:"Detects prevented re-renders in React"},hasSuggestions:true,messages:{unnecessaryRerender:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Unnecessary re-render",description:"{{expression}} causes unnecessary re-renders",severity:"MEDIUM",fix:"Use useMemo or useCallback to memoize {{expression}}",documentationLink:"https://react.dev/reference/react/useMemo"}),useMemo:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use useMemo",description:"Memoize with useMemo",severity:"LOW",fix:"const memoized = useMemo(() => value, [deps])",documentationLink:"https://react.dev/reference/react/useMemo"}),useCallback:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use useCallback",description:"Memoize callback with useCallback",severity:"LOW",fix:"const handler = useCallback(() => {}, [deps])",documentationLink:"https://react.dev/reference/react/useCallback"}),extractToVariable:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Extract Variable",description:"Extract to variable outside render",severity:"LOW",fix:"Define outside component or use useMemo",documentationLink:"https://react.dev/learn/render-and-commit"})},schema:[{type:"object",properties:{ignoreInTests:{type:"boolean",default:true},minSize:{type:"number",default:5,minimum:1}},additionalProperties:false}]},defaultOptions:[{ignoreInTests:true,minSize:5}],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnnecessaryRerenders=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function isInReactRenderContext(node){let current=node;let depth=0;const maxDepth=15;while(depth<maxDepth){const parent=current.parent;if(!parent)break;if(parent.type==="JSXElement"||parent.type==="JSXFragment"){return true}if(parent.type==="JSXAttribute"){return true}if(parent.type==="FunctionDeclaration"||parent.type==="FunctionExpression"||parent.type==="ArrowFunctionExpression"){if(parent.type==="FunctionDeclaration"&&parent.id){const name=parent.id.name;if(name&&/^[A-Z]/.test(name)){return true}}const body=parent.type==="FunctionDeclaration"?parent.body:parent.type==="FunctionExpression"?parent.body:parent.body;if(body&&body.type==="BlockStatement"){const hasJSX=body.body.some(stmt=>stmt.type==="ReturnStatement"&&stmt.argument&&(stmt.argument.type==="JSXElement"||stmt.argument.type==="JSXFragment"));if(hasJSX){return true}}}current=parent;depth++}return false}function shouldBeMemoized(node,minSize=5){if(node.type==="ObjectExpression"){const properties=node.properties.length;return properties>=minSize}if(node.type==="ArrayExpression"){const elements=node.elements.filter(el=>el!==null).length;return elements>=minSize}if(node.type==="ArrowFunctionExpression"||node.type==="FunctionExpression"){return true}return false}exports.noUnnecessaryRerenders=(0,eslint_devkit_2.createRule)({name:"no-unnecessary-rerenders",meta:{interop:{runtimes:["eslint","oxlint"]},type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-unnecessary-rerenders.md",description:"Detects prevented re-renders in React"},hasSuggestions:true,messages:{unnecessaryRerender:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Unnecessary re-render",description:"{{expression}} causes unnecessary re-renders",severity:"MEDIUM",fix:"Use useMemo or useCallback to memoize {{expression}}",documentationLink:"https://react.dev/reference/react/useMemo"}),useMemo:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use useMemo",description:"Memoize with useMemo",severity:"LOW",fix:"const memoized = useMemo(() => value, [deps])",documentationLink:"https://react.dev/reference/react/useMemo"}),useCallback:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use useCallback",description:"Memoize callback with useCallback",severity:"LOW",fix:"const handler = useCallback(() => {}, [deps])",documentationLink:"https://react.dev/reference/react/useCallback"}),extractToVariable:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Extract Variable",description:"Extract to variable outside render",severity:"LOW",fix:"Define outside component or use useMemo",documentationLink:"https://react.dev/learn/render-and-commit"})},schema:[{type:"object",properties:{ignoreInTests:{type:"boolean",default:true},minSize:{type:"number",default:5,minimum:1}},additionalProperties:false}]},defaultOptions:[{ignoreInTests:true,minSize:5}],createOnce(context,currentOptions){let ignoreInTests;let minSize;let sourceCode;function checkJSXAttribute(node){try{if(!node.value){return}const value=node.value.type==="JSXExpressionContainer"?node.value.expression:null;if(!value){return}if(!isInReactRenderContext(value)){return}if(shouldBeMemoized(value,minSize)){let expressionText="";try{expressionText=sourceCode.getText(value).replace(/\s+/g," ").trim().substring(0,50)}catch{expressionText="expression"}const isFunction=value.type==="ArrowFunctionExpression"||value.type==="FunctionExpression";const firstSuggestionMessageId=isFunction?"useCallback":"useMemo";context.report({node:value,messageId:"unnecessaryRerender",data:{expression:expressionText},suggest:[{messageId:firstSuggestionMessageId,fix:()=>null},{messageId:"extractToVariable",fix:()=>null}]})}}catch{return}}return{before(){const[options={}]=currentOptions();({ignoreInTests=true,minSize=5}=options||{});const filename=context.filename;const isTestFile=ignoreInTests&&/\.(test|spec)\.[cm]?[jt]sx?$/.test(filename);if(isTestFile){return false}sourceCode=context.sourceCode;return true},JSXAttribute:checkJSXAttribute}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.reactNoInlineFunctions=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.reactNoInlineFunctions=(0,eslint_devkit_2.createRule)({name:"react-no-inline-functions",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/react-no-inline-functions.md",description:"Prevent inline functions in React renders with performance metrics"},messages:{inlineFunction:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Inline function",description:"Inline function detected",severity:"MEDIUM",fix:"Use useCallback hook or extract to component method",documentationLink:"https://react.dev/reference/react/useCallback"}),useCallback:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use useCallback",description:"Wrap with useCallback",severity:"LOW",fix:"const handler = useCallback(() => {}, [deps])",documentationLink:"https://react.dev/reference/react/useCallback"}),extractFunction:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Extract Function",description:"Extract to component method",severity:"LOW",fix:"Define function outside JSX or in useCallback",documentationLink:"https://react.dev/learn/your-first-component"}),strategyUseCallback:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.STRATEGY,issueName:"useCallback Strategy",description:"Use useCallback to memoize",severity:"LOW",fix:"useCallback(() => {}, [dependencies])",documentationLink:"https://react.dev/reference/react/useCallback"}),strategyUseMemo:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.STRATEGY,issueName:"useMemo Strategy",description:"Use useMemo for computed values",severity:"LOW",fix:"useMemo(() => computedValue, [deps])",documentationLink:"https://react.dev/reference/react/useMemo"}),strategyExtract:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.STRATEGY,issueName:"Extract Strategy",description:"Extract function outside render",severity:"LOW",fix:"Define function before return statement",documentationLink:"https://react.dev/learn/your-first-component"})},schema:[{type:"object",properties:{allowInEventHandlers:{type:"boolean",default:false},minArraySize:{type:"number",default:5,description:"Minimum array size to report inline functions in .map()"}},additionalProperties:false}]},defaultOptions:[{allowInEventHandlers:false,minArraySize:5}],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.reactNoInlineFunctions=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.reactNoInlineFunctions=(0,eslint_devkit_2.createRule)({name:"react-no-inline-functions",meta:{interop:{runtimes:["eslint","oxlint"]},type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/react-no-inline-functions.md",description:"Prevent inline functions in React renders with performance metrics"},messages:{inlineFunction:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Inline function",description:"Inline function detected",severity:"MEDIUM",fix:"Use useCallback hook or extract to component method",documentationLink:"https://react.dev/reference/react/useCallback"}),useCallback:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use useCallback",description:"Wrap with useCallback",severity:"LOW",fix:"const handler = useCallback(() => {}, [deps])",documentationLink:"https://react.dev/reference/react/useCallback"}),extractFunction:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Extract Function",description:"Extract to component method",severity:"LOW",fix:"Define function outside JSX or in useCallback",documentationLink:"https://react.dev/learn/your-first-component"}),strategyUseCallback:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.STRATEGY,issueName:"useCallback Strategy",description:"Use useCallback to memoize",severity:"LOW",fix:"useCallback(() => {}, [dependencies])",documentationLink:"https://react.dev/reference/react/useCallback"}),strategyUseMemo:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.STRATEGY,issueName:"useMemo Strategy",description:"Use useMemo for computed values",severity:"LOW",fix:"useMemo(() => computedValue, [deps])",documentationLink:"https://react.dev/reference/react/useMemo"}),strategyExtract:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.STRATEGY,issueName:"Extract Strategy",description:"Extract function outside render",severity:"LOW",fix:"Define function before return statement",documentationLink:"https://react.dev/learn/your-first-component"})},schema:[{type:"object",properties:{allowInEventHandlers:{type:"boolean",default:false},minArraySize:{type:"number",default:5,description:"Minimum array size to report inline functions in .map()"}},additionalProperties:false}]},defaultOptions:[{allowInEventHandlers:false,minArraySize:5}],createOnce(context){let allowInEventHandlers;let minArraySize;const isInJSX=node=>{let parent=node.parent;while(parent){if(parent.type==="JSXExpressionContainer"||parent.type==="JSXAttribute"){return true}parent=parent.parent}return false};const isInArrayMethod=node=>{const parent=node.parent;if(parent?.type==="CallExpression"){const callee=parent.callee;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"){const method=callee.property.name;if(["map","forEach","filter","reduce","sort"].includes(method)){return{inArray:true,method,estimatedSize:minArraySize}}}}return{inArray:false}};const calculateImpact=arrayInfo=>{if(arrayInfo.inArray&&arrayInfo.estimatedSize&&arrayInfo.estimatedSize>50){return{severity:"high",estimatedSlowdown:"30-50ms per render",affectedMetric:"Interaction to Next Paint (INP)"}}return{severity:"medium",estimatedSlowdown:"15-30ms per render",affectedMetric:"Interaction to Next Paint (INP)"}};const isInJSXExpressionContainer=node=>{let current=node;while(current){if(current.type==="JSXExpressionContainer"){return true}current=current.parent}return false};return{before(){const options=context.options[0]||{};({allowInEventHandlers=false,minArraySize=10}=options)},"JSXExpressionContainer > ArrowFunctionExpression, JSXExpressionContainer > FunctionExpression"(node){if(!isInJSX(node))return;const parent=node.parent;if(allowInEventHandlers&&parent?.parent?.type==="JSXAttribute"){const attr=parent.parent;if(attr.name.type==="JSXIdentifier"&&attr.name.name.startsWith("on")){return}}const arrayInfo=isInArrayMethod(node);const impact=calculateImpact(arrayInfo);context.report({node,messageId:"inlineFunction",data:{impact:impact.severity,location:arrayInfo.inArray?`${arrayInfo.method}() call`:"JSX prop"}})},"CallExpression > ArrowFunctionExpression, CallExpression > FunctionExpression"(node){if(!isInJSXExpressionContainer(node))return;let current=node;while(current){if(current.type==="JSXAttribute"){const attr=current;if(allowInEventHandlers&&attr.name.type==="JSXIdentifier"&&attr.name.name.startsWith("on")){return}}current=current.parent}const arrayInfo=isInArrayMethod(node);const impact=calculateImpact(arrayInfo);context.report({node,messageId:"inlineFunction",data:{impact:impact.severity,location:arrayInfo.inArray?`${arrayInfo.method}() call`:"JSX prop"}})}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.reactRenderOptimization=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function isInlineObject(node){return node.type==="ObjectExpression"}function isInlineArray(node){return node.type==="ArrayExpression"}function isInlineArrowFunction(node){return node.type==="ArrowFunctionExpression"}function isInlineFunctionExpression(node){return node.type==="FunctionExpression"}function estimateComplexity(node){let complexity=0;if(node.type==="ForStatement"||node.type==="ForOfStatement"||node.type==="ForInStatement"||node.type==="WhileStatement"){complexity+=3}if(node.type==="IfStatement"||node.type==="ConditionalExpression"){complexity+=1}if(node.type==="CallExpression"){complexity+=1}return complexity}function isExpensiveComputation(node,minComplexity){if(node.type==="BinaryExpression"||node.type==="LogicalExpression"){return false}let current=node;let depth=0;const maxDepth=5;while(current&&depth<maxDepth){const complexity=estimateComplexity(current);if(complexity>=minComplexity){return true}if("body"in current&¤t.body){if(Array.isArray(current.body)){for(const child of current.body){if(estimateComplexity(child)>=minComplexity){return true}}}}current=current.parent??null;depth++}return false}exports.reactRenderOptimization=(0,eslint_devkit_2.createRule)({name:"react-render-optimization",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/react-render-optimization.md",description:"Detects unnecessary re-renders and expensive computations in React"},hasSuggestions:true,messages:{unnecessaryRerender:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Unnecessary re-render",description:"Inline {{type}} prop causes re-render on every render",severity:"MEDIUM",fix:"Extract to constant or use useMemo/useCallback",documentationLink:"https://react.dev/learn/render-and-commit"}),missingMemoization:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Missing memoization",description:"Expensive computation should be memoized",severity:"MEDIUM",fix:"Wrap computation in useMemo hook",documentationLink:"https://react.dev/reference/react/useMemo"}),expensiveComputation:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Expensive computation",description:"Complex computation detected (complexity: {{complexity}})",severity:"MEDIUM",fix:"Use useMemo to memoize result",documentationLink:"https://react.dev/reference/react/useMemo"}),useMemo:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use useMemo",description:"Memoize with useMemo",severity:"LOW",fix:"const memoized = useMemo(() => value, [deps])",documentationLink:"https://react.dev/reference/react/useMemo"}),useCallback:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use useCallback",description:"Memoize callback function",severity:"LOW",fix:"const handler = useCallback(() => {}, [deps])",documentationLink:"https://react.dev/reference/react/useCallback"}),useReactMemo:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use React.memo",description:"Wrap component with React.memo",severity:"LOW",fix:"export default React.memo(Component)",documentationLink:"https://react.dev/reference/react/memo"})},schema:[{type:"object",properties:{detectInlineProps:{type:"boolean",default:true,description:"Detect inline object/array props"},detectInlineFunctions:{type:"boolean",default:true,description:"Detect inline function props"},detectExpensiveComputations:{type:"boolean",default:true,description:"Detect expensive computations without useMemo"},minComputationComplexity:{type:"number",default:3,minimum:1,description:"Minimum computation complexity to flag"},ignoreInTests:{type:"boolean",default:true,description:"Ignore in test files"}},additionalProperties:false}]},defaultOptions:[{detectInlineProps:true,detectInlineFunctions:true,detectExpensiveComputations:true,minComputationComplexity:3,ignoreInTests:true}],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.reactRenderOptimization=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function isInlineObject(node){return node.type==="ObjectExpression"}function isInlineArray(node){return node.type==="ArrayExpression"}function isInlineArrowFunction(node){return node.type==="ArrowFunctionExpression"}function isInlineFunctionExpression(node){return node.type==="FunctionExpression"}function estimateComplexity(node){let complexity=0;if(node.type==="ForStatement"||node.type==="ForOfStatement"||node.type==="ForInStatement"||node.type==="WhileStatement"){complexity+=3}if(node.type==="IfStatement"||node.type==="ConditionalExpression"){complexity+=1}if(node.type==="CallExpression"){complexity+=1}return complexity}function isExpensiveComputation(node,minComplexity){if(node.type==="BinaryExpression"||node.type==="LogicalExpression"){return false}let current=node;let depth=0;const maxDepth=5;while(current&&depth<maxDepth){const complexity=estimateComplexity(current);if(complexity>=minComplexity){return true}if("body"in current&¤t.body){if(Array.isArray(current.body)){for(const child of current.body){if(estimateComplexity(child)>=minComplexity){return true}}}}current=current.parent??null;depth++}return false}exports.reactRenderOptimization=(0,eslint_devkit_2.createRule)({name:"react-render-optimization",meta:{interop:{runtimes:["eslint","oxlint"]},type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/react-render-optimization.md",description:"Detects unnecessary re-renders and expensive computations in React"},hasSuggestions:true,messages:{unnecessaryRerender:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Unnecessary re-render",description:"Inline {{type}} prop causes re-render on every render",severity:"MEDIUM",fix:"Extract to constant or use useMemo/useCallback",documentationLink:"https://react.dev/learn/render-and-commit"}),missingMemoization:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Missing memoization",description:"Expensive computation should be memoized",severity:"MEDIUM",fix:"Wrap computation in useMemo hook",documentationLink:"https://react.dev/reference/react/useMemo"}),expensiveComputation:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Expensive computation",description:"Complex computation detected (complexity: {{complexity}})",severity:"MEDIUM",fix:"Use useMemo to memoize result",documentationLink:"https://react.dev/reference/react/useMemo"}),useMemo:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use useMemo",description:"Memoize with useMemo",severity:"LOW",fix:"const memoized = useMemo(() => value, [deps])",documentationLink:"https://react.dev/reference/react/useMemo"}),useCallback:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use useCallback",description:"Memoize callback function",severity:"LOW",fix:"const handler = useCallback(() => {}, [deps])",documentationLink:"https://react.dev/reference/react/useCallback"}),useReactMemo:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use React.memo",description:"Wrap component with React.memo",severity:"LOW",fix:"export default React.memo(Component)",documentationLink:"https://react.dev/reference/react/memo"})},schema:[{type:"object",properties:{detectInlineProps:{type:"boolean",default:true,description:"Detect inline object/array props"},detectInlineFunctions:{type:"boolean",default:true,description:"Detect inline function props"},detectExpensiveComputations:{type:"boolean",default:true,description:"Detect expensive computations without useMemo"},minComputationComplexity:{type:"number",default:3,minimum:1,description:"Minimum computation complexity to flag"},ignoreInTests:{type:"boolean",default:true,description:"Ignore in test files"}},additionalProperties:false}]},defaultOptions:[{detectInlineProps:true,detectInlineFunctions:true,detectExpensiveComputations:true,minComputationComplexity:3,ignoreInTests:true}],createOnce(context,currentOptions){let detectInlineProps;let detectInlineFunctions;let detectExpensiveComputations;let minComputationComplexity;let ignoreInTests;function checkJSXAttribute(node){try{if(!node.value){return}let value=null;if(node.value.type==="JSXExpressionContainer"){value=node.value.expression}else if(node.value.type==="Literal"){return}if(!value){return}if(detectInlineProps&&isInlineObject(value)){context.report({node,messageId:"unnecessaryRerender",data:{type:"object"},suggest:[{messageId:"useMemo",fix:()=>null}]});return}if(detectInlineProps&&isInlineArray(value)){context.report({node,messageId:"unnecessaryRerender",data:{type:"array"},suggest:[{messageId:"useMemo",fix:()=>null}]});return}if(detectInlineFunctions&&(isInlineArrowFunction(value)||isInlineFunctionExpression(value))){context.report({node,messageId:"unnecessaryRerender",data:{type:"function"},suggest:[{messageId:"useCallback",fix:()=>null}]});return}if(detectExpensiveComputations&&isExpensiveComputation(value,minComputationComplexity)){const complexity=estimateComplexity(value);context.report({node,messageId:"expensiveComputation",data:{complexity:String(complexity)},suggest:[{messageId:"useMemo",fix:()=>null}]})}}catch{return}}return{before(){const[options={}]=currentOptions();({detectInlineProps=true,detectInlineFunctions=true,detectExpensiveComputations=true,minComputationComplexity=3,ignoreInTests=true}=options||{});const filename=context.filename;const isTestFile=ignoreInTests&&/\.(test|spec)\.[cm]?[jt]sx?$/.test(filename);if(isTestFile){return false}return true},JSXAttribute:checkJSXAttribute}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.checkedRequiresOnchangeOrReadonly=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.checkedRequiresOnchangeOrReadonly=(0,eslint_devkit_1.createRule)({name:"checked-requires-onchange-or-readonly",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/checked-requires-onchange-or-readonly.md",description:"Ensure controlled inputs have onChange or readOnly"},schema:[],messages:{checkedRequiresOnChangeOrReadOnly:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Controlled Input Missing Handler",description:"Checked input missing onChange or readOnly",severity:"MEDIUM",fix:"Add onChange handler or readOnly attribute",documentationLink:"https://react.dev/reference/react-dom/components/input#controlling-an-input-with-a-state-variable"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.checkedRequiresOnchangeOrReadonly=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.checkedRequiresOnchangeOrReadonly=(0,eslint_devkit_1.createRule)({name:"checked-requires-onchange-or-readonly",meta:{interop:{runtimes:["eslint","oxlint"],nativeEquivalent:"react/checked-requires-onchange-or-readonly"},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/checked-requires-onchange-or-readonly.md",description:"Ensure controlled inputs have onChange or readOnly"},schema:[],messages:{checkedRequiresOnChangeOrReadOnly:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Controlled Input Missing Handler",description:"Checked input missing onChange or readOnly",severity:"MEDIUM",fix:"Add onChange handler or readOnly attribute",documentationLink:"https://react.dev/reference/react-dom/components/input#controlling-an-input-with-a-state-variable"})}},defaultOptions:[],createOnce(context){return{JSXElement(node){if(node.openingElement.name.type!=="JSXIdentifier"){return}const tagName=node.openingElement.name.name;if(!["input","textarea","select"].includes(tagName)){return}const attributes=node.openingElement.attributes;let hasChecked=false;let hasValue=false;let hasOnChange=false;let hasReadOnly=false;for(const attr of attributes){if(attr.type!=="JSXAttribute")continue;const attrName=attr.name.type==="JSXIdentifier"?attr.name.name:"";if(attrName==="checked"){hasChecked=true}else if(attrName==="value"){hasValue=true}else if(attrName==="onChange"||attrName==="onInput"){hasOnChange=true}else if(attrName==="readOnly"){hasReadOnly=true}}if((hasChecked||hasValue)&&!hasOnChange&&!hasReadOnly){context.report({node:node.openingElement.name,messageId:"checkedRequiresOnChangeOrReadOnly"})}}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.defaultPropsMatchPropTypes=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.defaultPropsMatchPropTypes=(0,eslint_devkit_1.createRule)({name:"default-props-match-prop-types",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/default-props-match-prop-types.md",description:"Validate default props match prop types"},schema:[],messages:{defaultPropsMatchPropTypes:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Default Props Mismatch",description:"Default prop does not match prop type",severity:"MEDIUM",fix:"Update default prop to match propTypes or update propTypes",documentationLink:"https://react.dev/learn/components-and-props#default-props"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.defaultPropsMatchPropTypes=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.defaultPropsMatchPropTypes=(0,eslint_devkit_1.createRule)({name:"default-props-match-prop-types",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/default-props-match-prop-types.md",description:"Validate default props match prop types"},schema:[],messages:{defaultPropsMatchPropTypes:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Default Props Mismatch",description:"Default prop does not match prop type",severity:"MEDIUM",fix:"Update default prop to match propTypes or update propTypes",documentationLink:"https://react.dev/learn/components-and-props#default-props"})}},defaultOptions:[],createOnce(context){let propTypes;let defaultProps;return{before(){propTypes=new Map;defaultProps=new Map},'PropertyDefinition[key.name="propTypes"]'(node){if(node.value&&node.value.type==="ObjectExpression"){for(const prop of node.value.properties){if(prop.type==="Property"&&prop.key.type==="Identifier"){propTypes.set(prop.key.name,prop)}}}},'PropertyDefinition[key.name="defaultProps"]'(node){if(node.value&&node.value.type==="ObjectExpression"){for(const prop of node.value.properties){if(prop.type==="Property"&&prop.key.type==="Identifier"){defaultProps.set(prop.key.name,prop)}}}},"ClassDeclaration:exit"(){for(const[propName,defaultProp]of defaultProps){const propType=propTypes.get(propName);if(propType&&defaultProp.value&&propType.value&&defaultProp.value.type!=="TSEmptyBodyFunctionExpression"&&propType.value.type!=="TSEmptyBodyFunctionExpression"&&!isPattern(defaultProp.value)&&!isPattern(propType.value)&&!isCompatibleDefaultValue(defaultProp.value,propType.value)){context.report({node:defaultProp.key,messageId:"defaultPropsMatchPropTypes"})}}propTypes.clear();defaultProps.clear()}}}});function isCompatibleDefaultValue(defaultValue,propType){if(defaultValue.type==="Literal"&&propType.type==="MemberExpression"){const propTypeName=getPropTypeName(propType);const defaultType=typeof defaultValue.value;switch(propTypeName){case"string":return defaultType==="string";case"number":return defaultType==="number";case"bool":return defaultType==="boolean";default:return true}}return true}function getPropTypeName(node){if(node.object.type==="Identifier"&&node.object.name==="PropTypes"){return(0,eslint_devkit_1.propertyName)(node)??""}return""}function isPattern(node){return node.type==="AssignmentPattern"||node.type==="ArrayPattern"||node.type==="ObjectPattern"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.displayName=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const REACT_WRAPPERS=new Set(["memo","forwardRef"]);exports.displayName=(0,eslint_devkit_1.createRule)({name:"display-name",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/display-name.md",description:"Enforce component display names"},schema:[],messages:{displayName:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Anonymous Component",description:'Component has no name React can infer, so it renders as "Anonymous" in DevTools and stack traces',severity:"LOW",fix:"Assign it to a named variable, name the function, or set a displayName",documentationLink:"https://react.dev/learn/components-and-props#displaying-a-custom-component"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.displayName=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const REACT_WRAPPERS=new Set(["memo","forwardRef"]);exports.displayName=(0,eslint_devkit_1.createRule)({name:"display-name",meta:{interop:{runtimes:["eslint","oxlint"],nativeEquivalent:"react/display-name"},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/display-name.md",description:"Enforce component display names"},schema:[],messages:{displayName:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Anonymous Component",description:'Component has no name React can infer, so it renders as "Anonymous" in DevTools and stack traces',severity:"LOW",fix:"Assign it to a named variable, name the function, or set a displayName",documentationLink:"https://react.dev/learn/components-and-props#displaying-a-custom-component"})}},defaultOptions:[],createOnce(context){const report=node=>{context.report({node,messageId:"displayName"})};return{ExportDefaultDeclaration(node){const declaration=node.declaration;if(!isFunctionNode(declaration)||declaration.id)return;if(containsJSX(declaration.body))report(declaration)},CallExpression(node){if(!isReactWrapperCall(node)||hasInferableName(node))return;const inner=node.arguments[0];if(inner&&isFunctionNode(inner)&&!inner.id&&containsJSX(inner.body)){report(inner)}},"ClassDeclaration, ClassExpression"(node){if(node.id||!isReactComponent(node))return;if(hasDisplayNameProperty(node)||hasInferableName(node))return;report(node)}}}});function hasInferableName(node){let current=node.parent;while(current&&isReactWrapperCall(current)){current=current.parent}switch(current?.type){case eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator:return current.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier;case eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression:case eslint_devkit_1.AST_NODE_TYPES.Property:case eslint_devkit_1.AST_NODE_TYPES.PropertyDefinition:return true;default:return false}}function isReactWrapperCall(node){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression)return false;const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return REACT_WRAPPERS.has(callee.name)}return callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),REACT_WRAPPERS)}function isFunctionNode(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration||node.type===eslint_devkit_1.AST_NODE_TYPES.FunctionExpression||node.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression}function isReactComponent(node){if(!node.superClass)return false;if(node.superClass.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return node.superClass.name==="Component"||node.superClass.name==="PureComponent"}if(node.superClass.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){return node.superClass.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.superClass.object.name==="React"&&((0,eslint_devkit_1.propertyName)(node.superClass)==="Component"||(0,eslint_devkit_1.propertyName)(node.superClass)==="PureComponent")}return false}function hasDisplayNameProperty(node){for(const member of node.body.body){if(member.type===eslint_devkit_1.AST_NODE_TYPES.PropertyDefinition&&member.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&member.key.name==="displayName"&&member.static){return true}}return false}function containsJSX(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.JSXElement||node.type===eslint_devkit_1.AST_NODE_TYPES.JSXFragment){return true}for(const key in node){if(key==="parent")continue;const child=node[key];if(!child||typeof child!=="object")continue;if(Array.isArray(child)){for(const item of child){if(item&&typeof item==="object"&&"type"in item){if(containsJSX(item))return true}}}else if("type"in child){if(containsJSX(child))return true}}return false}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.hooksExhaustiveDeps=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const SKIP_KEYS=new Set(["parent","loc","range","tokens","comments","type"]);const CHILD_KEYS_CACHE=new Map;function getChildKeys(node){const cached=CHILD_KEYS_CACHE.get(node.type);if(cached)return cached;const keys=[];for(const key of Object.keys(node)){if(SKIP_KEYS.has(key))continue;const v=node[key];if(v&&typeof v==="object"){keys.push(key)}}CHILD_KEYS_CACHE.set(node.type,keys);return keys}const HOOKS_WITH_DEPS=new Set(["useEffect","useLayoutEffect","useCallback","useMemo","useImperativeHandle"]);exports.hooksExhaustiveDeps=(0,eslint_devkit_1.createRule)({name:"hooks-exhaustive-deps",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/hooks-exhaustive-deps.md",description:"Enforce exhaustive dependencies in React hooks to prevent stale closures",confidence:"high"},hasSuggestions:true,messages:{missingDep:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Missing Hook Dependency",description:"React Hook {{hookName}} has missing dependencies: {{deps}}",severity:"HIGH",fix:"Add missing dependencies to the dependency array or memoize values with useMemo/useCallback",documentationLink:"https://react.dev/reference/react/useEffect#specifying-reactive-dependencies"}),extraDep:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Unnecessary Hook Dependency",description:"React Hook {{hookName}} has unnecessary dependency: {{dep}}",severity:"MEDIUM",fix:"Remove the unnecessary dependency from the array - it never changes or is not used in the effect",documentationLink:"https://react.dev/reference/react/useEffect#removing-unnecessary-dependencies"}),unnecessaryDep:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Unnecessary Dependency",description:"The dependency {{dep}} is stable and never changes",severity:"LOW",fix:"Consider removing stable dependencies like setState functions or refs",documentationLink:"https://react.dev/reference/react/useEffect#removing-unnecessary-dependencies"}),suggestAddDep:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Add Missing Dependency",description:"Add {{dep}} to dependency array",severity:"LOW",fix:"Add the missing dependency to prevent stale closures",documentationLink:"https://react.dev/reference/react/useEffect#specifying-reactive-dependencies"}),suggestRemoveDep:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Remove Unnecessary Dependency",description:"Remove {{dep}} from dependency array",severity:"LOW",fix:"Remove the unnecessary dependency",documentationLink:"https://react.dev/reference/react/useEffect#removing-unnecessary-dependencies"}),depsNotArrayLiteral:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Non-literal Dependency Array",description:"React Hook {{hookName}} was passed a dependency list that is not an array literal. This means we cannot statically verify whether you have passed the correct dependencies.",severity:"HIGH",fix:"Replace the variable with an inline array literal: [dep1, dep2]. If you need dynamic deps, refactor to compute them inside the hook callback instead.",documentationLink:"https://react.dev/reference/react/useEffect#specifying-reactive-dependencies"})},schema:[{type:"object",properties:{additionalHooks:{type:"string",description:'Regex pattern for additional hooks to check (e.g., "useMyCustomHook")'},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean",default:false,description:"Enable autofix (warning: may cause infinite loops)"}},additionalProperties:false}]},defaultOptions:[{}],create(context){const options=context.options[0]||{};const additionalHooksPattern=options.additionalHooks?new RegExp(options.additionalHooks):null;function isHookWithDeps(node){const callee=node.callee;if(callee.type==="Identifier"){if(HOOKS_WITH_DEPS.has(callee.name)){return true}if(additionalHooksPattern?.test(callee.name)){return true}}if(callee.type==="MemberExpression"&&callee.object.type==="Identifier"&&callee.object.name==="React"&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),HOOKS_WITH_DEPS)){return true}return false}function getHookName(node){const callee=node.callee;if(callee.type==="Identifier"){return callee.name}return(0,eslint_devkit_1.propertyName)(callee)}function extractLocallyDeclaredIdentifiers(node){const declared=new Set;const visited=new WeakSet;function visit(n){if(visited.has(n))return;visited.add(n);if(n.type==="VariableDeclaration"){for(const declarator of n.declarations){if(declarator.id.type==="Identifier"){declared.add(declarator.id.name)}else if(declarator.id.type==="ObjectPattern"){for(const prop of declarator.id.properties){if(prop.type==="Property"&&prop.value.type==="Identifier"){declared.add(prop.value.name)}}}else if(declarator.id.type==="ArrayPattern"){for(const element of declarator.id.elements){if(element&&element.type==="Identifier"){declared.add(element.name)}}}}}if(n.type==="FunctionDeclaration"&&n.id){declared.add(n.id.name)}if(n.type==="ArrowFunctionExpression"||n.type==="FunctionExpression"||n.type==="FunctionDeclaration"){const collectFromPattern=param=>{if(param.type==="Identifier"){declared.add(param.name)}else if(param.type==="ObjectPattern"){for(const prop of param.properties){if(prop.type==="Property"&&prop.value.type==="Identifier"){declared.add(prop.value.name)}else if(prop.type==="RestElement"&&prop.argument.type==="Identifier"){declared.add(prop.argument.name)}}}else if(param.type==="ArrayPattern"){for(const el of param.elements){if(el&&el.type==="Identifier")declared.add(el.name)}}else if(param.type==="RestElement"&¶m.argument.type==="Identifier"){declared.add(param.argument.name)}else if(param.type==="AssignmentPattern"&¶m.left.type==="Identifier"){declared.add(param.left.name)}};for(const param of n.params??[])collectFromPattern(param)}const keys=getChildKeys(n);for(let i=0;i<keys.length;i++){const child=n[keys[i]];if(Array.isArray(child)){for(let j=0;j<child.length;j++){const c=child[j];if(c&&typeof c==="object"&&"type"in c){visit(c)}}}else if(child&&typeof child==="object"&&"type"in child){visit(child)}}}visit(node);return declared}function extractUsedIdentifiers(node){const used=new Set;const visited=new WeakSet;function visit(n,isPropertyKey=false){if(visited.has(n)){return}visited.add(n);if(n.type==="MemberExpression"){visit(n.object,false);if(n.computed&&n.property){visit(n.property,false)}return}if(n.type==="CallExpression"){if(n.callee){visit(n.callee,false)}if(n.arguments){n.arguments.forEach(arg=>visit(arg,false))}return}if(n.type==="Identifier"&&!isPropertyKey){used.add(n.name)}const keys=getChildKeys(n);for(let i=0;i<keys.length;i++){const child=n[keys[i]];if(Array.isArray(child)){for(let j=0;j<child.length;j++){const c=child[j];if(c&&typeof c==="object"&&"type"in c){visit(c,false)}}}else if(child&&typeof child==="object"&&"type"in child){visit(child,false)}}}visit(node);return used}function extractDependencies(depsArray){const deps=new Set;for(const element of depsArray.elements){if(element?.type==="Identifier"){deps.add(element.name)}else if(element?.type==="MemberExpression"&&element.object.type==="Identifier"){const sourceCode=context.sourceCode;deps.add(sourceCode.getText(element))}}return deps}function isStableReference(name,scope){for(let current=scope;current;current=current.upper){const variable=current.variables.find(v=>v.name===name);if(!variable)continue;const owner=variable.scope.type;if(owner==="module"||owner==="global")return true;return variable.defs.some(def=>isStableDefinition(def,name))}return true}function isStableDefinition(def,name){if(def.type!=="Variable")return false;const declarator=def.node;const init=declarator.init;if(!init||init.type!=="CallExpression")return false;const callee=init.callee;const hookName=callee.type==="Identifier"?callee.name:callee.type==="MemberExpression"?(0,eslint_devkit_1.propertyName)(callee)??"":"";if(hookName==="useRef")return declarator.id.type==="Identifier";if(hookName==="useState"||hookName==="useReducer"){if(declarator.id.type!=="ArrayPattern")return false;const second=declarator.id.elements[1];return second?.type==="Identifier"&&second.name===name}return false}function filterReactiveDeps(used,scope){const reactive=new Set;const nonReactive=new Set(["undefined","null","true","false","console","window","document","Math","JSON","Object","Array","String","Number","Boolean","Date","Promise","Error","Map","Set","WeakMap","WeakSet","Symbol","Reflect","Proxy","Intl","navigator","localStorage","sessionStorage","fetch","setTimeout","setInterval","clearTimeout","clearInterval","requestAnimationFrame","cancelAnimationFrame"]);for(const name of used){if(!nonReactive.has(name)&&!isStableReference(name,scope)){reactive.add(name)}}return reactive}return{CallExpression(node){if(!isHookWithDeps(node)){return}const hookName=getHookName(node);const args=node.arguments;if(args.length===0){return}const callback=args[0];if(callback.type!=="ArrowFunctionExpression"&&callback.type!=="FunctionExpression"){return}const depsArg=args[1];if(!depsArg){return}const isTSAsArrayExpression=depsArg.type==="TSAsExpression"&&depsArg.expression?.type==="ArrayExpression";const isArrayExpression=depsArg.type==="ArrayExpression";if(!isArrayExpression&&!isTSAsArrayExpression){context.report({node:depsArg,messageId:"depsNotArrayLiteral",data:{hookName}});return}const depsArrayNode=isTSAsArrayExpression?depsArg.expression:depsArg;const usedInCallback=extractUsedIdentifiers(callback.body);const locallyDeclared=extractLocallyDeclaredIdentifiers(callback);const externalUsed=new Set;for(const id of usedInCallback){if(!locallyDeclared.has(id)){externalUsed.add(id)}}const reactiveDeps=filterReactiveDeps(externalUsed,context.sourceCode.getScope(callback));const declaredDeps=extractDependencies(depsArrayNode);const missingDeps=[];for(const dep of reactiveDeps){if(!declaredDeps.has(dep)&&/^[a-z]/.test(dep)){missingDeps.push(dep)}}const extraDeps=[];for(const dep of declaredDeps){if(!usedInCallback.has(dep)&&!dep.includes(".")){extraDeps.push(dep)}}if(missingDeps.length>0){context.report({node:depsArg,messageId:"missingDep",data:{hookName,deps:missingDeps.join(", ")},suggest:missingDeps.map(dep=>({messageId:"suggestAddDep",data:{dep},fix(fixer){const lastElement=depsArrayNode.elements[depsArrayNode.elements.length-1];if(lastElement){return fixer.insertTextAfter(lastElement,`, ${dep}`)}else{return fixer.insertTextAfterRange([depsArrayNode.range[0]+1,depsArrayNode.range[0]+1],dep)}}}))})}for(const dep of extraDeps){context.report({node:depsArg,messageId:"extraDep",data:{hookName,dep},suggest:[{messageId:"suggestRemoveDep",data:{dep},fix(fixer){const element=depsArrayNode.elements.find(el=>el?.type==="Identifier"&&el.name===dep);if(element){const index=depsArrayNode.elements.indexOf(element);const isLast=index===depsArrayNode.elements.length-1;const isFirst=index===0;if(isFirst&&depsArrayNode.elements.length>1){const nextElement=depsArrayNode.elements[1];if(nextElement){return fixer.removeRange([element.range[0],nextElement.range[0]])}}else if(isLast&&index>0){const prevElement=depsArrayNode.elements[index-1];if(prevElement){return fixer.removeRange([prevElement.range[1],element.range[1]])}}return fixer.remove(element)}return null}}]})}}}}});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.hooksExhaustiveDeps=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const SKIP_KEYS=new Set(["parent","loc","range","tokens","comments","type"]);const CHILD_KEYS_CACHE=new Map;function getChildKeys(node){const cached=CHILD_KEYS_CACHE.get(node.type);if(cached)return cached;const keys=[];for(const key of Object.keys(node)){if(SKIP_KEYS.has(key))continue;const v=node[key];if(v&&typeof v==="object"){keys.push(key)}}CHILD_KEYS_CACHE.set(node.type,keys);return keys}const HOOKS_WITH_DEPS=new Set(["useEffect","useLayoutEffect","useCallback","useMemo","useImperativeHandle"]);exports.hooksExhaustiveDeps=(0,eslint_devkit_1.createRule)({name:"hooks-exhaustive-deps",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/hooks-exhaustive-deps.md",description:"Enforce exhaustive dependencies in React hooks to prevent stale closures",confidence:"high"},hasSuggestions:true,messages:{missingDep:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Missing Hook Dependency",description:"React Hook {{hookName}} has missing dependencies: {{deps}}",severity:"HIGH",fix:"Add missing dependencies to the dependency array or memoize values with useMemo/useCallback",documentationLink:"https://react.dev/reference/react/useEffect#specifying-reactive-dependencies"}),extraDep:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Unnecessary Hook Dependency",description:"React Hook {{hookName}} has unnecessary dependency: {{dep}}",severity:"MEDIUM",fix:"Remove the unnecessary dependency from the array - it never changes or is not used in the effect",documentationLink:"https://react.dev/reference/react/useEffect#removing-unnecessary-dependencies"}),unnecessaryDep:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Unnecessary Dependency",description:"The dependency {{dep}} is stable and never changes",severity:"LOW",fix:"Consider removing stable dependencies like setState functions or refs",documentationLink:"https://react.dev/reference/react/useEffect#removing-unnecessary-dependencies"}),suggestAddDep:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Add Missing Dependency",description:"Add {{dep}} to dependency array",severity:"LOW",fix:"Add the missing dependency to prevent stale closures",documentationLink:"https://react.dev/reference/react/useEffect#specifying-reactive-dependencies"}),suggestRemoveDep:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Remove Unnecessary Dependency",description:"Remove {{dep}} from dependency array",severity:"LOW",fix:"Remove the unnecessary dependency",documentationLink:"https://react.dev/reference/react/useEffect#removing-unnecessary-dependencies"}),depsNotArrayLiteral:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Non-literal Dependency Array",description:"React Hook {{hookName}} was passed a dependency list that is not an array literal. This means we cannot statically verify whether you have passed the correct dependencies.",severity:"HIGH",fix:"Replace the variable with an inline array literal: [dep1, dep2]. If you need dynamic deps, refactor to compute them inside the hook callback instead.",documentationLink:"https://react.dev/reference/react/useEffect#specifying-reactive-dependencies"})},schema:[{type:"object",properties:{additionalHooks:{type:"string",description:'Regex pattern for additional hooks to check (e.g., "useMyCustomHook")'},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean",default:false,description:"Enable autofix (warning: may cause infinite loops)"}},additionalProperties:false}]},defaultOptions:[{}],createOnce(context){let additionalHooksPattern;function isHookWithDeps(node){const callee=node.callee;if(callee.type==="Identifier"){if(HOOKS_WITH_DEPS.has(callee.name)){return true}if(additionalHooksPattern?.test(callee.name)){return true}}if(callee.type==="MemberExpression"&&callee.object.type==="Identifier"&&callee.object.name==="React"&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),HOOKS_WITH_DEPS)){return true}return false}function getHookName(node){const callee=node.callee;if(callee.type==="Identifier"){return callee.name}return(0,eslint_devkit_1.propertyName)(callee)}function extractLocallyDeclaredIdentifiers(node){const declared=new Set;const visited=new WeakSet;function visit(n){if(visited.has(n))return;visited.add(n);if(n.type==="VariableDeclaration"){for(const declarator of n.declarations){if(declarator.id.type==="Identifier"){declared.add(declarator.id.name)}else if(declarator.id.type==="ObjectPattern"){for(const prop of declarator.id.properties){if(prop.type==="Property"&&prop.value.type==="Identifier"){declared.add(prop.value.name)}}}else if(declarator.id.type==="ArrayPattern"){for(const element of declarator.id.elements){if(element&&element.type==="Identifier"){declared.add(element.name)}}}}}if(n.type==="FunctionDeclaration"&&n.id){declared.add(n.id.name)}if(n.type==="ArrowFunctionExpression"||n.type==="FunctionExpression"||n.type==="FunctionDeclaration"){const collectFromPattern=param=>{if(param.type==="Identifier"){declared.add(param.name)}else if(param.type==="ObjectPattern"){for(const prop of param.properties){if(prop.type==="Property"&&prop.value.type==="Identifier"){declared.add(prop.value.name)}else if(prop.type==="RestElement"&&prop.argument.type==="Identifier"){declared.add(prop.argument.name)}}}else if(param.type==="ArrayPattern"){for(const el of param.elements){if(el&&el.type==="Identifier")declared.add(el.name)}}else if(param.type==="RestElement"&¶m.argument.type==="Identifier"){declared.add(param.argument.name)}else if(param.type==="AssignmentPattern"&¶m.left.type==="Identifier"){declared.add(param.left.name)}};for(const param of n.params??[])collectFromPattern(param)}const keys=getChildKeys(n);for(let i=0;i<keys.length;i++){const child=n[keys[i]];if(Array.isArray(child)){for(let j=0;j<child.length;j++){const c=child[j];if(c&&typeof c==="object"&&"type"in c){visit(c)}}}else if(child&&typeof child==="object"&&"type"in child){visit(child)}}}visit(node);return declared}function extractUsedIdentifiers(node){const used=new Set;const visited=new WeakSet;function visit(n,isPropertyKey=false){if(visited.has(n)){return}visited.add(n);if(n.type==="MemberExpression"){visit(n.object,false);if(n.computed&&n.property){visit(n.property,false)}return}if(n.type==="CallExpression"){if(n.callee){visit(n.callee,false)}if(n.arguments){n.arguments.forEach(arg=>visit(arg,false))}return}if(n.type==="Identifier"&&!isPropertyKey){used.add(n.name)}const keys=getChildKeys(n);for(let i=0;i<keys.length;i++){const child=n[keys[i]];if(Array.isArray(child)){for(let j=0;j<child.length;j++){const c=child[j];if(c&&typeof c==="object"&&"type"in c){visit(c,false)}}}else if(child&&typeof child==="object"&&"type"in child){visit(child,false)}}}visit(node);return used}function extractDependencies(depsArray){const deps=new Set;for(const element of depsArray.elements){if(element?.type==="Identifier"){deps.add(element.name)}else if(element?.type==="MemberExpression"&&element.object.type==="Identifier"){const sourceCode=context.sourceCode;deps.add(sourceCode.getText(element))}}return deps}function isStableReference(name,scope){for(let current=scope;current;current=current.upper){const variable=current.variables.find(v=>v.name===name);if(!variable)continue;const owner=variable.scope.type;if(owner==="module"||owner==="global")return true;return variable.defs.some(def=>isStableDefinition(def,name))}return true}function isStableDefinition(def,name){if(def.type!=="Variable")return false;const declarator=def.node;const init=declarator.init;if(!init||init.type!=="CallExpression")return false;const callee=init.callee;const hookName=callee.type==="Identifier"?callee.name:callee.type==="MemberExpression"?(0,eslint_devkit_1.propertyName)(callee)??"":"";if(hookName==="useRef")return declarator.id.type==="Identifier";if(hookName==="useState"||hookName==="useReducer"){if(declarator.id.type!=="ArrayPattern")return false;const second=declarator.id.elements[1];return second?.type==="Identifier"&&second.name===name}return false}function filterReactiveDeps(used,scope){const reactive=new Set;const nonReactive=new Set(["undefined","null","true","false","console","window","document","Math","JSON","Object","Array","String","Number","Boolean","Date","Promise","Error","Map","Set","WeakMap","WeakSet","Symbol","Reflect","Proxy","Intl","navigator","localStorage","sessionStorage","fetch","setTimeout","setInterval","clearTimeout","clearInterval","requestAnimationFrame","cancelAnimationFrame"]);for(const name of used){if(!nonReactive.has(name)&&!isStableReference(name,scope)){reactive.add(name)}}return reactive}return{before(){const options=context.options[0]||{};additionalHooksPattern=options.additionalHooks?new RegExp(options.additionalHooks):null},CallExpression(node){if(!isHookWithDeps(node)){return}const hookName=getHookName(node);const args=node.arguments;if(args.length===0){return}const callback=args[0];if(callback.type!=="ArrowFunctionExpression"&&callback.type!=="FunctionExpression"){return}const depsArg=args[1];if(!depsArg){return}const isTSAsArrayExpression=depsArg.type==="TSAsExpression"&&depsArg.expression?.type==="ArrayExpression";const isArrayExpression=depsArg.type==="ArrayExpression";if(!isArrayExpression&&!isTSAsArrayExpression){context.report({node:depsArg,messageId:"depsNotArrayLiteral",data:{hookName}});return}const depsArrayNode=isTSAsArrayExpression?depsArg.expression:depsArg;const usedInCallback=extractUsedIdentifiers(callback.body);const locallyDeclared=extractLocallyDeclaredIdentifiers(callback);const externalUsed=new Set;for(const id of usedInCallback){if(!locallyDeclared.has(id)){externalUsed.add(id)}}const reactiveDeps=filterReactiveDeps(externalUsed,context.sourceCode.getScope(callback));const declaredDeps=extractDependencies(depsArrayNode);const missingDeps=[];for(const dep of reactiveDeps){if(!declaredDeps.has(dep)&&/^[a-z]/.test(dep)){missingDeps.push(dep)}}const extraDeps=[];for(const dep of declaredDeps){if(!usedInCallback.has(dep)&&!dep.includes(".")){extraDeps.push(dep)}}if(missingDeps.length>0){context.report({node:depsArg,messageId:"missingDep",data:{hookName,deps:missingDeps.join(", ")},suggest:missingDeps.map(dep=>({messageId:"suggestAddDep",data:{dep},fix(fixer){const lastElement=depsArrayNode.elements[depsArrayNode.elements.length-1];if(lastElement){return fixer.insertTextAfter(lastElement,`, ${dep}`)}else{return fixer.insertTextAfterRange([depsArrayNode.range[0]+1,depsArrayNode.range[0]+1],dep)}}}))})}for(const dep of extraDeps){context.report({node:depsArg,messageId:"extraDep",data:{hookName,dep},suggest:[{messageId:"suggestRemoveDep",data:{dep},fix(fixer){const element=depsArrayNode.elements.find(el=>el?.type==="Identifier"&&el.name===dep);if(element){const index=depsArrayNode.elements.indexOf(element);const isLast=index===depsArrayNode.elements.length-1;const isFirst=index===0;if(isFirst&&depsArrayNode.elements.length>1){const nextElement=depsArrayNode.elements[1];if(nextElement){return fixer.removeRange([element.range[0],nextElement.range[0]])}}else if(isLast&&index>0){const prevElement=depsArrayNode.elements[index-1];if(prevElement){return fixer.removeRange([prevElement.range[1],element.range[1]])}}return fixer.remove(element)}return null}}]})}}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jsxHandlerNames=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.jsxHandlerNames=(0,eslint_devkit_1.createRule)({name:"jsx-handler-names",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-handler-names.md",description:"Enforce event handler naming conventions"},schema:[],messages:{jsxHandlerNames:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Invalid Handler Name",description:"Event handler does not follow naming convention",severity:"LOW",fix:'Rename handler to start with "handle" or "on" (e.g., handleClick, onSubmit)',documentationLink:"https://react.dev/learn/responding-to-events#naming-event-handler-functions"})}},defaultOptions:[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jsxHandlerNames=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.jsxHandlerNames=(0,eslint_devkit_1.createRule)({name:"jsx-handler-names",meta:{interop:{runtimes:["eslint","oxlint"],nativeEquivalent:"react/jsx-handler-names"},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-handler-names.md",description:"Enforce event handler naming conventions"},schema:[],messages:{jsxHandlerNames:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Invalid Handler Name",description:"Event handler does not follow naming convention",severity:"LOW",fix:'Rename handler to start with "handle" or "on" (e.g., handleClick, onSubmit)',documentationLink:"https://react.dev/learn/responding-to-events#naming-event-handler-functions"})}},defaultOptions:[],createOnce(context){return{JSXAttribute(node){if(node.name.type==="JSXIdentifier"){const attrName=node.name.name;if(attrName.startsWith("on")&&attrName.length>2){if(node.value&&node.value.type==="JSXExpressionContainer"){const expression=node.value.expression;if(expression.type==="Identifier"){const handlerName=expression.name;if(!handlerName.startsWith("handle")&&!handlerName.startsWith("on")){context.report({node:expression,messageId:"jsxHandlerNames"})}}}}}}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jsxKey=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const keyExpressionForParam=param=>{if(param.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentPattern){return keyExpressionForParam(param.left)}if(param.type===eslint_devkit_1.AST_NODE_TYPES.Identifier)return`${param.name}.id`;if(param.type===eslint_devkit_1.AST_NODE_TYPES.ObjectPattern){for(const prop of param.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if((0,eslint_devkit_1.objectKeyName)(prop)!=="id")continue;const bound=prop.value.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentPattern?prop.value.left:prop.value;if(bound.type===eslint_devkit_1.AST_NODE_TYPES.Identifier)return bound.name}}return null};const keyExpressionForCallback=fn=>fn.params.length>0?keyExpressionForParam(fn.params[0]):null;exports.jsxKey=(0,eslint_devkit_1.createRule)({name:"jsx-key",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-key.md",description:"Detect missing or problematic React keys that could break reconciliation"},hasSuggestions:true,messages:{missingKey:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Missing React Key",description:"Missing key prop for element in iterator",severity:"HIGH",fix:"Add unique, stable key prop based on item data",documentationLink:"https://react.dev/learn/render-and-commit#lists-and-keys"}),invalidKey:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Invalid React Key",description:"Key prop should be unique and stable",severity:"MEDIUM",fix:"Use item.id, item.key, or index as last resort",documentationLink:"https://react.dev/learn/render-and-commit#lists-and-keys"}),duplicateKey:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Duplicate React Key",description:"Duplicate key values can break reconciliation",severity:"HIGH",fix:"Ensure all keys in the array are unique",documentationLink:"https://react.dev/learn/render-and-commit#lists-and-keys"}),unstableKey:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Unstable React Key",description:"Using index as key can cause reconciliation issues",severity:"MEDIUM",fix:"Use stable identifier from data instead of array index",documentationLink:"https://react.dev/learn/render-and-commit#lists-and-keys"}),suggestKey:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Add Key Prop",description:"Add unique key prop to element",severity:"LOW",fix:"key={item.id}",documentationLink:"https://react.dev/learn/render-and-commit#lists-and-keys"})},schema:[{type:"object",properties:{warnUnstableKeys:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{warnUnstableKeys:true}],
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jsxKey=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const keyExpressionForParam=param=>{if(param.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentPattern){return keyExpressionForParam(param.left)}if(param.type===eslint_devkit_1.AST_NODE_TYPES.Identifier)return`${param.name}.id`;if(param.type===eslint_devkit_1.AST_NODE_TYPES.ObjectPattern){for(const prop of param.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if((0,eslint_devkit_1.objectKeyName)(prop)!=="id")continue;const bound=prop.value.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentPattern?prop.value.left:prop.value;if(bound.type===eslint_devkit_1.AST_NODE_TYPES.Identifier)return bound.name}}return null};const keyExpressionForCallback=fn=>fn.params.length>0?keyExpressionForParam(fn.params[0]):null;exports.jsxKey=(0,eslint_devkit_1.createRule)({name:"jsx-key",meta:{interop:{runtimes:["eslint","oxlint"],nativeEquivalent:"react/jsx-key"},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-key.md",description:"Detect missing or problematic React keys that could break reconciliation"},hasSuggestions:true,messages:{missingKey:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Missing React Key",description:"Missing key prop for element in iterator",severity:"HIGH",fix:"Add unique, stable key prop based on item data",documentationLink:"https://react.dev/learn/render-and-commit#lists-and-keys"}),invalidKey:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Invalid React Key",description:"Key prop should be unique and stable",severity:"MEDIUM",fix:"Use item.id, item.key, or index as last resort",documentationLink:"https://react.dev/learn/render-and-commit#lists-and-keys"}),duplicateKey:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Duplicate React Key",description:"Duplicate key values can break reconciliation",severity:"HIGH",fix:"Ensure all keys in the array are unique",documentationLink:"https://react.dev/learn/render-and-commit#lists-and-keys"}),unstableKey:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Unstable React Key",description:"Using index as key can cause reconciliation issues",severity:"MEDIUM",fix:"Use stable identifier from data instead of array index",documentationLink:"https://react.dev/learn/render-and-commit#lists-and-keys"}),suggestKey:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Add Key Prop",description:"Add unique key prop to element",severity:"LOW",fix:"key={item.id}",documentationLink:"https://react.dev/learn/render-and-commit#lists-and-keys"})},schema:[{type:"object",properties:{warnUnstableKeys:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{warnUnstableKeys:true}],createOnce(context){let warnUnstableKeys;let keyTracker;let ITERATOR_METHODS;function resetKeyTracker(){keyTracker.clear()}function isIteratorCall(node){if(node.type!=="CallExpression"){return false}const{callee}=node;if(callee.type==="MemberExpression"&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),ITERATOR_METHODS)){return true}if(callee.type==="MemberExpression"&&callee.object.type==="Identifier"&&callee.object.name==="Array"&&(0,eslint_devkit_1.propertyName)(callee)==="from"&&node.arguments.length>=2){const mapFn=node.arguments[1];if(mapFn.type==="ArrowFunctionExpression"||mapFn.type==="FunctionExpression"){return true}}return false}function isInsideArrayFromMapFn(node){let current=node;while(current?.parent){const parent=current.parent;if(parent.type==="ArrowFunctionExpression"||parent.type==="FunctionExpression"){const grandParent=parent.parent;if(grandParent?.type==="CallExpression"&&grandParent.callee.type==="MemberExpression"&&grandParent.callee.object.type==="Identifier"&&grandParent.callee.object.name==="Array"&&(0,eslint_devkit_1.propertyName)(grandParent.callee)==="from"&&grandParent.arguments[1]===parent){return true}}current=parent}return false}function isInsideChildrenMap(node){let current=node;while(current?.parent){const parent=current.parent;if(parent.type==="ArrowFunctionExpression"||parent.type==="FunctionExpression"){const grandParent=parent.parent;if(grandParent?.type==="CallExpression"){const callee=grandParent.callee;if(callee.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(callee)==="map"){const obj=callee.object;if(obj.type==="Identifier"&&obj.name==="Children"){return true}if(obj.type==="MemberExpression"&&obj.object.type==="Identifier"&&obj.object.name==="React"&&(0,eslint_devkit_1.propertyName)(obj)==="Children"){return true}}}}current=parent}return false}function isDirectIteratorReturn(node){if(isInsideArrayFromMapFn(node)){return isDirectReturnFromFunction(node)}if(isInsideChildrenMap(node)){return isDirectReturnFromFunction(node)}let current=node;while(current.parent){const parent=current.parent;if(parent.type==="JSXElement"||parent.type==="JSXFragment"){return false}if(parent.type==="ArrowFunctionExpression"&&parent.body===current){if(parent.parent&&isIteratorCall(parent.parent)){return true}}if(parent.type==="ReturnStatement"&&parent.argument===current){let funcParent=parent.parent;while(funcParent){if(funcParent.type==="ArrowFunctionExpression"||funcParent.type==="FunctionExpression"){if(funcParent.parent&&isIteratorCall(funcParent.parent)){return true}break}if(funcParent.type==="BlockStatement"){funcParent=funcParent.parent;continue}break}}if(parent.type==="JSXExpressionContainer"){if(current.type==="JSXElement"&&parent.parent?.type==="JSXElement"){return false}}if(parent.type==="ConditionalExpression"||parent.type==="LogicalExpression"||parent.type==="SequenceExpression"){current=parent;continue}if(parent.type==="CallExpression"){break}current=parent}return false}function isDirectReturnFromFunction(node){let current=node;while(current.parent){const parent=current.parent;if(parent.type==="JSXElement"||parent.type==="JSXFragment"){return false}if(parent.type==="ArrowFunctionExpression"&&parent.body===current){return true}if(parent.type==="ReturnStatement"&&parent.argument===current){return true}if(parent.type==="ConditionalExpression"||parent.type==="LogicalExpression"){current=parent;continue}current=parent}return false}function getIteratorKeyExpression(node){let current=node.parent;while(!((current.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression||current.type===eslint_devkit_1.AST_NODE_TYPES.FunctionExpression)&&isIteratorCall(current.parent))){current=current.parent}return keyExpressionForCallback(current)}function checkJSXElementInIteration(node){const isDirectReturn=isDirectIteratorReturn(node);if(!isDirectReturn){return}const keyProp=node.openingElement.attributes.find(attr=>attr.type==="JSXAttribute"&&attr.name.type==="JSXIdentifier"&&attr.name.name==="key");if(!keyProp){const keyExpression=getIteratorKeyExpression(node);context.report({node:node.openingElement,messageId:"missingKey",...keyExpression===null?{}:{suggest:[{messageId:"suggestKey",fix(fixer){return fixer.insertTextAfter(node.openingElement.name,` key={${keyExpression}}`)}}]}});return}if(keyProp.type==="JSXAttribute"&&keyProp.value){const keyValue=keyProp.value;if(warnUnstableKeys&&keyValue.type==="JSXExpressionContainer"&&keyValue.expression.type==="Identifier"&&["i","index","idx","key"].includes(keyValue.expression.name)){context.report({node:keyProp,messageId:"unstableKey"})}}}return{before(){const[options]=context.options;({warnUnstableKeys=true}=options||{});keyTracker=new Map;ITERATOR_METHODS=new Set(["map","forEach","flatMap"])},JSXElement(node){checkJSXElementInIteration(node)},CallExpression(node){if(isIteratorCall(node)){resetKeyTracker()}}}}});
|