eslint-plugin-react-features 1.2.8 → 1.2.10

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 (65) hide show
  1. package/package.json +2 -3
  2. package/src/index.js +1 -239
  3. package/src/oxlint.js +1 -3
  4. package/src/rules/component-api/no-arbitrary-token-class.js +1 -74
  5. package/src/rules/component-api/no-default-test-id.js +1 -46
  6. package/src/rules/component-api/no-inline-style.js +1 -57
  7. package/src/rules/component-api/no-is-prefix-prop.js +1 -59
  8. package/src/rules/component-api/no-kind-prop-discriminator.js +1 -57
  9. package/src/rules/component-api/no-raw-color-literal.js +1 -55
  10. package/src/rules/component-api/no-wrapper-sub-component.js +1 -95
  11. package/src/rules/component-api/require-data-slot.js +1 -40
  12. package/src/rules/migration/react-class-to-hooks.js +1 -159
  13. package/src/rules/performance/no-unnecessary-rerenders.js +1 -185
  14. package/src/rules/performance/react-no-inline-functions.js +1 -187
  15. package/src/rules/performance/react-render-optimization.js +1 -256
  16. package/src/rules/react/checked-requires-onchange-or-readonly.js +1 -68
  17. package/src/rules/react/default-props-match-prop-types.js +1 -99
  18. package/src/rules/react/display-name.js +1 -133
  19. package/src/rules/react/hooks-exhaustive-deps.js +1 -466
  20. package/src/rules/react/jsx-handler-names.js +1 -50
  21. package/src/rules/react/jsx-key.js +1 -323
  22. package/src/rules/react/jsx-max-depth.js +1 -71
  23. package/src/rules/react/jsx-no-bind.js +1 -55
  24. package/src/rules/react/jsx-no-duplicate-props.js +1 -66
  25. package/src/rules/react/jsx-no-literals.js +1 -79
  26. package/src/rules/react/jsx-no-script-url.js +1 -119
  27. package/src/rules/react/jsx-no-target-blank.js +1 -163
  28. package/src/rules/react/no-access-state-in-setstate.js +1 -80
  29. package/src/rules/react/no-adjacent-inline-elements.js +1 -72
  30. package/src/rules/react/no-arrow-function-lifecycle.js +1 -57
  31. package/src/rules/react/no-children-prop.js +1 -54
  32. package/src/rules/react/no-danger-with-children.js +1 -99
  33. package/src/rules/react/no-danger.js +1 -43
  34. package/src/rules/react/no-deprecated.js +1 -130
  35. package/src/rules/react/no-did-mount-set-state.js +1 -50
  36. package/src/rules/react/no-did-update-set-state.js +1 -71
  37. package/src/rules/react/no-direct-mutation-state.js +3 -211
  38. package/src/rules/react/no-find-dom-node.js +1 -50
  39. package/src/rules/react/no-invalid-html-attribute.js +1 -80
  40. package/src/rules/react/no-is-mounted.js +1 -46
  41. package/src/rules/react/no-multi-comp.js +1 -150
  42. package/src/rules/react/no-namespace.js +1 -37
  43. package/src/rules/react/no-object-type-as-default-prop.js +1 -53
  44. package/src/rules/react/no-redundant-should-component-update.js +1 -50
  45. package/src/rules/react/no-render-return-value.js +1 -67
  46. package/src/rules/react/no-set-state.js +1 -45
  47. package/src/rules/react/no-string-refs.js +1 -61
  48. package/src/rules/react/no-this-in-sfc.js +1 -55
  49. package/src/rules/react/no-typos.js +1 -90
  50. package/src/rules/react/no-unescaped-entities.js +1 -44
  51. package/src/rules/react/no-unknown-property.js +1 -124
  52. package/src/rules/react/no-unsafe.js +1 -106
  53. package/src/rules/react/prefer-es6-class.js +1 -50
  54. package/src/rules/react/prefer-stateless-function.js +1 -126
  55. package/src/rules/react/prop-types.js +1 -143
  56. package/src/rules/react/react-in-jsx-scope.js +1 -86
  57. package/src/rules/react/require-default-props.js +1 -134
  58. package/src/rules/react/require-optimization.js +1 -397
  59. package/src/rules/react/require-render-return.js +1 -79
  60. package/src/rules/react/required-attributes.js +1 -185
  61. package/src/rules/react/sort-comp.js +1 -146
  62. package/src/rules/react/state-in-constructor.js +1 -95
  63. package/src/rules/react/static-property-placement.js +1 -122
  64. package/src/rules/react/void-dom-elements-no-children.js +1 -89
  65. package/src/types/index.js +1 -2
@@ -1,54 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noChildrenProp = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noChildrenProp = (0, eslint_devkit_1.createRule)({
7
- name: 'no-children-prop',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-children-prop.md',
12
- description: 'Disallow passing children as props',
13
- },
14
- schema: [],
15
- messages: {
16
- noChildrenProp: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.WARNING,
18
- issueName: 'Children as Prop',
19
- description: 'Passing children as a prop',
20
- severity: 'HIGH',
21
- fix: 'Use JSX children syntax: <Component>children</Component>',
22
- documentationLink: 'https://react.dev/learn/passing-props-to-a-component#passing-jsx-as-children',
23
- }),
24
- },
25
- },
26
- defaultOptions: [],
27
- create(context) {
28
- return {
29
- JSXAttribute(node) {
30
- if (node.name.type === 'JSXIdentifier' &&
31
- node.name.name === 'children') {
32
- context.report({
33
- node: node.name,
34
- messageId: 'noChildrenProp',
35
- });
36
- }
37
- },
38
- JSXSpreadAttribute(node) {
39
- if (node.argument.type === 'ObjectExpression') {
40
- for (const prop of node.argument.properties) {
41
- if (prop.type === 'Property' &&
42
- prop.key.type === 'Identifier' &&
43
- prop.key.name === 'children') {
44
- context.report({
45
- node: prop.key,
46
- messageId: 'noChildrenProp',
47
- });
48
- }
49
- }
50
- }
51
- },
52
- };
53
- },
54
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noChildrenProp=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noChildrenProp=(0,eslint_devkit_1.createRule)({name:"no-children-prop",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-children-prop.md",description:"Disallow passing children as props"},schema:[],messages:{noChildrenProp:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Children as Prop",description:"Passing children as a prop",severity:"HIGH",fix:"Use JSX children syntax: <Component>children</Component>",documentationLink:"https://react.dev/learn/passing-props-to-a-component#passing-jsx-as-children"})}},defaultOptions:[],create(context){return{JSXAttribute(node){if(node.name.type==="JSXIdentifier"&&node.name.name==="children"){context.report({node:node.name,messageId:"noChildrenProp"})}},JSXSpreadAttribute(node){if(node.argument.type==="ObjectExpression"){for(const prop of node.argument.properties){if(prop.type==="Property"&&prop.key.type==="Identifier"&&prop.key.name==="children"){context.report({node:prop.key,messageId:"noChildrenProp"})}}}}}}});
@@ -1,99 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDangerWithChildren = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noDangerWithChildren = (0, eslint_devkit_2.createRule)({
7
- name: 'no-danger-with-children',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-danger-with-children.md',
12
- description: 'Prevent using both children and dangerouslySetInnerHTML',
13
- },
14
- messages: {
15
- dangerWithChildren: (0, eslint_devkit_1.formatLLMMessage)({
16
- icon: eslint_devkit_1.MessageIcons.WARNING,
17
- issueName: 'dangerouslySetInnerHTML with Children',
18
- description: 'Cannot use children and dangerouslySetInnerHTML at the same time - React will throw an error',
19
- severity: 'CRITICAL',
20
- fix: 'Remove either children or dangerouslySetInnerHTML',
21
- documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger-with-children.md',
22
- }),
23
- },
24
- schema: [],
25
- },
26
- defaultOptions: [],
27
- create(context) {
28
- function hasDangerouslySetInnerHTML(node) {
29
- return node.attributes.some((attr) => attr.type === 'JSXAttribute' &&
30
- attr.name.type === 'JSXIdentifier' &&
31
- attr.name.name === 'dangerouslySetInnerHTML');
32
- }
33
- function hasChildrenProp(node) {
34
- return node.attributes.some((attr) => attr.type === 'JSXAttribute' &&
35
- attr.name.type === 'JSXIdentifier' &&
36
- attr.name.name === 'children');
37
- }
38
- function hasJSXChildren(node) {
39
- return node.children.some(child => {
40
- if (child.type === 'JSXText') {
41
- return !/^\s*$/.test(child.value);
42
- }
43
- if (child.type === 'JSXExpressionContainer') {
44
- return child.expression.type !== 'JSXEmptyExpression';
45
- }
46
- return true;
47
- });
48
- }
49
- return {
50
- JSXElement(node) {
51
- const openingElement = node.openingElement;
52
- if (!hasDangerouslySetInnerHTML(openingElement)) {
53
- return;
54
- }
55
- const hasChildren = hasChildrenProp(openingElement) || hasJSXChildren(node);
56
- if (hasChildren) {
57
- context.report({
58
- node: openingElement,
59
- messageId: 'dangerWithChildren',
60
- });
61
- }
62
- },
63
- CallExpression(node) {
64
- if (node.callee.type !== 'MemberExpression')
65
- return;
66
- if (node.callee.object.type !== 'Identifier' || node.callee.object.name !== 'React')
67
- return;
68
- if (node.callee.property.type !== 'Identifier' || node.callee.property.name !== 'createElement')
69
- return;
70
- if (node.arguments.length < 2)
71
- return;
72
- const propsArg = node.arguments[1];
73
- const hasExtraChildren = node.arguments.length > 2;
74
- if (propsArg.type !== 'ObjectExpression')
75
- return;
76
- let hasDanger = false;
77
- let hasChildrenInProps = false;
78
- for (const prop of propsArg.properties) {
79
- if (prop.type !== 'Property')
80
- continue;
81
- if (prop.key.type !== 'Identifier')
82
- continue;
83
- if (prop.key.name === 'dangerouslySetInnerHTML') {
84
- hasDanger = true;
85
- }
86
- if (prop.key.name === 'children') {
87
- hasChildrenInProps = true;
88
- }
89
- }
90
- if (hasDanger && (hasChildrenInProps || hasExtraChildren)) {
91
- context.report({
92
- node,
93
- messageId: 'dangerWithChildren',
94
- });
95
- }
96
- },
97
- };
98
- },
99
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDangerWithChildren=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noDangerWithChildren=(0,eslint_devkit_2.createRule)({name:"no-danger-with-children",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-danger-with-children.md",description:"Prevent using both children and dangerouslySetInnerHTML"},messages:{dangerWithChildren:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"dangerouslySetInnerHTML with Children",description:"Cannot use children and dangerouslySetInnerHTML at the same time - React will throw an error",severity:"CRITICAL",fix:"Remove either children or dangerouslySetInnerHTML",documentationLink:"https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger-with-children.md"})},schema:[]},defaultOptions:[],create(context){function hasDangerouslySetInnerHTML(node){return node.attributes.some(attr=>attr.type==="JSXAttribute"&&attr.name.type==="JSXIdentifier"&&attr.name.name==="dangerouslySetInnerHTML")}function hasChildrenProp(node){return node.attributes.some(attr=>attr.type==="JSXAttribute"&&attr.name.type==="JSXIdentifier"&&attr.name.name==="children")}function hasJSXChildren(node){return node.children.some(child=>{if(child.type==="JSXText"){return!/^\s*$/.test(child.value)}if(child.type==="JSXExpressionContainer"){return child.expression.type!=="JSXEmptyExpression"}return true})}return{JSXElement(node){const openingElement=node.openingElement;if(!hasDangerouslySetInnerHTML(openingElement)){return}const hasChildren=hasChildrenProp(openingElement)||hasJSXChildren(node);if(hasChildren){context.report({node:openingElement,messageId:"dangerWithChildren"})}},CallExpression(node){if(node.callee.type!=="MemberExpression")return;if(node.callee.object.type!=="Identifier"||node.callee.object.name!=="React")return;if(node.callee.property.type!=="Identifier"||node.callee.property.name!=="createElement")return;if(node.arguments.length<2)return;const propsArg=node.arguments[1];const hasExtraChildren=node.arguments.length>2;if(propsArg.type!=="ObjectExpression")return;let hasDanger=false;let hasChildrenInProps=false;for(const prop of propsArg.properties){if(prop.type!=="Property")continue;if(prop.key.type!=="Identifier")continue;if(prop.key.name==="dangerouslySetInnerHTML"){hasDanger=true}if(prop.key.name==="children"){hasChildrenInProps=true}}if(hasDanger&&(hasChildrenInProps||hasExtraChildren)){context.report({node,messageId:"dangerWithChildren"})}}}}});
@@ -1,43 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDanger = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noDanger = (0, eslint_devkit_1.createRule)({
7
- name: 'no-danger',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-danger.md',
12
- description: 'Disallow dangerouslySetInnerHTML usage',
13
- cwe: 'CWE-79',
14
- cvss: 9.5,
15
- },
16
- schema: [],
17
- messages: {
18
- noDanger: (0, eslint_devkit_2.formatLLMMessage)({
19
- icon: eslint_devkit_2.MessageIcons.SECURITY,
20
- issueName: 'Dangerous HTML',
21
- cwe: 'CWE-79',
22
- description: 'Usage of dangerouslySetInnerHTML detected',
23
- severity: 'CRITICAL',
24
- fix: 'Sanitize HTML input or use React elements instead',
25
- documentationLink: 'https://react.dev/reference/react-dom/components/common#dangerously-setting-the-inner-html',
26
- }),
27
- },
28
- },
29
- defaultOptions: [],
30
- create(context) {
31
- return {
32
- JSXAttribute(node) {
33
- if (node.name.type === 'JSXIdentifier' &&
34
- node.name.name === 'dangerouslySetInnerHTML') {
35
- context.report({
36
- node: node.name,
37
- messageId: 'noDanger',
38
- });
39
- }
40
- },
41
- };
42
- },
43
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDanger=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noDanger=(0,eslint_devkit_1.createRule)({name:"no-danger",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-danger.md",description:"Disallow dangerouslySetInnerHTML usage",cwe:"CWE-79",cvss:9.5},schema:[],messages:{noDanger:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Dangerous HTML",cwe:"CWE-79",description:"Usage of dangerouslySetInnerHTML detected",severity:"CRITICAL",fix:"Sanitize HTML input or use React elements instead",documentationLink:"https://react.dev/reference/react-dom/components/common#dangerously-setting-the-inner-html"})}},defaultOptions:[],create(context){return{JSXAttribute(node){if(node.name.type==="JSXIdentifier"&&node.name.name==="dangerouslySetInnerHTML"){context.report({node:node.name,messageId:"noDanger"})}}}}});
@@ -1,130 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDeprecated = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- const DEPRECATED_APIS = {
7
- 'React.createClass': { replacement: 'class extends React.Component', since: 'React 16' },
8
- 'React.PropTypes': { replacement: 'import PropTypes from "prop-types"', since: 'React 15.5' },
9
- 'React.findDOMNode': { replacement: 'refs', since: 'React 16.3' },
10
- 'ReactDOM.render': { replacement: 'createRoot().render()', since: 'React 18' },
11
- 'ReactDOM.hydrate': { replacement: 'hydrateRoot()', since: 'React 18' },
12
- 'ReactDOM.unmountComponentAtNode': { replacement: 'root.unmount()', since: 'React 18' },
13
- 'ReactDOM.findDOMNode': { replacement: 'refs', since: 'React 16.3' },
14
- 'componentWillMount': { replacement: 'componentDidMount or constructor', since: 'React 16.3' },
15
- 'componentWillReceiveProps': { replacement: 'static getDerivedStateFromProps', since: 'React 16.3' },
16
- 'componentWillUpdate': { replacement: 'getSnapshotBeforeUpdate', since: 'React 16.3' },
17
- 'UNSAFE_componentWillMount': { replacement: 'componentDidMount or constructor', since: 'React 17' },
18
- 'UNSAFE_componentWillReceiveProps': { replacement: 'static getDerivedStateFromProps', since: 'React 17' },
19
- 'UNSAFE_componentWillUpdate': { replacement: 'getSnapshotBeforeUpdate', since: 'React 17' },
20
- };
21
- exports.noDeprecated = (0, eslint_devkit_2.createRule)({
22
- name: 'no-deprecated',
23
- meta: {
24
- type: 'problem',
25
- docs: {
26
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-deprecated.md',
27
- description: 'Prevent using deprecated React methods',
28
- },
29
- messages: {
30
- deprecated: (0, eslint_devkit_1.formatLLMMessage)({
31
- icon: eslint_devkit_1.MessageIcons.DEPRECATION,
32
- issueName: 'Deprecated React API',
33
- description: '"{{name}}" is deprecated since {{since}}',
34
- severity: 'MEDIUM',
35
- fix: 'Use {{replacement}} instead',
36
- documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md',
37
- }),
38
- },
39
- schema: [],
40
- },
41
- defaultOptions: [],
42
- create(context) {
43
- let inClassComponent = false;
44
- function checkMemberExpression(node) {
45
- if (node.object.type !== 'Identifier')
46
- return;
47
- if (node.property.type !== 'Identifier')
48
- return;
49
- const fullName = `${node.object.name}.${node.property.name}`;
50
- const deprecation = DEPRECATED_APIS[fullName];
51
- if (deprecation) {
52
- context.report({
53
- node,
54
- messageId: 'deprecated',
55
- data: {
56
- name: fullName,
57
- replacement: deprecation.replacement,
58
- since: deprecation.since,
59
- },
60
- });
61
- }
62
- }
63
- function checkLifecycleMethod(node) {
64
- if (!inClassComponent)
65
- return;
66
- if (node.key.type !== 'Identifier')
67
- return;
68
- const methodName = node.key.name;
69
- const deprecation = DEPRECATED_APIS[methodName];
70
- if (deprecation) {
71
- context.report({
72
- node,
73
- messageId: 'deprecated',
74
- data: {
75
- name: methodName,
76
- replacement: deprecation.replacement,
77
- since: deprecation.since,
78
- },
79
- });
80
- }
81
- }
82
- return {
83
- ClassDeclaration(node) {
84
- if (!node.superClass)
85
- return;
86
- if (node.superClass.type === 'MemberExpression') {
87
- if (node.superClass.object.type === 'Identifier' &&
88
- node.superClass.object.name === 'React' &&
89
- node.superClass.property.type === 'Identifier' &&
90
- (node.superClass.property.name === 'Component' ||
91
- node.superClass.property.name === 'PureComponent')) {
92
- inClassComponent = true;
93
- }
94
- }
95
- else if (node.superClass.type === 'Identifier') {
96
- if (node.superClass.name === 'Component' || node.superClass.name === 'PureComponent') {
97
- inClassComponent = true;
98
- }
99
- }
100
- },
101
- 'ClassDeclaration:exit'() {
102
- inClassComponent = false;
103
- },
104
- ClassExpression(node) {
105
- if (!node.superClass)
106
- return;
107
- if (node.superClass.type === 'MemberExpression') {
108
- if (node.superClass.object.type === 'Identifier' &&
109
- node.superClass.object.name === 'React' &&
110
- node.superClass.property.type === 'Identifier' &&
111
- (node.superClass.property.name === 'Component' ||
112
- node.superClass.property.name === 'PureComponent')) {
113
- inClassComponent = true;
114
- }
115
- }
116
- else if (node.superClass.type === 'Identifier') {
117
- if (node.superClass.name === 'Component' || node.superClass.name === 'PureComponent') {
118
- inClassComponent = true;
119
- }
120
- }
121
- },
122
- 'ClassExpression:exit'() {
123
- inClassComponent = false;
124
- },
125
- MemberExpression: checkMemberExpression,
126
- MethodDefinition: checkLifecycleMethod,
127
- PropertyDefinition: checkLifecycleMethod,
128
- };
129
- },
130
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDeprecated=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const DEPRECATED_APIS={"React.createClass":{replacement:"class extends React.Component",since:"React 16"},"React.PropTypes":{replacement:'import PropTypes from "prop-types"',since:"React 15.5"},"React.findDOMNode":{replacement:"refs",since:"React 16.3"},"ReactDOM.render":{replacement:"createRoot().render()",since:"React 18"},"ReactDOM.hydrate":{replacement:"hydrateRoot()",since:"React 18"},"ReactDOM.unmountComponentAtNode":{replacement:"root.unmount()",since:"React 18"},"ReactDOM.findDOMNode":{replacement:"refs",since:"React 16.3"},"componentWillMount":{replacement:"componentDidMount or constructor",since:"React 16.3"},"componentWillReceiveProps":{replacement:"static getDerivedStateFromProps",since:"React 16.3"},"componentWillUpdate":{replacement:"getSnapshotBeforeUpdate",since:"React 16.3"},"UNSAFE_componentWillMount":{replacement:"componentDidMount or constructor",since:"React 17"},"UNSAFE_componentWillReceiveProps":{replacement:"static getDerivedStateFromProps",since:"React 17"},"UNSAFE_componentWillUpdate":{replacement:"getSnapshotBeforeUpdate",since:"React 17"}};exports.noDeprecated=(0,eslint_devkit_2.createRule)({name:"no-deprecated",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-deprecated.md",description:"Prevent using deprecated React methods"},messages:{deprecated:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.DEPRECATION,issueName:"Deprecated React API",description:'"{{name}}" is deprecated since {{since}}',severity:"MEDIUM",fix:"Use {{replacement}} instead",documentationLink:"https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md"})},schema:[]},defaultOptions:[],create(context){let inClassComponent=false;function checkMemberExpression(node){if(node.object.type!=="Identifier")return;if(node.property.type!=="Identifier")return;const fullName=`${node.object.name}.${node.property.name}`;const deprecation=DEPRECATED_APIS[fullName];if(deprecation){context.report({node,messageId:"deprecated",data:{name:fullName,replacement:deprecation.replacement,since:deprecation.since}})}}function checkLifecycleMethod(node){if(!inClassComponent)return;if(node.key.type!=="Identifier")return;const methodName=node.key.name;const deprecation=DEPRECATED_APIS[methodName];if(deprecation){context.report({node,messageId:"deprecated",data:{name:methodName,replacement:deprecation.replacement,since:deprecation.since}})}}return{ClassDeclaration(node){if(!node.superClass)return;if(node.superClass.type==="MemberExpression"){if(node.superClass.object.type==="Identifier"&&node.superClass.object.name==="React"&&node.superClass.property.type==="Identifier"&&(node.superClass.property.name==="Component"||node.superClass.property.name==="PureComponent")){inClassComponent=true}}else if(node.superClass.type==="Identifier"){if(node.superClass.name==="Component"||node.superClass.name==="PureComponent"){inClassComponent=true}}},"ClassDeclaration:exit"(){inClassComponent=false},ClassExpression(node){if(!node.superClass)return;if(node.superClass.type==="MemberExpression"){if(node.superClass.object.type==="Identifier"&&node.superClass.object.name==="React"&&node.superClass.property.type==="Identifier"&&(node.superClass.property.name==="Component"||node.superClass.property.name==="PureComponent")){inClassComponent=true}}else if(node.superClass.type==="Identifier"){if(node.superClass.name==="Component"||node.superClass.name==="PureComponent"){inClassComponent=true}}},"ClassExpression:exit"(){inClassComponent=false},MemberExpression:checkMemberExpression,MethodDefinition:checkLifecycleMethod,PropertyDefinition:checkLifecycleMethod}}});
@@ -1,50 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDidMountSetState = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noDidMountSetState = (0, eslint_devkit_1.createRule)({
7
- name: 'no-did-mount-set-state',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-did-mount-set-state.md',
12
- description: 'Prevent setState in componentDidMount',
13
- },
14
- schema: [],
15
- messages: {
16
- noDidMountSetState: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.WARNING,
18
- issueName: 'setState in componentDidMount',
19
- description: 'setState called in componentDidMount',
20
- severity: 'HIGH',
21
- fix: 'Use initial state or constructor instead',
22
- documentationLink: 'https://react.dev/reference/react/Component#componentdidmount',
23
- }),
24
- },
25
- },
26
- defaultOptions: [],
27
- create(context) {
28
- let inComponentDidMount = false;
29
- return {
30
- 'MethodDefinition[key.name="componentDidMount"]'() {
31
- inComponentDidMount = true;
32
- },
33
- 'MethodDefinition[key.name="componentDidMount"]:exit'() {
34
- inComponentDidMount = false;
35
- },
36
- CallExpression(node) {
37
- if (!inComponentDidMount)
38
- return;
39
- if (node.callee.type === 'MemberExpression' &&
40
- node.callee.property.type === 'Identifier' &&
41
- node.callee.property.name === 'setState') {
42
- context.report({
43
- node: node.callee.property,
44
- messageId: 'noDidMountSetState',
45
- });
46
- }
47
- },
48
- };
49
- },
50
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDidMountSetState=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noDidMountSetState=(0,eslint_devkit_1.createRule)({name:"no-did-mount-set-state",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-did-mount-set-state.md",description:"Prevent setState in componentDidMount"},schema:[],messages:{noDidMountSetState:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"setState in componentDidMount",description:"setState called in componentDidMount",severity:"HIGH",fix:"Use initial state or constructor instead",documentationLink:"https://react.dev/reference/react/Component#componentdidmount"})}},defaultOptions:[],create(context){let inComponentDidMount=false;return{'MethodDefinition[key.name="componentDidMount"]'(){inComponentDidMount=true},'MethodDefinition[key.name="componentDidMount"]:exit'(){inComponentDidMount=false},CallExpression(node){if(!inComponentDidMount)return;if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="setState"){context.report({node:node.callee.property,messageId:"noDidMountSetState"})}}}}});
@@ -1,71 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDidUpdateSetState = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noDidUpdateSetState = (0, eslint_devkit_1.createRule)({
7
- name: 'no-did-update-set-state',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-did-update-set-state.md',
12
- description: 'Prevent setState in componentDidUpdate',
13
- },
14
- messages: {
15
- noDidUpdateSetState: (0, eslint_devkit_2.formatLLMMessage)({
16
- icon: eslint_devkit_2.MessageIcons.WARNING,
17
- issueName: 'setState in componentDidUpdate',
18
- description: 'setState called in componentDidUpdate without condition',
19
- severity: 'HIGH',
20
- fix: 'Add condition to prevent infinite re-render loop',
21
- documentationLink: 'https://react.dev/reference/react/Component#componentdidupdate',
22
- }),
23
- },
24
- schema: [
25
- {
26
- type: 'object',
27
- properties: {
28
- allowInCallback: {
29
- type: 'boolean',
30
- default: false,
31
- },
32
- },
33
- additionalProperties: false,
34
- },
35
- ],
36
- },
37
- defaultOptions: [{ allowInCallback: false }],
38
- create(context) {
39
- const [options] = context.options;
40
- let inComponentDidUpdate = false;
41
- let hasConditionalCheck = false;
42
- return {
43
- 'MethodDefinition[key.name="componentDidUpdate"]'(node) {
44
- inComponentDidUpdate = true;
45
- hasConditionalCheck = false;
46
- },
47
- 'MethodDefinition[key.name="componentDidUpdate"]:exit'(node) {
48
- inComponentDidUpdate = false;
49
- },
50
- IfStatement(node) {
51
- if (inComponentDidUpdate) {
52
- hasConditionalCheck = true;
53
- }
54
- },
55
- CallExpression(node) {
56
- if (!inComponentDidUpdate)
57
- return;
58
- if (node.callee.type === 'MemberExpression' &&
59
- node.callee.property.type === 'Identifier' &&
60
- node.callee.property.name === 'setState') {
61
- if (!hasConditionalCheck && !options?.allowInCallback) {
62
- context.report({
63
- node: node.callee.property,
64
- messageId: 'noDidUpdateSetState',
65
- });
66
- }
67
- }
68
- },
69
- };
70
- },
71
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDidUpdateSetState=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noDidUpdateSetState=(0,eslint_devkit_1.createRule)({name:"no-did-update-set-state",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-did-update-set-state.md",description:"Prevent setState in componentDidUpdate"},messages:{noDidUpdateSetState:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"setState in componentDidUpdate",description:"setState called in componentDidUpdate without condition",severity:"HIGH",fix:"Add condition to prevent infinite re-render loop",documentationLink:"https://react.dev/reference/react/Component#componentdidupdate"})},schema:[{type:"object",properties:{allowInCallback:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{allowInCallback:false}],create(context){const[options]=context.options;let inComponentDidUpdate=false;let hasConditionalCheck=false;return{'MethodDefinition[key.name="componentDidUpdate"]'(node){inComponentDidUpdate=true;hasConditionalCheck=false},'MethodDefinition[key.name="componentDidUpdate"]:exit'(node){inComponentDidUpdate=false},IfStatement(node){if(inComponentDidUpdate){hasConditionalCheck=true}},CallExpression(node){if(!inComponentDidUpdate)return;if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="setState"){if(!hasConditionalCheck&&!options?.allowInCallback){context.report({node:node.callee.property,messageId:"noDidUpdateSetState"})}}}}}});