eslint-plugin-react-features 1.2.0 → 1.2.2
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 +15 -0
- package/README.md +1 -1
- package/package.json +2 -2
- package/src/index.js +1 -1
- package/src/rules/migration/react-class-to-hooks.js +2 -1
- package/src/rules/performance/react-no-inline-functions.js +2 -1
- package/src/rules/react/jsx-key.js +3 -18
- package/src/rules/react/no-direct-mutation-state.js +6 -4
- package/src/rules/react/no-unknown-property.js +6 -0
- package/src/rules/react/require-default-props.js +4 -1
- package/src/rules/react/require-optimization.js +4 -6
- package/src/rules/react/required-attributes.js +2 -1
- package/src/rules/react/static-property-placement.js +7 -38
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
## [1.1.4] - 2026-05-03
|
|
2
2
|
|
|
3
|
+
## 1.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#225](https://github.com/ofri-peretz/eslint/pull/225) [`34ff5a8`](https://github.com/ofri-peretz/eslint/commit/34ff5a8e6f5126c5d1c0a524759e0af2b5476b46) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - CI-only: pin all coverage thresholds at 100% (integration target, merges last).
|
|
8
|
+
|
|
9
|
+
## 1.2.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#229](https://github.com/ofri-peretz/eslint/pull/229) [`acc81a7`](https://github.com/ofri-peretz/eslint/commit/acc81a74d0c329027bf6011f5db4b1bf9beba650) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - `no-unknown-property` no longer fires on custom React components. The rule now
|
|
14
|
+
only checks host (lowercase DOM) elements, matching upstream
|
|
15
|
+
`react/no-unknown-property` — uppercase and member-expression JSX names
|
|
16
|
+
(`<Box surface="card">`, `<Motion.div />`) accept arbitrary props.
|
|
17
|
+
|
|
3
18
|
## 1.2.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<a href="https://www.npmjs.com/package/eslint-plugin-react-features" target="_blank"><img src="https://img.shields.io/npm/v/eslint-plugin-react-features.svg" alt="NPM Version" /></a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/eslint-plugin-react-features" target="_blank"><img src="https://img.shields.io/npm/dm/eslint-plugin-react-features.svg" alt="NPM Downloads" /></a>
|
|
12
12
|
<a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Package License" /></a>
|
|
13
|
-
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/
|
|
13
|
+
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/tree/main" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?flag=eslint-plugin-react-features" alt="Codecov" /></a>
|
|
14
14
|
<a href="https://github.com/ofri-peretz/eslint" target="_blank"><img src="https://img.shields.io/badge/Since-Dec_2025-blue?logo=rocket&logoColor=white" alt="Since Dec 2025" /></a>
|
|
15
15
|
</p>
|
|
16
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-features",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "ESLint React rules for modern react features, hooks, and patterns.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsx ../../scripts/build-package.ts",
|
|
73
|
-
"test": "vitest run",
|
|
73
|
+
"test": "vitest run --coverage",
|
|
74
74
|
"test:coverage": "vitest run --coverage",
|
|
75
75
|
"typecheck": "tsc -p tsconfig.lib.json --noEmit"
|
|
76
76
|
},
|
package/src/index.js
CHANGED
|
@@ -73,7 +73,8 @@ exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
|
73
73
|
],
|
|
74
74
|
create(context) {
|
|
75
75
|
const options = context.options[0] || {};
|
|
76
|
-
|
|
76
|
+
// `options` is always an object here (`|| {}` above), so no second fallback.
|
|
77
|
+
const { allowComplexLifecycle = false } = options;
|
|
77
78
|
const sourceCode = context.sourceCode;
|
|
78
79
|
/**
|
|
79
80
|
* Check if class extends React.Component
|
|
@@ -94,7 +94,8 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
94
94
|
],
|
|
95
95
|
create(context) {
|
|
96
96
|
const options = context.options[0] || {};
|
|
97
|
-
|
|
97
|
+
// `options` is already object-coerced above, so no second `||` fallback.
|
|
98
|
+
const { allowInEventHandlers = false, minArraySize = 10 } = options;
|
|
98
99
|
/**
|
|
99
100
|
* Check if node is inside JSX
|
|
100
101
|
*/
|
|
@@ -118,24 +118,9 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
|
|
|
118
118
|
return true;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
callee.property.name === 'map') {
|
|
125
|
-
const obj = callee.object;
|
|
126
|
-
// Children.map()
|
|
127
|
-
if (obj.type === 'Identifier' && obj.name === 'Children') {
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
// React.Children.map()
|
|
131
|
-
if (obj.type === 'MemberExpression' &&
|
|
132
|
-
obj.object.type === 'Identifier' &&
|
|
133
|
-
obj.object.name === 'React' &&
|
|
134
|
-
obj.property.type === 'Identifier' &&
|
|
135
|
-
obj.property.name === 'Children') {
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
121
|
+
// NOTE: React.Children.map(children, fn) / Children.map(children, fn)
|
|
122
|
+
// are already matched by Pattern 1 above — any member call named `map`
|
|
123
|
+
// returns true there, so no separate pattern is needed.
|
|
139
124
|
return false;
|
|
140
125
|
}
|
|
141
126
|
/**
|
|
@@ -112,8 +112,9 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
|
|
|
112
112
|
column: 0
|
|
113
113
|
});
|
|
114
114
|
const lineText = sourceCode.getText().slice(lineStart, start);
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
// Leading-whitespace run — computed without a regex null-check
|
|
116
|
+
// branch (`/^\s*/` can never fail to match).
|
|
117
|
+
const indent = lineText.slice(0, lineText.length - lineText.trimStart().length);
|
|
117
118
|
return fixer.insertTextBefore(node, `// TODO: Use setState instead of direct mutation\n${indent}`);
|
|
118
119
|
},
|
|
119
120
|
},
|
|
@@ -128,8 +129,9 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
|
|
|
128
129
|
column: 0
|
|
129
130
|
});
|
|
130
131
|
const lineText = sourceCode.getText().slice(lineStart, start);
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
// Leading-whitespace run — computed without a regex null-check
|
|
133
|
+
// branch (`/^\s*/` can never fail to match).
|
|
134
|
+
const indent = lineText.slice(0, lineText.length - lineText.trimStart().length);
|
|
133
135
|
return fixer.insertTextBefore(node, `// TODO: Use functional setState for immutable updates\n${indent}`);
|
|
134
136
|
},
|
|
135
137
|
},
|
|
@@ -111,6 +111,12 @@ exports.noUnknownProperty = (0, eslint_devkit_1.createRule)({
|
|
|
111
111
|
create(context) {
|
|
112
112
|
return {
|
|
113
113
|
JSXAttribute(node) {
|
|
114
|
+
// Only host (DOM) elements have a fixed property set. Custom
|
|
115
|
+
// components (<Box />, <Motion.div />) accept arbitrary props.
|
|
116
|
+
const elementName = node.parent.name;
|
|
117
|
+
if (elementName.type !== 'JSXIdentifier' || !/^[a-z]/.test(elementName.name)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
114
120
|
if (node.name.type === 'JSXIdentifier') {
|
|
115
121
|
const propName = node.name.name;
|
|
116
122
|
// Skip React-specific props and data attributes
|
|
@@ -101,7 +101,10 @@ exports.requireDefaultProps = (0, eslint_devkit_1.createRule)({
|
|
|
101
101
|
messageId: 'requireDefaultProps',
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
// `hasDefault` is intentionally not re-checked here: `get()`
|
|
105
|
+
// returning a value is the same condition, and this keeps the
|
|
106
|
+
// no-default arm of the lookup reachable.
|
|
107
|
+
if (forbidDefaultForRequired && isRequired && defaultsMap) {
|
|
105
108
|
const defaultProp = defaultsMap.get(propName);
|
|
106
109
|
if (defaultProp) {
|
|
107
110
|
context.report({
|
|
@@ -207,7 +207,7 @@ exports.requireOptimization = (0, eslint_devkit_1.createRule)({
|
|
|
207
207
|
if (body) {
|
|
208
208
|
analyzeNode(body);
|
|
209
209
|
}
|
|
210
|
-
|
|
210
|
+
const componentData = {
|
|
211
211
|
name: componentName,
|
|
212
212
|
type: node.type === 'ArrowFunctionExpression' ? 'arrow' : 'function',
|
|
213
213
|
node,
|
|
@@ -217,12 +217,10 @@ exports.requireOptimization = (0, eslint_devkit_1.createRule)({
|
|
|
217
217
|
hasInlineFunctions,
|
|
218
218
|
renderStatements,
|
|
219
219
|
linesOfCode,
|
|
220
|
-
}
|
|
220
|
+
};
|
|
221
|
+
components.set(componentName, componentData);
|
|
221
222
|
// Analyze and suggest optimizations
|
|
222
|
-
|
|
223
|
-
if (componentData) {
|
|
224
|
-
analyzeComponentOptimizations(componentName, componentData);
|
|
225
|
-
}
|
|
223
|
+
analyzeComponentOptimizations(componentName, componentData);
|
|
226
224
|
}
|
|
227
225
|
function analyzeClassComponent(node) {
|
|
228
226
|
const componentName = node.id?.name;
|
|
@@ -80,7 +80,8 @@ exports.requiredAttributes = (0, eslint_devkit_2.createRule)({
|
|
|
80
80
|
],
|
|
81
81
|
create(context) {
|
|
82
82
|
const options = context.options[0] || {};
|
|
83
|
-
|
|
83
|
+
// `options` is always an object here (`|| {}` above), so no second fallback.
|
|
84
|
+
const { attributes = [], ignoreComponents = [] } = options;
|
|
84
85
|
/**
|
|
85
86
|
* Get element name from JSX opening element
|
|
86
87
|
*/
|
|
@@ -105,24 +105,13 @@ exports.staticPropertyPlacement = (0, eslint_devkit_1.createRule)({
|
|
|
105
105
|
const current = staticProperties[i];
|
|
106
106
|
const previous = staticProperties[i - 1];
|
|
107
107
|
if (!areInSameGroup(current.name, previous.name, groups)) {
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const name = getPropertyName(member);
|
|
116
|
-
if (name && shouldBeBetween(name, previous.name, current.name, groups)) {
|
|
117
|
-
context.report({
|
|
118
|
-
node: getPropertyKeyNode(current.node),
|
|
119
|
-
messageId: 'staticPropertyPlacement',
|
|
120
|
-
});
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/* v8 ignore stop */
|
|
125
|
-
}
|
|
108
|
+
// `staticProperties` holds every named static member in source
|
|
109
|
+
// order, so the members strictly between `previous` and `current`
|
|
110
|
+
// are either non-static or computed-key statics (no name). The
|
|
111
|
+
// historical implementation walked that gap looking for a named
|
|
112
|
+
// static property to report — a provably unreachable path (a named
|
|
113
|
+
// static in the gap would itself already be in `staticProperties`).
|
|
114
|
+
// That dead branch was deleted rather than coverage-ignored.
|
|
126
115
|
}
|
|
127
116
|
}
|
|
128
117
|
}
|
|
@@ -140,12 +129,6 @@ exports.staticPropertyPlacement = (0, eslint_devkit_1.createRule)({
|
|
|
140
129
|
}
|
|
141
130
|
return null;
|
|
142
131
|
}
|
|
143
|
-
/* v8 ignore start - only used in unreachable code path above */
|
|
144
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
145
|
-
function getPropertyKeyNode(member) {
|
|
146
|
-
return member.key;
|
|
147
|
-
}
|
|
148
|
-
/* v8 ignore stop */
|
|
149
132
|
// oxlint-disable-next-line consistent-function-scoping
|
|
150
133
|
function areInSameGroup(name1, name2, groups) {
|
|
151
134
|
for (const group of groups) {
|
|
@@ -155,19 +138,5 @@ exports.staticPropertyPlacement = (0, eslint_devkit_1.createRule)({
|
|
|
155
138
|
}
|
|
156
139
|
return false;
|
|
157
140
|
}
|
|
158
|
-
/* v8 ignore start - only used in unreachable code path above */
|
|
159
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
160
|
-
function shouldBeBetween(name, before, after, groups) {
|
|
161
|
-
for (const group of groups) {
|
|
162
|
-
const beforeIndex = group.properties.indexOf(before);
|
|
163
|
-
const afterIndex = group.properties.indexOf(after);
|
|
164
|
-
const nameIndex = group.properties.indexOf(name);
|
|
165
|
-
if (beforeIndex !== -1 && afterIndex !== -1 && nameIndex !== -1) {
|
|
166
|
-
return nameIndex > beforeIndex && nameIndex < afterIndex;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
/* v8 ignore stop */
|
|
172
141
|
},
|
|
173
142
|
});
|