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,119 @@
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.defaultPropsMatchPropTypes = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.defaultPropsMatchPropTypes = (0, eslint_devkit_1.createRule)({
12
+ name: 'default-props-match-prop-types',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Validate default props match prop types',
17
+ },
18
+ schema: [],
19
+ messages: {
20
+ defaultPropsMatchPropTypes: (0, eslint_devkit_2.formatLLMMessage)({
21
+ icon: eslint_devkit_2.MessageIcons.WARNING,
22
+ issueName: 'Default Props Mismatch',
23
+ description: 'Default prop does not match prop type',
24
+ severity: 'MEDIUM',
25
+ fix: 'Update default prop to match propTypes or update propTypes',
26
+ documentationLink: 'https://react.dev/learn/components-and-props#default-props',
27
+ }),
28
+ },
29
+ },
30
+ defaultOptions: [],
31
+ create(context) {
32
+ const propTypes = new Map();
33
+ const defaultProps = new Map();
34
+ return {
35
+ // Collect propTypes (PropertyDefinition is used by TypeScript parser)
36
+ 'PropertyDefinition[key.name="propTypes"]'(node) {
37
+ if (node.value && node.value.type === 'ObjectExpression') {
38
+ for (const prop of node.value.properties) {
39
+ if (prop.type === 'Property' && prop.key.type === 'Identifier') {
40
+ propTypes.set(prop.key.name, prop);
41
+ }
42
+ }
43
+ }
44
+ },
45
+ // Collect defaultProps (PropertyDefinition is used by TypeScript parser)
46
+ 'PropertyDefinition[key.name="defaultProps"]'(node) {
47
+ if (node.value && node.value.type === 'ObjectExpression') {
48
+ for (const prop of node.value.properties) {
49
+ if (prop.type === 'Property' && prop.key.type === 'Identifier') {
50
+ defaultProps.set(prop.key.name, prop);
51
+ }
52
+ }
53
+ }
54
+ },
55
+ // Check after collecting both
56
+ 'ClassDeclaration:exit'() {
57
+ for (const [propName, defaultProp] of defaultProps) {
58
+ const propType = propTypes.get(propName);
59
+ // Only check if both values are expressions (not patterns or TSEmptyBodyFunctionExpression)
60
+ if (propType &&
61
+ defaultProp.value &&
62
+ propType.value &&
63
+ defaultProp.value.type !== 'TSEmptyBodyFunctionExpression' &&
64
+ propType.value.type !== 'TSEmptyBodyFunctionExpression' &&
65
+ !isPattern(defaultProp.value) &&
66
+ !isPattern(propType.value) &&
67
+ !isCompatibleDefaultValue(defaultProp.value, propType.value)) {
68
+ context.report({
69
+ node: defaultProp.key,
70
+ messageId: 'defaultPropsMatchPropTypes',
71
+ });
72
+ }
73
+ }
74
+ // Clear maps for next class
75
+ propTypes.clear();
76
+ defaultProps.clear();
77
+ },
78
+ };
79
+ },
80
+ });
81
+ /**
82
+ * Check if default value is compatible with prop type
83
+ */
84
+ function isCompatibleDefaultValue(defaultValue, propType) {
85
+ // This is a simplified check - in practice, you'd want more comprehensive validation
86
+ // For now, just check if both are literals of the same type
87
+ if (defaultValue.type === 'Literal' && propType.type === 'MemberExpression') {
88
+ const propTypeName = getPropTypeName(propType);
89
+ const defaultType = typeof defaultValue.value;
90
+ switch (propTypeName) {
91
+ case 'string':
92
+ return defaultType === 'string';
93
+ case 'number':
94
+ return defaultType === 'number';
95
+ case 'bool':
96
+ return defaultType === 'boolean';
97
+ default:
98
+ return true; // Allow other types for now
99
+ }
100
+ }
101
+ return true; // Allow complex types for now
102
+ }
103
+ /**
104
+ * Extract prop type name from PropTypes expression
105
+ */
106
+ function getPropTypeName(node) {
107
+ if (node.object.type === 'Identifier' &&
108
+ node.object.name === 'PropTypes' &&
109
+ node.property.type === 'Identifier') {
110
+ return node.property.name;
111
+ }
112
+ return '';
113
+ }
114
+ /**
115
+ * Check if a node is a pattern (not an expression)
116
+ */
117
+ function isPattern(node) {
118
+ return node.type === 'AssignmentPattern' || node.type === 'ArrayPattern' || node.type === 'ObjectPattern';
119
+ }
@@ -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: display-name
8
+ * Enforce component display names
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ export declare const displayName: TSESLint.RuleModule<"displayName", [], unknown, TSESLint.RuleListener> & {
12
+ name: string;
13
+ };
@@ -0,0 +1,164 @@
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.displayName = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.displayName = (0, eslint_devkit_1.createRule)({
12
+ name: 'display-name',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Enforce component display names',
17
+ },
18
+ schema: [],
19
+ messages: {
20
+ displayName: (0, eslint_devkit_2.formatLLMMessage)({
21
+ icon: eslint_devkit_2.MessageIcons.WARNING,
22
+ issueName: 'Missing Display Name',
23
+ description: 'Component missing display name',
24
+ severity: 'LOW',
25
+ fix: 'Add displayName static property or named export',
26
+ documentationLink: 'https://react.dev/learn/components-and-props#displaying-a-custom-component',
27
+ }),
28
+ },
29
+ },
30
+ defaultOptions: [],
31
+ create(context) {
32
+ return {
33
+ // Check class components
34
+ ClassDeclaration(node) {
35
+ if (isReactComponent(node)) {
36
+ const hasDisplayName = hasDisplayNameProperty(node);
37
+ if (!hasDisplayName) {
38
+ context.report({
39
+ node: node.id || node,
40
+ messageId: 'displayName',
41
+ });
42
+ }
43
+ }
44
+ },
45
+ // Check function components
46
+ 'VariableDeclarator, FunctionDeclaration'(node) {
47
+ const component = getComponentFromDeclaration(node);
48
+ if (component && isReactComponentFunction(component) && !hasDisplayNameInScope()) {
49
+ context.report({
50
+ node: getComponentNameNode(node),
51
+ messageId: 'displayName',
52
+ });
53
+ }
54
+ },
55
+ };
56
+ },
57
+ });
58
+ /**
59
+ * Check if class declaration is a React component
60
+ */
61
+ function isReactComponent(node) {
62
+ if (!node.superClass)
63
+ return false;
64
+ if (node.superClass.type === 'Identifier') {
65
+ return node.superClass.name === 'Component' || node.superClass.name === 'PureComponent';
66
+ }
67
+ if (node.superClass.type === 'MemberExpression') {
68
+ return (node.superClass.object.type === 'Identifier' &&
69
+ node.superClass.object.name === 'React' &&
70
+ node.superClass.property.type === 'Identifier' &&
71
+ (node.superClass.property.name === 'Component' || node.superClass.property.name === 'PureComponent'));
72
+ }
73
+ return false;
74
+ }
75
+ /**
76
+ * Check if class has displayName property
77
+ */
78
+ function hasDisplayNameProperty(node) {
79
+ for (const member of node.body.body) {
80
+ if (member.type === 'PropertyDefinition' &&
81
+ member.key.type === 'Identifier' &&
82
+ member.key.name === 'displayName' &&
83
+ member.static) {
84
+ return true;
85
+ }
86
+ }
87
+ return false;
88
+ }
89
+ /**
90
+ * Get component from declaration
91
+ */
92
+ function getComponentFromDeclaration(node) {
93
+ if (node.type === 'FunctionDeclaration') {
94
+ return node;
95
+ }
96
+ if (node.type === 'VariableDeclarator' && node.init) {
97
+ if (node.init.type === 'FunctionExpression' || node.init.type === 'ArrowFunctionExpression') {
98
+ return node.init;
99
+ }
100
+ }
101
+ return null;
102
+ }
103
+ /**
104
+ * Check if function is a React component
105
+ */
106
+ function isReactComponentFunction(node) {
107
+ // Simple heuristic: check if function returns JSX or contains JSX
108
+ const body = node.type === 'FunctionDeclaration' ? node.body : node.body;
109
+ return containsJSX(body);
110
+ }
111
+ /**
112
+ * Check if component has displayName in scope
113
+ */
114
+ function hasDisplayNameInScope() {
115
+ // Check for assignment to displayName after component declaration
116
+ // This is a simplified check - in practice, you'd want to check the scope
117
+ return false; // For now, always require explicit displayName
118
+ }
119
+ /**
120
+ * Get component name node for reporting
121
+ */
122
+ function getComponentNameNode(node) {
123
+ if (node.type === 'FunctionDeclaration') {
124
+ return node.id || node;
125
+ }
126
+ return node.id || node;
127
+ }
128
+ /**
129
+ * Check if node contains JSX
130
+ */
131
+ function containsJSX(node, visited = new Set()) {
132
+ if (!node)
133
+ return false;
134
+ if (visited.has(node))
135
+ return false;
136
+ visited.add(node);
137
+ if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
138
+ return true;
139
+ }
140
+ // Skip non-child keys to avoid circular references
141
+ const skipKeys = new Set(['parent', 'range', 'loc', 'start', 'end', 'tokens', 'comments']);
142
+ for (const key in node) {
143
+ if (skipKeys.has(key))
144
+ continue;
145
+ const child = node[key];
146
+ if (child && typeof child === 'object') {
147
+ if (Array.isArray(child)) {
148
+ for (const item of child) {
149
+ if (item && typeof item === 'object' && 'type' in item) {
150
+ if (containsJSX(item, visited)) {
151
+ return true;
152
+ }
153
+ }
154
+ }
155
+ }
156
+ else if ('type' in child) {
157
+ if (containsJSX(child, visited)) {
158
+ return true;
159
+ }
160
+ }
161
+ }
162
+ }
163
+ return false;
164
+ }
@@ -0,0 +1,25 @@
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: hooks-exhaustive-deps
8
+ * LLM-optimized wrapper for React hooks dependency array checking
9
+ *
10
+ * This rule detects missing or extra dependencies in React hooks like
11
+ * useEffect, useCallback, useMemo, and useLayoutEffect.
12
+ */
13
+ import type { TSESLint } from '@interlace/eslint-devkit';
14
+ type MessageIds = 'missingDep' | 'extraDep' | 'unnecessaryDep' | 'suggestAddDep' | 'suggestRemoveDep';
15
+ export interface Options {
16
+ /** Additional hooks to check (e.g., custom hooks using useEffect internally) */
17
+ additionalHooks?: string;
18
+ /** Enable stale closure detection warnings */
19
+ enableDangerousAutofixThisMayCauseInfiniteLoops?: boolean;
20
+ }
21
+ type RuleOptions = [Options?];
22
+ export declare const hooksExhaustiveDeps: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
23
+ name: string;
24
+ };
25
+ export {};