eslint-plugin-react-features 1.2.1 → 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 CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 1.2.1
4
10
 
5
11
  ### Patch 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/components?components%5B0%5D=react-features" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?component=react-features" alt="Codecov" /></a>
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.1",
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",
package/src/index.js CHANGED
@@ -208,7 +208,7 @@ exports.rules = {
208
208
  exports.plugin = {
209
209
  meta: {
210
210
  name: 'eslint-plugin-react-features',
211
- version: '1.2.1',
211
+ version: '1.2.2',
212
212
  },
213
213
  rules: exports.rules,
214
214
  };
@@ -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
- const { allowComplexLifecycle = false } = options || {};
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
- const { allowInEventHandlers = false, minArraySize = 10 } = options || {};
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
- // Pattern 3: React.Children.map(children, fn) or Children.map(children, fn)
122
- if (callee.type === 'MemberExpression' &&
123
- callee.property.type === 'Identifier' &&
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
- const indentMatch = lineText.match(/^(\s*)/);
116
- const indent = indentMatch ? indentMatch[1] : '';
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
- const indentMatch = lineText.match(/^(\s*)/);
132
- const indent = indentMatch ? indentMatch[1] : '';
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
  },
@@ -101,7 +101,10 @@ exports.requireDefaultProps = (0, eslint_devkit_1.createRule)({
101
101
  messageId: 'requireDefaultProps',
102
102
  });
103
103
  }
104
- if (forbidDefaultForRequired && isRequired && hasDefault && defaultsMap) {
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
- components.set(componentName, {
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
- const componentData = components.get(componentName);
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
- const { attributes = [], ignoreComponents = [] } = options || {};
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
- // Check if there's a gap that should be filled
109
- // Note: This code path is rarely reachable because staticProperties already
110
- // contains all static properties with valid names in member order.
111
- for (let j = previous.index + 1; j < current.index; j++) {
112
- const member = members[j];
113
- /* v8 ignore start */
114
- if (isStaticProperty(member)) {
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
  });