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,65 @@
|
|
|
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.noThisInSfc = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
exports.noThisInSfc = (0, eslint_devkit_1.createRule)({
|
|
12
|
+
name: 'no-this-in-sfc',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Disallow this from being used in stateless functional components',
|
|
17
|
+
},
|
|
18
|
+
schema: [],
|
|
19
|
+
messages: {
|
|
20
|
+
noThisInSfc: (0, eslint_devkit_2.formatLLMMessage)({
|
|
21
|
+
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
22
|
+
issueName: 'Invalid this usage',
|
|
23
|
+
description: 'this cannot be used in stateless functional components',
|
|
24
|
+
severity: 'HIGH',
|
|
25
|
+
fix: 'Convert to class component or use hooks for state',
|
|
26
|
+
documentationLink: 'https://react.dev/learn/your-first-component',
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
defaultOptions: [],
|
|
31
|
+
create(context) {
|
|
32
|
+
let inClassContext = false;
|
|
33
|
+
return {
|
|
34
|
+
// Track class context
|
|
35
|
+
ClassDeclaration() {
|
|
36
|
+
inClassContext = true;
|
|
37
|
+
},
|
|
38
|
+
'ClassDeclaration:exit'() {
|
|
39
|
+
inClassContext = false;
|
|
40
|
+
},
|
|
41
|
+
ClassExpression() {
|
|
42
|
+
inClassContext = true;
|
|
43
|
+
},
|
|
44
|
+
'ClassExpression:exit'() {
|
|
45
|
+
inClassContext = false;
|
|
46
|
+
},
|
|
47
|
+
// Track method context within classes
|
|
48
|
+
MethodDefinition() {
|
|
49
|
+
// Already in class context, this is allowed
|
|
50
|
+
},
|
|
51
|
+
ThisExpression(node) {
|
|
52
|
+
// Allow 'this' in class contexts
|
|
53
|
+
if (inClassContext) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// Flag 'this' usage outside of class contexts
|
|
57
|
+
// In React, this typically indicates the code should be in a class component
|
|
58
|
+
context.report({
|
|
59
|
+
node,
|
|
60
|
+
messageId: 'noThisInSfc',
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
});
|
|
@@ -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-typos
|
|
8
|
+
* Catch common typos
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const noTypos: TSESLint.RuleModule<"noTypos", [], unknown, TSESLint.RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
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.noTypos = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
const COMMON_TYPOS = new Map([
|
|
12
|
+
['defaulProps', 'defaultProps'],
|
|
13
|
+
['defaulProps', 'defaultProps'],
|
|
14
|
+
['defalutProps', 'defaultProps'],
|
|
15
|
+
['defualtProps', 'defaultProps'],
|
|
16
|
+
['DefaulProps', 'DefaultProps'],
|
|
17
|
+
['DefalutProps', 'DefaultProps'],
|
|
18
|
+
['DefualtProps', 'DefaultProps'],
|
|
19
|
+
['propTypes', 'propTypes'], // This would catch variations
|
|
20
|
+
['PropTypes', 'PropTypes'],
|
|
21
|
+
['componenDidMount', 'componentDidMount'],
|
|
22
|
+
['componenDidUpdate', 'componentDidUpdate'],
|
|
23
|
+
['componenWillUnmount', 'componentWillUnmount'],
|
|
24
|
+
['componenWillMount', 'componentWillMount'],
|
|
25
|
+
['componenWillReceiveProps', 'componentWillReceiveProps'],
|
|
26
|
+
['componenWillUpdate', 'componentWillUpdate'],
|
|
27
|
+
['shoudComponentUpdate', 'shouldComponentUpdate'],
|
|
28
|
+
['getDerivedStateFromProps', 'getDerivedStateFromProps'],
|
|
29
|
+
['getSnapshoBeforeUpdate', 'getSnapshotBeforeUpdate'],
|
|
30
|
+
['UNSAFE_componenWillMount', 'UNSAFE_componentWillMount'],
|
|
31
|
+
['UNSAFE_componenWillReceiveProps', 'UNSAFE_componentWillReceiveProps'],
|
|
32
|
+
['UNSAFE_componenWillUpdate', 'UNSAFE_componentWillUpdate'],
|
|
33
|
+
]);
|
|
34
|
+
exports.noTypos = (0, eslint_devkit_1.createRule)({
|
|
35
|
+
name: 'no-typos',
|
|
36
|
+
meta: {
|
|
37
|
+
type: 'problem',
|
|
38
|
+
docs: {
|
|
39
|
+
description: 'Catch common typos',
|
|
40
|
+
},
|
|
41
|
+
schema: [],
|
|
42
|
+
messages: {
|
|
43
|
+
noTypos: (0, eslint_devkit_2.formatLLMMessage)({
|
|
44
|
+
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
45
|
+
issueName: 'Typo Detected',
|
|
46
|
+
description: 'Common typo in React method/property name',
|
|
47
|
+
severity: 'LOW',
|
|
48
|
+
fix: 'Correct the spelling to match React API',
|
|
49
|
+
documentationLink: 'https://react.dev/reference/react/Component',
|
|
50
|
+
}),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
defaultOptions: [],
|
|
54
|
+
create(context) {
|
|
55
|
+
return {
|
|
56
|
+
// Check class property names (PropertyDefinition is used by TypeScript parser)
|
|
57
|
+
PropertyDefinition(node) {
|
|
58
|
+
if (node.key.type === 'Identifier') {
|
|
59
|
+
const name = node.key.name;
|
|
60
|
+
const correction = COMMON_TYPOS.get(name);
|
|
61
|
+
if (correction) {
|
|
62
|
+
context.report({
|
|
63
|
+
node: node.key,
|
|
64
|
+
messageId: 'noTypos',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
// Check method names
|
|
70
|
+
MethodDefinition(node) {
|
|
71
|
+
if (node.key.type === 'Identifier') {
|
|
72
|
+
const name = node.key.name;
|
|
73
|
+
const correction = COMMON_TYPOS.get(name);
|
|
74
|
+
if (correction) {
|
|
75
|
+
context.report({
|
|
76
|
+
node: node.key,
|
|
77
|
+
messageId: 'noTypos',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
// Check property access
|
|
83
|
+
MemberExpression(node) {
|
|
84
|
+
if (node.property.type === 'Identifier') {
|
|
85
|
+
const name = node.property.name;
|
|
86
|
+
const correction = COMMON_TYPOS.get(name);
|
|
87
|
+
if (correction) {
|
|
88
|
+
context.report({
|
|
89
|
+
node: node.property,
|
|
90
|
+
messageId: 'noTypos',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
});
|
|
@@ -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-unescaped-entities
|
|
8
|
+
* Prevent unescaped entities
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const noUnescapedEntities: TSESLint.RuleModule<"noUnescapedEntities", [], 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.noUnescapedEntities = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
const UNESCAPED_ENTITIES = /[<>"]/;
|
|
12
|
+
exports.noUnescapedEntities = (0, eslint_devkit_1.createRule)({
|
|
13
|
+
name: 'no-unescaped-entities',
|
|
14
|
+
meta: {
|
|
15
|
+
type: 'problem',
|
|
16
|
+
docs: {
|
|
17
|
+
description: 'Prevent unescaped entities',
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
noUnescapedEntities: (0, eslint_devkit_2.formatLLMMessage)({
|
|
21
|
+
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
22
|
+
issueName: 'Unescaped Entity',
|
|
23
|
+
description: 'Unescaped HTML entity in JSX text',
|
|
24
|
+
severity: 'MEDIUM',
|
|
25
|
+
fix: 'Use HTML entities (<, >, ") or wrap in curly braces',
|
|
26
|
+
documentationLink: 'https://react.dev/learn/javascript-in-jsx-with-curly-braces',
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
schema: [],
|
|
30
|
+
},
|
|
31
|
+
defaultOptions: [],
|
|
32
|
+
create(context) {
|
|
33
|
+
return {
|
|
34
|
+
JSXText(node) {
|
|
35
|
+
const text = node.value;
|
|
36
|
+
// Skip whitespace-only text
|
|
37
|
+
if (!text.trim()) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Check for unescaped entities
|
|
41
|
+
if (UNESCAPED_ENTITIES.test(text)) {
|
|
42
|
+
context.report({
|
|
43
|
+
node,
|
|
44
|
+
messageId: 'noUnescapedEntities',
|
|
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-unknown-property
|
|
8
|
+
* Disallow unknown DOM properties in JSX
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const noUnknownProperty: TSESLint.RuleModule<"noUnknownProperty", [], unknown, TSESLint.RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
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.noUnknownProperty = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
const VALID_DOM_PROPERTIES = new Set([
|
|
12
|
+
// HTML attributes
|
|
13
|
+
'accept', 'acceptCharset', 'accessKey', 'action', 'allowFullScreen', 'allowTransparency',
|
|
14
|
+
'alt', 'async', 'autoComplete', 'autoFocus', 'autoPlay', 'capture', 'cellPadding',
|
|
15
|
+
'cellSpacing', 'challenge', 'charSet', 'checked', 'cite', 'classID', 'className',
|
|
16
|
+
'colSpan', 'cols', 'content', 'contentEditable', 'contextMenu', 'controls', 'coords',
|
|
17
|
+
'crossOrigin', 'data', 'dateTime', 'default', 'defer', 'dir', 'disabled', 'download',
|
|
18
|
+
'draggable', 'encType', 'form', 'formAction', 'formEncType', 'formMethod', 'formNoValidate',
|
|
19
|
+
'formTarget', 'frameBorder', 'headers', 'height', 'hidden', 'high', 'href', 'hrefLang',
|
|
20
|
+
'htmlFor', 'httpEquiv', 'icon', 'id', 'inputMode', 'integrity', 'is', 'keyParams',
|
|
21
|
+
'keyType', 'kind', 'label', 'lang', 'list', 'loop', 'low', 'manifest', 'marginHeight',
|
|
22
|
+
'marginWidth', 'max', 'maxLength', 'media', 'mediaGroup', 'method', 'min', 'minLength',
|
|
23
|
+
'multiple', 'muted', 'name', 'noValidate', 'nonce', 'open', 'optimum', 'pattern',
|
|
24
|
+
'placeholder', 'poster', 'preload', 'profile', 'radioGroup', 'readOnly', 'rel',
|
|
25
|
+
'required', 'reversed', 'role', 'rowSpan', 'rows', 'sandbox', 'scope', 'scoped',
|
|
26
|
+
'scrolling', 'seamless', 'selected', 'shape', 'size', 'sizes', 'span', 'spellCheck',
|
|
27
|
+
'src', 'srcDoc', 'srcLang', 'srcSet', 'start', 'step', 'style', 'summary', 'tabIndex',
|
|
28
|
+
'target', 'title', 'type', 'useMap', 'value', 'width', 'wmode', 'wrap',
|
|
29
|
+
// React-specific attributes
|
|
30
|
+
'children', 'dangerouslySetInnerHTML', 'key', 'ref', 'suppressContentEditableWarning',
|
|
31
|
+
'suppressHydrationWarning',
|
|
32
|
+
// SVG attributes
|
|
33
|
+
'accentHeight', 'accumulate', 'additive', 'alignmentBaseline', 'allowReorder',
|
|
34
|
+
'alphabetic', 'amplitude', 'arabicForm', 'ascent', 'attributeName', 'attributeType',
|
|
35
|
+
'autoReverse', 'azimuth', 'baseFrequency', 'baselineShift', 'baseProfile', 'bbox',
|
|
36
|
+
'begin', 'bias', 'by', 'calcMode', 'capHeight', 'clip', 'clipPath', 'clipPathUnits',
|
|
37
|
+
'clipRule', 'colorInterpolation', 'colorInterpolationFilters', 'colorProfile',
|
|
38
|
+
'colorRendering', 'contentScriptType', 'contentStyleType', 'cursor', 'cx', 'cy',
|
|
39
|
+
'd', 'decelerate', 'descent', 'diffuseConstant', 'direction', 'display', 'divisor',
|
|
40
|
+
'dominantBaseline', 'dur', 'dx', 'dy', 'edgeMode', 'elevation', 'enableBackground',
|
|
41
|
+
'end', 'exponent', 'externalResourcesRequired', 'fill', 'fillOpacity', 'fillRule',
|
|
42
|
+
'filter', 'filterRes', 'filterUnits', 'floodColor', 'floodOpacity', 'focusable',
|
|
43
|
+
'fontFamily', 'fontSize', 'fontSizeAdjust', 'fontStretch', 'fontStyle', 'fontVariant',
|
|
44
|
+
'fontWeight', 'format', 'from', 'fx', 'fy', 'g1', 'g2', 'glyphName', 'glyphOrientationHorizontal',
|
|
45
|
+
'glyphOrientationVertical', 'glyphRef', 'gradientTransform', 'gradientUnits', 'hanging',
|
|
46
|
+
'horizAdvX', 'horizOriginX', 'ideographic', 'imageRendering', 'in', 'in2', 'intercept',
|
|
47
|
+
'k', 'k1', 'k2', 'k3', 'k4', 'kernelMatrix', 'kernelUnitLength', 'kerning', 'keyPoints',
|
|
48
|
+
'keySplines', 'keyTimes', 'lengthAdjust', 'letterSpacing', 'lightingColor', 'limitingConeAngle',
|
|
49
|
+
'local', 'markerEnd', 'markerHeight', 'markerMid', 'markerStart', 'markerUnits', 'markerWidth',
|
|
50
|
+
'mask', 'maskContentUnits', 'maskUnits', 'mathematical', 'mode', 'numOctaves', 'offset',
|
|
51
|
+
'opacity', 'operator', 'order', 'orient', 'orientation', 'origin', 'overflow', 'overlinePosition',
|
|
52
|
+
'overlineThickness', 'paintOrder', 'panose1', 'pathLength', 'patternContentUnits',
|
|
53
|
+
'patternTransform', 'patternUnits', 'pointerEvents', 'points', 'pointsAtX', 'pointsAtY',
|
|
54
|
+
'pointsAtZ', 'preserveAlpha', 'preserveAspectRatio', 'primitiveUnits', 'r', 'radius',
|
|
55
|
+
'refX', 'refY', 'renderingIntent', 'repeatCount', 'repeatDur', 'requiredExtensions',
|
|
56
|
+
'requiredFeatures', 'restart', 'result', 'rotate', 'rx', 'ry', 'scale', 'seed', 'shapeRendering',
|
|
57
|
+
'slope', 'spacing', 'specularConstant', 'specularExponent', 'speed', 'spreadMethod',
|
|
58
|
+
'startOffset', 'stdDeviation', 'stemh', 'stemv', 'stitchTiles', 'stopColor', 'stopOpacity',
|
|
59
|
+
'strikethroughPosition', 'strikethroughThickness', 'string', 'stroke', 'strokeDasharray',
|
|
60
|
+
'strokeDashoffset', 'strokeLinecap', 'strokeLinejoin', 'strokeMiterlimit', 'strokeOpacity',
|
|
61
|
+
'strokeWidth', 'surfaceScale', 'systemLanguage', 'tableValues', 'targetX', 'targetY',
|
|
62
|
+
'textAnchor', 'textDecoration', 'textLength', 'textRendering', 'to', 'transform', 'u1',
|
|
63
|
+
'u2', 'underlinePosition', 'underlineThickness', 'unicode', 'unicodeBidi', 'unicodeRange',
|
|
64
|
+
'unitsPerEm', 'vAlphabetic', 'values', 'vectorEffect', 'version', 'vertAdvY', 'vertOriginX',
|
|
65
|
+
'vertOriginY', 'vHanging', 'vIdeographic', 'viewBox', 'viewTarget', 'visibility', 'vMathematical',
|
|
66
|
+
'widths', 'wordSpacing', 'writingMode', 'x', 'x1', 'x2', 'xChannelSelector', 'xHeight',
|
|
67
|
+
'xlinkActuate', 'xlinkArcrole', 'xlinkHref', 'xlinkRole', 'xlinkShow', 'xlinkTitle',
|
|
68
|
+
'xlinkType', 'xmlBase', 'xmlLang', 'xmlSpace', 'y', 'y1', 'y2', 'yChannelSelector',
|
|
69
|
+
'z', 'zoomAndPan',
|
|
70
|
+
// Event handlers
|
|
71
|
+
'onAbort', 'onAnimationEnd', 'onAnimationIteration', 'onAnimationStart', 'onAuxClick',
|
|
72
|
+
'onBeforeInput', 'onBlur', 'onCanPlay', 'onCanPlayThrough', 'onChange', 'onClick',
|
|
73
|
+
'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate', 'onContextMenu',
|
|
74
|
+
'onCopy', 'onCut', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit',
|
|
75
|
+
'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onDurationChange', 'onEmptied',
|
|
76
|
+
'onEncrypted', 'onEnded', 'onError', 'onFocus', 'onFocusIn', 'onFocusOut', 'onFormData',
|
|
77
|
+
'onGotPointerCapture', 'onInput', 'onInvalid', 'onKeyDown', 'onKeyPress', 'onKeyUp',
|
|
78
|
+
'onLoad', 'onLoadStart', 'onLoadedData', 'onLoadedMetadata', 'onLostPointerCapture',
|
|
79
|
+
'onMouseDown', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver',
|
|
80
|
+
'onMouseUp', 'onPaste', 'onPause', 'onPlay', 'onPlaying', 'onPointerCancel', 'onPointerDown',
|
|
81
|
+
'onPointerEnter', 'onPointerLeave', 'onPointerMove', 'onPointerOut', 'onPointerOver',
|
|
82
|
+
'onPointerUp', 'onProgress', 'onRateChange', 'onReset', 'onResize', 'onScroll', 'onSeeked',
|
|
83
|
+
'onSeeking', 'onSelect', 'onStalled', 'onSubmit', 'onSuspend', 'onTimeUpdate', 'onToggle',
|
|
84
|
+
'onTouchCancel', 'onTouchEnd', 'onTouchMove', 'onTouchStart', 'onTransitionEnd', 'onVolumeChange',
|
|
85
|
+
'onWaiting', 'onWheel',
|
|
86
|
+
]);
|
|
87
|
+
const REACT_PROPS = new Set([
|
|
88
|
+
'defaultChecked', 'defaultValue', 'suppressContentEditableWarning', 'suppressHydrationWarning',
|
|
89
|
+
]);
|
|
90
|
+
exports.noUnknownProperty = (0, eslint_devkit_1.createRule)({
|
|
91
|
+
name: 'no-unknown-property',
|
|
92
|
+
meta: {
|
|
93
|
+
type: 'problem',
|
|
94
|
+
docs: {
|
|
95
|
+
description: 'Disallow unknown DOM properties',
|
|
96
|
+
},
|
|
97
|
+
schema: [],
|
|
98
|
+
messages: {
|
|
99
|
+
noUnknownProperty: (0, eslint_devkit_2.formatLLMMessage)({
|
|
100
|
+
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
101
|
+
issueName: 'Unknown DOM Property',
|
|
102
|
+
description: 'Unknown DOM property detected',
|
|
103
|
+
severity: 'MEDIUM',
|
|
104
|
+
fix: 'Use standard DOM properties or data attributes (data-*)',
|
|
105
|
+
documentationLink: 'https://react.dev/learn/writing-markup-with-jsx#html-attributes',
|
|
106
|
+
}),
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
defaultOptions: [],
|
|
110
|
+
create(context) {
|
|
111
|
+
return {
|
|
112
|
+
JSXAttribute(node) {
|
|
113
|
+
if (node.name.type === 'JSXIdentifier') {
|
|
114
|
+
const propName = node.name.name;
|
|
115
|
+
// Skip React-specific props and data attributes
|
|
116
|
+
if (REACT_PROPS.has(propName) || propName.startsWith('data-') || propName.startsWith('aria-')) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
// Check if it's a valid DOM property
|
|
120
|
+
if (!VALID_DOM_PROPERTIES.has(propName)) {
|
|
121
|
+
context.report({
|
|
122
|
+
node: node.name,
|
|
123
|
+
messageId: 'noUnknownProperty',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
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-unsafe
|
|
8
|
+
* Prevent usage of unsafe lifecycle methods
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unsafe.md
|
|
11
|
+
*/
|
|
12
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
13
|
+
type Options = {
|
|
14
|
+
checkAliases?: boolean;
|
|
15
|
+
};
|
|
16
|
+
type RuleOptions = [Options?];
|
|
17
|
+
export declare const noUnsafe: TSESLint.RuleModule<"noUnsafe", RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
18
|
+
name: string;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
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.noUnsafe = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
const UNSAFE_METHODS = {
|
|
12
|
+
'UNSAFE_componentWillMount': { replacement: 'componentDidMount or useEffect' },
|
|
13
|
+
'UNSAFE_componentWillReceiveProps': { replacement: 'static getDerivedStateFromProps or useEffect' },
|
|
14
|
+
'UNSAFE_componentWillUpdate': { replacement: 'getSnapshotBeforeUpdate or useEffect' },
|
|
15
|
+
};
|
|
16
|
+
const LEGACY_METHODS = {
|
|
17
|
+
'componentWillMount': { replacement: 'componentDidMount or useEffect' },
|
|
18
|
+
'componentWillReceiveProps': { replacement: 'static getDerivedStateFromProps or useEffect' },
|
|
19
|
+
'componentWillUpdate': { replacement: 'getSnapshotBeforeUpdate or useEffect' },
|
|
20
|
+
};
|
|
21
|
+
exports.noUnsafe = (0, eslint_devkit_2.createRule)({
|
|
22
|
+
name: 'no-unsafe',
|
|
23
|
+
meta: {
|
|
24
|
+
type: 'problem',
|
|
25
|
+
docs: {
|
|
26
|
+
description: 'Prevent usage of unsafe lifecycle methods',
|
|
27
|
+
},
|
|
28
|
+
messages: {
|
|
29
|
+
noUnsafe: (0, eslint_devkit_1.formatLLMMessage)({
|
|
30
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
31
|
+
issueName: 'Unsafe Lifecycle Method',
|
|
32
|
+
description: '"{{method}}" is unsafe and may cause bugs in concurrent mode',
|
|
33
|
+
severity: 'HIGH',
|
|
34
|
+
fix: 'Use {{replacement}} instead',
|
|
35
|
+
documentationLink: 'https://react.dev/blog/2018/03/27/update-on-async-rendering',
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
schema: [
|
|
39
|
+
{
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
checkAliases: { type: 'boolean', default: false },
|
|
43
|
+
},
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
defaultOptions: [{}],
|
|
49
|
+
create(context, [options = {}]) {
|
|
50
|
+
const { checkAliases = false } = options ?? {};
|
|
51
|
+
let inClassComponent = false;
|
|
52
|
+
function checkMethod(node) {
|
|
53
|
+
if (!inClassComponent)
|
|
54
|
+
return;
|
|
55
|
+
if (node.key.type !== 'Identifier')
|
|
56
|
+
return;
|
|
57
|
+
const methodName = node.key.name;
|
|
58
|
+
// Check UNSAFE_ prefixed methods
|
|
59
|
+
const unsafeInfo = UNSAFE_METHODS[methodName];
|
|
60
|
+
if (unsafeInfo) {
|
|
61
|
+
context.report({
|
|
62
|
+
node,
|
|
63
|
+
messageId: 'noUnsafe',
|
|
64
|
+
data: {
|
|
65
|
+
method: methodName,
|
|
66
|
+
replacement: unsafeInfo.replacement,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// Check legacy methods if checkAliases is enabled
|
|
72
|
+
if (checkAliases) {
|
|
73
|
+
const legacyInfo = LEGACY_METHODS[methodName];
|
|
74
|
+
if (legacyInfo) {
|
|
75
|
+
context.report({
|
|
76
|
+
node,
|
|
77
|
+
messageId: 'noUnsafe',
|
|
78
|
+
data: {
|
|
79
|
+
method: methodName,
|
|
80
|
+
replacement: legacyInfo.replacement,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
ClassDeclaration(node) {
|
|
88
|
+
if (!node.superClass)
|
|
89
|
+
return;
|
|
90
|
+
if (node.superClass.type === 'MemberExpression') {
|
|
91
|
+
if (node.superClass.object.type === 'Identifier' &&
|
|
92
|
+
node.superClass.object.name === 'React' &&
|
|
93
|
+
node.superClass.property.type === 'Identifier' &&
|
|
94
|
+
(node.superClass.property.name === 'Component' ||
|
|
95
|
+
node.superClass.property.name === 'PureComponent')) {
|
|
96
|
+
inClassComponent = true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (node.superClass.type === 'Identifier') {
|
|
100
|
+
if (node.superClass.name === 'Component' || node.superClass.name === 'PureComponent') {
|
|
101
|
+
inClassComponent = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
'ClassDeclaration:exit'() {
|
|
106
|
+
inClassComponent = false;
|
|
107
|
+
},
|
|
108
|
+
MethodDefinition: checkMethod,
|
|
109
|
+
PropertyDefinition: checkMethod,
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
});
|
|
@@ -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: prefer-es6-class
|
|
8
|
+
* Prefer ES6 classes over createClass
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export declare const preferEs6Class: TSESLint.RuleModule<"preferEs6Class", [], unknown, TSESLint.RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
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.preferEs6Class = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
exports.preferEs6Class = (0, eslint_devkit_1.createRule)({
|
|
12
|
+
name: 'prefer-es6-class',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Prefer ES6 classes over createClass',
|
|
17
|
+
},
|
|
18
|
+
schema: [],
|
|
19
|
+
messages: {
|
|
20
|
+
preferEs6Class: (0, eslint_devkit_2.formatLLMMessage)({
|
|
21
|
+
icon: eslint_devkit_2.MessageIcons.MIGRATION,
|
|
22
|
+
issueName: 'Legacy createClass',
|
|
23
|
+
description: 'React.createClass() is deprecated',
|
|
24
|
+
severity: 'HIGH',
|
|
25
|
+
fix: 'Convert to ES6 class component',
|
|
26
|
+
documentationLink: 'https://react.dev/reference/react/createClass',
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
defaultOptions: [],
|
|
31
|
+
create(context) {
|
|
32
|
+
return {
|
|
33
|
+
CallExpression(node) {
|
|
34
|
+
// Check for React.createClass()
|
|
35
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
36
|
+
node.callee.object.type === 'Identifier' &&
|
|
37
|
+
node.callee.object.name === 'React' &&
|
|
38
|
+
node.callee.property.type === 'Identifier' &&
|
|
39
|
+
node.callee.property.name === 'createClass') {
|
|
40
|
+
context.report({
|
|
41
|
+
node: node.callee.property,
|
|
42
|
+
messageId: 'preferEs6Class',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Check for createClass() (imported)
|
|
46
|
+
if (node.callee.type === 'Identifier' &&
|
|
47
|
+
node.callee.name === 'createClass') {
|
|
48
|
+
context.report({
|
|
49
|
+
node: node.callee,
|
|
50
|
+
messageId: 'preferEs6Class',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: prefer-stateless-function
|
|
8
|
+
* Prefer stateless functions
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
export interface Options {
|
|
12
|
+
ignorePureComponents?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const preferStatelessFunction: TSESLint.RuleModule<"preferStatelessFunction", [Options], unknown, TSESLint.RuleListener> & {
|
|
15
|
+
name: string;
|
|
16
|
+
};
|