eslint-plugin-react-features 1.1.3 → 1.2.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/README.md +99 -19
  3. package/package.json +20 -4
  4. package/src/index.d.ts +1004 -21
  5. package/src/index.js +78 -16
  6. package/src/oxlint.d.ts +20 -0
  7. package/src/oxlint.js +21 -0
  8. package/src/rules/component-api/no-arbitrary-token-class.d.ts +17 -0
  9. package/src/rules/component-api/no-arbitrary-token-class.js +85 -0
  10. package/src/rules/component-api/no-default-test-id.d.ts +15 -0
  11. package/src/rules/component-api/no-default-test-id.js +53 -0
  12. package/src/rules/component-api/no-inline-style.d.ts +15 -0
  13. package/src/rules/component-api/no-inline-style.js +63 -0
  14. package/src/rules/component-api/no-is-prefix-prop.d.ts +17 -0
  15. package/src/rules/component-api/no-is-prefix-prop.js +66 -0
  16. package/src/rules/component-api/no-kind-prop-discriminator.d.ts +25 -0
  17. package/src/rules/component-api/no-kind-prop-discriminator.js +62 -0
  18. package/src/rules/component-api/no-raw-color-literal.d.ts +16 -0
  19. package/src/rules/component-api/no-raw-color-literal.js +63 -0
  20. package/src/rules/component-api/no-wrapper-sub-component.d.ts +23 -0
  21. package/src/rules/component-api/no-wrapper-sub-component.js +103 -0
  22. package/src/rules/component-api/require-data-slot.d.ts +15 -0
  23. package/src/rules/component-api/require-data-slot.js +45 -0
  24. package/src/rules/migration/react-class-to-hooks.js +6 -1
  25. package/src/rules/performance/no-unnecessary-rerenders.js +7 -3
  26. package/src/rules/performance/react-no-inline-functions.js +3 -1
  27. package/src/rules/performance/react-render-optimization.js +2 -1
  28. package/src/rules/react/checked-requires-onchange-or-readonly.js +1 -0
  29. package/src/rules/react/default-props-match-prop-types.js +1 -0
  30. package/src/rules/react/display-name.js +1 -0
  31. package/src/rules/react/hooks-exhaustive-deps.d.ts +1 -1
  32. package/src/rules/react/hooks-exhaustive-deps.js +136 -47
  33. package/src/rules/react/jsx-handler-names.js +1 -0
  34. package/src/rules/react/jsx-key.js +3 -2
  35. package/src/rules/react/jsx-max-depth.js +1 -0
  36. package/src/rules/react/jsx-no-bind.js +1 -0
  37. package/src/rules/react/jsx-no-duplicate-props.js +1 -0
  38. package/src/rules/react/jsx-no-literals.js +1 -0
  39. package/src/rules/react/jsx-no-script-url.js +6 -2
  40. package/src/rules/react/jsx-no-target-blank.js +7 -1
  41. package/src/rules/react/no-access-state-in-setstate.js +1 -0
  42. package/src/rules/react/no-adjacent-inline-elements.js +1 -0
  43. package/src/rules/react/no-arrow-function-lifecycle.js +1 -0
  44. package/src/rules/react/no-children-prop.js +1 -0
  45. package/src/rules/react/no-danger-with-children.js +2 -0
  46. package/src/rules/react/no-danger.js +3 -0
  47. package/src/rules/react/no-deprecated.js +1 -0
  48. package/src/rules/react/no-did-mount-set-state.js +1 -0
  49. package/src/rules/react/no-did-update-set-state.js +1 -0
  50. package/src/rules/react/no-direct-mutation-state.js +24 -66
  51. package/src/rules/react/no-find-dom-node.js +1 -0
  52. package/src/rules/react/no-invalid-html-attribute.js +1 -0
  53. package/src/rules/react/no-is-mounted.js +1 -0
  54. package/src/rules/react/no-multi-comp.js +4 -0
  55. package/src/rules/react/no-namespace.js +1 -0
  56. package/src/rules/react/no-object-type-as-default-prop.js +1 -0
  57. package/src/rules/react/no-redundant-should-component-update.js +1 -0
  58. package/src/rules/react/no-render-return-value.js +1 -0
  59. package/src/rules/react/no-set-state.js +1 -0
  60. package/src/rules/react/no-string-refs.js +1 -0
  61. package/src/rules/react/no-this-in-sfc.js +1 -0
  62. package/src/rules/react/no-typos.js +1 -0
  63. package/src/rules/react/no-unescaped-entities.js +1 -0
  64. package/src/rules/react/no-unknown-property.js +1 -0
  65. package/src/rules/react/no-unsafe.js +1 -0
  66. package/src/rules/react/prefer-es6-class.js +1 -0
  67. package/src/rules/react/prefer-stateless-function.js +8 -3
  68. package/src/rules/react/prop-types.js +2 -0
  69. package/src/rules/react/react-in-jsx-scope.js +1 -0
  70. package/src/rules/react/require-default-props.js +4 -0
  71. package/src/rules/react/require-optimization.js +1 -0
  72. package/src/rules/react/require-render-return.js +1 -0
  73. package/src/rules/react/required-attributes.js +6 -0
  74. package/src/rules/react/sort-comp.js +17 -13
  75. package/src/rules/react/state-in-constructor.js +3 -0
  76. package/src/rules/react/static-property-placement.js +7 -0
  77. package/src/rules/react/void-dom-elements-no-children.js +2 -0
@@ -13,6 +13,7 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-direct-mutation-state.md',
16
17
  description: 'Prevent direct mutation of this.state that breaks React reconciliation',
17
18
  },
18
19
  hasSuggestions: true,
@@ -63,6 +64,7 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
63
64
  let inClassComponent = false;
64
65
  let inLifecycleMethod = false;
65
66
  const classStack = [];
67
+ // oxlint-disable-next-line consistent-function-scoping
66
68
  function isLifecycleMethod(methodName) {
67
69
  const lifecycleMethods = [
68
70
  'componentDidMount',
@@ -103,7 +105,7 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
103
105
  messageId: 'suggestSetState',
104
106
  fix(fixer) {
105
107
  // Get the source code to determine indentation
106
- const sourceCode = context.getSourceCode();
108
+ const sourceCode = context.sourceCode;
107
109
  const start = node.range[0];
108
110
  const lineStart = sourceCode.getIndexFromLoc({
109
111
  line: sourceCode.getLocFromIndex(start).line,
@@ -119,7 +121,7 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
119
121
  messageId: 'suggestFunctionalUpdate',
120
122
  fix(fixer) {
121
123
  // Get the source code to determine indentation
122
- const sourceCode = context.getSourceCode();
124
+ const sourceCode = context.sourceCode;
123
125
  const start = node.range[0];
124
126
  const lineStart = sourceCode.getIndexFromLoc({
125
127
  line: sourceCode.getLocFromIndex(start).line,
@@ -134,6 +136,26 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
134
136
  ],
135
137
  });
136
138
  }
139
+ // Shared helper — uses `target` to avoid shadowing visitor `node` params
140
+ // oxlint-disable-next-line consistent-function-scoping
141
+ function isStatePropertyAccess(target) {
142
+ if (target.type === 'MemberExpression' &&
143
+ target.object.type === 'MemberExpression' &&
144
+ target.object.object.type === 'ThisExpression' &&
145
+ target.object.property.type === 'Identifier' &&
146
+ target.object.property.name === 'state') {
147
+ return true; // this.state.xxx
148
+ }
149
+ // Handle deeper nesting
150
+ if (target.type === 'MemberExpression') {
151
+ return isStatePropertyAccess(target.object);
152
+ }
153
+ // Handle logical expressions like (this.state.items || [])
154
+ if (target.type === 'LogicalExpression') {
155
+ return isStatePropertyAccess(target.left);
156
+ }
157
+ return false;
158
+ }
137
159
  return {
138
160
  ClassDeclaration(node) {
139
161
  // Check if this is a React component class
@@ -168,21 +190,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
168
190
  // Assignment to this.state properties
169
191
  AssignmentExpression(node) {
170
192
  if (node.left.type === 'MemberExpression') {
171
- // Check if this is assignment to this.state.xxx (but not this.state itself)
172
- function isStatePropertyAccess(node) {
173
- if (node.type === 'MemberExpression' &&
174
- node.object.type === 'MemberExpression' &&
175
- node.object.object.type === 'ThisExpression' &&
176
- node.object.property.type === 'Identifier' &&
177
- node.object.property.name === 'state') {
178
- return true; // this.state.xxx
179
- }
180
- // Handle deeper nesting
181
- if (node.type === 'MemberExpression') {
182
- return isStatePropertyAccess(node.object);
183
- }
184
- return false;
185
- }
186
193
  if (isStatePropertyAccess(node.left)) {
187
194
  reportStateMutation(node, 'assignment');
188
195
  }
@@ -191,21 +198,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
191
198
  // Update expressions on this.state properties (++state.count, state.count--)
192
199
  UpdateExpression(node) {
193
200
  if (node.argument.type === 'MemberExpression') {
194
- // Check if this is update on this.state.xxx
195
- function isStatePropertyAccess(node) {
196
- if (node.type === 'MemberExpression' &&
197
- node.object.type === 'MemberExpression' &&
198
- node.object.object.type === 'ThisExpression' &&
199
- node.object.property.type === 'Identifier' &&
200
- node.object.property.name === 'state') {
201
- return true; // this.state.xxx
202
- }
203
- // Handle deeper nesting
204
- if (node.type === 'MemberExpression') {
205
- return isStatePropertyAccess(node.object);
206
- }
207
- return false;
208
- }
209
201
  if (isStatePropertyAccess(node.argument)) {
210
202
  reportStateMutation(node, 'update');
211
203
  }
@@ -214,21 +206,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
214
206
  // Delete operator on this.state properties
215
207
  UnaryExpression(node) {
216
208
  if (node.operator === 'delete' && node.argument.type === 'MemberExpression') {
217
- // Check if this is delete on this.state.xxx
218
- function isStatePropertyAccess(node) {
219
- if (node.type === 'MemberExpression' &&
220
- node.object.type === 'MemberExpression' &&
221
- node.object.object.type === 'ThisExpression' &&
222
- node.object.property.type === 'Identifier' &&
223
- node.object.property.name === 'state') {
224
- return true; // this.state.xxx
225
- }
226
- // Handle deeper nesting
227
- if (node.type === 'MemberExpression') {
228
- return isStatePropertyAccess(node.object);
229
- }
230
- return false;
231
- }
232
209
  if (isStatePropertyAccess(node.argument)) {
233
210
  reportStateMutation(node, 'delete operator');
234
211
  }
@@ -239,25 +216,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
239
216
  if (node.callee.type === 'MemberExpression' &&
240
217
  node.callee.property.type === 'Identifier') {
241
218
  const methodName = node.callee.property.name;
242
- // Check if this is a call on this.state.xxx
243
- function isStatePropertyAccess(node) {
244
- if (node.type === 'MemberExpression' &&
245
- node.object.type === 'MemberExpression' &&
246
- node.object.object.type === 'ThisExpression' &&
247
- node.object.property.type === 'Identifier' &&
248
- node.object.property.name === 'state') {
249
- return true; // this.state.xxx
250
- }
251
- // Handle deeper nesting
252
- if (node.type === 'MemberExpression') {
253
- return isStatePropertyAccess(node.object);
254
- }
255
- // Handle logical expressions like (this.state.items || [])
256
- if (node.type === 'LogicalExpression') {
257
- return isStatePropertyAccess(node.left);
258
- }
259
- return false;
260
- }
261
219
  if (isStatePropertyAccess(node.callee.object)) {
262
220
  // Methods that mutate arrays/objects
263
221
  const mutatingMethods = [
@@ -13,6 +13,7 @@ exports.noFindDomNode = (0, eslint_devkit_2.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-find-dom-node.md',
16
17
  description: 'Prevent using findDOMNode',
17
18
  },
18
19
  messages: {
@@ -51,6 +51,7 @@ exports.noInvalidHtmlAttribute = (0, eslint_devkit_1.createRule)({
51
51
  meta: {
52
52
  type: 'problem',
53
53
  docs: {
54
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-invalid-html-attribute.md',
54
55
  description: 'Prevent invalid HTML attributes',
55
56
  },
56
57
  messages: {
@@ -13,6 +13,7 @@ exports.noIsMounted = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-is-mounted.md',
16
17
  description: 'Prevent isMounted anti-pattern',
17
18
  },
18
19
  schema: [],
@@ -13,6 +13,7 @@ exports.noMultiComp = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-multi-comp.md',
16
17
  description: 'Prevent multiple components per file',
17
18
  },
18
19
  schema: [
@@ -75,6 +76,7 @@ exports.noMultiComp = (0, eslint_devkit_1.createRule)({
75
76
  }
76
77
  },
77
78
  };
79
+ // oxlint-disable-next-line consistent-function-scoping
78
80
  function getComponentFromDeclaration(node) {
79
81
  if (node.type === 'FunctionDeclaration') {
80
82
  return node;
@@ -126,6 +128,7 @@ exports.noMultiComp = (0, eslint_devkit_1.createRule)({
126
128
  }
127
129
  return false;
128
130
  }
131
+ // oxlint-disable-next-line consistent-function-scoping
129
132
  function isReactComponent(node) {
130
133
  if (!node.superClass)
131
134
  return false;
@@ -144,6 +147,7 @@ exports.noMultiComp = (0, eslint_devkit_1.createRule)({
144
147
  // Simple heuristic: check if it's a function component without useState
145
148
  return !isReactComponent(node);
146
149
  }
150
+ // oxlint-disable-next-line consistent-function-scoping
147
151
  function getComponentNameNode(node) {
148
152
  if (node.type === 'ClassDeclaration') {
149
153
  return node.id || node;
@@ -13,6 +13,7 @@ exports.noNamespace = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-namespace.md',
16
17
  description: 'Prevent namespace imports',
17
18
  },
18
19
  messages: {
@@ -13,6 +13,7 @@ exports.noObjectTypeAsDefaultProp = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-object-type-as-default-prop.md',
16
17
  description: 'Prevent object types as default props',
17
18
  },
18
19
  messages: {
@@ -13,6 +13,7 @@ exports.noRedundantShouldComponentUpdate = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-redundant-should-component-update.md',
16
17
  description: 'Prevent redundant shouldComponentUpdate',
17
18
  },
18
19
  messages: {
@@ -13,6 +13,7 @@ exports.noRenderReturnValue = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-render-return-value.md',
16
17
  description: 'Prevent using render return value',
17
18
  },
18
19
  messages: {
@@ -13,6 +13,7 @@ exports.noSetState = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-set-state.md',
16
17
  description: 'Disallow usage of setState to encourage functional components with hooks',
17
18
  },
18
19
  messages: {
@@ -13,6 +13,7 @@ exports.noStringRefs = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-string-refs.md',
16
17
  description: 'Disallow string refs',
17
18
  },
18
19
  messages: {
@@ -13,6 +13,7 @@ exports.noThisInSfc = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-this-in-sfc.md',
16
17
  description: 'Disallow this from being used in stateless functional components',
17
18
  },
18
19
  schema: [],
@@ -36,6 +36,7 @@ exports.noTypos = (0, eslint_devkit_1.createRule)({
36
36
  meta: {
37
37
  type: 'problem',
38
38
  docs: {
39
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-typos.md',
39
40
  description: 'Catch common typos',
40
41
  },
41
42
  schema: [],
@@ -14,6 +14,7 @@ exports.noUnescapedEntities = (0, eslint_devkit_1.createRule)({
14
14
  meta: {
15
15
  type: 'problem',
16
16
  docs: {
17
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-unescaped-entities.md',
17
18
  description: 'Prevent unescaped entities',
18
19
  },
19
20
  messages: {
@@ -92,6 +92,7 @@ exports.noUnknownProperty = (0, eslint_devkit_1.createRule)({
92
92
  meta: {
93
93
  type: 'problem',
94
94
  docs: {
95
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-unknown-property.md',
95
96
  description: 'Disallow unknown DOM properties',
96
97
  },
97
98
  schema: [],
@@ -23,6 +23,7 @@ exports.noUnsafe = (0, eslint_devkit_2.createRule)({
23
23
  meta: {
24
24
  type: 'problem',
25
25
  docs: {
26
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-unsafe.md',
26
27
  description: 'Prevent usage of unsafe lifecycle methods',
27
28
  },
28
29
  messages: {
@@ -13,6 +13,7 @@ exports.preferEs6Class = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/prefer-es6-class.md',
16
17
  description: 'Prefer ES6 classes over createClass',
17
18
  },
18
19
  schema: [],
@@ -13,6 +13,7 @@ exports.preferStatelessFunction = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/prefer-stateless-function.md',
16
17
  description: 'Prefer stateless functions',
17
18
  },
18
19
  messages: {
@@ -57,6 +58,7 @@ exports.preferStatelessFunction = (0, eslint_devkit_1.createRule)({
57
58
  }
58
59
  },
59
60
  };
61
+ // oxlint-disable-next-line consistent-function-scoping
60
62
  function isReactComponent(node) {
61
63
  if (!node.superClass)
62
64
  return false;
@@ -71,6 +73,7 @@ exports.preferStatelessFunction = (0, eslint_devkit_1.createRule)({
71
73
  }
72
74
  return false;
73
75
  }
76
+ // oxlint-disable-next-line consistent-function-scoping
74
77
  function isPureComponent(node) {
75
78
  if (!node.superClass)
76
79
  return false;
@@ -85,6 +88,7 @@ exports.preferStatelessFunction = (0, eslint_devkit_1.createRule)({
85
88
  }
86
89
  return false;
87
90
  }
91
+ // oxlint-disable-next-line consistent-function-scoping
88
92
  function hasState(node) {
89
93
  for (const member of node.body.body) {
90
94
  // PropertyDefinition is used by TypeScript parser for class properties
@@ -114,17 +118,18 @@ exports.preferStatelessFunction = (0, eslint_devkit_1.createRule)({
114
118
  }
115
119
  return false;
116
120
  }
121
+ // oxlint-disable-next-line consistent-function-scoping
117
122
  function hasLifecycleMethods(node) {
118
- const lifecycleMethods = [
123
+ const lifecycleMethods = new Set([
119
124
  'componentDidMount', 'componentDidUpdate', 'componentWillUnmount',
120
125
  'componentWillMount', 'componentWillReceiveProps', 'componentWillUpdate',
121
126
  'shouldComponentUpdate', 'getDerivedStateFromProps', 'getSnapshotBeforeUpdate',
122
127
  'UNSAFE_componentWillMount', 'UNSAFE_componentWillReceiveProps', 'UNSAFE_componentWillUpdate',
123
- ];
128
+ ]);
124
129
  for (const member of node.body.body) {
125
130
  if (member.type === 'MethodDefinition' &&
126
131
  member.key.type === 'Identifier' &&
127
- lifecycleMethods.includes(member.key.name)) {
132
+ lifecycleMethods.has(member.key.name)) {
128
133
  return true;
129
134
  }
130
135
  }
@@ -13,6 +13,7 @@ exports.propTypes = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/prop-types.md',
16
17
  description: 'Enforce prop types usage',
17
18
  },
18
19
  schema: [
@@ -86,6 +87,7 @@ exports.propTypes = (0, eslint_devkit_1.createRule)({
86
87
  }
87
88
  },
88
89
  };
90
+ // oxlint-disable-next-line consistent-function-scoping
89
91
  function isReactComponent(node) {
90
92
  if (!node.superClass)
91
93
  return false;
@@ -13,6 +13,7 @@ exports.reactInJsxScope = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/react-in-jsx-scope.md',
16
17
  description: 'Ensure React is in scope',
17
18
  },
18
19
  schema: [],
@@ -13,6 +13,7 @@ exports.requireDefaultProps = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/require-default-props.md',
16
17
  description: 'Require default props',
17
18
  },
18
19
  messages: {
@@ -113,12 +114,14 @@ exports.requireDefaultProps = (0, eslint_devkit_1.createRule)({
113
114
  }
114
115
  },
115
116
  };
117
+ // oxlint-disable-next-line consistent-function-scoping
116
118
  function getComponentName(node) {
117
119
  if (node.parent.type === 'ClassBody' && node.parent.parent.type === 'ClassDeclaration') {
118
120
  return node.parent.parent.id?.name || null;
119
121
  }
120
122
  return null;
121
123
  }
124
+ // oxlint-disable-next-line consistent-function-scoping
122
125
  function isReactComponent(node) {
123
126
  if (!node.superClass)
124
127
  return false;
@@ -133,6 +136,7 @@ exports.requireDefaultProps = (0, eslint_devkit_1.createRule)({
133
136
  }
134
137
  return false;
135
138
  }
139
+ // oxlint-disable-next-line consistent-function-scoping
136
140
  function isRequiredProp(propType) {
137
141
  // Check if prop type ends with .isRequired
138
142
  if (propType.value.type === 'MemberExpression' &&
@@ -13,6 +13,7 @@ exports.requireOptimization = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'suggestion',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/require-optimization.md',
16
17
  description: 'Require performance optimizations for React components based on usage patterns',
17
18
  },
18
19
  hasSuggestions: true,
@@ -13,6 +13,7 @@ exports.requireRenderReturn = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/require-render-return.md',
16
17
  description: 'Require render methods to return',
17
18
  },
18
19
  schema: [],
@@ -13,7 +13,10 @@ exports.requiredAttributes = (0, eslint_devkit_2.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/required-attributes.md',
16
17
  description: 'Enforce required attributes on React components with customizable ignore lists',
18
+ cwe: 'CWE-252',
19
+ cvss: 5,
17
20
  },
18
21
  fixable: 'code',
19
22
  hasSuggestions: true,
@@ -117,6 +120,7 @@ exports.requiredAttributes = (0, eslint_devkit_2.createRule)({
117
120
  /**
118
121
  * Get attribute purpose based on name
119
122
  */
123
+ // oxlint-disable-next-line consistent-function-scoping
120
124
  const getAttributePurpose = (attribute) => {
121
125
  const purposes = {
122
126
  'data-testid': 'Testing & QA automation',
@@ -137,9 +141,11 @@ exports.requiredAttributes = (0, eslint_devkit_2.createRule)({
137
141
  /**
138
142
  * Check if an element is a form element that should have type/name attributes
139
143
  */
144
+ // oxlint-disable-next-line consistent-function-scoping
140
145
  const isFormElement = (elementName) => {
141
146
  return ['input', 'button', 'select', 'textarea'].includes(elementName.toLowerCase());
142
147
  };
148
+ // oxlint-disable-next-line consistent-function-scoping
143
149
  const getDefaultSuggestedValue = (attribute, elementName) => {
144
150
  if (attribute === 'data-testid') {
145
151
  // Generate kebab-case testid from element name
@@ -16,7 +16,7 @@ const DEFAULT_ORDER = [
16
16
  'everything-else',
17
17
  'render'
18
18
  ];
19
- const LIFECYCLE_METHODS = [
19
+ const LIFECYCLE_METHODS = new Set([
20
20
  'constructor',
21
21
  'getDerivedStateFromProps',
22
22
  'componentWillMount',
@@ -31,12 +31,13 @@ const LIFECYCLE_METHODS = [
31
31
  'componentDidUpdate',
32
32
  'componentDidCatch',
33
33
  'componentWillUnmount',
34
- ];
34
+ ]);
35
35
  exports.sortComp = (0, eslint_devkit_1.createRule)({
36
36
  name: 'sort-comp',
37
37
  meta: {
38
38
  type: 'problem',
39
39
  docs: {
40
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/sort-comp.md',
40
41
  description: 'Enforce component method ordering',
41
42
  },
42
43
  messages: {
@@ -73,6 +74,7 @@ exports.sortComp = (0, eslint_devkit_1.createRule)({
73
74
  }
74
75
  },
75
76
  };
77
+ // oxlint-disable-next-line consistent-function-scoping
76
78
  function isReactComponent(node) {
77
79
  if (!node.superClass)
78
80
  return false;
@@ -87,7 +89,7 @@ exports.sortComp = (0, eslint_devkit_1.createRule)({
87
89
  }
88
90
  return false;
89
91
  }
90
- function checkMethodOrder(node, order) {
92
+ function checkMethodOrder(node, sortOrder) {
91
93
  const members = node.body.body;
92
94
  const methodOrder = [];
93
95
  // Collect all methods/properties with their order index
@@ -95,7 +97,7 @@ exports.sortComp = (0, eslint_devkit_1.createRule)({
95
97
  const member = members[i];
96
98
  const methodName = getMemberName(member);
97
99
  if (methodName) {
98
- const orderIndex = getOrderIndex(methodName, member, order);
100
+ const orderIndex = getOrderIndex(methodName, member, sortOrder);
99
101
  methodOrder.push({ name: methodName, index: orderIndex, node: member });
100
102
  }
101
103
  }
@@ -110,6 +112,7 @@ exports.sortComp = (0, eslint_devkit_1.createRule)({
110
112
  }
111
113
  }
112
114
  }
115
+ // oxlint-disable-next-line consistent-function-scoping
113
116
  function getMemberName(member) {
114
117
  if (member.type === 'MethodDefinition' && member.key.type === 'Identifier') {
115
118
  return member.key.name;
@@ -120,6 +123,7 @@ exports.sortComp = (0, eslint_devkit_1.createRule)({
120
123
  }
121
124
  return null;
122
125
  }
126
+ // oxlint-disable-next-line consistent-function-scoping
123
127
  function getMemberKeyNode(member) {
124
128
  if (member.type === 'MethodDefinition' && member.key.type === 'Identifier') {
125
129
  return member.key;
@@ -130,31 +134,31 @@ exports.sortComp = (0, eslint_devkit_1.createRule)({
130
134
  }
131
135
  return member;
132
136
  }
133
- function getOrderIndex(name, member, order) {
137
+ function getOrderIndex(name, member, sortOrder) {
134
138
  // Static methods and properties
135
139
  if (member.type === 'MethodDefinition' && member.static) {
136
140
  if (name === 'render')
137
- return order.indexOf('render');
138
- return order.indexOf('static-methods');
141
+ return sortOrder.indexOf('render');
142
+ return sortOrder.indexOf('static-methods');
139
143
  }
140
144
  // Handle PropertyDefinition (TypeScript parser)
141
145
  if (member.type === 'PropertyDefinition' && member.static) {
142
- return order.indexOf('static-variables');
146
+ return sortOrder.indexOf('static-variables');
143
147
  }
144
148
  // Instance variables - Handle PropertyDefinition (TypeScript parser)
145
149
  if (member.type === 'PropertyDefinition' && !member.static) {
146
- return order.indexOf('instance-variables');
150
+ return sortOrder.indexOf('instance-variables');
147
151
  }
148
152
  // Lifecycle methods
149
- if (LIFECYCLE_METHODS.includes(name)) {
150
- return order.indexOf('lifecycle');
153
+ if (LIFECYCLE_METHODS.has(name)) {
154
+ return sortOrder.indexOf('lifecycle');
151
155
  }
152
156
  // Render method
153
157
  if (name === 'render') {
154
- return order.indexOf('render');
158
+ return sortOrder.indexOf('render');
155
159
  }
156
160
  // Everything else
157
- return order.indexOf('everything-else');
161
+ return sortOrder.indexOf('everything-else');
158
162
  }
159
163
  },
160
164
  });
@@ -13,6 +13,7 @@ exports.stateInConstructor = (0, eslint_devkit_1.createRule)({
13
13
  meta: {
14
14
  type: 'problem',
15
15
  docs: {
16
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/state-in-constructor.md',
16
17
  description: 'Enforce state initialization in constructor',
17
18
  },
18
19
  schema: [],
@@ -36,6 +37,7 @@ exports.stateInConstructor = (0, eslint_devkit_1.createRule)({
36
37
  }
37
38
  },
38
39
  };
40
+ // oxlint-disable-next-line consistent-function-scoping
39
41
  function isReactComponent(node) {
40
42
  if (!node.superClass)
41
43
  return false;
@@ -83,6 +85,7 @@ exports.stateInConstructor = (0, eslint_devkit_1.createRule)({
83
85
  }
84
86
  }
85
87
  }
88
+ // oxlint-disable-next-line consistent-function-scoping
86
89
  function hasStateInitializationInConstructor(constructor) {
87
90
  if (constructor.value.type === 'FunctionExpression') {
88
91
  const body = constructor.value.body;