eslint-plugin-react-features 1.2.8 → 1.2.10

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.
Files changed (65) hide show
  1. package/package.json +2 -3
  2. package/src/index.js +1 -239
  3. package/src/oxlint.js +1 -3
  4. package/src/rules/component-api/no-arbitrary-token-class.js +1 -74
  5. package/src/rules/component-api/no-default-test-id.js +1 -46
  6. package/src/rules/component-api/no-inline-style.js +1 -57
  7. package/src/rules/component-api/no-is-prefix-prop.js +1 -59
  8. package/src/rules/component-api/no-kind-prop-discriminator.js +1 -57
  9. package/src/rules/component-api/no-raw-color-literal.js +1 -55
  10. package/src/rules/component-api/no-wrapper-sub-component.js +1 -95
  11. package/src/rules/component-api/require-data-slot.js +1 -40
  12. package/src/rules/migration/react-class-to-hooks.js +1 -159
  13. package/src/rules/performance/no-unnecessary-rerenders.js +1 -185
  14. package/src/rules/performance/react-no-inline-functions.js +1 -187
  15. package/src/rules/performance/react-render-optimization.js +1 -256
  16. package/src/rules/react/checked-requires-onchange-or-readonly.js +1 -68
  17. package/src/rules/react/default-props-match-prop-types.js +1 -99
  18. package/src/rules/react/display-name.js +1 -133
  19. package/src/rules/react/hooks-exhaustive-deps.js +1 -466
  20. package/src/rules/react/jsx-handler-names.js +1 -50
  21. package/src/rules/react/jsx-key.js +1 -323
  22. package/src/rules/react/jsx-max-depth.js +1 -71
  23. package/src/rules/react/jsx-no-bind.js +1 -55
  24. package/src/rules/react/jsx-no-duplicate-props.js +1 -66
  25. package/src/rules/react/jsx-no-literals.js +1 -79
  26. package/src/rules/react/jsx-no-script-url.js +1 -119
  27. package/src/rules/react/jsx-no-target-blank.js +1 -163
  28. package/src/rules/react/no-access-state-in-setstate.js +1 -80
  29. package/src/rules/react/no-adjacent-inline-elements.js +1 -72
  30. package/src/rules/react/no-arrow-function-lifecycle.js +1 -57
  31. package/src/rules/react/no-children-prop.js +1 -54
  32. package/src/rules/react/no-danger-with-children.js +1 -99
  33. package/src/rules/react/no-danger.js +1 -43
  34. package/src/rules/react/no-deprecated.js +1 -130
  35. package/src/rules/react/no-did-mount-set-state.js +1 -50
  36. package/src/rules/react/no-did-update-set-state.js +1 -71
  37. package/src/rules/react/no-direct-mutation-state.js +3 -211
  38. package/src/rules/react/no-find-dom-node.js +1 -50
  39. package/src/rules/react/no-invalid-html-attribute.js +1 -80
  40. package/src/rules/react/no-is-mounted.js +1 -46
  41. package/src/rules/react/no-multi-comp.js +1 -150
  42. package/src/rules/react/no-namespace.js +1 -37
  43. package/src/rules/react/no-object-type-as-default-prop.js +1 -53
  44. package/src/rules/react/no-redundant-should-component-update.js +1 -50
  45. package/src/rules/react/no-render-return-value.js +1 -67
  46. package/src/rules/react/no-set-state.js +1 -45
  47. package/src/rules/react/no-string-refs.js +1 -61
  48. package/src/rules/react/no-this-in-sfc.js +1 -55
  49. package/src/rules/react/no-typos.js +1 -90
  50. package/src/rules/react/no-unescaped-entities.js +1 -44
  51. package/src/rules/react/no-unknown-property.js +1 -124
  52. package/src/rules/react/no-unsafe.js +1 -106
  53. package/src/rules/react/prefer-es6-class.js +1 -50
  54. package/src/rules/react/prefer-stateless-function.js +1 -126
  55. package/src/rules/react/prop-types.js +1 -143
  56. package/src/rules/react/react-in-jsx-scope.js +1 -86
  57. package/src/rules/react/require-default-props.js +1 -134
  58. package/src/rules/react/require-optimization.js +1 -397
  59. package/src/rules/react/require-render-return.js +1 -79
  60. package/src/rules/react/required-attributes.js +1 -185
  61. package/src/rules/react/sort-comp.js +1 -146
  62. package/src/rules/react/state-in-constructor.js +1 -95
  63. package/src/rules/react/static-property-placement.js +1 -122
  64. package/src/rules/react/void-dom-elements-no-children.js +1 -89
  65. package/src/types/index.js +1 -2
@@ -1,50 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsxHandlerNames = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.jsxHandlerNames = (0, eslint_devkit_1.createRule)({
7
- name: 'jsx-handler-names',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-handler-names.md',
12
- description: 'Enforce event handler naming conventions',
13
- },
14
- schema: [],
15
- messages: {
16
- jsxHandlerNames: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.WARNING,
18
- issueName: 'Invalid Handler Name',
19
- description: 'Event handler does not follow naming convention',
20
- severity: 'LOW',
21
- fix: 'Rename handler to start with "handle" or "on" (e.g., handleClick, onSubmit)',
22
- documentationLink: 'https://react.dev/learn/responding-to-events#naming-event-handler-functions',
23
- }),
24
- },
25
- },
26
- defaultOptions: [],
27
- create(context) {
28
- return {
29
- JSXAttribute(node) {
30
- if (node.name.type === 'JSXIdentifier') {
31
- const attrName = node.name.name;
32
- if (attrName.startsWith('on') && attrName.length > 2) {
33
- if (node.value && node.value.type === 'JSXExpressionContainer') {
34
- const expression = node.value.expression;
35
- if (expression.type === 'Identifier') {
36
- const handlerName = expression.name;
37
- if (!handlerName.startsWith('handle') && !handlerName.startsWith('on')) {
38
- context.report({
39
- node: expression,
40
- messageId: 'jsxHandlerNames',
41
- });
42
- }
43
- }
44
- }
45
- }
46
- }
47
- },
48
- };
49
- },
50
- });
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:[],create(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,323 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsxKey = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.jsxKey = (0, eslint_devkit_1.createRule)({
7
- name: 'jsx-key',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-key.md',
12
- description: 'Detect missing or problematic React keys that could break reconciliation',
13
- },
14
- hasSuggestions: true,
15
- messages: {
16
- missingKey: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.WARNING,
18
- issueName: 'Missing React Key',
19
- description: 'Missing key prop for element in iterator',
20
- severity: 'HIGH',
21
- fix: 'Add unique, stable key prop based on item data',
22
- documentationLink: 'https://react.dev/learn/render-and-commit#lists-and-keys',
23
- }),
24
- invalidKey: (0, eslint_devkit_2.formatLLMMessage)({
25
- icon: eslint_devkit_2.MessageIcons.WARNING,
26
- issueName: 'Invalid React Key',
27
- description: 'Key prop should be unique and stable',
28
- severity: 'MEDIUM',
29
- fix: 'Use item.id, item.key, or index as last resort',
30
- documentationLink: 'https://react.dev/learn/render-and-commit#lists-and-keys',
31
- }),
32
- duplicateKey: (0, eslint_devkit_2.formatLLMMessage)({
33
- icon: eslint_devkit_2.MessageIcons.WARNING,
34
- issueName: 'Duplicate React Key',
35
- description: 'Duplicate key values can break reconciliation',
36
- severity: 'HIGH',
37
- fix: 'Ensure all keys in the array are unique',
38
- documentationLink: 'https://react.dev/learn/render-and-commit#lists-and-keys',
39
- }),
40
- unstableKey: (0, eslint_devkit_2.formatLLMMessage)({
41
- icon: eslint_devkit_2.MessageIcons.WARNING,
42
- issueName: 'Unstable React Key',
43
- description: 'Using index as key can cause reconciliation issues',
44
- severity: 'MEDIUM',
45
- fix: 'Use stable identifier from data instead of array index',
46
- documentationLink: 'https://react.dev/learn/render-and-commit#lists-and-keys',
47
- }),
48
- suggestKey: (0, eslint_devkit_2.formatLLMMessage)({
49
- icon: eslint_devkit_2.MessageIcons.INFO,
50
- issueName: 'Add Key Prop',
51
- description: 'Add unique key prop to element',
52
- severity: 'LOW',
53
- fix: 'key={item.id}',
54
- documentationLink: 'https://react.dev/learn/render-and-commit#lists-and-keys',
55
- }),
56
- },
57
- schema: [
58
- {
59
- type: 'object',
60
- properties: {
61
- warnUnstableKeys: {
62
- type: 'boolean',
63
- default: true,
64
- },
65
- },
66
- additionalProperties: false,
67
- },
68
- ],
69
- },
70
- defaultOptions: [{ warnUnstableKeys: true }],
71
- create(context) {
72
- const [options] = context.options;
73
- const { warnUnstableKeys = true } = options || {};
74
- const keyTracker = new Map();
75
- function resetKeyTracker() {
76
- keyTracker.clear();
77
- }
78
- const ITERATOR_METHODS = new Set(['map', 'forEach', 'flatMap']);
79
- function isIteratorCall(node) {
80
- if (node.type !== 'CallExpression') {
81
- return false;
82
- }
83
- const { callee } = node;
84
- if (callee.type === 'MemberExpression' &&
85
- callee.property.type === 'Identifier' &&
86
- ITERATOR_METHODS.has(callee.property.name)) {
87
- return true;
88
- }
89
- if (callee.type === 'MemberExpression' &&
90
- callee.object.type === 'Identifier' &&
91
- callee.object.name === 'Array' &&
92
- callee.property.type === 'Identifier' &&
93
- callee.property.name === 'from' &&
94
- node.arguments.length >= 2) {
95
- const mapFn = node.arguments[1];
96
- if (mapFn.type === 'ArrowFunctionExpression' ||
97
- mapFn.type === 'FunctionExpression') {
98
- return true;
99
- }
100
- }
101
- return false;
102
- }
103
- function isInsideArrayFromMapFn(node) {
104
- let current = node;
105
- while (current?.parent) {
106
- const parent = current.parent;
107
- if (parent.type === 'ArrowFunctionExpression' ||
108
- parent.type === 'FunctionExpression') {
109
- const grandParent = parent.parent;
110
- if (grandParent?.type === 'CallExpression' &&
111
- grandParent.callee.type === 'MemberExpression' &&
112
- grandParent.callee.object.type === 'Identifier' &&
113
- grandParent.callee.object.name === 'Array' &&
114
- grandParent.callee.property.type === 'Identifier' &&
115
- grandParent.callee.property.name === 'from' &&
116
- grandParent.arguments[1] === parent) {
117
- return true;
118
- }
119
- }
120
- current = parent;
121
- }
122
- return false;
123
- }
124
- function isInsideChildrenMap(node) {
125
- let current = node;
126
- while (current?.parent) {
127
- const parent = current.parent;
128
- if (parent.type === 'ArrowFunctionExpression' ||
129
- parent.type === 'FunctionExpression') {
130
- const grandParent = parent.parent;
131
- if (grandParent?.type === 'CallExpression') {
132
- const callee = grandParent.callee;
133
- if (callee.type === 'MemberExpression' &&
134
- callee.property.type === 'Identifier' &&
135
- callee.property.name === 'map') {
136
- const obj = callee.object;
137
- if (obj.type === 'Identifier' && obj.name === 'Children') {
138
- return true;
139
- }
140
- if (obj.type === 'MemberExpression' &&
141
- obj.object.type === 'Identifier' &&
142
- obj.object.name === 'React' &&
143
- obj.property.type === 'Identifier' &&
144
- obj.property.name === 'Children') {
145
- return true;
146
- }
147
- }
148
- }
149
- }
150
- current = parent;
151
- }
152
- return false;
153
- }
154
- function isDirectIteratorReturn(node) {
155
- if (isInsideArrayFromMapFn(node)) {
156
- return isDirectReturnFromFunction(node);
157
- }
158
- if (isInsideChildrenMap(node)) {
159
- return isDirectReturnFromFunction(node);
160
- }
161
- let current = node;
162
- while (current.parent) {
163
- const parent = current.parent;
164
- if (parent.type === 'JSXElement' || parent.type === 'JSXFragment') {
165
- return false;
166
- }
167
- if (parent.type === 'ArrowFunctionExpression' &&
168
- parent.body === current) {
169
- if (parent.parent && isIteratorCall(parent.parent)) {
170
- return true;
171
- }
172
- }
173
- if (parent.type === 'ReturnStatement' &&
174
- parent.argument === current) {
175
- let funcParent = parent.parent;
176
- while (funcParent) {
177
- if (funcParent.type === 'ArrowFunctionExpression' ||
178
- funcParent.type === 'FunctionExpression') {
179
- if (funcParent.parent && isIteratorCall(funcParent.parent)) {
180
- return true;
181
- }
182
- break;
183
- }
184
- if (funcParent.type === 'BlockStatement') {
185
- funcParent = funcParent.parent;
186
- continue;
187
- }
188
- break;
189
- }
190
- }
191
- if (parent.type === 'JSXExpressionContainer') {
192
- if (current.type === 'JSXElement' && parent.parent?.type === 'JSXElement') {
193
- return false;
194
- }
195
- }
196
- if (parent.type === 'ConditionalExpression' ||
197
- parent.type === 'LogicalExpression' ||
198
- parent.type === 'SequenceExpression') {
199
- current = parent;
200
- continue;
201
- }
202
- if (parent.type === 'CallExpression') {
203
- break;
204
- }
205
- current = parent;
206
- }
207
- return false;
208
- }
209
- function isDirectReturnFromFunction(node) {
210
- let current = node;
211
- while (current.parent) {
212
- const parent = current.parent;
213
- if (parent.type === 'JSXElement' || parent.type === 'JSXFragment') {
214
- return false;
215
- }
216
- if (parent.type === 'ArrowFunctionExpression' &&
217
- parent.body === current) {
218
- return true;
219
- }
220
- if (parent.type === 'ReturnStatement' &&
221
- parent.argument === current) {
222
- return true;
223
- }
224
- if (parent.type === 'ConditionalExpression' ||
225
- parent.type === 'LogicalExpression') {
226
- current = parent;
227
- continue;
228
- }
229
- current = parent;
230
- }
231
- return false;
232
- }
233
- function getIteratorCallbackParamName(node) {
234
- let current = node;
235
- while (current.parent) {
236
- const parent = current.parent;
237
- const grandParent = parent.parent;
238
- if (parent.type === 'ArrowFunctionExpression' &&
239
- parent.params.length > 0 &&
240
- parent.params[0].type === 'Identifier' &&
241
- grandParent &&
242
- isIteratorCall(grandParent)) {
243
- return parent.params[0].name;
244
- }
245
- if (parent.type === 'FunctionExpression' &&
246
- parent.params.length > 0 &&
247
- parent.params[0].type === 'Identifier' &&
248
- grandParent &&
249
- isIteratorCall(grandParent)) {
250
- return parent.params[0].name;
251
- }
252
- if (parent.type === 'ReturnStatement') {
253
- let funcParent = parent.parent;
254
- while (funcParent) {
255
- if ((funcParent.type === 'ArrowFunctionExpression' ||
256
- funcParent.type === 'FunctionExpression') &&
257
- funcParent.params.length > 0 &&
258
- funcParent.params[0].type === 'Identifier') {
259
- if (funcParent.parent && isIteratorCall(funcParent.parent)) {
260
- return funcParent.params[0].name;
261
- }
262
- break;
263
- }
264
- if (funcParent.type === 'BlockStatement') {
265
- funcParent = funcParent.parent;
266
- continue;
267
- }
268
- break;
269
- }
270
- }
271
- current = parent;
272
- }
273
- return 'item';
274
- }
275
- function checkJSXElementInIteration(node) {
276
- const isDirectReturn = isDirectIteratorReturn(node);
277
- if (!isDirectReturn) {
278
- return;
279
- }
280
- const keyProp = node.openingElement.attributes.find((attr) => attr.type === 'JSXAttribute' &&
281
- attr.name.type === 'JSXIdentifier' &&
282
- attr.name.name === 'key');
283
- if (!keyProp) {
284
- const paramName = getIteratorCallbackParamName(node);
285
- context.report({
286
- node: node.openingElement,
287
- messageId: 'missingKey',
288
- suggest: [
289
- {
290
- messageId: 'suggestKey',
291
- fix(fixer) {
292
- return fixer.insertTextAfter(node.openingElement.name, ` key={${paramName}.id}`);
293
- },
294
- },
295
- ],
296
- });
297
- return;
298
- }
299
- if (keyProp.type === 'JSXAttribute' && keyProp.value) {
300
- const keyValue = keyProp.value;
301
- if (warnUnstableKeys &&
302
- keyValue.type === 'JSXExpressionContainer' &&
303
- keyValue.expression.type === 'Identifier' &&
304
- ['i', 'index', 'idx', 'key'].includes(keyValue.expression.name)) {
305
- context.report({
306
- node: keyProp,
307
- messageId: 'unstableKey',
308
- });
309
- }
310
- }
311
- }
312
- return {
313
- JSXElement(node) {
314
- checkJSXElementInIteration(node);
315
- },
316
- CallExpression(node) {
317
- if (isIteratorCall(node)) {
318
- resetKeyTracker();
319
- }
320
- },
321
- };
322
- },
323
- });
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");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}],create(context){const[options]=context.options;const{warnUnstableKeys=true}=options||{};const keyTracker=new Map;function resetKeyTracker(){keyTracker.clear()}const ITERATOR_METHODS=new Set(["map","forEach","flatMap"]);function isIteratorCall(node){if(node.type!=="CallExpression"){return false}const{callee}=node;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"&&ITERATOR_METHODS.has(callee.property.name)){return true}if(callee.type==="MemberExpression"&&callee.object.type==="Identifier"&&callee.object.name==="Array"&&callee.property.type==="Identifier"&&callee.property.name==="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"&&grandParent.callee.property.type==="Identifier"&&grandParent.callee.property.name==="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"&&callee.property.type==="Identifier"&&callee.property.name==="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"&&obj.property.type==="Identifier"&&obj.property.name==="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 getIteratorCallbackParamName(node){let current=node;while(current.parent){const parent=current.parent;const grandParent=parent.parent;if(parent.type==="ArrowFunctionExpression"&&parent.params.length>0&&parent.params[0].type==="Identifier"&&grandParent&&isIteratorCall(grandParent)){return parent.params[0].name}if(parent.type==="FunctionExpression"&&parent.params.length>0&&parent.params[0].type==="Identifier"&&grandParent&&isIteratorCall(grandParent)){return parent.params[0].name}if(parent.type==="ReturnStatement"){let funcParent=parent.parent;while(funcParent){if((funcParent.type==="ArrowFunctionExpression"||funcParent.type==="FunctionExpression")&&funcParent.params.length>0&&funcParent.params[0].type==="Identifier"){if(funcParent.parent&&isIteratorCall(funcParent.parent)){return funcParent.params[0].name}break}if(funcParent.type==="BlockStatement"){funcParent=funcParent.parent;continue}break}}current=parent}return"item"}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 paramName=getIteratorCallbackParamName(node);context.report({node:node.openingElement,messageId:"missingKey",suggest:[{messageId:"suggestKey",fix(fixer){return fixer.insertTextAfter(node.openingElement.name,` key={${paramName}.id}`)}}]});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{JSXElement(node){checkJSXElementInIteration(node)},CallExpression(node){if(isIteratorCall(node)){resetKeyTracker()}}}}});
@@ -1,71 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsxMaxDepth = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.jsxMaxDepth = (0, eslint_devkit_1.createRule)({
7
- name: 'jsx-max-depth',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-max-depth.md',
12
- description: 'Limit JSX nesting depth',
13
- },
14
- messages: {
15
- jsxMaxDepth: (0, eslint_devkit_2.formatLLMMessage)({
16
- icon: eslint_devkit_2.MessageIcons.WARNING,
17
- issueName: 'Excessive JSX Depth',
18
- description: 'JSX nesting depth exceeds maximum',
19
- severity: 'MEDIUM',
20
- fix: 'Extract nested JSX into separate component or reduce nesting',
21
- documentationLink: 'https://react.dev/learn/thinking-in-react#step-4-identify-where-your-state-should-live',
22
- }),
23
- },
24
- schema: [
25
- {
26
- type: 'object',
27
- properties: {
28
- max: {
29
- type: 'number',
30
- default: 5,
31
- minimum: 1,
32
- },
33
- },
34
- additionalProperties: false,
35
- },
36
- ],
37
- },
38
- defaultOptions: [{ max: 5 }],
39
- create(context) {
40
- const [options] = context.options;
41
- const maxDepth = options?.max ?? 5;
42
- return {
43
- JSXElement(node) {
44
- const depth = calculateDepth(node);
45
- if (depth > maxDepth) {
46
- context.report({
47
- node: node.openingElement.name,
48
- messageId: 'jsxMaxDepth',
49
- });
50
- }
51
- },
52
- };
53
- },
54
- });
55
- function calculateDepth(node, currentDepth = 0) {
56
- let maxDepth = currentDepth;
57
- for (const child of node.children) {
58
- if (child.type === 'JSXElement') {
59
- const childDepth = calculateDepth(child, currentDepth + 1);
60
- maxDepth = Math.max(maxDepth, childDepth);
61
- }
62
- else if (child.type === 'JSXExpressionContainer') {
63
- const expression = child.expression;
64
- if (expression.type === 'JSXElement') {
65
- const childDepth = calculateDepth(expression, currentDepth + 1);
66
- maxDepth = Math.max(maxDepth, childDepth);
67
- }
68
- }
69
- }
70
- return maxDepth;
71
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jsxMaxDepth=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.jsxMaxDepth=(0,eslint_devkit_1.createRule)({name:"jsx-max-depth",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-max-depth.md",description:"Limit JSX nesting depth"},messages:{jsxMaxDepth:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Excessive JSX Depth",description:"JSX nesting depth exceeds maximum",severity:"MEDIUM",fix:"Extract nested JSX into separate component or reduce nesting",documentationLink:"https://react.dev/learn/thinking-in-react#step-4-identify-where-your-state-should-live"})},schema:[{type:"object",properties:{max:{type:"number",default:5,minimum:1}},additionalProperties:false}]},defaultOptions:[{max:5}],create(context){const[options]=context.options;const maxDepth=options?.max??5;return{JSXElement(node){const depth=calculateDepth(node);if(depth>maxDepth){context.report({node:node.openingElement.name,messageId:"jsxMaxDepth"})}}}}});function calculateDepth(node,currentDepth=0){let maxDepth=currentDepth;for(const child of node.children){if(child.type==="JSXElement"){const childDepth=calculateDepth(child,currentDepth+1);maxDepth=Math.max(maxDepth,childDepth)}else if(child.type==="JSXExpressionContainer"){const expression=child.expression;if(expression.type==="JSXElement"){const childDepth=calculateDepth(expression,currentDepth+1);maxDepth=Math.max(maxDepth,childDepth)}}}return maxDepth}
@@ -1,55 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsxNoBind = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.jsxNoBind = (0, eslint_devkit_1.createRule)({
7
- name: 'jsx-no-bind',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-no-bind.md',
12
- description: 'Prevent .bind() in JSX',
13
- },
14
- schema: [],
15
- messages: {
16
- jsxNoBind: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.PERFORMANCE,
18
- issueName: 'Bind in JSX',
19
- description: 'Using .bind() in JSX creates new function on every render',
20
- severity: 'HIGH',
21
- fix: 'Use arrow function or bind in constructor/class field',
22
- documentationLink: 'https://react.dev/learn/render-and-commit#should-you-add-eslint-rules',
23
- }),
24
- },
25
- },
26
- defaultOptions: [],
27
- create(context) {
28
- return {
29
- JSXAttribute(node) {
30
- if (node.value && node.value.type === 'JSXExpressionContainer') {
31
- const expression = node.value.expression;
32
- if (expression.type === 'JSXEmptyExpression') {
33
- return;
34
- }
35
- if (isBindCall(expression)) {
36
- context.report({
37
- node: expression,
38
- messageId: 'jsxNoBind',
39
- });
40
- }
41
- }
42
- },
43
- };
44
- },
45
- });
46
- function isBindCall(node) {
47
- if (node.type === 'CallExpression') {
48
- if (node.callee.type === 'MemberExpression' &&
49
- node.callee.property.type === 'Identifier' &&
50
- node.callee.property.name === 'bind') {
51
- return true;
52
- }
53
- }
54
- return false;
55
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jsxNoBind=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.jsxNoBind=(0,eslint_devkit_1.createRule)({name:"jsx-no-bind",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-no-bind.md",description:"Prevent .bind() in JSX"},schema:[],messages:{jsxNoBind:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.PERFORMANCE,issueName:"Bind in JSX",description:"Using .bind() in JSX creates new function on every render",severity:"HIGH",fix:"Use arrow function or bind in constructor/class field",documentationLink:"https://react.dev/learn/render-and-commit#should-you-add-eslint-rules"})}},defaultOptions:[],create(context){return{JSXAttribute(node){if(node.value&&node.value.type==="JSXExpressionContainer"){const expression=node.value.expression;if(expression.type==="JSXEmptyExpression"){return}if(isBindCall(expression)){context.report({node:expression,messageId:"jsxNoBind"})}}}}}});function isBindCall(node){if(node.type==="CallExpression"){if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="bind"){return true}}return false}
@@ -1,66 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsxNoDuplicateProps = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.jsxNoDuplicateProps = (0, eslint_devkit_2.createRule)({
7
- name: 'jsx-no-duplicate-props',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-no-duplicate-props.md',
12
- description: 'Prevent duplicate props in JSX',
13
- },
14
- messages: {
15
- duplicateProp: (0, eslint_devkit_1.formatLLMMessage)({
16
- icon: eslint_devkit_1.MessageIcons.WARNING,
17
- issueName: 'Duplicate Prop',
18
- description: 'Prop "{{name}}" is duplicated - the last value will be used',
19
- severity: 'HIGH',
20
- fix: 'Remove the duplicate prop',
21
- documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md',
22
- }),
23
- },
24
- schema: [
25
- {
26
- type: 'object',
27
- properties: {
28
- ignoreCase: { type: 'boolean', default: false },
29
- },
30
- additionalProperties: false,
31
- },
32
- ],
33
- },
34
- defaultOptions: [{}],
35
- create(context, [options = {}]) {
36
- const { ignoreCase = false } = options ?? {};
37
- return {
38
- JSXOpeningElement(node) {
39
- const seenProps = new Map();
40
- for (const attr of node.attributes) {
41
- if (attr.type !== 'JSXAttribute')
42
- continue;
43
- if (attr.name.type !== 'JSXIdentifier')
44
- continue;
45
- let propName = attr.name.name;
46
- if (ignoreCase) {
47
- propName = propName.toLowerCase();
48
- }
49
- const previousAttr = seenProps.get(propName);
50
- if (previousAttr) {
51
- context.report({
52
- node: attr,
53
- messageId: 'duplicateProp',
54
- data: {
55
- name: attr.name.name,
56
- },
57
- });
58
- }
59
- else {
60
- seenProps.set(propName, attr);
61
- }
62
- }
63
- },
64
- };
65
- },
66
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jsxNoDuplicateProps=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.jsxNoDuplicateProps=(0,eslint_devkit_2.createRule)({name:"jsx-no-duplicate-props",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-no-duplicate-props.md",description:"Prevent duplicate props in JSX"},messages:{duplicateProp:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Duplicate Prop",description:'Prop "{{name}}" is duplicated - the last value will be used',severity:"HIGH",fix:"Remove the duplicate prop",documentationLink:"https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md"})},schema:[{type:"object",properties:{ignoreCase:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{}],create(context,[options={}]){const{ignoreCase=false}=options??{};return{JSXOpeningElement(node){const seenProps=new Map;for(const attr of node.attributes){if(attr.type!=="JSXAttribute")continue;if(attr.name.type!=="JSXIdentifier")continue;let propName=attr.name.name;if(ignoreCase){propName=propName.toLowerCase()}const previousAttr=seenProps.get(propName);if(previousAttr){context.report({node:attr,messageId:"duplicateProp",data:{name:attr.name.name}})}else{seenProps.set(propName,attr)}}}}}});