eslint-plugin-react-features 1.1.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 (114) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/LICENSE +23 -0
  3. package/README.md +155 -0
  4. package/package.json +65 -0
  5. package/src/index.d.ts +1093 -0
  6. package/src/index.js +212 -0
  7. package/src/rules/migration/react-class-to-hooks.d.ts +22 -0
  8. package/src/rules/migration/react-class-to-hooks.js +178 -0
  9. package/src/rules/performance/no-unnecessary-rerenders.d.ts +26 -0
  10. package/src/rules/performance/no-unnecessary-rerenders.js +212 -0
  11. package/src/rules/performance/react-no-inline-functions.d.ts +24 -0
  12. package/src/rules/performance/react-no-inline-functions.js +211 -0
  13. package/src/rules/performance/react-render-optimization.d.ts +31 -0
  14. package/src/rules/performance/react-render-optimization.js +294 -0
  15. package/src/rules/react/checked-requires-onchange-or-readonly.d.ts +16 -0
  16. package/src/rules/react/checked-requires-onchange-or-readonly.js +74 -0
  17. package/src/rules/react/default-props-match-prop-types.d.ts +13 -0
  18. package/src/rules/react/default-props-match-prop-types.js +119 -0
  19. package/src/rules/react/display-name.d.ts +13 -0
  20. package/src/rules/react/display-name.js +164 -0
  21. package/src/rules/react/hooks-exhaustive-deps.d.ts +25 -0
  22. package/src/rules/react/hooks-exhaustive-deps.js +466 -0
  23. package/src/rules/react/jsx-handler-names.d.ts +13 -0
  24. package/src/rules/react/jsx-handler-names.js +57 -0
  25. package/src/rules/react/jsx-key.d.ts +20 -0
  26. package/src/rules/react/jsx-key.js +421 -0
  27. package/src/rules/react/jsx-max-depth.d.ts +19 -0
  28. package/src/rules/react/jsx-max-depth.js +80 -0
  29. package/src/rules/react/jsx-no-bind.d.ts +13 -0
  30. package/src/rules/react/jsx-no-bind.js +64 -0
  31. package/src/rules/react/jsx-no-duplicate-props.d.ts +21 -0
  32. package/src/rules/react/jsx-no-duplicate-props.js +70 -0
  33. package/src/rules/react/jsx-no-literals.d.ts +20 -0
  34. package/src/rules/react/jsx-no-literals.js +83 -0
  35. package/src/rules/react/jsx-no-script-url.d.ts +25 -0
  36. package/src/rules/react/jsx-no-script-url.js +131 -0
  37. package/src/rules/react/jsx-no-target-blank.d.ts +26 -0
  38. package/src/rules/react/jsx-no-target-blank.js +176 -0
  39. package/src/rules/react/no-access-state-in-setstate.d.ts +13 -0
  40. package/src/rules/react/no-access-state-in-setstate.js +92 -0
  41. package/src/rules/react/no-adjacent-inline-elements.d.ts +13 -0
  42. package/src/rules/react/no-adjacent-inline-elements.js +81 -0
  43. package/src/rules/react/no-arrow-function-lifecycle.d.ts +13 -0
  44. package/src/rules/react/no-arrow-function-lifecycle.js +63 -0
  45. package/src/rules/react/no-children-prop.d.ts +13 -0
  46. package/src/rules/react/no-children-prop.js +60 -0
  47. package/src/rules/react/no-danger-with-children.d.ts +16 -0
  48. package/src/rules/react/no-danger-with-children.js +110 -0
  49. package/src/rules/react/no-danger.d.ts +13 -0
  50. package/src/rules/react/no-danger.js +45 -0
  51. package/src/rules/react/no-deprecated.d.ts +16 -0
  52. package/src/rules/react/no-deprecated.js +140 -0
  53. package/src/rules/react/no-did-mount-set-state.d.ts +13 -0
  54. package/src/rules/react/no-did-mount-set-state.js +55 -0
  55. package/src/rules/react/no-did-update-set-state.d.ts +19 -0
  56. package/src/rules/react/no-did-update-set-state.js +80 -0
  57. package/src/rules/react/no-direct-mutation-state.d.ts +20 -0
  58. package/src/rules/react/no-direct-mutation-state.js +277 -0
  59. package/src/rules/react/no-find-dom-node.d.ts +15 -0
  60. package/src/rules/react/no-find-dom-node.js +56 -0
  61. package/src/rules/react/no-invalid-html-attribute.d.ts +13 -0
  62. package/src/rules/react/no-invalid-html-attribute.js +84 -0
  63. package/src/rules/react/no-is-mounted.d.ts +13 -0
  64. package/src/rules/react/no-is-mounted.js +52 -0
  65. package/src/rules/react/no-multi-comp.d.ts +18 -0
  66. package/src/rules/react/no-multi-comp.js +160 -0
  67. package/src/rules/react/no-namespace.d.ts +13 -0
  68. package/src/rules/react/no-namespace.js +41 -0
  69. package/src/rules/react/no-object-type-as-default-prop.d.ts +13 -0
  70. package/src/rules/react/no-object-type-as-default-prop.js +61 -0
  71. package/src/rules/react/no-redundant-should-component-update.d.ts +13 -0
  72. package/src/rules/react/no-redundant-should-component-update.js +55 -0
  73. package/src/rules/react/no-render-return-value.d.ts +13 -0
  74. package/src/rules/react/no-render-return-value.js +74 -0
  75. package/src/rules/react/no-set-state.d.ts +13 -0
  76. package/src/rules/react/no-set-state.js +50 -0
  77. package/src/rules/react/no-string-refs.d.ts +13 -0
  78. package/src/rules/react/no-string-refs.js +68 -0
  79. package/src/rules/react/no-this-in-sfc.d.ts +13 -0
  80. package/src/rules/react/no-this-in-sfc.js +65 -0
  81. package/src/rules/react/no-typos.d.ts +13 -0
  82. package/src/rules/react/no-typos.js +97 -0
  83. package/src/rules/react/no-unescaped-entities.d.ts +13 -0
  84. package/src/rules/react/no-unescaped-entities.js +50 -0
  85. package/src/rules/react/no-unknown-property.d.ts +13 -0
  86. package/src/rules/react/no-unknown-property.js +130 -0
  87. package/src/rules/react/no-unsafe.d.ts +20 -0
  88. package/src/rules/react/no-unsafe.js +112 -0
  89. package/src/rules/react/prefer-es6-class.d.ts +13 -0
  90. package/src/rules/react/prefer-es6-class.js +56 -0
  91. package/src/rules/react/prefer-stateless-function.d.ts +16 -0
  92. package/src/rules/react/prefer-stateless-function.js +134 -0
  93. package/src/rules/react/prop-types.d.ts +18 -0
  94. package/src/rules/react/prop-types.js +153 -0
  95. package/src/rules/react/react-in-jsx-scope.d.ts +13 -0
  96. package/src/rules/react/react-in-jsx-scope.js +94 -0
  97. package/src/rules/react/require-default-props.d.ts +16 -0
  98. package/src/rules/react/require-default-props.js +146 -0
  99. package/src/rules/react/require-optimization.d.ts +26 -0
  100. package/src/rules/react/require-optimization.js +436 -0
  101. package/src/rules/react/require-render-return.d.ts +13 -0
  102. package/src/rules/react/require-render-return.js +87 -0
  103. package/src/rules/react/required-attributes.d.ts +28 -0
  104. package/src/rules/react/required-attributes.js +212 -0
  105. package/src/rules/react/sort-comp.d.ts +17 -0
  106. package/src/rules/react/sort-comp.js +160 -0
  107. package/src/rules/react/state-in-constructor.d.ts +13 -0
  108. package/src/rules/react/state-in-constructor.js +103 -0
  109. package/src/rules/react/static-property-placement.d.ts +20 -0
  110. package/src/rules/react/static-property-placement.js +166 -0
  111. package/src/rules/react/void-dom-elements-no-children.d.ts +15 -0
  112. package/src/rules/react/void-dom-elements-no-children.js +94 -0
  113. package/src/types/index.d.ts +54 -0
  114. package/src/types/index.js +7 -0
@@ -0,0 +1,81 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.noAdjacentInlineElements = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ const INLINE_ELEMENTS = new Set([
12
+ 'span', 'a', 'strong', 'em', 'b', 'i', 'u', 'small', 'big', 'sub', 'sup',
13
+ 'code', 'kbd', 'samp', 'var', 'cite', 'abbr', 'acronym', 'dfn', 'q', 'time',
14
+ 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'wbr', 'ins', 'del', 's', 'strike'
15
+ ]);
16
+ exports.noAdjacentInlineElements = (0, eslint_devkit_1.createRule)({
17
+ name: 'no-adjacent-inline-elements',
18
+ meta: {
19
+ type: 'problem',
20
+ docs: {
21
+ description: 'Prevent adjacent inline elements',
22
+ },
23
+ schema: [],
24
+ messages: {
25
+ noAdjacentInlineElements: (0, eslint_devkit_2.formatLLMMessage)({
26
+ icon: eslint_devkit_2.MessageIcons.WARNING,
27
+ issueName: 'Adjacent Inline Elements',
28
+ description: 'Adjacent inline elements can cause layout issues',
29
+ severity: 'MEDIUM',
30
+ fix: 'Wrap adjacent inline elements in a block-level container',
31
+ documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements',
32
+ }),
33
+ },
34
+ },
35
+ defaultOptions: [],
36
+ create(context) {
37
+ return {
38
+ JSXElement(node) {
39
+ if (node.children.length < 2)
40
+ return;
41
+ // Find sequences of adjacent inline elements
42
+ let consecutiveInlineCount = 0;
43
+ let lastInlineElement = null;
44
+ for (const child of node.children) {
45
+ if (child.type === 'JSXElement') {
46
+ const elementName = getElementName(child);
47
+ if (elementName && INLINE_ELEMENTS.has(elementName)) {
48
+ consecutiveInlineCount++;
49
+ lastInlineElement = child;
50
+ if (consecutiveInlineCount >= 2) {
51
+ context.report({
52
+ node: lastInlineElement.openingElement.name,
53
+ messageId: 'noAdjacentInlineElements',
54
+ });
55
+ }
56
+ }
57
+ else {
58
+ consecutiveInlineCount = 0;
59
+ lastInlineElement = null;
60
+ }
61
+ }
62
+ else if (child.type === 'JSXText') {
63
+ // Reset counter on text nodes
64
+ consecutiveInlineCount = 0;
65
+ lastInlineElement = null;
66
+ }
67
+ }
68
+ },
69
+ };
70
+ },
71
+ });
72
+ /**
73
+ * Get the name of a JSX element
74
+ */
75
+ function getElementName(node) {
76
+ const openingElement = node.openingElement;
77
+ if (openingElement.name.type === 'JSXIdentifier') {
78
+ return openingElement.name.name;
79
+ }
80
+ return null;
81
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-arrow-function-lifecycle
8
+ * Prevent arrow functions in lifecycle methods
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ export declare const noArrowFunctionLifecycle: TSESLint.RuleModule<"noArrowFunctionLifecycle", [], unknown, TSESLint.RuleListener> & {
12
+ name: string;
13
+ };
@@ -0,0 +1,63 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.noArrowFunctionLifecycle = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ const LIFECYCLE_METHODS = new Set([
12
+ 'componentDidMount',
13
+ 'componentDidUpdate',
14
+ 'componentWillUnmount',
15
+ 'componentWillMount',
16
+ 'componentWillReceiveProps',
17
+ 'componentWillUpdate',
18
+ 'shouldComponentUpdate',
19
+ 'getDerivedStateFromProps',
20
+ 'getSnapshotBeforeUpdate',
21
+ 'componentDidCatch',
22
+ 'UNSAFE_componentWillMount',
23
+ 'UNSAFE_componentWillReceiveProps',
24
+ 'UNSAFE_componentWillUpdate',
25
+ ]);
26
+ exports.noArrowFunctionLifecycle = (0, eslint_devkit_1.createRule)({
27
+ name: 'no-arrow-function-lifecycle',
28
+ meta: {
29
+ type: 'problem',
30
+ docs: {
31
+ description: 'Prevent arrow functions in lifecycle methods',
32
+ },
33
+ messages: {
34
+ noArrowFunctionLifecycle: (0, eslint_devkit_2.formatLLMMessage)({
35
+ icon: eslint_devkit_2.MessageIcons.WARNING,
36
+ issueName: 'Arrow Function Lifecycle',
37
+ description: 'Arrow function used in lifecycle method',
38
+ severity: 'HIGH',
39
+ fix: 'Use regular method syntax for lifecycle methods',
40
+ documentationLink: 'https://react.dev/reference/react/Component#defining-a-class-component',
41
+ }),
42
+ },
43
+ schema: [],
44
+ },
45
+ defaultOptions: [],
46
+ create(context) {
47
+ return {
48
+ // PropertyDefinition is used by TypeScript parser for class properties
49
+ // Only report on arrow function properties, NOT regular method definitions
50
+ PropertyDefinition(node) {
51
+ if (node.key.type === 'Identifier' &&
52
+ LIFECYCLE_METHODS.has(node.key.name) &&
53
+ node.value &&
54
+ node.value.type === 'ArrowFunctionExpression') {
55
+ context.report({
56
+ node: node.key,
57
+ messageId: 'noArrowFunctionLifecycle',
58
+ });
59
+ }
60
+ },
61
+ };
62
+ },
63
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-children-prop
8
+ * Disallow passing children as props (dangerous pattern)
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ export declare const noChildrenProp: TSESLint.RuleModule<"noChildrenProp", [], unknown, TSESLint.RuleListener> & {
12
+ name: string;
13
+ };
@@ -0,0 +1,60 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.noChildrenProp = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.noChildrenProp = (0, eslint_devkit_1.createRule)({
12
+ name: 'no-children-prop',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Disallow passing children as props',
17
+ },
18
+ schema: [],
19
+ messages: {
20
+ noChildrenProp: (0, eslint_devkit_2.formatLLMMessage)({
21
+ icon: eslint_devkit_2.MessageIcons.WARNING,
22
+ issueName: 'Children as Prop',
23
+ description: 'Passing children as a prop',
24
+ severity: 'HIGH',
25
+ fix: 'Use JSX children syntax: <Component>children</Component>',
26
+ documentationLink: 'https://react.dev/learn/passing-props-to-a-component#passing-jsx-as-children',
27
+ }),
28
+ },
29
+ },
30
+ defaultOptions: [],
31
+ create(context) {
32
+ return {
33
+ JSXAttribute(node) {
34
+ if (node.name.type === 'JSXIdentifier' &&
35
+ node.name.name === 'children') {
36
+ context.report({
37
+ node: node.name,
38
+ messageId: 'noChildrenProp',
39
+ });
40
+ }
41
+ },
42
+ // Check for children in spread attributes
43
+ JSXSpreadAttribute(node) {
44
+ if (node.argument.type === 'ObjectExpression') {
45
+ // Check if the spread contains a children property
46
+ for (const prop of node.argument.properties) {
47
+ if (prop.type === 'Property' &&
48
+ prop.key.type === 'Identifier' &&
49
+ prop.key.name === 'children') {
50
+ context.report({
51
+ node: prop.key,
52
+ messageId: 'noChildrenProp',
53
+ });
54
+ }
55
+ }
56
+ }
57
+ },
58
+ };
59
+ },
60
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-danger-with-children
8
+ * Prevent using both children and dangerouslySetInnerHTML
9
+ *
10
+ * Bug Prevention: React will throw an error when both are present
11
+ * @see https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger-with-children.md
12
+ */
13
+ import type { TSESLint } from '@interlace/eslint-devkit';
14
+ export declare const noDangerWithChildren: TSESLint.RuleModule<"dangerWithChildren", [], unknown, TSESLint.RuleListener> & {
15
+ name: string;
16
+ };
@@ -0,0 +1,110 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.noDangerWithChildren = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.noDangerWithChildren = (0, eslint_devkit_2.createRule)({
12
+ name: 'no-danger-with-children',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Prevent using both children and dangerouslySetInnerHTML',
17
+ },
18
+ messages: {
19
+ dangerWithChildren: (0, eslint_devkit_1.formatLLMMessage)({
20
+ icon: eslint_devkit_1.MessageIcons.WARNING,
21
+ issueName: 'dangerouslySetInnerHTML with Children',
22
+ description: 'Cannot use children and dangerouslySetInnerHTML at the same time - React will throw an error',
23
+ severity: 'CRITICAL',
24
+ fix: 'Remove either children or dangerouslySetInnerHTML',
25
+ documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger-with-children.md',
26
+ }),
27
+ },
28
+ schema: [],
29
+ },
30
+ defaultOptions: [],
31
+ create(context) {
32
+ function hasDangerouslySetInnerHTML(node) {
33
+ return node.attributes.some((attr) => attr.type === 'JSXAttribute' &&
34
+ attr.name.type === 'JSXIdentifier' &&
35
+ attr.name.name === 'dangerouslySetInnerHTML');
36
+ }
37
+ function hasChildrenProp(node) {
38
+ return node.attributes.some((attr) => attr.type === 'JSXAttribute' &&
39
+ attr.name.type === 'JSXIdentifier' &&
40
+ attr.name.name === 'children');
41
+ }
42
+ function hasJSXChildren(node) {
43
+ // Check if there are any meaningful children
44
+ return node.children.some(child => {
45
+ if (child.type === 'JSXText') {
46
+ // Only count non-whitespace text
47
+ return !/^\s*$/.test(child.value);
48
+ }
49
+ if (child.type === 'JSXExpressionContainer') {
50
+ // Ignore empty expressions or just comments
51
+ return child.expression.type !== 'JSXEmptyExpression';
52
+ }
53
+ // JSXElement, JSXFragment, JSXSpreadChild all count as children
54
+ return true;
55
+ });
56
+ }
57
+ return {
58
+ JSXElement(node) {
59
+ const openingElement = node.openingElement;
60
+ if (!hasDangerouslySetInnerHTML(openingElement)) {
61
+ return;
62
+ }
63
+ // Check for children prop or JSX children
64
+ const hasChildren = hasChildrenProp(openingElement) || hasJSXChildren(node);
65
+ if (hasChildren) {
66
+ context.report({
67
+ node: openingElement,
68
+ messageId: 'dangerWithChildren',
69
+ });
70
+ }
71
+ },
72
+ // Also check React.createElement() calls
73
+ CallExpression(node) {
74
+ if (node.callee.type !== 'MemberExpression')
75
+ return;
76
+ if (node.callee.object.type !== 'Identifier' || node.callee.object.name !== 'React')
77
+ return;
78
+ if (node.callee.property.type !== 'Identifier' || node.callee.property.name !== 'createElement')
79
+ return;
80
+ // React.createElement(type, props, ...children)
81
+ if (node.arguments.length < 2)
82
+ return;
83
+ const propsArg = node.arguments[1];
84
+ const hasExtraChildren = node.arguments.length > 2;
85
+ if (propsArg.type !== 'ObjectExpression')
86
+ return;
87
+ let hasDanger = false;
88
+ let hasChildrenInProps = false;
89
+ for (const prop of propsArg.properties) {
90
+ if (prop.type !== 'Property')
91
+ continue;
92
+ if (prop.key.type !== 'Identifier')
93
+ continue;
94
+ if (prop.key.name === 'dangerouslySetInnerHTML') {
95
+ hasDanger = true;
96
+ }
97
+ if (prop.key.name === 'children') {
98
+ hasChildrenInProps = true;
99
+ }
100
+ }
101
+ if (hasDanger && (hasChildrenInProps || hasExtraChildren)) {
102
+ context.report({
103
+ node,
104
+ messageId: 'dangerWithChildren',
105
+ });
106
+ }
107
+ },
108
+ };
109
+ },
110
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-danger
8
+ * Disallow dangerouslySetInnerHTML usage (XSS prevention)
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ export declare const noDanger: TSESLint.RuleModule<"noDanger", [], unknown, TSESLint.RuleListener> & {
12
+ name: string;
13
+ };
@@ -0,0 +1,45 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.noDanger = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.noDanger = (0, eslint_devkit_1.createRule)({
12
+ name: 'no-danger',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Disallow dangerouslySetInnerHTML usage',
17
+ },
18
+ schema: [],
19
+ messages: {
20
+ noDanger: (0, eslint_devkit_2.formatLLMMessage)({
21
+ icon: eslint_devkit_2.MessageIcons.SECURITY,
22
+ issueName: 'Dangerous HTML',
23
+ cwe: 'CWE-79',
24
+ description: 'Usage of dangerouslySetInnerHTML detected',
25
+ severity: 'CRITICAL',
26
+ fix: 'Sanitize HTML input or use React elements instead',
27
+ documentationLink: 'https://react.dev/reference/react-dom/components/common#dangerously-setting-the-inner-html',
28
+ }),
29
+ },
30
+ },
31
+ defaultOptions: [],
32
+ create(context) {
33
+ return {
34
+ JSXAttribute(node) {
35
+ if (node.name.type === 'JSXIdentifier' &&
36
+ node.name.name === 'dangerouslySetInnerHTML') {
37
+ context.report({
38
+ node: node.name,
39
+ messageId: 'noDanger',
40
+ });
41
+ }
42
+ },
43
+ };
44
+ },
45
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-deprecated
8
+ * Prevent using deprecated React methods
9
+ *
10
+ * Maintenance: Helps with React upgrades and migration
11
+ * @see https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md
12
+ */
13
+ import type { TSESLint } from '@interlace/eslint-devkit';
14
+ export declare const noDeprecated: TSESLint.RuleModule<"deprecated", [], unknown, TSESLint.RuleListener> & {
15
+ name: string;
16
+ };
@@ -0,0 +1,140 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.noDeprecated = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ // Deprecated React APIs (React 16+)
12
+ const DEPRECATED_APIS = {
13
+ // React methods
14
+ 'React.createClass': { replacement: 'class extends React.Component', since: 'React 16' },
15
+ 'React.PropTypes': { replacement: 'import PropTypes from "prop-types"', since: 'React 15.5' },
16
+ 'React.findDOMNode': { replacement: 'refs', since: 'React 16.3' },
17
+ // ReactDOM methods
18
+ 'ReactDOM.render': { replacement: 'createRoot().render()', since: 'React 18' },
19
+ 'ReactDOM.hydrate': { replacement: 'hydrateRoot()', since: 'React 18' },
20
+ 'ReactDOM.unmountComponentAtNode': { replacement: 'root.unmount()', since: 'React 18' },
21
+ 'ReactDOM.findDOMNode': { replacement: 'refs', since: 'React 16.3' },
22
+ // Lifecycle methods (deprecated in strict mode)
23
+ 'componentWillMount': { replacement: 'componentDidMount or constructor', since: 'React 16.3' },
24
+ 'componentWillReceiveProps': { replacement: 'static getDerivedStateFromProps', since: 'React 16.3' },
25
+ 'componentWillUpdate': { replacement: 'getSnapshotBeforeUpdate', since: 'React 16.3' },
26
+ 'UNSAFE_componentWillMount': { replacement: 'componentDidMount or constructor', since: 'React 17' },
27
+ 'UNSAFE_componentWillReceiveProps': { replacement: 'static getDerivedStateFromProps', since: 'React 17' },
28
+ 'UNSAFE_componentWillUpdate': { replacement: 'getSnapshotBeforeUpdate', since: 'React 17' },
29
+ };
30
+ exports.noDeprecated = (0, eslint_devkit_2.createRule)({
31
+ name: 'no-deprecated',
32
+ meta: {
33
+ type: 'problem',
34
+ docs: {
35
+ description: 'Prevent using deprecated React methods',
36
+ },
37
+ messages: {
38
+ deprecated: (0, eslint_devkit_1.formatLLMMessage)({
39
+ icon: eslint_devkit_1.MessageIcons.DEPRECATION,
40
+ issueName: 'Deprecated React API',
41
+ description: '"{{name}}" is deprecated since {{since}}',
42
+ severity: 'MEDIUM',
43
+ fix: 'Use {{replacement}} instead',
44
+ documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md',
45
+ }),
46
+ },
47
+ schema: [],
48
+ },
49
+ defaultOptions: [],
50
+ create(context) {
51
+ // Track lifecycle methods in class components
52
+ let inClassComponent = false;
53
+ function checkMemberExpression(node) {
54
+ if (node.object.type !== 'Identifier')
55
+ return;
56
+ if (node.property.type !== 'Identifier')
57
+ return;
58
+ const fullName = `${node.object.name}.${node.property.name}`;
59
+ const deprecation = DEPRECATED_APIS[fullName];
60
+ if (deprecation) {
61
+ context.report({
62
+ node,
63
+ messageId: 'deprecated',
64
+ data: {
65
+ name: fullName,
66
+ replacement: deprecation.replacement,
67
+ since: deprecation.since,
68
+ },
69
+ });
70
+ }
71
+ }
72
+ function checkLifecycleMethod(node) {
73
+ if (!inClassComponent)
74
+ return;
75
+ if (node.key.type !== 'Identifier')
76
+ return;
77
+ const methodName = node.key.name;
78
+ const deprecation = DEPRECATED_APIS[methodName];
79
+ if (deprecation) {
80
+ context.report({
81
+ node,
82
+ messageId: 'deprecated',
83
+ data: {
84
+ name: methodName,
85
+ replacement: deprecation.replacement,
86
+ since: deprecation.since,
87
+ },
88
+ });
89
+ }
90
+ }
91
+ return {
92
+ ClassDeclaration(node) {
93
+ // Check if this extends React.Component or React.PureComponent
94
+ if (!node.superClass)
95
+ return;
96
+ if (node.superClass.type === 'MemberExpression') {
97
+ if (node.superClass.object.type === 'Identifier' &&
98
+ node.superClass.object.name === 'React' &&
99
+ node.superClass.property.type === 'Identifier' &&
100
+ (node.superClass.property.name === 'Component' ||
101
+ node.superClass.property.name === 'PureComponent')) {
102
+ inClassComponent = true;
103
+ }
104
+ }
105
+ else if (node.superClass.type === 'Identifier') {
106
+ if (node.superClass.name === 'Component' || node.superClass.name === 'PureComponent') {
107
+ inClassComponent = true;
108
+ }
109
+ }
110
+ },
111
+ 'ClassDeclaration:exit'() {
112
+ inClassComponent = false;
113
+ },
114
+ ClassExpression(node) {
115
+ if (!node.superClass)
116
+ return;
117
+ if (node.superClass.type === 'MemberExpression') {
118
+ if (node.superClass.object.type === 'Identifier' &&
119
+ node.superClass.object.name === 'React' &&
120
+ node.superClass.property.type === 'Identifier' &&
121
+ (node.superClass.property.name === 'Component' ||
122
+ node.superClass.property.name === 'PureComponent')) {
123
+ inClassComponent = true;
124
+ }
125
+ }
126
+ else if (node.superClass.type === 'Identifier') {
127
+ if (node.superClass.name === 'Component' || node.superClass.name === 'PureComponent') {
128
+ inClassComponent = true;
129
+ }
130
+ }
131
+ },
132
+ 'ClassExpression:exit'() {
133
+ inClassComponent = false;
134
+ },
135
+ MemberExpression: checkMemberExpression,
136
+ MethodDefinition: checkLifecycleMethod,
137
+ PropertyDefinition: checkLifecycleMethod,
138
+ };
139
+ },
140
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-did-mount-set-state
8
+ * Prevent setState in componentDidMount
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ export declare const noDidMountSetState: TSESLint.RuleModule<"noDidMountSetState", [], unknown, TSESLint.RuleListener> & {
12
+ name: string;
13
+ };
@@ -0,0 +1,55 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.noDidMountSetState = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.noDidMountSetState = (0, eslint_devkit_1.createRule)({
12
+ name: 'no-did-mount-set-state',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Prevent setState in componentDidMount',
17
+ },
18
+ schema: [],
19
+ messages: {
20
+ noDidMountSetState: (0, eslint_devkit_2.formatLLMMessage)({
21
+ icon: eslint_devkit_2.MessageIcons.WARNING,
22
+ issueName: 'setState in componentDidMount',
23
+ description: 'setState called in componentDidMount',
24
+ severity: 'HIGH',
25
+ fix: 'Use initial state or constructor instead',
26
+ documentationLink: 'https://react.dev/reference/react/Component#componentdidmount',
27
+ }),
28
+ },
29
+ },
30
+ defaultOptions: [],
31
+ create(context) {
32
+ let inComponentDidMount = false;
33
+ return {
34
+ 'MethodDefinition[key.name="componentDidMount"]'() {
35
+ inComponentDidMount = true;
36
+ },
37
+ 'MethodDefinition[key.name="componentDidMount"]:exit'() {
38
+ inComponentDidMount = false;
39
+ },
40
+ CallExpression(node) {
41
+ if (!inComponentDidMount)
42
+ return;
43
+ // Check if this is a setState call
44
+ if (node.callee.type === 'MemberExpression' &&
45
+ node.callee.property.type === 'Identifier' &&
46
+ node.callee.property.name === 'setState') {
47
+ context.report({
48
+ node: node.callee.property,
49
+ messageId: 'noDidMountSetState',
50
+ });
51
+ }
52
+ },
53
+ };
54
+ },
55
+ });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-did-update-set-state
8
+ * Prevent setState in componentDidUpdate
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ export interface Options {
12
+ /** Allow setState in callback functions */
13
+ allowInCallback?: boolean;
14
+ }
15
+ type RuleOptions = [Options?];
16
+ export declare const noDidUpdateSetState: TSESLint.RuleModule<"noDidUpdateSetState", RuleOptions, unknown, TSESLint.RuleListener> & {
17
+ name: string;
18
+ };
19
+ export {};