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.
- package/CHANGELOG.md +70 -0
- package/LICENSE +23 -0
- package/README.md +155 -0
- package/package.json +65 -0
- package/src/index.d.ts +1093 -0
- package/src/index.js +212 -0
- package/src/rules/migration/react-class-to-hooks.d.ts +22 -0
- package/src/rules/migration/react-class-to-hooks.js +178 -0
- package/src/rules/performance/no-unnecessary-rerenders.d.ts +26 -0
- package/src/rules/performance/no-unnecessary-rerenders.js +212 -0
- package/src/rules/performance/react-no-inline-functions.d.ts +24 -0
- package/src/rules/performance/react-no-inline-functions.js +211 -0
- package/src/rules/performance/react-render-optimization.d.ts +31 -0
- package/src/rules/performance/react-render-optimization.js +294 -0
- package/src/rules/react/checked-requires-onchange-or-readonly.d.ts +16 -0
- package/src/rules/react/checked-requires-onchange-or-readonly.js +74 -0
- package/src/rules/react/default-props-match-prop-types.d.ts +13 -0
- package/src/rules/react/default-props-match-prop-types.js +119 -0
- package/src/rules/react/display-name.d.ts +13 -0
- package/src/rules/react/display-name.js +164 -0
- package/src/rules/react/hooks-exhaustive-deps.d.ts +25 -0
- package/src/rules/react/hooks-exhaustive-deps.js +466 -0
- package/src/rules/react/jsx-handler-names.d.ts +13 -0
- package/src/rules/react/jsx-handler-names.js +57 -0
- package/src/rules/react/jsx-key.d.ts +20 -0
- package/src/rules/react/jsx-key.js +421 -0
- package/src/rules/react/jsx-max-depth.d.ts +19 -0
- package/src/rules/react/jsx-max-depth.js +80 -0
- package/src/rules/react/jsx-no-bind.d.ts +13 -0
- package/src/rules/react/jsx-no-bind.js +64 -0
- package/src/rules/react/jsx-no-duplicate-props.d.ts +21 -0
- package/src/rules/react/jsx-no-duplicate-props.js +70 -0
- package/src/rules/react/jsx-no-literals.d.ts +20 -0
- package/src/rules/react/jsx-no-literals.js +83 -0
- package/src/rules/react/jsx-no-script-url.d.ts +25 -0
- package/src/rules/react/jsx-no-script-url.js +131 -0
- package/src/rules/react/jsx-no-target-blank.d.ts +26 -0
- package/src/rules/react/jsx-no-target-blank.js +176 -0
- package/src/rules/react/no-access-state-in-setstate.d.ts +13 -0
- package/src/rules/react/no-access-state-in-setstate.js +92 -0
- package/src/rules/react/no-adjacent-inline-elements.d.ts +13 -0
- package/src/rules/react/no-adjacent-inline-elements.js +81 -0
- package/src/rules/react/no-arrow-function-lifecycle.d.ts +13 -0
- package/src/rules/react/no-arrow-function-lifecycle.js +63 -0
- package/src/rules/react/no-children-prop.d.ts +13 -0
- package/src/rules/react/no-children-prop.js +60 -0
- package/src/rules/react/no-danger-with-children.d.ts +16 -0
- package/src/rules/react/no-danger-with-children.js +110 -0
- package/src/rules/react/no-danger.d.ts +13 -0
- package/src/rules/react/no-danger.js +45 -0
- package/src/rules/react/no-deprecated.d.ts +16 -0
- package/src/rules/react/no-deprecated.js +140 -0
- package/src/rules/react/no-did-mount-set-state.d.ts +13 -0
- package/src/rules/react/no-did-mount-set-state.js +55 -0
- package/src/rules/react/no-did-update-set-state.d.ts +19 -0
- package/src/rules/react/no-did-update-set-state.js +80 -0
- package/src/rules/react/no-direct-mutation-state.d.ts +20 -0
- package/src/rules/react/no-direct-mutation-state.js +277 -0
- package/src/rules/react/no-find-dom-node.d.ts +15 -0
- package/src/rules/react/no-find-dom-node.js +56 -0
- package/src/rules/react/no-invalid-html-attribute.d.ts +13 -0
- package/src/rules/react/no-invalid-html-attribute.js +84 -0
- package/src/rules/react/no-is-mounted.d.ts +13 -0
- package/src/rules/react/no-is-mounted.js +52 -0
- package/src/rules/react/no-multi-comp.d.ts +18 -0
- package/src/rules/react/no-multi-comp.js +160 -0
- package/src/rules/react/no-namespace.d.ts +13 -0
- package/src/rules/react/no-namespace.js +41 -0
- package/src/rules/react/no-object-type-as-default-prop.d.ts +13 -0
- package/src/rules/react/no-object-type-as-default-prop.js +61 -0
- package/src/rules/react/no-redundant-should-component-update.d.ts +13 -0
- package/src/rules/react/no-redundant-should-component-update.js +55 -0
- package/src/rules/react/no-render-return-value.d.ts +13 -0
- package/src/rules/react/no-render-return-value.js +74 -0
- package/src/rules/react/no-set-state.d.ts +13 -0
- package/src/rules/react/no-set-state.js +50 -0
- package/src/rules/react/no-string-refs.d.ts +13 -0
- package/src/rules/react/no-string-refs.js +68 -0
- package/src/rules/react/no-this-in-sfc.d.ts +13 -0
- package/src/rules/react/no-this-in-sfc.js +65 -0
- package/src/rules/react/no-typos.d.ts +13 -0
- package/src/rules/react/no-typos.js +97 -0
- package/src/rules/react/no-unescaped-entities.d.ts +13 -0
- package/src/rules/react/no-unescaped-entities.js +50 -0
- package/src/rules/react/no-unknown-property.d.ts +13 -0
- package/src/rules/react/no-unknown-property.js +130 -0
- package/src/rules/react/no-unsafe.d.ts +20 -0
- package/src/rules/react/no-unsafe.js +112 -0
- package/src/rules/react/prefer-es6-class.d.ts +13 -0
- package/src/rules/react/prefer-es6-class.js +56 -0
- package/src/rules/react/prefer-stateless-function.d.ts +16 -0
- package/src/rules/react/prefer-stateless-function.js +134 -0
- package/src/rules/react/prop-types.d.ts +18 -0
- package/src/rules/react/prop-types.js +153 -0
- package/src/rules/react/react-in-jsx-scope.d.ts +13 -0
- package/src/rules/react/react-in-jsx-scope.js +94 -0
- package/src/rules/react/require-default-props.d.ts +16 -0
- package/src/rules/react/require-default-props.js +146 -0
- package/src/rules/react/require-optimization.d.ts +26 -0
- package/src/rules/react/require-optimization.js +436 -0
- package/src/rules/react/require-render-return.d.ts +13 -0
- package/src/rules/react/require-render-return.js +87 -0
- package/src/rules/react/required-attributes.d.ts +28 -0
- package/src/rules/react/required-attributes.js +212 -0
- package/src/rules/react/sort-comp.d.ts +17 -0
- package/src/rules/react/sort-comp.js +160 -0
- package/src/rules/react/state-in-constructor.d.ts +13 -0
- package/src/rules/react/state-in-constructor.js +103 -0
- package/src/rules/react/static-property-placement.d.ts +20 -0
- package/src/rules/react/static-property-placement.js +166 -0
- package/src/rules/react/void-dom-elements-no-children.d.ts +15 -0
- package/src/rules/react/void-dom-elements-no-children.js +94 -0
- package/src/types/index.d.ts +54 -0
- package/src/types/index.js +7 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
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.configs = exports.plugin = exports.rules = void 0;
|
|
9
|
+
// React rules
|
|
10
|
+
const required_attributes_1 = require("./rules/react/required-attributes");
|
|
11
|
+
const jsx_key_1 = require("./rules/react/jsx-key");
|
|
12
|
+
const no_direct_mutation_state_1 = require("./rules/react/no-direct-mutation-state");
|
|
13
|
+
const require_optimization_1 = require("./rules/react/require-optimization");
|
|
14
|
+
const no_set_state_1 = require("./rules/react/no-set-state");
|
|
15
|
+
const no_this_in_sfc_1 = require("./rules/react/no-this-in-sfc");
|
|
16
|
+
const no_access_state_in_setstate_1 = require("./rules/react/no-access-state-in-setstate");
|
|
17
|
+
const no_children_prop_1 = require("./rules/react/no-children-prop");
|
|
18
|
+
const no_danger_1 = require("./rules/react/no-danger");
|
|
19
|
+
const no_string_refs_1 = require("./rules/react/no-string-refs");
|
|
20
|
+
const no_unknown_property_1 = require("./rules/react/no-unknown-property");
|
|
21
|
+
const checked_requires_onchange_or_readonly_1 = require("./rules/react/checked-requires-onchange-or-readonly");
|
|
22
|
+
const default_props_match_prop_types_1 = require("./rules/react/default-props-match-prop-types");
|
|
23
|
+
const display_name_1 = require("./rules/react/display-name");
|
|
24
|
+
const jsx_handler_names_1 = require("./rules/react/jsx-handler-names");
|
|
25
|
+
const jsx_max_depth_1 = require("./rules/react/jsx-max-depth");
|
|
26
|
+
const jsx_no_bind_1 = require("./rules/react/jsx-no-bind");
|
|
27
|
+
const jsx_no_literals_1 = require("./rules/react/jsx-no-literals");
|
|
28
|
+
const no_adjacent_inline_elements_1 = require("./rules/react/no-adjacent-inline-elements");
|
|
29
|
+
const no_arrow_function_lifecycle_1 = require("./rules/react/no-arrow-function-lifecycle");
|
|
30
|
+
const no_did_mount_set_state_1 = require("./rules/react/no-did-mount-set-state");
|
|
31
|
+
const no_did_update_set_state_1 = require("./rules/react/no-did-update-set-state");
|
|
32
|
+
const no_invalid_html_attribute_1 = require("./rules/react/no-invalid-html-attribute");
|
|
33
|
+
const no_is_mounted_1 = require("./rules/react/no-is-mounted");
|
|
34
|
+
const no_multi_comp_1 = require("./rules/react/no-multi-comp");
|
|
35
|
+
const no_namespace_1 = require("./rules/react/no-namespace");
|
|
36
|
+
const no_object_type_as_default_prop_1 = require("./rules/react/no-object-type-as-default-prop");
|
|
37
|
+
const no_redundant_should_component_update_1 = require("./rules/react/no-redundant-should-component-update");
|
|
38
|
+
const no_render_return_value_1 = require("./rules/react/no-render-return-value");
|
|
39
|
+
const no_typos_1 = require("./rules/react/no-typos");
|
|
40
|
+
const no_unescaped_entities_1 = require("./rules/react/no-unescaped-entities");
|
|
41
|
+
const prefer_es6_class_1 = require("./rules/react/prefer-es6-class");
|
|
42
|
+
const prefer_stateless_function_1 = require("./rules/react/prefer-stateless-function");
|
|
43
|
+
const prop_types_1 = require("./rules/react/prop-types");
|
|
44
|
+
const react_in_jsx_scope_1 = require("./rules/react/react-in-jsx-scope");
|
|
45
|
+
const require_default_props_1 = require("./rules/react/require-default-props");
|
|
46
|
+
const require_render_return_1 = require("./rules/react/require-render-return");
|
|
47
|
+
const sort_comp_1 = require("./rules/react/sort-comp");
|
|
48
|
+
const state_in_constructor_1 = require("./rules/react/state-in-constructor");
|
|
49
|
+
const static_property_placement_1 = require("./rules/react/static-property-placement");
|
|
50
|
+
const hooks_exhaustive_deps_1 = require("./rules/react/hooks-exhaustive-deps");
|
|
51
|
+
// Security rules
|
|
52
|
+
const jsx_no_target_blank_1 = require("./rules/react/jsx-no-target-blank");
|
|
53
|
+
const jsx_no_script_url_1 = require("./rules/react/jsx-no-script-url");
|
|
54
|
+
const jsx_no_duplicate_props_1 = require("./rules/react/jsx-no-duplicate-props");
|
|
55
|
+
const no_danger_with_children_1 = require("./rules/react/no-danger-with-children");
|
|
56
|
+
const no_deprecated_1 = require("./rules/react/no-deprecated");
|
|
57
|
+
// Deprecated API rules
|
|
58
|
+
const no_find_dom_node_1 = require("./rules/react/no-find-dom-node");
|
|
59
|
+
const no_unsafe_1 = require("./rules/react/no-unsafe");
|
|
60
|
+
const void_dom_elements_no_children_1 = require("./rules/react/void-dom-elements-no-children");
|
|
61
|
+
// Migration rules
|
|
62
|
+
const react_class_to_hooks_1 = require("./rules/migration/react-class-to-hooks");
|
|
63
|
+
// React Performance rules
|
|
64
|
+
const no_unnecessary_rerenders_1 = require("./rules/performance/no-unnecessary-rerenders");
|
|
65
|
+
const react_render_optimization_1 = require("./rules/performance/react-render-optimization");
|
|
66
|
+
const react_no_inline_functions_1 = require("./rules/performance/react-no-inline-functions");
|
|
67
|
+
exports.rules = {
|
|
68
|
+
// Flat names
|
|
69
|
+
'required-attributes': required_attributes_1.requiredAttributes,
|
|
70
|
+
'jsx-key': jsx_key_1.jsxKey,
|
|
71
|
+
'no-direct-mutation-state': no_direct_mutation_state_1.noDirectMutationState,
|
|
72
|
+
'require-optimization': require_optimization_1.requireOptimization,
|
|
73
|
+
'no-set-state': no_set_state_1.noSetState,
|
|
74
|
+
'no-this-in-sfc': no_this_in_sfc_1.noThisInSfc,
|
|
75
|
+
'no-access-state-in-setstate': no_access_state_in_setstate_1.noAccessStateInSetState,
|
|
76
|
+
'no-children-prop': no_children_prop_1.noChildrenProp,
|
|
77
|
+
'no-danger': no_danger_1.noDanger,
|
|
78
|
+
'no-string-refs': no_string_refs_1.noStringRefs,
|
|
79
|
+
'no-unknown-property': no_unknown_property_1.noUnknownProperty,
|
|
80
|
+
'checked-requires-onchange-or-readonly': checked_requires_onchange_or_readonly_1.checkedRequiresOnchangeOrReadonly,
|
|
81
|
+
'default-props-match-prop-types': default_props_match_prop_types_1.defaultPropsMatchPropTypes,
|
|
82
|
+
'display-name': display_name_1.displayName,
|
|
83
|
+
'jsx-handler-names': jsx_handler_names_1.jsxHandlerNames,
|
|
84
|
+
'jsx-max-depth': jsx_max_depth_1.jsxMaxDepth,
|
|
85
|
+
'jsx-no-bind': jsx_no_bind_1.jsxNoBind,
|
|
86
|
+
'jsx-no-literals': jsx_no_literals_1.jsxNoLiterals,
|
|
87
|
+
'no-adjacent-inline-elements': no_adjacent_inline_elements_1.noAdjacentInlineElements,
|
|
88
|
+
'no-arrow-function-lifecycle': no_arrow_function_lifecycle_1.noArrowFunctionLifecycle,
|
|
89
|
+
'no-did-mount-set-state': no_did_mount_set_state_1.noDidMountSetState,
|
|
90
|
+
'no-did-update-set-state': no_did_update_set_state_1.noDidUpdateSetState,
|
|
91
|
+
'no-invalid-html-attribute': no_invalid_html_attribute_1.noInvalidHtmlAttribute,
|
|
92
|
+
'no-is-mounted': no_is_mounted_1.noIsMounted,
|
|
93
|
+
'no-multi-comp': no_multi_comp_1.noMultiComp,
|
|
94
|
+
'no-namespace': no_namespace_1.noNamespace,
|
|
95
|
+
'no-object-type-as-default-prop': no_object_type_as_default_prop_1.noObjectTypeAsDefaultProp,
|
|
96
|
+
'no-redundant-should-component-update': no_redundant_should_component_update_1.noRedundantShouldComponentUpdate,
|
|
97
|
+
'no-render-return-value': no_render_return_value_1.noRenderReturnValue,
|
|
98
|
+
'no-typos': no_typos_1.noTypos,
|
|
99
|
+
'no-unescaped-entities': no_unescaped_entities_1.noUnescapedEntities,
|
|
100
|
+
'prefer-es6-class': prefer_es6_class_1.preferEs6Class,
|
|
101
|
+
'prefer-stateless-function': prefer_stateless_function_1.preferStatelessFunction,
|
|
102
|
+
'prop-types': prop_types_1.propTypes,
|
|
103
|
+
'react-in-jsx-scope': react_in_jsx_scope_1.reactInJsxScope,
|
|
104
|
+
'require-default-props': require_default_props_1.requireDefaultProps,
|
|
105
|
+
'require-render-return': require_render_return_1.requireRenderReturn,
|
|
106
|
+
'sort-comp': sort_comp_1.sortComp,
|
|
107
|
+
'state-in-constructor': state_in_constructor_1.stateInConstructor,
|
|
108
|
+
'static-property-placement': static_property_placement_1.staticPropertyPlacement,
|
|
109
|
+
'hooks-exhaustive-deps': hooks_exhaustive_deps_1.hooksExhaustiveDeps,
|
|
110
|
+
// Security and bug prevention
|
|
111
|
+
'jsx-no-target-blank': jsx_no_target_blank_1.jsxNoTargetBlank,
|
|
112
|
+
'jsx-no-script-url': jsx_no_script_url_1.jsxNoScriptUrl,
|
|
113
|
+
'jsx-no-duplicate-props': jsx_no_duplicate_props_1.jsxNoDuplicateProps,
|
|
114
|
+
'no-danger-with-children': no_danger_with_children_1.noDangerWithChildren,
|
|
115
|
+
'no-deprecated': no_deprecated_1.noDeprecated,
|
|
116
|
+
// Deprecated API rules
|
|
117
|
+
'no-find-dom-node': no_find_dom_node_1.noFindDomNode,
|
|
118
|
+
'no-unsafe': no_unsafe_1.noUnsafe,
|
|
119
|
+
'void-dom-elements-no-children': void_dom_elements_no_children_1.voidDomElementsNoChildren,
|
|
120
|
+
'react-class-to-hooks': react_class_to_hooks_1.reactClassToHooks,
|
|
121
|
+
'no-unnecessary-rerenders': no_unnecessary_rerenders_1.noUnnecessaryRerenders,
|
|
122
|
+
'react-render-optimization': react_render_optimization_1.reactRenderOptimization,
|
|
123
|
+
'react-no-inline-functions': react_no_inline_functions_1.reactNoInlineFunctions,
|
|
124
|
+
// Categorized names
|
|
125
|
+
'react/required-attributes': required_attributes_1.requiredAttributes,
|
|
126
|
+
'react/jsx-key': jsx_key_1.jsxKey,
|
|
127
|
+
'react/no-direct-mutation-state': no_direct_mutation_state_1.noDirectMutationState,
|
|
128
|
+
'react/require-optimization': require_optimization_1.requireOptimization,
|
|
129
|
+
'react/no-set-state': no_set_state_1.noSetState,
|
|
130
|
+
'react/no-this-in-sfc': no_this_in_sfc_1.noThisInSfc,
|
|
131
|
+
'react/no-access-state-in-setstate': no_access_state_in_setstate_1.noAccessStateInSetState,
|
|
132
|
+
'react/no-children-prop': no_children_prop_1.noChildrenProp,
|
|
133
|
+
'react/no-danger': no_danger_1.noDanger,
|
|
134
|
+
'react/no-string-refs': no_string_refs_1.noStringRefs,
|
|
135
|
+
'react/no-unknown-property': no_unknown_property_1.noUnknownProperty,
|
|
136
|
+
'react/checked-requires-onchange-or-readonly': checked_requires_onchange_or_readonly_1.checkedRequiresOnchangeOrReadonly,
|
|
137
|
+
'react/default-props-match-prop-types': default_props_match_prop_types_1.defaultPropsMatchPropTypes,
|
|
138
|
+
'react/display-name': display_name_1.displayName,
|
|
139
|
+
'react/jsx-handler-names': jsx_handler_names_1.jsxHandlerNames,
|
|
140
|
+
'react/jsx-max-depth': jsx_max_depth_1.jsxMaxDepth,
|
|
141
|
+
'react/jsx-no-bind': jsx_no_bind_1.jsxNoBind,
|
|
142
|
+
'react/jsx-no-literals': jsx_no_literals_1.jsxNoLiterals,
|
|
143
|
+
'react/no-adjacent-inline-elements': no_adjacent_inline_elements_1.noAdjacentInlineElements,
|
|
144
|
+
'react/no-arrow-function-lifecycle': no_arrow_function_lifecycle_1.noArrowFunctionLifecycle,
|
|
145
|
+
'react/no-did-mount-set-state': no_did_mount_set_state_1.noDidMountSetState,
|
|
146
|
+
'react/no-did-update-set-state': no_did_update_set_state_1.noDidUpdateSetState,
|
|
147
|
+
'react/no-invalid-html-attribute': no_invalid_html_attribute_1.noInvalidHtmlAttribute,
|
|
148
|
+
'react/no-is-mounted': no_is_mounted_1.noIsMounted,
|
|
149
|
+
'react/no-multi-comp': no_multi_comp_1.noMultiComp,
|
|
150
|
+
'react/no-namespace': no_namespace_1.noNamespace,
|
|
151
|
+
'react/no-object-type-as-default-prop': no_object_type_as_default_prop_1.noObjectTypeAsDefaultProp,
|
|
152
|
+
'react/no-redundant-should-component-update': no_redundant_should_component_update_1.noRedundantShouldComponentUpdate,
|
|
153
|
+
'react/no-render-return-value': no_render_return_value_1.noRenderReturnValue,
|
|
154
|
+
'react/no-typos': no_typos_1.noTypos,
|
|
155
|
+
'react/no-unescaped-entities': no_unescaped_entities_1.noUnescapedEntities,
|
|
156
|
+
'react/prefer-es6-class': prefer_es6_class_1.preferEs6Class,
|
|
157
|
+
'react/prefer-stateless-function': prefer_stateless_function_1.preferStatelessFunction,
|
|
158
|
+
'react/prop-types': prop_types_1.propTypes,
|
|
159
|
+
'react/react-in-jsx-scope': react_in_jsx_scope_1.reactInJsxScope,
|
|
160
|
+
'react/require-default-props': require_default_props_1.requireDefaultProps,
|
|
161
|
+
'react/require-render-return': require_render_return_1.requireRenderReturn,
|
|
162
|
+
'react/sort-comp': sort_comp_1.sortComp,
|
|
163
|
+
'react/state-in-constructor': state_in_constructor_1.stateInConstructor,
|
|
164
|
+
'react/static-property-placement': static_property_placement_1.staticPropertyPlacement,
|
|
165
|
+
'react/hooks-exhaustive-deps': hooks_exhaustive_deps_1.hooksExhaustiveDeps,
|
|
166
|
+
// Security and bug prevention (categorized)
|
|
167
|
+
'react/jsx-no-target-blank': jsx_no_target_blank_1.jsxNoTargetBlank,
|
|
168
|
+
'react/jsx-no-script-url': jsx_no_script_url_1.jsxNoScriptUrl,
|
|
169
|
+
'react/jsx-no-duplicate-props': jsx_no_duplicate_props_1.jsxNoDuplicateProps,
|
|
170
|
+
'react/no-danger-with-children': no_danger_with_children_1.noDangerWithChildren,
|
|
171
|
+
'react/no-deprecated': no_deprecated_1.noDeprecated,
|
|
172
|
+
// Deprecated API rules (categorized)
|
|
173
|
+
'react/no-find-dom-node': no_find_dom_node_1.noFindDomNode,
|
|
174
|
+
'react/no-unsafe': no_unsafe_1.noUnsafe,
|
|
175
|
+
'react/void-dom-elements-no-children': void_dom_elements_no_children_1.voidDomElementsNoChildren,
|
|
176
|
+
'migration/react-class-to-hooks': react_class_to_hooks_1.reactClassToHooks,
|
|
177
|
+
'performance/no-unnecessary-rerenders': no_unnecessary_rerenders_1.noUnnecessaryRerenders,
|
|
178
|
+
'performance/react-render-optimization': react_render_optimization_1.reactRenderOptimization,
|
|
179
|
+
'performance/react-no-inline-functions': react_no_inline_functions_1.reactNoInlineFunctions,
|
|
180
|
+
};
|
|
181
|
+
exports.plugin = {
|
|
182
|
+
meta: {
|
|
183
|
+
name: 'eslint-plugin-react-features',
|
|
184
|
+
version: '1.0.0',
|
|
185
|
+
},
|
|
186
|
+
rules: exports.rules,
|
|
187
|
+
};
|
|
188
|
+
exports.configs = {
|
|
189
|
+
recommended: {
|
|
190
|
+
plugins: {
|
|
191
|
+
'@eslint/react-features': exports.plugin,
|
|
192
|
+
},
|
|
193
|
+
rules: {
|
|
194
|
+
'@eslint/react-features/react/jsx-key': 'error',
|
|
195
|
+
'@eslint/react-features/react/no-children-prop': 'warn',
|
|
196
|
+
'@eslint/react-features/react/no-danger': 'warn',
|
|
197
|
+
'@eslint/react-features/react/no-string-refs': 'error',
|
|
198
|
+
'@eslint/react-features/react/no-unknown-property': 'error',
|
|
199
|
+
'@eslint/react-features/react/hooks-exhaustive-deps': 'warn',
|
|
200
|
+
// Security rules
|
|
201
|
+
'@eslint/react-features/react/jsx-no-target-blank': 'error',
|
|
202
|
+
'@eslint/react-features/react/jsx-no-script-url': 'error',
|
|
203
|
+
'@eslint/react-features/react/jsx-no-duplicate-props': 'error',
|
|
204
|
+
'@eslint/react-features/react/no-danger-with-children': 'error',
|
|
205
|
+
'@eslint/react-features/react/no-deprecated': 'warn',
|
|
206
|
+
// Performance
|
|
207
|
+
'@eslint/react-features/performance/no-unnecessary-rerenders': 'warn',
|
|
208
|
+
'@eslint/react-features/performance/react-render-optimization': 'warn',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
exports.default = exports.plugin;
|
|
@@ -0,0 +1,22 @@
|
|
|
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: react-class-to-hooks
|
|
8
|
+
* Detects React class components that can be migrated to hooks with transformation context
|
|
9
|
+
*/
|
|
10
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
11
|
+
type MessageIds = 'migrateToHooks' | 'convertToFunction' | 'viewMigrationGuide';
|
|
12
|
+
export interface Options {
|
|
13
|
+
/** Ignore PureComponent classes. Default: false */
|
|
14
|
+
ignorePureRenderComponents?: boolean;
|
|
15
|
+
/** Allow classes with complex lifecycle patterns. Default: false */
|
|
16
|
+
allowComplexLifecycle?: boolean;
|
|
17
|
+
}
|
|
18
|
+
type RuleOptions = [Options?];
|
|
19
|
+
export declare const reactClassToHooks: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,178 @@
|
|
|
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.reactClassToHooks = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
12
|
+
name: 'react-class-to-hooks',
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'suggestion',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Suggest migrating React class components to hooks with detailed migration path',
|
|
17
|
+
},
|
|
18
|
+
fixable: 'code',
|
|
19
|
+
hasSuggestions: true,
|
|
20
|
+
messages: {
|
|
21
|
+
// 🎯 Token optimization: 44% reduction (64→36 tokens) - class to hooks migration simplified
|
|
22
|
+
migrateToHooks: (0, eslint_devkit_1.formatLLMMessage)({
|
|
23
|
+
icon: eslint_devkit_1.MessageIcons.MIGRATION,
|
|
24
|
+
issueName: 'React class component',
|
|
25
|
+
cwe: 'CWE-1078',
|
|
26
|
+
description: 'React class component detected',
|
|
27
|
+
severity: 'MEDIUM',
|
|
28
|
+
fix: 'Use functional component with useEffect/useState (Complexity: {{complexity}})',
|
|
29
|
+
documentationLink: 'https://react.dev/reference/react/hooks',
|
|
30
|
+
}),
|
|
31
|
+
convertToFunction: (0, eslint_devkit_1.formatLLMMessage)({
|
|
32
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
33
|
+
issueName: 'Convert to Functional',
|
|
34
|
+
description: 'Convert to functional component with hooks',
|
|
35
|
+
severity: 'LOW',
|
|
36
|
+
fix: 'function Component() { const [state, setState] = useState() }',
|
|
37
|
+
documentationLink: 'https://react.dev/reference/react/hooks',
|
|
38
|
+
}),
|
|
39
|
+
viewMigrationGuide: (0, eslint_devkit_1.formatLLMMessage)({
|
|
40
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
41
|
+
issueName: 'Migration Guide',
|
|
42
|
+
description: 'View detailed migration guide',
|
|
43
|
+
severity: 'LOW',
|
|
44
|
+
fix: 'Follow React hooks migration guide',
|
|
45
|
+
documentationLink: 'https://react.dev/reference/react/hooks',
|
|
46
|
+
}),
|
|
47
|
+
},
|
|
48
|
+
schema: [
|
|
49
|
+
{
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
ignorePureRenderComponents: {
|
|
53
|
+
type: 'boolean',
|
|
54
|
+
default: false,
|
|
55
|
+
},
|
|
56
|
+
allowComplexLifecycle: {
|
|
57
|
+
type: 'boolean',
|
|
58
|
+
default: false,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
additionalProperties: false,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
defaultOptions: [
|
|
66
|
+
{
|
|
67
|
+
ignorePureRenderComponents: false,
|
|
68
|
+
allowComplexLifecycle: false,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
create(context) {
|
|
72
|
+
const options = context.options[0] || {};
|
|
73
|
+
const { allowComplexLifecycle = false } = options || {};
|
|
74
|
+
const sourceCode = context.sourceCode || context.sourceCode;
|
|
75
|
+
/**
|
|
76
|
+
* Check if class extends React.Component
|
|
77
|
+
*/
|
|
78
|
+
const isReactComponent = (node) => {
|
|
79
|
+
if (!node.superClass)
|
|
80
|
+
return false;
|
|
81
|
+
// Check for Identifier (e.g., Component, PureComponent)
|
|
82
|
+
if (node.superClass.type === 'Identifier') {
|
|
83
|
+
return (node.superClass.name === 'Component' ||
|
|
84
|
+
node.superClass.name === 'PureComponent');
|
|
85
|
+
}
|
|
86
|
+
// Check for MemberExpression (e.g., React.Component, React.PureComponent)
|
|
87
|
+
if (node.superClass.type === 'MemberExpression') {
|
|
88
|
+
if (node.superClass.object.type === 'Identifier' &&
|
|
89
|
+
node.superClass.object.name === 'React' &&
|
|
90
|
+
node.superClass.property.type === 'Identifier') {
|
|
91
|
+
return (node.superClass.property.name === 'Component' ||
|
|
92
|
+
node.superClass.property.name === 'PureComponent');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Analyze lifecycle methods used
|
|
99
|
+
*/
|
|
100
|
+
const analyzeLifecycleMethods = (node) => {
|
|
101
|
+
const lifecycleMethods = [];
|
|
102
|
+
const classBody = node.body.body;
|
|
103
|
+
const lifecycleMap = {
|
|
104
|
+
componentDidMount: 'useEffect',
|
|
105
|
+
componentDidUpdate: 'useEffect',
|
|
106
|
+
componentWillUnmount: 'useEffect cleanup',
|
|
107
|
+
shouldComponentUpdate: 'React.memo',
|
|
108
|
+
getDerivedStateFromProps: 'useState + useEffect',
|
|
109
|
+
getSnapshotBeforeUpdate: 'useEffect', // Complex lifecycle, no simple hook equivalent
|
|
110
|
+
};
|
|
111
|
+
for (const member of classBody) {
|
|
112
|
+
if (member.type === 'MethodDefinition' &&
|
|
113
|
+
member.key.type === 'Identifier' &&
|
|
114
|
+
lifecycleMap[member.key.name]) {
|
|
115
|
+
lifecycleMethods.push(member.key.name);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const suggestedHooks = [
|
|
119
|
+
...new Set(lifecycleMethods.map((m) => lifecycleMap[m])),
|
|
120
|
+
];
|
|
121
|
+
let complexity = 'simple';
|
|
122
|
+
if (lifecycleMethods.length > 2)
|
|
123
|
+
complexity = 'medium';
|
|
124
|
+
if (lifecycleMethods.includes('getDerivedStateFromProps') ||
|
|
125
|
+
lifecycleMethods.includes('getSnapshotBeforeUpdate')) {
|
|
126
|
+
complexity = 'complex';
|
|
127
|
+
}
|
|
128
|
+
return { methods: lifecycleMethods, suggestedHooks, complexity };
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
ClassDeclaration(node) {
|
|
132
|
+
if (!isReactComponent(node))
|
|
133
|
+
return;
|
|
134
|
+
if (!node.id)
|
|
135
|
+
return;
|
|
136
|
+
const componentName = node.id.name;
|
|
137
|
+
const { complexity, methods: lifecycleMethods } = analyzeLifecycleMethods(node);
|
|
138
|
+
// Check if component has render() method (fixer doesn't handle it properly)
|
|
139
|
+
const hasRenderMethod = node.body.body.some((member) => member.type === 'MethodDefinition' &&
|
|
140
|
+
member.key.type === 'Identifier' &&
|
|
141
|
+
member.key.name === 'render');
|
|
142
|
+
// Skip if too complex and option is set
|
|
143
|
+
if (complexity === 'complex' && allowComplexLifecycle) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
context.report({
|
|
147
|
+
node,
|
|
148
|
+
messageId: 'migrateToHooks',
|
|
149
|
+
data: {
|
|
150
|
+
componentName,
|
|
151
|
+
complexity,
|
|
152
|
+
},
|
|
153
|
+
// Only provide suggestions for simple components without lifecycle methods or render()
|
|
154
|
+
// The fixer doesn't work properly for components with lifecycle methods or render()
|
|
155
|
+
...(complexity === 'simple' && lifecycleMethods.length === 0 && !hasRenderMethod ? {
|
|
156
|
+
suggest: [
|
|
157
|
+
{
|
|
158
|
+
messageId: 'convertToFunction',
|
|
159
|
+
fix: (fixer) => {
|
|
160
|
+
// Simple auto-fix for basic components
|
|
161
|
+
const classText = sourceCode.getText(node);
|
|
162
|
+
// This is a simplified transformation
|
|
163
|
+
// Real implementation would need more sophisticated AST manipulation
|
|
164
|
+
const funcText = classText
|
|
165
|
+
// Match: class Name extends React.Component or class Name extends Component
|
|
166
|
+
.replace(/class\s+(\w+)\s+extends\s+(\w+\.)?\w+/, 'function $1(props)')
|
|
167
|
+
.replace(/this\.props\./g, 'props.')
|
|
168
|
+
.replace(/this\.state\.(\w+)/g, (_, name) => name);
|
|
169
|
+
return fixer.replaceText(node, funcText);
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
} : {}),
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
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-unnecessary-rerenders
|
|
8
|
+
* Detects prevented re-renders in React
|
|
9
|
+
* React-specific performance rule
|
|
10
|
+
*
|
|
11
|
+
* @see https://react.dev/reference/react/useMemo
|
|
12
|
+
* @see https://react.dev/reference/react/useCallback
|
|
13
|
+
*/
|
|
14
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
15
|
+
type MessageIds = 'unnecessaryRerender' | 'useMemo' | 'useCallback' | 'extractToVariable';
|
|
16
|
+
export interface Options {
|
|
17
|
+
/** Ignore in test files. Default: true */
|
|
18
|
+
ignoreInTests?: boolean;
|
|
19
|
+
/** Minimum array/object size to warn. Default: 5 */
|
|
20
|
+
minSize?: number;
|
|
21
|
+
}
|
|
22
|
+
type RuleOptions = [Options?];
|
|
23
|
+
export declare const noUnnecessaryRerenders: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,212 @@
|
|
|
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.noUnnecessaryRerenders = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
/**
|
|
12
|
+
* Check if a node is in a React component render context
|
|
13
|
+
*/
|
|
14
|
+
function isInReactRenderContext(node) {
|
|
15
|
+
let current = node;
|
|
16
|
+
let depth = 0;
|
|
17
|
+
const maxDepth = 15;
|
|
18
|
+
while (current && depth < maxDepth) {
|
|
19
|
+
const parent = current.parent;
|
|
20
|
+
if (!parent)
|
|
21
|
+
break;
|
|
22
|
+
// Check if we're in JSX
|
|
23
|
+
if (parent.type === 'JSXElement' || parent.type === 'JSXFragment') {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
// Check if we're in a JSX attribute
|
|
27
|
+
if (parent.type === 'JSXAttribute') {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
// Check if we're in a function that's likely a React component
|
|
31
|
+
if (parent.type === 'FunctionDeclaration' || parent.type === 'FunctionExpression' ||
|
|
32
|
+
parent.type === 'ArrowFunctionExpression') {
|
|
33
|
+
// Check function name patterns (Component, useCallback, etc.)
|
|
34
|
+
if (parent.type === 'FunctionDeclaration' && parent.id) {
|
|
35
|
+
const name = parent.id.name;
|
|
36
|
+
if (name && /^[A-Z]/.test(name)) { // PascalCase suggests React component
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Check for JSX return statement
|
|
41
|
+
const body = parent.type === 'FunctionDeclaration' ? parent.body :
|
|
42
|
+
parent.type === 'FunctionExpression' ? parent.body :
|
|
43
|
+
parent.body;
|
|
44
|
+
if (body && body.type === 'BlockStatement') {
|
|
45
|
+
const hasJSX = body.body.some((stmt) => stmt.type === 'ReturnStatement' &&
|
|
46
|
+
stmt.argument &&
|
|
47
|
+
(stmt.argument.type === 'JSXElement' || stmt.argument.type === 'JSXFragment'));
|
|
48
|
+
if (hasJSX) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
current = parent;
|
|
54
|
+
depth++;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if expression should be memoized
|
|
60
|
+
*/
|
|
61
|
+
function shouldBeMemoized(node, minSize = 5) {
|
|
62
|
+
// Check for object literals - only if they have at least minSize properties
|
|
63
|
+
if (node.type === 'ObjectExpression') {
|
|
64
|
+
const properties = node.properties.length;
|
|
65
|
+
return properties >= minSize;
|
|
66
|
+
}
|
|
67
|
+
// Check for array literals - only if they have at least minSize elements
|
|
68
|
+
if (node.type === 'ArrayExpression') {
|
|
69
|
+
const elements = node.elements.filter((el) => el !== null).length;
|
|
70
|
+
return elements >= minSize;
|
|
71
|
+
}
|
|
72
|
+
// Check for function expressions in JSX props (always report, size doesn't matter)
|
|
73
|
+
if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
exports.noUnnecessaryRerenders = (0, eslint_devkit_2.createRule)({
|
|
79
|
+
name: 'no-unnecessary-rerenders',
|
|
80
|
+
meta: {
|
|
81
|
+
type: 'suggestion',
|
|
82
|
+
docs: {
|
|
83
|
+
description: 'Detects prevented re-renders in React',
|
|
84
|
+
},
|
|
85
|
+
hasSuggestions: true,
|
|
86
|
+
messages: {
|
|
87
|
+
unnecessaryRerender: (0, eslint_devkit_1.formatLLMMessage)({
|
|
88
|
+
icon: eslint_devkit_1.MessageIcons.PERFORMANCE,
|
|
89
|
+
issueName: 'Unnecessary re-render',
|
|
90
|
+
description: '{{expression}} causes unnecessary re-renders',
|
|
91
|
+
severity: 'MEDIUM',
|
|
92
|
+
fix: 'Use useMemo or useCallback to memoize {{expression}}',
|
|
93
|
+
documentationLink: 'https://react.dev/reference/react/useMemo',
|
|
94
|
+
}),
|
|
95
|
+
useMemo: (0, eslint_devkit_1.formatLLMMessage)({
|
|
96
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
97
|
+
issueName: 'Use useMemo',
|
|
98
|
+
description: 'Memoize with useMemo',
|
|
99
|
+
severity: 'LOW',
|
|
100
|
+
fix: 'const memoized = useMemo(() => value, [deps])',
|
|
101
|
+
documentationLink: 'https://react.dev/reference/react/useMemo',
|
|
102
|
+
}),
|
|
103
|
+
useCallback: (0, eslint_devkit_1.formatLLMMessage)({
|
|
104
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
105
|
+
issueName: 'Use useCallback',
|
|
106
|
+
description: 'Memoize callback with useCallback',
|
|
107
|
+
severity: 'LOW',
|
|
108
|
+
fix: 'const handler = useCallback(() => {}, [deps])',
|
|
109
|
+
documentationLink: 'https://react.dev/reference/react/useCallback',
|
|
110
|
+
}),
|
|
111
|
+
extractToVariable: (0, eslint_devkit_1.formatLLMMessage)({
|
|
112
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
113
|
+
issueName: 'Extract Variable',
|
|
114
|
+
description: 'Extract to variable outside render',
|
|
115
|
+
severity: 'LOW',
|
|
116
|
+
fix: 'Define outside component or use useMemo',
|
|
117
|
+
documentationLink: 'https://react.dev/learn/render-and-commit',
|
|
118
|
+
}),
|
|
119
|
+
},
|
|
120
|
+
schema: [
|
|
121
|
+
{
|
|
122
|
+
type: 'object',
|
|
123
|
+
properties: {
|
|
124
|
+
ignoreInTests: {
|
|
125
|
+
type: 'boolean',
|
|
126
|
+
default: true,
|
|
127
|
+
},
|
|
128
|
+
minSize: {
|
|
129
|
+
type: 'number',
|
|
130
|
+
default: 5,
|
|
131
|
+
minimum: 1,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
additionalProperties: false,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
defaultOptions: [
|
|
139
|
+
{
|
|
140
|
+
ignoreInTests: true,
|
|
141
|
+
minSize: 5,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
create(context, [options = {}]) {
|
|
145
|
+
const { ignoreInTests = true, minSize = 5 } = options || {};
|
|
146
|
+
const filename = context.getFilename();
|
|
147
|
+
// Only skip if ignoreInTests is true AND filename matches test pattern
|
|
148
|
+
// If ignoreInTests is explicitly false, always run the rule
|
|
149
|
+
const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
150
|
+
if (isTestFile) {
|
|
151
|
+
return {};
|
|
152
|
+
}
|
|
153
|
+
const sourceCode = context.sourceCode || context.sourceCode;
|
|
154
|
+
/**
|
|
155
|
+
* Check JSX attributes for unnecessary re-renders
|
|
156
|
+
*/
|
|
157
|
+
function checkJSXAttribute(node) {
|
|
158
|
+
try {
|
|
159
|
+
if (!node.value) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const value = node.value.type === 'JSXExpressionContainer'
|
|
163
|
+
? node.value.expression
|
|
164
|
+
: null;
|
|
165
|
+
if (!value) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
// Only check if we're in a React render context
|
|
169
|
+
if (!isInReactRenderContext(value)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// Check if it's an object/array literal or function that should be memoized
|
|
173
|
+
if (shouldBeMemoized(value, minSize)) {
|
|
174
|
+
let expressionText = '';
|
|
175
|
+
try {
|
|
176
|
+
expressionText = sourceCode.getText(value).substring(0, 50);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
expressionText = 'expression';
|
|
180
|
+
}
|
|
181
|
+
// Determine which suggestion to use based on node type
|
|
182
|
+
const isFunction = value.type === 'ArrowFunctionExpression' || value.type === 'FunctionExpression';
|
|
183
|
+
const firstSuggestionMessageId = isFunction ? 'useCallback' : 'useMemo';
|
|
184
|
+
context.report({
|
|
185
|
+
node: value,
|
|
186
|
+
messageId: 'unnecessaryRerender',
|
|
187
|
+
data: {
|
|
188
|
+
expression: expressionText,
|
|
189
|
+
},
|
|
190
|
+
suggest: [
|
|
191
|
+
{
|
|
192
|
+
messageId: firstSuggestionMessageId,
|
|
193
|
+
fix: () => null,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
messageId: 'extractToVariable',
|
|
197
|
+
fix: () => null,
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// Silently skip if there's an error processing this attribute
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
JSXAttribute: checkJSXAttribute,
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
});
|