eslint-plugin-react-features 1.2.5 → 1.2.7

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 (129) hide show
  1. package/package.json +7 -18
  2. package/src/index.d.ts +15 -2074
  3. package/src/index.js +1 -36
  4. package/src/oxlint.d.ts +17 -20
  5. package/src/oxlint.js +0 -18
  6. package/src/rules/component-api/no-arbitrary-token-class.js +0 -11
  7. package/src/rules/component-api/no-default-test-id.js +0 -7
  8. package/src/rules/component-api/no-inline-style.js +0 -6
  9. package/src/rules/component-api/no-is-prefix-prop.js +0 -7
  10. package/src/rules/component-api/no-kind-prop-discriminator.js +0 -5
  11. package/src/rules/component-api/no-raw-color-literal.js +0 -8
  12. package/src/rules/component-api/no-wrapper-sub-component.js +0 -8
  13. package/src/rules/component-api/require-data-slot.js +0 -5
  14. package/src/rules/migration/react-class-to-hooks.js +1 -26
  15. package/src/rules/performance/no-unnecessary-rerenders.js +1 -32
  16. package/src/rules/performance/react-no-inline-functions.js +2 -29
  17. package/src/rules/performance/react-render-optimization.js +1 -40
  18. package/src/rules/react/checked-requires-onchange-or-readonly.js +0 -7
  19. package/src/rules/react/default-props-match-prop-types.js +2 -23
  20. package/src/rules/react/display-name.js +1 -33
  21. package/src/rules/react/hooks-exhaustive-deps.js +1 -90
  22. package/src/rules/react/jsx-handler-names.js +0 -8
  23. package/src/rules/react/jsx-key.js +0 -84
  24. package/src/rules/react/jsx-max-depth.js +0 -10
  25. package/src/rules/react/jsx-no-bind.js +0 -10
  26. package/src/rules/react/jsx-no-duplicate-props.js +0 -5
  27. package/src/rules/react/jsx-no-literals.js +0 -5
  28. package/src/rules/react/jsx-no-script-url.js +0 -16
  29. package/src/rules/react/jsx-no-target-blank.js +1 -20
  30. package/src/rules/react/no-access-state-in-setstate.js +0 -13
  31. package/src/rules/react/no-adjacent-inline-elements.js +0 -10
  32. package/src/rules/react/no-arrow-function-lifecycle.js +0 -7
  33. package/src/rules/react/no-children-prop.js +0 -7
  34. package/src/rules/react/no-danger-with-children.js +0 -13
  35. package/src/rules/react/no-danger.js +0 -5
  36. package/src/rules/react/no-deprecated.js +0 -11
  37. package/src/rules/react/no-did-mount-set-state.js +0 -6
  38. package/src/rules/react/no-did-update-set-state.js +0 -10
  39. package/src/rules/react/no-direct-mutation-state.js +3 -29
  40. package/src/rules/react/no-find-dom-node.js +0 -7
  41. package/src/rules/react/no-invalid-html-attribute.js +36 -41
  42. package/src/rules/react/no-is-mounted.js +0 -7
  43. package/src/rules/react/no-multi-comp.js +0 -14
  44. package/src/rules/react/no-namespace.js +0 -5
  45. package/src/rules/react/no-object-type-as-default-prop.js +0 -9
  46. package/src/rules/react/no-redundant-should-component-update.js +0 -6
  47. package/src/rules/react/no-render-return-value.js +1 -9
  48. package/src/rules/react/no-set-state.js +0 -6
  49. package/src/rules/react/no-string-refs.js +0 -8
  50. package/src/rules/react/no-this-in-sfc.js +0 -11
  51. package/src/rules/react/no-typos.js +1 -9
  52. package/src/rules/react/no-unescaped-entities.js +0 -7
  53. package/src/rules/react/no-unknown-property.js +0 -13
  54. package/src/rules/react/no-unsafe.js +0 -7
  55. package/src/rules/react/prefer-es6-class.js +0 -7
  56. package/src/rules/react/prefer-stateless-function.js +0 -13
  57. package/src/rules/react/prop-types.js +0 -12
  58. package/src/rules/react/react-in-jsx-scope.js +0 -9
  59. package/src/rules/react/require-default-props.js +0 -19
  60. package/src/rules/react/require-optimization.js +6 -44
  61. package/src/rules/react/require-render-return.js +0 -9
  62. package/src/rules/react/required-attributes.js +0 -34
  63. package/src/rules/react/sort-comp.js +1 -19
  64. package/src/rules/react/state-in-constructor.js +0 -11
  65. package/src/rules/react/static-property-placement.js +1 -21
  66. package/src/rules/react/void-dom-elements-no-children.js +0 -7
  67. package/src/types/index.js +0 -5
  68. package/CHANGELOG.md +0 -255
  69. package/src/rules/component-api/no-arbitrary-token-class.d.ts +0 -17
  70. package/src/rules/component-api/no-default-test-id.d.ts +0 -15
  71. package/src/rules/component-api/no-inline-style.d.ts +0 -15
  72. package/src/rules/component-api/no-is-prefix-prop.d.ts +0 -17
  73. package/src/rules/component-api/no-kind-prop-discriminator.d.ts +0 -25
  74. package/src/rules/component-api/no-raw-color-literal.d.ts +0 -16
  75. package/src/rules/component-api/no-wrapper-sub-component.d.ts +0 -23
  76. package/src/rules/component-api/require-data-slot.d.ts +0 -15
  77. package/src/rules/migration/react-class-to-hooks.d.ts +0 -22
  78. package/src/rules/performance/no-unnecessary-rerenders.d.ts +0 -26
  79. package/src/rules/performance/react-no-inline-functions.d.ts +0 -24
  80. package/src/rules/performance/react-render-optimization.d.ts +0 -31
  81. package/src/rules/react/checked-requires-onchange-or-readonly.d.ts +0 -16
  82. package/src/rules/react/default-props-match-prop-types.d.ts +0 -13
  83. package/src/rules/react/display-name.d.ts +0 -13
  84. package/src/rules/react/hooks-exhaustive-deps.d.ts +0 -25
  85. package/src/rules/react/jsx-handler-names.d.ts +0 -13
  86. package/src/rules/react/jsx-key.d.ts +0 -20
  87. package/src/rules/react/jsx-max-depth.d.ts +0 -19
  88. package/src/rules/react/jsx-no-bind.d.ts +0 -13
  89. package/src/rules/react/jsx-no-duplicate-props.d.ts +0 -21
  90. package/src/rules/react/jsx-no-literals.d.ts +0 -20
  91. package/src/rules/react/jsx-no-script-url.d.ts +0 -25
  92. package/src/rules/react/jsx-no-target-blank.d.ts +0 -26
  93. package/src/rules/react/no-access-state-in-setstate.d.ts +0 -13
  94. package/src/rules/react/no-adjacent-inline-elements.d.ts +0 -13
  95. package/src/rules/react/no-arrow-function-lifecycle.d.ts +0 -13
  96. package/src/rules/react/no-children-prop.d.ts +0 -13
  97. package/src/rules/react/no-danger-with-children.d.ts +0 -16
  98. package/src/rules/react/no-danger.d.ts +0 -13
  99. package/src/rules/react/no-deprecated.d.ts +0 -16
  100. package/src/rules/react/no-did-mount-set-state.d.ts +0 -13
  101. package/src/rules/react/no-did-update-set-state.d.ts +0 -19
  102. package/src/rules/react/no-direct-mutation-state.d.ts +0 -20
  103. package/src/rules/react/no-find-dom-node.d.ts +0 -15
  104. package/src/rules/react/no-invalid-html-attribute.d.ts +0 -13
  105. package/src/rules/react/no-is-mounted.d.ts +0 -13
  106. package/src/rules/react/no-multi-comp.d.ts +0 -18
  107. package/src/rules/react/no-namespace.d.ts +0 -13
  108. package/src/rules/react/no-object-type-as-default-prop.d.ts +0 -13
  109. package/src/rules/react/no-redundant-should-component-update.d.ts +0 -13
  110. package/src/rules/react/no-render-return-value.d.ts +0 -13
  111. package/src/rules/react/no-set-state.d.ts +0 -13
  112. package/src/rules/react/no-string-refs.d.ts +0 -13
  113. package/src/rules/react/no-this-in-sfc.d.ts +0 -13
  114. package/src/rules/react/no-typos.d.ts +0 -13
  115. package/src/rules/react/no-unescaped-entities.d.ts +0 -13
  116. package/src/rules/react/no-unknown-property.d.ts +0 -13
  117. package/src/rules/react/no-unsafe.d.ts +0 -20
  118. package/src/rules/react/prefer-es6-class.d.ts +0 -13
  119. package/src/rules/react/prefer-stateless-function.d.ts +0 -16
  120. package/src/rules/react/prop-types.d.ts +0 -18
  121. package/src/rules/react/react-in-jsx-scope.d.ts +0 -13
  122. package/src/rules/react/require-default-props.d.ts +0 -16
  123. package/src/rules/react/require-optimization.d.ts +0 -26
  124. package/src/rules/react/require-render-return.d.ts +0 -13
  125. package/src/rules/react/required-attributes.d.ts +0 -28
  126. package/src/rules/react/sort-comp.d.ts +0 -17
  127. package/src/rules/react/state-in-constructor.d.ts +0 -13
  128. package/src/rules/react/static-property-placement.d.ts +0 -20
  129. package/src/rules/react/void-dom-elements-no-children.d.ts +0 -15
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.jsxNoDuplicateProps = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.jsxNoLiterals = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -1,14 +1,8 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.jsxNoScriptUrl = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
5
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- // Attributes that commonly accept URLs
12
6
  const URL_PROPS = new Set(['href', 'src', 'action', 'formAction', 'data', 'poster', 'background']);
13
7
  exports.jsxNoScriptUrl = (0, eslint_devkit_2.createRule)({
14
8
  name: 'jsx-no-script-url',
@@ -55,31 +49,24 @@ exports.jsxNoScriptUrl = (0, eslint_devkit_2.createRule)({
55
49
  },
56
50
  defaultOptions: [[], {}],
57
51
  create(context, [componentConfigs = []]) {
58
- // Build a map of component -> props to check
59
52
  const componentPropsMap = new Map();
60
- // Add custom component configurations
61
53
  for (const config of componentConfigs) {
62
54
  componentPropsMap.set(config.name, new Set(config.props));
63
55
  }
64
- // oxlint-disable-next-line consistent-function-scoping
65
56
  function isJavaScriptUrl(value) {
66
- // Match javascript: protocol (case insensitive, with optional whitespace)
67
57
  return /^\s*javascript:/i.test(value);
68
58
  }
69
59
  function checkAttribute(node, elementName) {
70
60
  if (node.name.type !== 'JSXIdentifier')
71
61
  return;
72
62
  const propName = node.name.name;
73
- // Check if this is a URL prop for standard elements
74
63
  const isUrlProp = URL_PROPS.has(propName);
75
- // Check if this is a configured custom component prop
76
64
  const customProps = componentPropsMap.get(elementName);
77
65
  const isCustomProp = customProps?.has(propName);
78
66
  if (!isUrlProp && !isCustomProp)
79
67
  return;
80
68
  if (!node.value)
81
69
  return;
82
- // Check literal string values
83
70
  if (node.value.type === 'Literal' && typeof node.value.value === 'string') {
84
71
  if (isJavaScriptUrl(node.value.value)) {
85
72
  context.report({
@@ -88,7 +75,6 @@ exports.jsxNoScriptUrl = (0, eslint_devkit_2.createRule)({
88
75
  });
89
76
  }
90
77
  }
91
- // Check JSX expression with template literal or string
92
78
  if (node.value.type === 'JSXExpressionContainer') {
93
79
  const expr = node.value.expression;
94
80
  if (expr.type === 'Literal' && typeof expr.value === 'string') {
@@ -100,7 +86,6 @@ exports.jsxNoScriptUrl = (0, eslint_devkit_2.createRule)({
100
86
  }
101
87
  }
102
88
  if (expr.type === 'TemplateLiteral' && expr.quasis.length > 0) {
103
- // Check if the template literal starts with javascript:
104
89
  const firstQuasi = expr.quasis[0];
105
90
  if (firstQuasi && isJavaScriptUrl(firstQuasi.value.raw)) {
106
91
  context.report({
@@ -118,7 +103,6 @@ exports.jsxNoScriptUrl = (0, eslint_devkit_2.createRule)({
118
103
  elementName = node.name.name;
119
104
  }
120
105
  else if (node.name.type === 'JSXMemberExpression') {
121
- // Handle Component.SubComponent
122
106
  elementName = context.sourceCode.getText(node.name);
123
107
  }
124
108
  else {
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.jsxNoTargetBlank = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -74,7 +69,6 @@ exports.jsxNoTargetBlank = (0, eslint_devkit_2.createRule)({
74
69
  if (targetAttr.value.type === 'Literal') {
75
70
  return targetAttr.value.value === '_blank';
76
71
  }
77
- // Dynamic value - check enforceDynamicLinks option
78
72
  if (enforceDynamicLinks === 'always') {
79
73
  return true;
80
74
  }
@@ -88,10 +82,8 @@ exports.jsxNoTargetBlank = (0, eslint_devkit_2.createRule)({
88
82
  return false;
89
83
  if (hrefAttr.value.type === 'Literal' && typeof hrefAttr.value.value === 'string') {
90
84
  const href = hrefAttr.value.value;
91
- // External if starts with http:// or https:// or //
92
85
  return /^(https?:)?\/\//.test(href) || href.startsWith('//');
93
86
  }
94
- // Dynamic href - assume external
95
87
  return enforceDynamicLinks === 'always';
96
88
  }
97
89
  function getRelAttribute(node) {
@@ -99,7 +91,6 @@ exports.jsxNoTargetBlank = (0, eslint_devkit_2.createRule)({
99
91
  attr.name.type === 'JSXIdentifier' &&
100
92
  attr.name.name === 'rel');
101
93
  }
102
- // oxlint-disable-next-line consistent-function-scoping
103
94
  function hasNoopener(relAttr) {
104
95
  if (!relAttr.value)
105
96
  return false;
@@ -109,7 +100,6 @@ exports.jsxNoTargetBlank = (0, eslint_devkit_2.createRule)({
109
100
  }
110
101
  return false;
111
102
  }
112
- // oxlint-disable-next-line consistent-function-scoping
113
103
  function hasNoreferrer(relAttr) {
114
104
  if (!relAttr.value)
115
105
  return false;
@@ -119,7 +109,6 @@ exports.jsxNoTargetBlank = (0, eslint_devkit_2.createRule)({
119
109
  }
120
110
  return false;
121
111
  }
122
- // oxlint-disable-next-line consistent-function-scoping
123
112
  function hasSpreadAttribute(node) {
124
113
  return node.attributes.some(attr => attr.type === 'JSXSpreadAttribute');
125
114
  }
@@ -128,36 +117,29 @@ exports.jsxNoTargetBlank = (0, eslint_devkit_2.createRule)({
128
117
  if (node.name.type !== 'JSXIdentifier' || !elementsToCheck.includes(node.name.name)) {
129
118
  return;
130
119
  }
131
- // Skip if spread attributes and not warning on them
132
120
  if (hasSpreadAttribute(node) && !warnOnSpreadAttributes) {
133
121
  return;
134
122
  }
135
123
  if (!hasTargetBlank(node)) {
136
124
  return;
137
125
  }
138
- // For anchors, only check external links
139
126
  if (node.name.name === 'a' && !hasExternalHref(node)) {
140
127
  return;
141
128
  }
142
129
  const relAttr = getRelAttribute(node);
143
130
  const hasNoopenerValue = relAttr ? hasNoopener(relAttr) : false;
144
131
  const hasNoreferrerValue = relAttr ? hasNoreferrer(relAttr) : false;
145
- // noreferrer implies noopener in modern browsers
146
132
  if (hasNoopenerValue || hasNoreferrerValue) {
147
- // If allowReferrer is false, we need both noopener and noreferrer (or just noreferrer)
148
133
  if (!allowReferrer && !hasNoreferrerValue) {
149
- // Has noopener but not noreferrer - acceptable if allowReferrer is true
150
- return; // noopener is sufficient for security
134
+ return;
151
135
  }
152
136
  return;
153
137
  }
154
- // Missing rel or rel doesn't have noopener/noreferrer
155
138
  context.report({
156
139
  node,
157
140
  messageId: relAttr ? 'noRelWithoutNoopener' : 'noTargetBlank',
158
141
  fix: (fixer) => {
159
142
  if (relAttr && relAttr.value && relAttr.value.type === 'Literal') {
160
- // Add noopener noreferrer to existing rel
161
143
  const currentRel = String(relAttr.value.value);
162
144
  const newRel = allowReferrer
163
145
  ? `${currentRel} noopener`.trim()
@@ -165,7 +147,6 @@ exports.jsxNoTargetBlank = (0, eslint_devkit_2.createRule)({
165
147
  return fixer.replaceText(relAttr.value, `"${newRel}"`);
166
148
  }
167
149
  else if (!relAttr) {
168
- // Add rel attribute
169
150
  const lastAttr = node.attributes[node.attributes.length - 1];
170
151
  const relValue = allowReferrer ? 'noopener' : 'noopener noreferrer';
171
152
  if (lastAttr) {
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noAccessStateInSetState = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -32,13 +27,11 @@ exports.noAccessStateInSetState = (0, eslint_devkit_1.createRule)({
32
27
  create(context) {
33
28
  return {
34
29
  CallExpression(node) {
35
- // Check if this is a setState call
36
30
  if (node.callee.type === 'MemberExpression' &&
37
31
  node.callee.property.type === 'Identifier' &&
38
32
  node.callee.property.name === 'setState' &&
39
33
  node.arguments.length > 0) {
40
34
  const [firstArg] = node.arguments;
41
- // Check if the first argument accesses this.state
42
35
  if (firstArg && containsThisStateAccess(firstArg)) {
43
36
  context.report({
44
37
  node: node.callee.property,
@@ -50,24 +43,18 @@ exports.noAccessStateInSetState = (0, eslint_devkit_1.createRule)({
50
43
  };
51
44
  },
52
45
  });
53
- /**
54
- * Check if a node contains access to this.state
55
- */
56
46
  function containsThisStateAccess(node, visited = new Set()) {
57
- // Prevent infinite recursion
58
47
  if (visited.has(node)) {
59
48
  return false;
60
49
  }
61
50
  visited.add(node);
62
51
  if (node.type === 'MemberExpression') {
63
- // Check for this.state or this.state.someProperty
64
52
  if (node.object.type === 'ThisExpression' &&
65
53
  node.property.type === 'Identifier' &&
66
54
  node.property.name === 'state') {
67
55
  return true;
68
56
  }
69
57
  }
70
- // Recursively check child nodes
71
58
  for (const key in node) {
72
59
  if (key === 'parent' || key === 'loc' || key === 'range')
73
60
  continue;
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noAdjacentInlineElements = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -39,7 +34,6 @@ exports.noAdjacentInlineElements = (0, eslint_devkit_1.createRule)({
39
34
  JSXElement(node) {
40
35
  if (node.children.length < 2)
41
36
  return;
42
- // Find sequences of adjacent inline elements
43
37
  let consecutiveInlineCount = 0;
44
38
  let lastInlineElement = null;
45
39
  for (const child of node.children) {
@@ -61,7 +55,6 @@ exports.noAdjacentInlineElements = (0, eslint_devkit_1.createRule)({
61
55
  }
62
56
  }
63
57
  else if (child.type === 'JSXText') {
64
- // Reset counter on text nodes
65
58
  consecutiveInlineCount = 0;
66
59
  lastInlineElement = null;
67
60
  }
@@ -70,9 +63,6 @@ exports.noAdjacentInlineElements = (0, eslint_devkit_1.createRule)({
70
63
  };
71
64
  },
72
65
  });
73
- /**
74
- * Get the name of a JSX element
75
- */
76
66
  function getElementName(node) {
77
67
  const openingElement = node.openingElement;
78
68
  if (openingElement.name.type === 'JSXIdentifier') {
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noArrowFunctionLifecycle = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -46,8 +41,6 @@ exports.noArrowFunctionLifecycle = (0, eslint_devkit_1.createRule)({
46
41
  defaultOptions: [],
47
42
  create(context) {
48
43
  return {
49
- // PropertyDefinition is used by TypeScript parser for class properties
50
- // Only report on arrow function properties, NOT regular method definitions
51
44
  PropertyDefinition(node) {
52
45
  if (node.key.type === 'Identifier' &&
53
46
  LIFECYCLE_METHODS.has(node.key.name) &&
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noChildrenProp = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -40,10 +35,8 @@ exports.noChildrenProp = (0, eslint_devkit_1.createRule)({
40
35
  });
41
36
  }
42
37
  },
43
- // Check for children in spread attributes
44
38
  JSXSpreadAttribute(node) {
45
39
  if (node.argument.type === 'ObjectExpression') {
46
- // Check if the spread contains a children property
47
40
  for (const prop of node.argument.properties) {
48
41
  if (prop.type === 'Property' &&
49
42
  prop.key.type === 'Identifier' &&
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noDangerWithChildren = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -40,19 +35,14 @@ exports.noDangerWithChildren = (0, eslint_devkit_2.createRule)({
40
35
  attr.name.type === 'JSXIdentifier' &&
41
36
  attr.name.name === 'children');
42
37
  }
43
- // oxlint-disable-next-line consistent-function-scoping
44
38
  function hasJSXChildren(node) {
45
- // Check if there are any meaningful children
46
39
  return node.children.some(child => {
47
40
  if (child.type === 'JSXText') {
48
- // Only count non-whitespace text
49
41
  return !/^\s*$/.test(child.value);
50
42
  }
51
43
  if (child.type === 'JSXExpressionContainer') {
52
- // Ignore empty expressions or just comments
53
44
  return child.expression.type !== 'JSXEmptyExpression';
54
45
  }
55
- // JSXElement, JSXFragment, JSXSpreadChild all count as children
56
46
  return true;
57
47
  });
58
48
  }
@@ -62,7 +52,6 @@ exports.noDangerWithChildren = (0, eslint_devkit_2.createRule)({
62
52
  if (!hasDangerouslySetInnerHTML(openingElement)) {
63
53
  return;
64
54
  }
65
- // Check for children prop or JSX children
66
55
  const hasChildren = hasChildrenProp(openingElement) || hasJSXChildren(node);
67
56
  if (hasChildren) {
68
57
  context.report({
@@ -71,7 +60,6 @@ exports.noDangerWithChildren = (0, eslint_devkit_2.createRule)({
71
60
  });
72
61
  }
73
62
  },
74
- // Also check React.createElement() calls
75
63
  CallExpression(node) {
76
64
  if (node.callee.type !== 'MemberExpression')
77
65
  return;
@@ -79,7 +67,6 @@ exports.noDangerWithChildren = (0, eslint_devkit_2.createRule)({
79
67
  return;
80
68
  if (node.callee.property.type !== 'Identifier' || node.callee.property.name !== 'createElement')
81
69
  return;
82
- // React.createElement(type, props, ...children)
83
70
  if (node.arguments.length < 2)
84
71
  return;
85
72
  const propsArg = node.arguments[1];
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noDanger = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -1,25 +1,16 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noDeprecated = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
5
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- // Deprecated React APIs (React 16+)
12
6
  const DEPRECATED_APIS = {
13
- // React methods
14
7
  'React.createClass': { replacement: 'class extends React.Component', since: 'React 16' },
15
8
  'React.PropTypes': { replacement: 'import PropTypes from "prop-types"', since: 'React 15.5' },
16
9
  'React.findDOMNode': { replacement: 'refs', since: 'React 16.3' },
17
- // ReactDOM methods
18
10
  'ReactDOM.render': { replacement: 'createRoot().render()', since: 'React 18' },
19
11
  'ReactDOM.hydrate': { replacement: 'hydrateRoot()', since: 'React 18' },
20
12
  'ReactDOM.unmountComponentAtNode': { replacement: 'root.unmount()', since: 'React 18' },
21
13
  'ReactDOM.findDOMNode': { replacement: 'refs', since: 'React 16.3' },
22
- // Lifecycle methods (deprecated in strict mode)
23
14
  'componentWillMount': { replacement: 'componentDidMount or constructor', since: 'React 16.3' },
24
15
  'componentWillReceiveProps': { replacement: 'static getDerivedStateFromProps', since: 'React 16.3' },
25
16
  'componentWillUpdate': { replacement: 'getSnapshotBeforeUpdate', since: 'React 16.3' },
@@ -49,7 +40,6 @@ exports.noDeprecated = (0, eslint_devkit_2.createRule)({
49
40
  },
50
41
  defaultOptions: [],
51
42
  create(context) {
52
- // Track lifecycle methods in class components
53
43
  let inClassComponent = false;
54
44
  function checkMemberExpression(node) {
55
45
  if (node.object.type !== 'Identifier')
@@ -91,7 +81,6 @@ exports.noDeprecated = (0, eslint_devkit_2.createRule)({
91
81
  }
92
82
  return {
93
83
  ClassDeclaration(node) {
94
- // Check if this extends React.Component or React.PureComponent
95
84
  if (!node.superClass)
96
85
  return;
97
86
  if (node.superClass.type === 'MemberExpression') {
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noDidMountSetState = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -41,7 +36,6 @@ exports.noDidMountSetState = (0, eslint_devkit_1.createRule)({
41
36
  CallExpression(node) {
42
37
  if (!inComponentDidMount)
43
38
  return;
44
- // Check if this is a setState call
45
39
  if (node.callee.type === 'MemberExpression' &&
46
40
  node.callee.property.type === 'Identifier' &&
47
41
  node.callee.property.name === 'setState') {
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noDidUpdateSetState = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -45,16 +40,13 @@ exports.noDidUpdateSetState = (0, eslint_devkit_1.createRule)({
45
40
  let inComponentDidUpdate = false;
46
41
  let hasConditionalCheck = false;
47
42
  return {
48
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
43
  'MethodDefinition[key.name="componentDidUpdate"]'(node) {
50
44
  inComponentDidUpdate = true;
51
45
  hasConditionalCheck = false;
52
46
  },
53
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
54
47
  'MethodDefinition[key.name="componentDidUpdate"]:exit'(node) {
55
48
  inComponentDidUpdate = false;
56
49
  },
57
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
50
  IfStatement(node) {
59
51
  if (inComponentDidUpdate) {
60
52
  hasConditionalCheck = true;
@@ -63,11 +55,9 @@ exports.noDidUpdateSetState = (0, eslint_devkit_1.createRule)({
63
55
  CallExpression(node) {
64
56
  if (!inComponentDidUpdate)
65
57
  return;
66
- // Check if this is a setState call
67
58
  if (node.callee.type === 'MemberExpression' &&
68
59
  node.callee.property.type === 'Identifier' &&
69
60
  node.callee.property.name === 'setState') {
70
- // Allow if there's a conditional check or callback is allowed
71
61
  if (!hasConditionalCheck && !options?.allowInCallback) {
72
62
  context.report({
73
63
  node: node.callee.property,
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noDirectMutationState = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -60,11 +55,9 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
60
55
  create(context) {
61
56
  const [options] = context.options;
62
57
  const { allowInLifecycleMethods = false } = options || {};
63
- // Track if we're in a class component
64
58
  let inClassComponent = false;
65
59
  let inLifecycleMethod = false;
66
60
  const classStack = [];
67
- // oxlint-disable-next-line consistent-function-scoping
68
61
  function isLifecycleMethod(methodName) {
69
62
  const lifecycleMethods = [
70
63
  'componentDidMount',
@@ -82,16 +75,14 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
82
75
  return lifecycleMethods.includes(methodName);
83
76
  }
84
77
  function isInReactClassComponent() {
85
- // Simple heuristic: check if we're in a class that extends Component
86
- // In a real implementation, this would be more sophisticated
87
78
  return inClassComponent;
88
79
  }
89
80
  function reportStateMutation(node, mutationType) {
90
81
  if (!isInReactClassComponent()) {
91
- return; // Only applies to class components
82
+ return;
92
83
  }
93
84
  if (allowInLifecycleMethods && inLifecycleMethod) {
94
- return; // Allowed in lifecycle methods if configured
85
+ return;
95
86
  }
96
87
  context.report({
97
88
  node,
@@ -104,7 +95,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
104
95
  {
105
96
  messageId: 'suggestSetState',
106
97
  fix(fixer) {
107
- // Get the source code to determine indentation
108
98
  const sourceCode = context.sourceCode;
109
99
  const start = node.range[0];
110
100
  const lineStart = sourceCode.getIndexFromLoc({
@@ -112,8 +102,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
112
102
  column: 0
113
103
  });
114
104
  const lineText = sourceCode.getText().slice(lineStart, start);
115
- // Leading-whitespace run — computed without a regex null-check
116
- // branch (`/^\s*/` can never fail to match).
117
105
  const indent = lineText.slice(0, lineText.length - lineText.trimStart().length);
118
106
  return fixer.insertTextBefore(node, `// TODO: Use setState instead of direct mutation\n${indent}`);
119
107
  },
@@ -121,7 +109,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
121
109
  {
122
110
  messageId: 'suggestFunctionalUpdate',
123
111
  fix(fixer) {
124
- // Get the source code to determine indentation
125
112
  const sourceCode = context.sourceCode;
126
113
  const start = node.range[0];
127
114
  const lineStart = sourceCode.getIndexFromLoc({
@@ -129,8 +116,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
129
116
  column: 0
130
117
  });
131
118
  const lineText = sourceCode.getText().slice(lineStart, start);
132
- // Leading-whitespace run — computed without a regex null-check
133
- // branch (`/^\s*/` can never fail to match).
134
119
  const indent = lineText.slice(0, lineText.length - lineText.trimStart().length);
135
120
  return fixer.insertTextBefore(node, `// TODO: Use functional setState for immutable updates\n${indent}`);
136
121
  },
@@ -138,21 +123,17 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
138
123
  ],
139
124
  });
140
125
  }
141
- // Shared helper — uses `target` to avoid shadowing visitor `node` params
142
- // oxlint-disable-next-line consistent-function-scoping
143
126
  function isStatePropertyAccess(target) {
144
127
  if (target.type === 'MemberExpression' &&
145
128
  target.object.type === 'MemberExpression' &&
146
129
  target.object.object.type === 'ThisExpression' &&
147
130
  target.object.property.type === 'Identifier' &&
148
131
  target.object.property.name === 'state') {
149
- return true; // this.state.xxx
132
+ return true;
150
133
  }
151
- // Handle deeper nesting
152
134
  if (target.type === 'MemberExpression') {
153
135
  return isStatePropertyAccess(target.object);
154
136
  }
155
- // Handle logical expressions like (this.state.items || [])
156
137
  if (target.type === 'LogicalExpression') {
157
138
  return isStatePropertyAccess(target.left);
158
139
  }
@@ -160,7 +141,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
160
141
  }
161
142
  return {
162
143
  ClassDeclaration(node) {
163
- // Check if this is a React component class
164
144
  if (node.superClass) {
165
145
  if (node.superClass.type === 'Identifier' &&
166
146
  ['Component', 'PureComponent'].includes(node.superClass.name)) {
@@ -189,7 +169,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
189
169
  'MethodDefinition:exit'() {
190
170
  inLifecycleMethod = false;
191
171
  },
192
- // Assignment to this.state properties
193
172
  AssignmentExpression(node) {
194
173
  if (node.left.type === 'MemberExpression') {
195
174
  if (isStatePropertyAccess(node.left)) {
@@ -197,7 +176,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
197
176
  }
198
177
  }
199
178
  },
200
- // Update expressions on this.state properties (++state.count, state.count--)
201
179
  UpdateExpression(node) {
202
180
  if (node.argument.type === 'MemberExpression') {
203
181
  if (isStatePropertyAccess(node.argument)) {
@@ -205,7 +183,6 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
205
183
  }
206
184
  }
207
185
  },
208
- // Delete operator on this.state properties
209
186
  UnaryExpression(node) {
210
187
  if (node.operator === 'delete' && node.argument.type === 'MemberExpression') {
211
188
  if (isStatePropertyAccess(node.argument)) {
@@ -213,17 +190,14 @@ exports.noDirectMutationState = (0, eslint_devkit_1.createRule)({
213
190
  }
214
191
  }
215
192
  },
216
- // Array/object methods that mutate this.state
217
193
  CallExpression(node) {
218
194
  if (node.callee.type === 'MemberExpression' &&
219
195
  node.callee.property.type === 'Identifier') {
220
196
  const methodName = node.callee.property.name;
221
197
  if (isStatePropertyAccess(node.callee.object)) {
222
- // Methods that mutate arrays/objects
223
198
  const mutatingMethods = [
224
199
  'push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse',
225
200
  'copyWithin', 'fill',
226
- // Object methods
227
201
  'defineProperty', 'deleteProperty', 'setPrototypeOf',
228
202
  ];
229
203
  if (mutatingMethods.includes(methodName)) {
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noFindDomNode = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -32,7 +27,6 @@ exports.noFindDomNode = (0, eslint_devkit_2.createRule)({
32
27
  create(context) {
33
28
  return {
34
29
  CallExpression(node) {
35
- // Check for ReactDOM.findDOMNode()
36
30
  if (node.callee.type === 'MemberExpression' &&
37
31
  node.callee.object.type === 'Identifier' &&
38
32
  node.callee.object.name === 'ReactDOM' &&
@@ -43,7 +37,6 @@ exports.noFindDomNode = (0, eslint_devkit_2.createRule)({
43
37
  messageId: 'noFindDOMNode',
44
38
  });
45
39
  }
46
- // Check for findDOMNode() imported directly
47
40
  if (node.callee.type === 'Identifier' &&
48
41
  node.callee.name === 'findDOMNode') {
49
42
  context.report({