eslint-plugin-react-features 1.1.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/CHANGELOG.md +70 -0
- package/LICENSE +23 -0
- package/README.md +155 -0
- package/package.json +65 -0
- package/src/index.d.ts +1093 -0
- package/src/index.js +212 -0
- package/src/rules/migration/react-class-to-hooks.d.ts +22 -0
- package/src/rules/migration/react-class-to-hooks.js +178 -0
- package/src/rules/performance/no-unnecessary-rerenders.d.ts +26 -0
- package/src/rules/performance/no-unnecessary-rerenders.js +212 -0
- package/src/rules/performance/react-no-inline-functions.d.ts +24 -0
- package/src/rules/performance/react-no-inline-functions.js +211 -0
- package/src/rules/performance/react-render-optimization.d.ts +31 -0
- package/src/rules/performance/react-render-optimization.js +294 -0
- package/src/rules/react/checked-requires-onchange-or-readonly.d.ts +16 -0
- package/src/rules/react/checked-requires-onchange-or-readonly.js +74 -0
- package/src/rules/react/default-props-match-prop-types.d.ts +13 -0
- package/src/rules/react/default-props-match-prop-types.js +119 -0
- package/src/rules/react/display-name.d.ts +13 -0
- package/src/rules/react/display-name.js +164 -0
- package/src/rules/react/hooks-exhaustive-deps.d.ts +25 -0
- package/src/rules/react/hooks-exhaustive-deps.js +466 -0
- package/src/rules/react/jsx-handler-names.d.ts +13 -0
- package/src/rules/react/jsx-handler-names.js +57 -0
- package/src/rules/react/jsx-key.d.ts +20 -0
- package/src/rules/react/jsx-key.js +421 -0
- package/src/rules/react/jsx-max-depth.d.ts +19 -0
- package/src/rules/react/jsx-max-depth.js +80 -0
- package/src/rules/react/jsx-no-bind.d.ts +13 -0
- package/src/rules/react/jsx-no-bind.js +64 -0
- package/src/rules/react/jsx-no-duplicate-props.d.ts +21 -0
- package/src/rules/react/jsx-no-duplicate-props.js +70 -0
- package/src/rules/react/jsx-no-literals.d.ts +20 -0
- package/src/rules/react/jsx-no-literals.js +83 -0
- package/src/rules/react/jsx-no-script-url.d.ts +25 -0
- package/src/rules/react/jsx-no-script-url.js +131 -0
- package/src/rules/react/jsx-no-target-blank.d.ts +26 -0
- package/src/rules/react/jsx-no-target-blank.js +176 -0
- package/src/rules/react/no-access-state-in-setstate.d.ts +13 -0
- package/src/rules/react/no-access-state-in-setstate.js +92 -0
- package/src/rules/react/no-adjacent-inline-elements.d.ts +13 -0
- package/src/rules/react/no-adjacent-inline-elements.js +81 -0
- package/src/rules/react/no-arrow-function-lifecycle.d.ts +13 -0
- package/src/rules/react/no-arrow-function-lifecycle.js +63 -0
- package/src/rules/react/no-children-prop.d.ts +13 -0
- package/src/rules/react/no-children-prop.js +60 -0
- package/src/rules/react/no-danger-with-children.d.ts +16 -0
- package/src/rules/react/no-danger-with-children.js +110 -0
- package/src/rules/react/no-danger.d.ts +13 -0
- package/src/rules/react/no-danger.js +45 -0
- package/src/rules/react/no-deprecated.d.ts +16 -0
- package/src/rules/react/no-deprecated.js +140 -0
- package/src/rules/react/no-did-mount-set-state.d.ts +13 -0
- package/src/rules/react/no-did-mount-set-state.js +55 -0
- package/src/rules/react/no-did-update-set-state.d.ts +19 -0
- package/src/rules/react/no-did-update-set-state.js +80 -0
- package/src/rules/react/no-direct-mutation-state.d.ts +20 -0
- package/src/rules/react/no-direct-mutation-state.js +277 -0
- package/src/rules/react/no-find-dom-node.d.ts +15 -0
- package/src/rules/react/no-find-dom-node.js +56 -0
- package/src/rules/react/no-invalid-html-attribute.d.ts +13 -0
- package/src/rules/react/no-invalid-html-attribute.js +84 -0
- package/src/rules/react/no-is-mounted.d.ts +13 -0
- package/src/rules/react/no-is-mounted.js +52 -0
- package/src/rules/react/no-multi-comp.d.ts +18 -0
- package/src/rules/react/no-multi-comp.js +160 -0
- package/src/rules/react/no-namespace.d.ts +13 -0
- package/src/rules/react/no-namespace.js +41 -0
- package/src/rules/react/no-object-type-as-default-prop.d.ts +13 -0
- package/src/rules/react/no-object-type-as-default-prop.js +61 -0
- package/src/rules/react/no-redundant-should-component-update.d.ts +13 -0
- package/src/rules/react/no-redundant-should-component-update.js +55 -0
- package/src/rules/react/no-render-return-value.d.ts +13 -0
- package/src/rules/react/no-render-return-value.js +74 -0
- package/src/rules/react/no-set-state.d.ts +13 -0
- package/src/rules/react/no-set-state.js +50 -0
- package/src/rules/react/no-string-refs.d.ts +13 -0
- package/src/rules/react/no-string-refs.js +68 -0
- package/src/rules/react/no-this-in-sfc.d.ts +13 -0
- package/src/rules/react/no-this-in-sfc.js +65 -0
- package/src/rules/react/no-typos.d.ts +13 -0
- package/src/rules/react/no-typos.js +97 -0
- package/src/rules/react/no-unescaped-entities.d.ts +13 -0
- package/src/rules/react/no-unescaped-entities.js +50 -0
- package/src/rules/react/no-unknown-property.d.ts +13 -0
- package/src/rules/react/no-unknown-property.js +130 -0
- package/src/rules/react/no-unsafe.d.ts +20 -0
- package/src/rules/react/no-unsafe.js +112 -0
- package/src/rules/react/prefer-es6-class.d.ts +13 -0
- package/src/rules/react/prefer-es6-class.js +56 -0
- package/src/rules/react/prefer-stateless-function.d.ts +16 -0
- package/src/rules/react/prefer-stateless-function.js +134 -0
- package/src/rules/react/prop-types.d.ts +18 -0
- package/src/rules/react/prop-types.js +153 -0
- package/src/rules/react/react-in-jsx-scope.d.ts +13 -0
- package/src/rules/react/react-in-jsx-scope.js +94 -0
- package/src/rules/react/require-default-props.d.ts +16 -0
- package/src/rules/react/require-default-props.js +146 -0
- package/src/rules/react/require-optimization.d.ts +26 -0
- package/src/rules/react/require-optimization.js +436 -0
- package/src/rules/react/require-render-return.d.ts +13 -0
- package/src/rules/react/require-render-return.js +87 -0
- package/src/rules/react/required-attributes.d.ts +28 -0
- package/src/rules/react/required-attributes.js +212 -0
- package/src/rules/react/sort-comp.d.ts +17 -0
- package/src/rules/react/sort-comp.js +160 -0
- package/src/rules/react/state-in-constructor.d.ts +13 -0
- package/src/rules/react/state-in-constructor.js +103 -0
- package/src/rules/react/static-property-placement.d.ts +20 -0
- package/src/rules/react/static-property-placement.js +166 -0
- package/src/rules/react/void-dom-elements-no-children.d.ts +15 -0
- package/src/rules/react/void-dom-elements-no-children.js +94 -0
- package/src/types/index.d.ts +54 -0
- package/src/types/index.js +7 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noMultiComp = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
exports.noMultiComp = (0, eslint_devkit_1.createRule)({
|
|
12
|
+
name: 'no-multi-comp',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Prevent multiple components per file',
|
|
17
|
+
},
|
|
18
|
+
schema: [
|
|
19
|
+
{
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
ignoreStateless: {
|
|
23
|
+
type: 'boolean',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
messages: {
|
|
30
|
+
noMultiComp: (0, eslint_devkit_2.formatLLMMessage)({
|
|
31
|
+
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
32
|
+
issueName: 'Multiple Components',
|
|
33
|
+
description: 'Multiple components defined in single file',
|
|
34
|
+
severity: 'LOW',
|
|
35
|
+
fix: 'Extract components to separate files',
|
|
36
|
+
documentationLink: 'https://react.dev/learn/thinking-in-react#step-3-identify-where-your-state-should-live',
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
defaultOptions: [{ ignoreStateless: false }],
|
|
41
|
+
create(context) {
|
|
42
|
+
const components = [];
|
|
43
|
+
return {
|
|
44
|
+
// Class components
|
|
45
|
+
ClassDeclaration(node) {
|
|
46
|
+
if (isReactComponent(node)) {
|
|
47
|
+
components.push(node);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
// Function components
|
|
51
|
+
'VariableDeclarator, FunctionDeclaration'(node) {
|
|
52
|
+
if (isReactComponentFunction(getComponentFromDeclaration(node))) {
|
|
53
|
+
components.push(node);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
'Program:exit'() {
|
|
57
|
+
const [firstOption] = context.options;
|
|
58
|
+
const ignoreStateless = firstOption?.ignoreStateless ?? false;
|
|
59
|
+
let componentCount = components.length;
|
|
60
|
+
if (ignoreStateless) {
|
|
61
|
+
// Count only stateful components
|
|
62
|
+
componentCount = components.filter(comp => !isStatelessComponent(comp)).length;
|
|
63
|
+
}
|
|
64
|
+
if (componentCount > 1) {
|
|
65
|
+
// Report on all components except the first
|
|
66
|
+
for (let i = 1; i < components.length; i++) {
|
|
67
|
+
const comp = components[i];
|
|
68
|
+
if (!ignoreStateless || !isStatelessComponent(comp)) {
|
|
69
|
+
context.report({
|
|
70
|
+
node: getComponentNameNode(comp),
|
|
71
|
+
messageId: 'noMultiComp',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
function getComponentFromDeclaration(node) {
|
|
79
|
+
if (node.type === 'FunctionDeclaration') {
|
|
80
|
+
return node;
|
|
81
|
+
}
|
|
82
|
+
if (node.type === 'VariableDeclarator' && node.init) {
|
|
83
|
+
if (node.init.type === 'FunctionExpression' || node.init.type === 'ArrowFunctionExpression') {
|
|
84
|
+
return node.init;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function isReactComponentFunction(node) {
|
|
90
|
+
if (!node)
|
|
91
|
+
return false;
|
|
92
|
+
const body = node.type === 'FunctionDeclaration' ? node.body : node.body;
|
|
93
|
+
return containsJSX(body);
|
|
94
|
+
}
|
|
95
|
+
function containsJSX(node, visited = new Set()) {
|
|
96
|
+
if (!node)
|
|
97
|
+
return false;
|
|
98
|
+
if (visited.has(node))
|
|
99
|
+
return false;
|
|
100
|
+
visited.add(node);
|
|
101
|
+
if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
// Skip non-child keys to avoid circular references
|
|
105
|
+
const skipKeys = new Set(['parent', 'range', 'loc', 'start', 'end', 'tokens', 'comments']);
|
|
106
|
+
for (const key in node) {
|
|
107
|
+
if (skipKeys.has(key))
|
|
108
|
+
continue;
|
|
109
|
+
const child = node[key];
|
|
110
|
+
if (child && typeof child === 'object') {
|
|
111
|
+
if (Array.isArray(child)) {
|
|
112
|
+
for (const item of child) {
|
|
113
|
+
if (item && typeof item === 'object' && 'type' in item) {
|
|
114
|
+
if (containsJSX(item, visited)) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if ('type' in child) {
|
|
121
|
+
if (containsJSX(child, visited)) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
function isReactComponent(node) {
|
|
130
|
+
if (!node.superClass)
|
|
131
|
+
return false;
|
|
132
|
+
if (node.superClass.type === 'Identifier') {
|
|
133
|
+
return node.superClass.name === 'Component' || node.superClass.name === 'PureComponent';
|
|
134
|
+
}
|
|
135
|
+
if (node.superClass.type === 'MemberExpression') {
|
|
136
|
+
return (node.superClass.object.type === 'Identifier' &&
|
|
137
|
+
node.superClass.object.name === 'React' &&
|
|
138
|
+
node.superClass.property.type === 'Identifier' &&
|
|
139
|
+
(node.superClass.property.name === 'Component' || node.superClass.property.name === 'PureComponent'));
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
function isStatelessComponent(node) {
|
|
144
|
+
// Simple heuristic: check if it's a function component without useState
|
|
145
|
+
return !isReactComponent(node);
|
|
146
|
+
}
|
|
147
|
+
function getComponentNameNode(node) {
|
|
148
|
+
if (node.type === 'ClassDeclaration') {
|
|
149
|
+
return node.id || node;
|
|
150
|
+
}
|
|
151
|
+
if (node.type === 'FunctionDeclaration') {
|
|
152
|
+
return node.id || node;
|
|
153
|
+
}
|
|
154
|
+
if (node.type === 'VariableDeclarator') {
|
|
155
|
+
return node.id || node;
|
|
156
|
+
}
|
|
157
|
+
return node;
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-namespace
|
|
8
|
+
* Prevent namespace imports
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const noNamespace: TSESLint.RuleModule<"noNamespace", [], unknown, TSESLint.RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noNamespace = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
exports.noNamespace = (0, eslint_devkit_1.createRule)({
|
|
12
|
+
name: 'no-namespace',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Prevent namespace imports',
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
noNamespace: (0, eslint_devkit_2.formatLLMMessage)({
|
|
20
|
+
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
21
|
+
issueName: 'Namespace Import',
|
|
22
|
+
description: 'Namespace import detected',
|
|
23
|
+
severity: 'LOW',
|
|
24
|
+
fix: 'Use named imports instead: import { Component } from "react"',
|
|
25
|
+
documentationLink: 'https://react.dev/learn/importing-and-exporting-components',
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
schema: [],
|
|
29
|
+
},
|
|
30
|
+
defaultOptions: [],
|
|
31
|
+
create(context) {
|
|
32
|
+
return {
|
|
33
|
+
ImportNamespaceSpecifier(node) {
|
|
34
|
+
context.report({
|
|
35
|
+
node,
|
|
36
|
+
messageId: 'noNamespace',
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-object-type-as-default-prop
|
|
8
|
+
* Prevent object types as default props
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const noObjectTypeAsDefaultProp: TSESLint.RuleModule<"noObjectTypeAsDefaultProp", [], unknown, TSESLint.RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noObjectTypeAsDefaultProp = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
exports.noObjectTypeAsDefaultProp = (0, eslint_devkit_1.createRule)({
|
|
12
|
+
name: 'no-object-type-as-default-prop',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Prevent object types as default props',
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
noObjectTypeAsDefaultProp: (0, eslint_devkit_2.formatLLMMessage)({
|
|
20
|
+
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
21
|
+
issueName: 'Object as Default Prop',
|
|
22
|
+
description: 'Object used as default prop value',
|
|
23
|
+
severity: 'MEDIUM',
|
|
24
|
+
fix: 'Create object outside component or use factory function',
|
|
25
|
+
documentationLink: 'https://react.dev/learn/passing-props-to-a-component#default-props',
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
schema: [],
|
|
29
|
+
},
|
|
30
|
+
defaultOptions: [],
|
|
31
|
+
create(context) {
|
|
32
|
+
return {
|
|
33
|
+
// Check defaultProps assignments (PropertyDefinition is used by TypeScript parser)
|
|
34
|
+
'PropertyDefinition[key.name="defaultProps"]'(node) {
|
|
35
|
+
if (node.value && node.value.type === 'ObjectExpression') {
|
|
36
|
+
for (const prop of node.value.properties) {
|
|
37
|
+
if (prop.type === 'Property' && prop.value.type === 'ObjectExpression') {
|
|
38
|
+
context.report({
|
|
39
|
+
node: prop.key,
|
|
40
|
+
messageId: 'noObjectTypeAsDefaultProp',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
// Check default parameter assignments in function components
|
|
47
|
+
AssignmentPattern(node) {
|
|
48
|
+
if (node.right.type === 'ObjectExpression') {
|
|
49
|
+
// Check if this is a destructured parameter in a function component
|
|
50
|
+
if (node.parent.type === 'Property' || node.parent.type === 'RestElement') {
|
|
51
|
+
// This is likely a function parameter with default value
|
|
52
|
+
context.report({
|
|
53
|
+
node: node.left,
|
|
54
|
+
messageId: 'noObjectTypeAsDefaultProp',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-redundant-should-component-update
|
|
8
|
+
* Prevent redundant shouldComponentUpdate
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const noRedundantShouldComponentUpdate: TSESLint.RuleModule<"noRedundantShouldComponentUpdate", [], unknown, TSESLint.RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noRedundantShouldComponentUpdate = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
exports.noRedundantShouldComponentUpdate = (0, eslint_devkit_1.createRule)({
|
|
12
|
+
name: 'no-redundant-should-component-update',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Prevent redundant shouldComponentUpdate',
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
noRedundantShouldComponentUpdate: (0, eslint_devkit_2.formatLLMMessage)({
|
|
20
|
+
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
21
|
+
issueName: 'Redundant shouldComponentUpdate',
|
|
22
|
+
description: 'shouldComponentUpdate method does nothing useful',
|
|
23
|
+
severity: 'MEDIUM',
|
|
24
|
+
fix: 'Remove redundant shouldComponentUpdate or implement proper logic',
|
|
25
|
+
documentationLink: 'https://react.dev/reference/react/Component#shouldcomponentupdate',
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
schema: [],
|
|
29
|
+
},
|
|
30
|
+
defaultOptions: [],
|
|
31
|
+
create(context) {
|
|
32
|
+
return {
|
|
33
|
+
MethodDefinition(node) {
|
|
34
|
+
if (node.key.type === 'Identifier' &&
|
|
35
|
+
node.key.name === 'shouldComponentUpdate' &&
|
|
36
|
+
node.value.type === 'FunctionExpression') {
|
|
37
|
+
// Check if the method just returns true
|
|
38
|
+
const body = node.value.body;
|
|
39
|
+
if (body.type === 'BlockStatement' && body.body.length === 1) {
|
|
40
|
+
const statement = body.body[0];
|
|
41
|
+
if (statement.type === 'ReturnStatement' &&
|
|
42
|
+
statement.argument &&
|
|
43
|
+
statement.argument.type === 'Literal' &&
|
|
44
|
+
statement.argument.value === true) {
|
|
45
|
+
context.report({
|
|
46
|
+
node: node.key,
|
|
47
|
+
messageId: 'noRedundantShouldComponentUpdate',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-render-return-value
|
|
8
|
+
* Prevent using render return value
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const noRenderReturnValue: TSESLint.RuleModule<"noRenderReturnValue", [], unknown, TSESLint.RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noRenderReturnValue = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
exports.noRenderReturnValue = (0, eslint_devkit_1.createRule)({
|
|
12
|
+
name: 'no-render-return-value',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Prevent using render return value',
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
noRenderReturnValue: (0, eslint_devkit_2.formatLLMMessage)({
|
|
20
|
+
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
21
|
+
issueName: 'Render Return Value Usage',
|
|
22
|
+
description: 'Using return value of ReactDOM.render()',
|
|
23
|
+
severity: 'HIGH',
|
|
24
|
+
fix: 'ReactDOM.render() return value is deprecated, use refs instead',
|
|
25
|
+
documentationLink: 'https://react.dev/reference/react-dom/render',
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
schema: [],
|
|
29
|
+
},
|
|
30
|
+
defaultOptions: [],
|
|
31
|
+
create(context) {
|
|
32
|
+
return {
|
|
33
|
+
VariableDeclarator(node) {
|
|
34
|
+
if (node.init &&
|
|
35
|
+
node.init.type === 'CallExpression' &&
|
|
36
|
+
isReactDOMRenderCall(node.init)) {
|
|
37
|
+
context.report({
|
|
38
|
+
node: node.id,
|
|
39
|
+
messageId: 'noRenderReturnValue',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
AssignmentExpression(node) {
|
|
44
|
+
if (node.right.type === 'CallExpression' &&
|
|
45
|
+
isReactDOMRenderCall(node.right)) {
|
|
46
|
+
context.report({
|
|
47
|
+
node: node.left,
|
|
48
|
+
messageId: 'noRenderReturnValue',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* Check if call expression is ReactDOM.render()
|
|
57
|
+
*/
|
|
58
|
+
function isReactDOMRenderCall(node) {
|
|
59
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
60
|
+
node.callee.object.type === 'MemberExpression' &&
|
|
61
|
+
node.callee.object.object.type === 'Identifier' &&
|
|
62
|
+
node.callee.object.object.name === 'ReactDOM' &&
|
|
63
|
+
node.callee.object.property.type === 'Identifier' &&
|
|
64
|
+
node.callee.object.property.name === 'render' &&
|
|
65
|
+
node.callee.property.type === 'Identifier' &&
|
|
66
|
+
node.callee.property.name === 'render') {
|
|
67
|
+
return false; // This would be ReactDOM.render.render which is invalid
|
|
68
|
+
}
|
|
69
|
+
return (node.callee.type === 'MemberExpression' &&
|
|
70
|
+
node.callee.object.type === 'Identifier' &&
|
|
71
|
+
node.callee.object.name === 'ReactDOM' &&
|
|
72
|
+
node.callee.property.type === 'Identifier' &&
|
|
73
|
+
node.callee.property.name === 'render');
|
|
74
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-set-state
|
|
8
|
+
* Disallow usage of setState (encourage functional components with hooks)
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const noSetState: TSESLint.RuleModule<"noSetState", [], unknown, TSESLint.RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noSetState = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
exports.noSetState = (0, eslint_devkit_1.createRule)({
|
|
12
|
+
name: 'no-set-state',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Disallow usage of setState to encourage functional components with hooks',
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
noSetState: (0, eslint_devkit_2.formatLLMMessage)({
|
|
20
|
+
icon: eslint_devkit_2.MessageIcons.MIGRATION,
|
|
21
|
+
issueName: 'setState Usage',
|
|
22
|
+
description: 'Usage of setState detected',
|
|
23
|
+
severity: 'MEDIUM',
|
|
24
|
+
fix: 'Convert to functional component with useState hook',
|
|
25
|
+
documentationLink: 'https://react.dev/reference/react/useState',
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
schema: [],
|
|
29
|
+
},
|
|
30
|
+
defaultOptions: [],
|
|
31
|
+
create(context) {
|
|
32
|
+
return {
|
|
33
|
+
CallExpression(node) {
|
|
34
|
+
// Check if this is a setState call
|
|
35
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
36
|
+
node.callee.property.type === 'Identifier' &&
|
|
37
|
+
node.callee.property.name === 'setState') {
|
|
38
|
+
context.report({
|
|
39
|
+
node: node.callee.property,
|
|
40
|
+
messageId: 'noSetState',
|
|
41
|
+
data: {
|
|
42
|
+
methodName: 'setState',
|
|
43
|
+
suggestion: 'Use useState hook in functional component',
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-string-refs
|
|
8
|
+
* Disallow string refs (deprecated pattern)
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const noStringRefs: TSESLint.RuleModule<"noStringRefs", [], unknown, TSESLint.RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noStringRefs = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
exports.noStringRefs = (0, eslint_devkit_1.createRule)({
|
|
12
|
+
name: 'no-string-refs',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Disallow string refs',
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
noStringRefs: (0, eslint_devkit_2.formatLLMMessage)({
|
|
20
|
+
icon: eslint_devkit_2.MessageIcons.MIGRATION,
|
|
21
|
+
issueName: 'String Refs',
|
|
22
|
+
description: 'Usage of string refs detected',
|
|
23
|
+
severity: 'HIGH',
|
|
24
|
+
fix: 'Use callback refs: ref={(el) => this.myRef = el} or createRef: this.myRef = React.createRef()',
|
|
25
|
+
documentationLink: 'https://react.dev/reference/react/forwardRef',
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
schema: [],
|
|
29
|
+
},
|
|
30
|
+
defaultOptions: [],
|
|
31
|
+
create(context) {
|
|
32
|
+
return {
|
|
33
|
+
JSXAttribute(node) {
|
|
34
|
+
if (node.name.type === 'JSXIdentifier' &&
|
|
35
|
+
node.name.name === 'ref') {
|
|
36
|
+
// Check for direct string literals
|
|
37
|
+
if (node.value &&
|
|
38
|
+
node.value.type === 'Literal' &&
|
|
39
|
+
typeof node.value.value === 'string') {
|
|
40
|
+
context.report({
|
|
41
|
+
node: node.name,
|
|
42
|
+
messageId: 'noStringRefs',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Check for string literals inside JSX expressions
|
|
46
|
+
else if (node.value &&
|
|
47
|
+
node.value.type === 'JSXExpressionContainer' &&
|
|
48
|
+
node.value.expression.type === 'Literal' &&
|
|
49
|
+
typeof node.value.expression.value === 'string') {
|
|
50
|
+
context.report({
|
|
51
|
+
node: node.name,
|
|
52
|
+
messageId: 'noStringRefs',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Check for template literals
|
|
56
|
+
else if (node.value &&
|
|
57
|
+
node.value.type === 'JSXExpressionContainer' &&
|
|
58
|
+
node.value.expression.type === 'TemplateLiteral') {
|
|
59
|
+
context.report({
|
|
60
|
+
node: node.name,
|
|
61
|
+
messageId: 'noStringRefs',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-this-in-sfc
|
|
8
|
+
* Disallow this from being used in stateless functional components
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const noThisInSfc: TSESLint.RuleModule<"noThisInSfc", [], unknown, TSESLint.RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|