eslint-plugin-react-features 1.2.9 → 1.2.11

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 (66) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/src/index.js +1 -179
  4. package/src/oxlint.js +1 -3
  5. package/src/rules/component-api/no-arbitrary-token-class.js +1 -74
  6. package/src/rules/component-api/no-default-test-id.js +1 -46
  7. package/src/rules/component-api/no-inline-style.js +1 -57
  8. package/src/rules/component-api/no-is-prefix-prop.js +1 -59
  9. package/src/rules/component-api/no-kind-prop-discriminator.js +1 -57
  10. package/src/rules/component-api/no-raw-color-literal.js +1 -55
  11. package/src/rules/component-api/no-wrapper-sub-component.js +1 -95
  12. package/src/rules/component-api/require-data-slot.js +1 -40
  13. package/src/rules/migration/react-class-to-hooks.js +1 -159
  14. package/src/rules/performance/no-unnecessary-rerenders.js +1 -185
  15. package/src/rules/performance/react-no-inline-functions.js +1 -187
  16. package/src/rules/performance/react-render-optimization.js +1 -256
  17. package/src/rules/react/checked-requires-onchange-or-readonly.js +1 -68
  18. package/src/rules/react/default-props-match-prop-types.js +1 -99
  19. package/src/rules/react/display-name.js +1 -133
  20. package/src/rules/react/hooks-exhaustive-deps.js +1 -466
  21. package/src/rules/react/jsx-handler-names.js +1 -50
  22. package/src/rules/react/jsx-key.js +1 -323
  23. package/src/rules/react/jsx-max-depth.js +1 -71
  24. package/src/rules/react/jsx-no-bind.js +1 -55
  25. package/src/rules/react/jsx-no-duplicate-props.js +1 -66
  26. package/src/rules/react/jsx-no-literals.js +1 -79
  27. package/src/rules/react/jsx-no-script-url.js +1 -119
  28. package/src/rules/react/jsx-no-target-blank.js +1 -163
  29. package/src/rules/react/no-access-state-in-setstate.js +1 -80
  30. package/src/rules/react/no-adjacent-inline-elements.js +1 -72
  31. package/src/rules/react/no-arrow-function-lifecycle.js +1 -57
  32. package/src/rules/react/no-children-prop.js +1 -54
  33. package/src/rules/react/no-danger-with-children.js +1 -99
  34. package/src/rules/react/no-danger.js +1 -43
  35. package/src/rules/react/no-deprecated.js +1 -130
  36. package/src/rules/react/no-did-mount-set-state.js +1 -50
  37. package/src/rules/react/no-did-update-set-state.js +1 -71
  38. package/src/rules/react/no-direct-mutation-state.js +3 -211
  39. package/src/rules/react/no-find-dom-node.js +1 -50
  40. package/src/rules/react/no-invalid-html-attribute.js +1 -80
  41. package/src/rules/react/no-is-mounted.js +1 -46
  42. package/src/rules/react/no-multi-comp.js +1 -150
  43. package/src/rules/react/no-namespace.js +1 -37
  44. package/src/rules/react/no-object-type-as-default-prop.js +1 -53
  45. package/src/rules/react/no-redundant-should-component-update.js +1 -50
  46. package/src/rules/react/no-render-return-value.js +1 -67
  47. package/src/rules/react/no-set-state.js +1 -45
  48. package/src/rules/react/no-string-refs.js +1 -61
  49. package/src/rules/react/no-this-in-sfc.js +1 -55
  50. package/src/rules/react/no-typos.js +1 -90
  51. package/src/rules/react/no-unescaped-entities.js +1 -44
  52. package/src/rules/react/no-unknown-property.js +1 -124
  53. package/src/rules/react/no-unsafe.js +1 -106
  54. package/src/rules/react/prefer-es6-class.js +1 -50
  55. package/src/rules/react/prefer-stateless-function.js +1 -126
  56. package/src/rules/react/prop-types.js +1 -143
  57. package/src/rules/react/react-in-jsx-scope.js +1 -86
  58. package/src/rules/react/require-default-props.js +1 -134
  59. package/src/rules/react/require-optimization.js +1 -397
  60. package/src/rules/react/require-render-return.js +1 -79
  61. package/src/rules/react/required-attributes.js +1 -185
  62. package/src/rules/react/sort-comp.js +1 -146
  63. package/src/rules/react/state-in-constructor.js +1 -95
  64. package/src/rules/react/static-property-placement.js +1 -122
  65. package/src/rules/react/void-dom-elements-no-children.js +1 -89
  66. package/src/types/index.js +1 -2
@@ -1,79 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsxNoLiterals = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.jsxNoLiterals = (0, eslint_devkit_1.createRule)({
7
- name: 'jsx-no-literals',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-no-literals.md',
12
- description: 'Prevent string literals in JSX',
13
- },
14
- messages: {
15
- jsxNoLiterals: (0, eslint_devkit_2.formatLLMMessage)({
16
- icon: eslint_devkit_2.MessageIcons.WARNING,
17
- issueName: 'String Literal in JSX',
18
- description: 'String literal found in JSX',
19
- severity: 'MEDIUM',
20
- fix: 'Extract string to variable or use translation key',
21
- documentationLink: 'https://react.dev/learn/passing-props-to-a-component#passing-jsx-as-children',
22
- }),
23
- },
24
- schema: [
25
- {
26
- type: 'object',
27
- properties: {
28
- noStrings: {
29
- type: 'boolean',
30
- default: true,
31
- },
32
- allowedStrings: {
33
- type: 'array',
34
- items: { type: 'string' },
35
- default: [],
36
- },
37
- ignoreProps: {
38
- type: 'boolean',
39
- default: true,
40
- },
41
- },
42
- additionalProperties: false,
43
- },
44
- ],
45
- },
46
- defaultOptions: [{}],
47
- create(context) {
48
- const [options] = context.options;
49
- const noStrings = options?.noStrings ?? true;
50
- const allowedStrings = options?.allowedStrings ?? [];
51
- const ignoreProps = options?.ignoreProps ?? true;
52
- return {
53
- JSXText(node) {
54
- if (!noStrings)
55
- return;
56
- const text = node.value.trim();
57
- if (text && !allowedStrings.includes(text)) {
58
- context.report({
59
- node,
60
- messageId: 'jsxNoLiterals',
61
- });
62
- }
63
- },
64
- JSXAttribute(node) {
65
- if (ignoreProps)
66
- return;
67
- if (node.value && node.value.type === 'Literal' && typeof node.value.value === 'string') {
68
- const text = node.value.value.trim();
69
- if (text && !allowedStrings.includes(text)) {
70
- context.report({
71
- node: node.value,
72
- messageId: 'jsxNoLiterals',
73
- });
74
- }
75
- }
76
- },
77
- };
78
- },
79
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jsxNoLiterals=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.jsxNoLiterals=(0,eslint_devkit_1.createRule)({name:"jsx-no-literals",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-no-literals.md",description:"Prevent string literals in JSX"},messages:{jsxNoLiterals:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"String Literal in JSX",description:"String literal found in JSX",severity:"MEDIUM",fix:"Extract string to variable or use translation key",documentationLink:"https://react.dev/learn/passing-props-to-a-component#passing-jsx-as-children"})},schema:[{type:"object",properties:{noStrings:{type:"boolean",default:true},allowedStrings:{type:"array",items:{type:"string"},default:[]},ignoreProps:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{}],create(context){const[options]=context.options;const noStrings=options?.noStrings??true;const allowedStrings=options?.allowedStrings??[];const ignoreProps=options?.ignoreProps??true;return{JSXText(node){if(!noStrings)return;const text=node.value.trim();if(text&&!allowedStrings.includes(text)){context.report({node,messageId:"jsxNoLiterals"})}},JSXAttribute(node){if(ignoreProps)return;if(node.value&&node.value.type==="Literal"&&typeof node.value.value==="string"){const text=node.value.value.trim();if(text&&!allowedStrings.includes(text)){context.report({node:node.value,messageId:"jsxNoLiterals"})}}}}}});
@@ -1,119 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsxNoScriptUrl = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- const URL_PROPS = new Set(['href', 'src', 'action', 'formAction', 'data', 'poster', 'background']);
7
- exports.jsxNoScriptUrl = (0, eslint_devkit_2.createRule)({
8
- name: 'jsx-no-script-url',
9
- meta: {
10
- type: 'problem',
11
- docs: {
12
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-no-script-url.md',
13
- description: 'Forbid javascript: URLs',
14
- cwe: 'CWE-79',
15
- cvss: 9.5,
16
- },
17
- messages: {
18
- noScriptUrl: (0, eslint_devkit_1.formatLLMMessage)({
19
- icon: eslint_devkit_1.MessageIcons.SECURITY,
20
- issueName: 'javascript: URL',
21
- cwe: 'CWE-79',
22
- description: 'javascript: URLs are a security risk and can lead to XSS attacks',
23
- severity: 'CRITICAL',
24
- fix: 'Use an onClick handler instead or a proper href',
25
- documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-script-url.md',
26
- }),
27
- },
28
- schema: [
29
- {
30
- type: 'array',
31
- items: {
32
- type: 'object',
33
- properties: {
34
- name: { type: 'string' },
35
- props: { type: 'array', items: { type: 'string' } },
36
- },
37
- required: ['name', 'props'],
38
- additionalProperties: false,
39
- },
40
- },
41
- {
42
- type: 'object',
43
- properties: {
44
- includeFromSettings: { type: 'boolean' },
45
- },
46
- additionalProperties: false,
47
- },
48
- ],
49
- },
50
- defaultOptions: [[], {}],
51
- create(context, [componentConfigs = []]) {
52
- const componentPropsMap = new Map();
53
- for (const config of componentConfigs) {
54
- componentPropsMap.set(config.name, new Set(config.props));
55
- }
56
- function isJavaScriptUrl(value) {
57
- return /^\s*javascript:/i.test(value);
58
- }
59
- function checkAttribute(node, elementName) {
60
- if (node.name.type !== 'JSXIdentifier')
61
- return;
62
- const propName = node.name.name;
63
- const isUrlProp = URL_PROPS.has(propName);
64
- const customProps = componentPropsMap.get(elementName);
65
- const isCustomProp = customProps?.has(propName);
66
- if (!isUrlProp && !isCustomProp)
67
- return;
68
- if (!node.value)
69
- return;
70
- if (node.value.type === 'Literal' && typeof node.value.value === 'string') {
71
- if (isJavaScriptUrl(node.value.value)) {
72
- context.report({
73
- node,
74
- messageId: 'noScriptUrl',
75
- });
76
- }
77
- }
78
- if (node.value.type === 'JSXExpressionContainer') {
79
- const expr = node.value.expression;
80
- if (expr.type === 'Literal' && typeof expr.value === 'string') {
81
- if (isJavaScriptUrl(expr.value)) {
82
- context.report({
83
- node,
84
- messageId: 'noScriptUrl',
85
- });
86
- }
87
- }
88
- if (expr.type === 'TemplateLiteral' && expr.quasis.length > 0) {
89
- const firstQuasi = expr.quasis[0];
90
- if (firstQuasi && isJavaScriptUrl(firstQuasi.value.raw)) {
91
- context.report({
92
- node,
93
- messageId: 'noScriptUrl',
94
- });
95
- }
96
- }
97
- }
98
- }
99
- return {
100
- JSXOpeningElement(node) {
101
- let elementName;
102
- if (node.name.type === 'JSXIdentifier') {
103
- elementName = node.name.name;
104
- }
105
- else if (node.name.type === 'JSXMemberExpression') {
106
- elementName = context.sourceCode.getText(node.name);
107
- }
108
- else {
109
- return;
110
- }
111
- for (const attr of node.attributes) {
112
- if (attr.type === 'JSXAttribute') {
113
- checkAttribute(attr, elementName);
114
- }
115
- }
116
- },
117
- };
118
- },
119
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jsxNoScriptUrl=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const URL_PROPS=new Set(["href","src","action","formAction","data","poster","background"]);exports.jsxNoScriptUrl=(0,eslint_devkit_2.createRule)({name:"jsx-no-script-url",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-no-script-url.md",description:"Forbid javascript: URLs",cwe:"CWE-79",cvss:9.5},messages:{noScriptUrl:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"javascript: URL",cwe:"CWE-79",description:"javascript: URLs are a security risk and can lead to XSS attacks",severity:"CRITICAL",fix:"Use an onClick handler instead or a proper href",documentationLink:"https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-script-url.md"})},schema:[{type:"array",items:{type:"object",properties:{name:{type:"string"},props:{type:"array",items:{type:"string"}}},required:["name","props"],additionalProperties:false}},{type:"object",properties:{includeFromSettings:{type:"boolean"}},additionalProperties:false}]},defaultOptions:[[],{}],create(context,[componentConfigs=[]]){const componentPropsMap=new Map;for(const config of componentConfigs){componentPropsMap.set(config.name,new Set(config.props))}function isJavaScriptUrl(value){return/^\s*javascript:/i.test(value)}function checkAttribute(node,elementName){if(node.name.type!=="JSXIdentifier")return;const propName=node.name.name;const isUrlProp=URL_PROPS.has(propName);const customProps=componentPropsMap.get(elementName);const isCustomProp=customProps?.has(propName);if(!isUrlProp&&!isCustomProp)return;if(!node.value)return;if(node.value.type==="Literal"&&typeof node.value.value==="string"){if(isJavaScriptUrl(node.value.value)){context.report({node,messageId:"noScriptUrl"})}}if(node.value.type==="JSXExpressionContainer"){const expr=node.value.expression;if(expr.type==="Literal"&&typeof expr.value==="string"){if(isJavaScriptUrl(expr.value)){context.report({node,messageId:"noScriptUrl"})}}if(expr.type==="TemplateLiteral"&&expr.quasis.length>0){const firstQuasi=expr.quasis[0];if(firstQuasi&&isJavaScriptUrl(firstQuasi.value.raw)){context.report({node,messageId:"noScriptUrl"})}}}}return{JSXOpeningElement(node){let elementName;if(node.name.type==="JSXIdentifier"){elementName=node.name.name}else if(node.name.type==="JSXMemberExpression"){elementName=context.sourceCode.getText(node.name)}else{return}for(const attr of node.attributes){if(attr.type==="JSXAttribute"){checkAttribute(attr,elementName)}}}}}});
@@ -1,163 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsxNoTargetBlank = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.jsxNoTargetBlank = (0, eslint_devkit_2.createRule)({
7
- name: 'jsx-no-target-blank',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-no-target-blank.md',
12
- description: 'Forbid target="_blank" without rel="noopener noreferrer"',
13
- cwe: 'CWE-1022',
14
- cvss: 7.5,
15
- },
16
- fixable: 'code',
17
- messages: {
18
- noTargetBlank: (0, eslint_devkit_1.formatLLMMessage)({
19
- icon: eslint_devkit_1.MessageIcons.SECURITY,
20
- issueName: 'Unsafe target="_blank"',
21
- cwe: 'CWE-1022',
22
- description: 'Using target="_blank" without rel="noopener noreferrer" is a security risk',
23
- severity: 'HIGH',
24
- fix: 'Add rel="noopener noreferrer" to prevent reverse tabnabbing',
25
- documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md',
26
- }),
27
- noRelWithoutNoopener: (0, eslint_devkit_1.formatLLMMessage)({
28
- icon: eslint_devkit_1.MessageIcons.SECURITY,
29
- issueName: 'Missing noopener',
30
- cwe: 'CWE-1022',
31
- description: 'rel attribute is missing "noopener" value',
32
- severity: 'MEDIUM',
33
- fix: 'Add "noopener" to the rel attribute',
34
- documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md',
35
- }),
36
- },
37
- schema: [
38
- {
39
- type: 'object',
40
- properties: {
41
- allowReferrer: { type: 'boolean', default: false },
42
- enforceDynamicLinks: {
43
- type: 'string',
44
- enum: ['always', 'never'],
45
- default: 'always'
46
- },
47
- warnOnSpreadAttributes: { type: 'boolean', default: false },
48
- links: { type: 'boolean', default: true },
49
- forms: { type: 'boolean', default: false },
50
- },
51
- additionalProperties: false,
52
- },
53
- ],
54
- },
55
- defaultOptions: [{}],
56
- create(context, [options = {}]) {
57
- const { allowReferrer = false, enforceDynamicLinks = 'always', warnOnSpreadAttributes = false, links = true, forms = false, } = options ?? {};
58
- const elementsToCheck = [];
59
- if (links)
60
- elementsToCheck.push('a');
61
- if (forms)
62
- elementsToCheck.push('form');
63
- function hasTargetBlank(node) {
64
- const targetAttr = node.attributes.find((attr) => attr.type === 'JSXAttribute' &&
65
- attr.name.type === 'JSXIdentifier' &&
66
- attr.name.name === 'target');
67
- if (!targetAttr || !targetAttr.value)
68
- return false;
69
- if (targetAttr.value.type === 'Literal') {
70
- return targetAttr.value.value === '_blank';
71
- }
72
- if (enforceDynamicLinks === 'always') {
73
- return true;
74
- }
75
- return false;
76
- }
77
- function hasExternalHref(node) {
78
- const hrefAttr = node.attributes.find((attr) => attr.type === 'JSXAttribute' &&
79
- attr.name.type === 'JSXIdentifier' &&
80
- attr.name.name === 'href');
81
- if (!hrefAttr || !hrefAttr.value)
82
- return false;
83
- if (hrefAttr.value.type === 'Literal' && typeof hrefAttr.value.value === 'string') {
84
- const href = hrefAttr.value.value;
85
- return /^(https?:)?\/\//.test(href) || href.startsWith('//');
86
- }
87
- return enforceDynamicLinks === 'always';
88
- }
89
- function getRelAttribute(node) {
90
- return node.attributes.find((attr) => attr.type === 'JSXAttribute' &&
91
- attr.name.type === 'JSXIdentifier' &&
92
- attr.name.name === 'rel');
93
- }
94
- function hasNoopener(relAttr) {
95
- if (!relAttr.value)
96
- return false;
97
- if (relAttr.value.type === 'Literal' && typeof relAttr.value.value === 'string') {
98
- const relValues = relAttr.value.value.toLowerCase().split(/\s+/);
99
- return relValues.includes('noopener');
100
- }
101
- return false;
102
- }
103
- function hasNoreferrer(relAttr) {
104
- if (!relAttr.value)
105
- return false;
106
- if (relAttr.value.type === 'Literal' && typeof relAttr.value.value === 'string') {
107
- const relValues = relAttr.value.value.toLowerCase().split(/\s+/);
108
- return relValues.includes('noreferrer');
109
- }
110
- return false;
111
- }
112
- function hasSpreadAttribute(node) {
113
- return node.attributes.some(attr => attr.type === 'JSXSpreadAttribute');
114
- }
115
- return {
116
- JSXOpeningElement(node) {
117
- if (node.name.type !== 'JSXIdentifier' || !elementsToCheck.includes(node.name.name)) {
118
- return;
119
- }
120
- if (hasSpreadAttribute(node) && !warnOnSpreadAttributes) {
121
- return;
122
- }
123
- if (!hasTargetBlank(node)) {
124
- return;
125
- }
126
- if (node.name.name === 'a' && !hasExternalHref(node)) {
127
- return;
128
- }
129
- const relAttr = getRelAttribute(node);
130
- const hasNoopenerValue = relAttr ? hasNoopener(relAttr) : false;
131
- const hasNoreferrerValue = relAttr ? hasNoreferrer(relAttr) : false;
132
- if (hasNoopenerValue || hasNoreferrerValue) {
133
- if (!allowReferrer && !hasNoreferrerValue) {
134
- return;
135
- }
136
- return;
137
- }
138
- context.report({
139
- node,
140
- messageId: relAttr ? 'noRelWithoutNoopener' : 'noTargetBlank',
141
- fix: (fixer) => {
142
- if (relAttr && relAttr.value && relAttr.value.type === 'Literal') {
143
- const currentRel = String(relAttr.value.value);
144
- const newRel = allowReferrer
145
- ? `${currentRel} noopener`.trim()
146
- : `${currentRel} noopener noreferrer`.trim();
147
- return fixer.replaceText(relAttr.value, `"${newRel}"`);
148
- }
149
- else if (!relAttr) {
150
- const lastAttr = node.attributes[node.attributes.length - 1];
151
- const relValue = allowReferrer ? 'noopener' : 'noopener noreferrer';
152
- if (lastAttr) {
153
- return fixer.insertTextAfter(lastAttr, ` rel="${relValue}"`);
154
- }
155
- return fixer.insertTextAfter(node.name, ` rel="${relValue}"`);
156
- }
157
- return null;
158
- },
159
- });
160
- },
161
- };
162
- },
163
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jsxNoTargetBlank=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.jsxNoTargetBlank=(0,eslint_devkit_2.createRule)({name:"jsx-no-target-blank",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/jsx-no-target-blank.md",description:'Forbid target="_blank" without rel="noopener noreferrer"',cwe:"CWE-1022",cvss:7.5},fixable:"code",messages:{noTargetBlank:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:'Unsafe target="_blank"',cwe:"CWE-1022",description:'Using target="_blank" without rel="noopener noreferrer" is a security risk',severity:"HIGH",fix:'Add rel="noopener noreferrer" to prevent reverse tabnabbing',documentationLink:"https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md"}),noRelWithoutNoopener:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing noopener",cwe:"CWE-1022",description:'rel attribute is missing "noopener" value',severity:"MEDIUM",fix:'Add "noopener" to the rel attribute',documentationLink:"https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md"})},schema:[{type:"object",properties:{allowReferrer:{type:"boolean",default:false},enforceDynamicLinks:{type:"string",enum:["always","never"],default:"always"},warnOnSpreadAttributes:{type:"boolean",default:false},links:{type:"boolean",default:true},forms:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{}],create(context,[options={}]){const{allowReferrer=false,enforceDynamicLinks="always",warnOnSpreadAttributes=false,links=true,forms=false}=options??{};const elementsToCheck=[];if(links)elementsToCheck.push("a");if(forms)elementsToCheck.push("form");function hasTargetBlank(node){const targetAttr=node.attributes.find(attr=>attr.type==="JSXAttribute"&&attr.name.type==="JSXIdentifier"&&attr.name.name==="target");if(!targetAttr||!targetAttr.value)return false;if(targetAttr.value.type==="Literal"){return targetAttr.value.value==="_blank"}if(enforceDynamicLinks==="always"){return true}return false}function hasExternalHref(node){const hrefAttr=node.attributes.find(attr=>attr.type==="JSXAttribute"&&attr.name.type==="JSXIdentifier"&&attr.name.name==="href");if(!hrefAttr||!hrefAttr.value)return false;if(hrefAttr.value.type==="Literal"&&typeof hrefAttr.value.value==="string"){const href=hrefAttr.value.value;return/^(https?:)?\/\//.test(href)||href.startsWith("//")}return enforceDynamicLinks==="always"}function getRelAttribute(node){return node.attributes.find(attr=>attr.type==="JSXAttribute"&&attr.name.type==="JSXIdentifier"&&attr.name.name==="rel")}function hasNoopener(relAttr){if(!relAttr.value)return false;if(relAttr.value.type==="Literal"&&typeof relAttr.value.value==="string"){const relValues=relAttr.value.value.toLowerCase().split(/\s+/);return relValues.includes("noopener")}return false}function hasNoreferrer(relAttr){if(!relAttr.value)return false;if(relAttr.value.type==="Literal"&&typeof relAttr.value.value==="string"){const relValues=relAttr.value.value.toLowerCase().split(/\s+/);return relValues.includes("noreferrer")}return false}function hasSpreadAttribute(node){return node.attributes.some(attr=>attr.type==="JSXSpreadAttribute")}return{JSXOpeningElement(node){if(node.name.type!=="JSXIdentifier"||!elementsToCheck.includes(node.name.name)){return}if(hasSpreadAttribute(node)&&!warnOnSpreadAttributes){return}if(!hasTargetBlank(node)){return}if(node.name.name==="a"&&!hasExternalHref(node)){return}const relAttr=getRelAttribute(node);const hasNoopenerValue=relAttr?hasNoopener(relAttr):false;const hasNoreferrerValue=relAttr?hasNoreferrer(relAttr):false;if(hasNoopenerValue||hasNoreferrerValue){if(!allowReferrer&&!hasNoreferrerValue){return}return}context.report({node,messageId:relAttr?"noRelWithoutNoopener":"noTargetBlank",fix:fixer=>{if(relAttr&&relAttr.value&&relAttr.value.type==="Literal"){const currentRel=String(relAttr.value.value);const newRel=allowReferrer?`${currentRel} noopener`.trim():`${currentRel} noopener noreferrer`.trim();return fixer.replaceText(relAttr.value,`"${newRel}"`)}else if(!relAttr){const lastAttr=node.attributes[node.attributes.length-1];const relValue=allowReferrer?"noopener":"noopener noreferrer";if(lastAttr){return fixer.insertTextAfter(lastAttr,` rel="${relValue}"`)}return fixer.insertTextAfter(node.name,` rel="${relValue}"`)}return null}})}}}});
@@ -1,80 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noAccessStateInSetState = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noAccessStateInSetState = (0, eslint_devkit_1.createRule)({
7
- name: 'no-access-state-in-setstate',
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-access-state-in-setstate.md',
12
- description: 'Disallow accessing this.state inside setState calls',
13
- },
14
- schema: [],
15
- messages: {
16
- noAccessStateInSetState: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.WARNING,
18
- issueName: 'State Access in setState',
19
- description: 'Accessing this.state inside setState call',
20
- severity: 'HIGH',
21
- fix: 'Use functional setState: this.setState(prevState => ({...prevState, ...updates}))',
22
- documentationLink: 'https://react.dev/reference/react/Component#setstate',
23
- }),
24
- },
25
- },
26
- defaultOptions: [],
27
- create(context) {
28
- return {
29
- CallExpression(node) {
30
- if (node.callee.type === 'MemberExpression' &&
31
- node.callee.property.type === 'Identifier' &&
32
- node.callee.property.name === 'setState' &&
33
- node.arguments.length > 0) {
34
- const [firstArg] = node.arguments;
35
- if (firstArg && containsThisStateAccess(firstArg)) {
36
- context.report({
37
- node: node.callee.property,
38
- messageId: 'noAccessStateInSetState',
39
- });
40
- }
41
- }
42
- },
43
- };
44
- },
45
- });
46
- function containsThisStateAccess(node, visited = new Set()) {
47
- if (visited.has(node)) {
48
- return false;
49
- }
50
- visited.add(node);
51
- if (node.type === 'MemberExpression') {
52
- if (node.object.type === 'ThisExpression' &&
53
- node.property.type === 'Identifier' &&
54
- node.property.name === 'state') {
55
- return true;
56
- }
57
- }
58
- for (const key in node) {
59
- if (key === 'parent' || key === 'loc' || key === 'range')
60
- continue;
61
- const child = node[key];
62
- if (child && typeof child === 'object') {
63
- if (Array.isArray(child)) {
64
- for (const item of child) {
65
- if (item && typeof item === 'object' && 'type' in item) {
66
- if (containsThisStateAccess(item, visited)) {
67
- return true;
68
- }
69
- }
70
- }
71
- }
72
- else if ('type' in child && child.type !== 'Program') {
73
- if (containsThisStateAccess(child, visited)) {
74
- return true;
75
- }
76
- }
77
- }
78
- }
79
- return false;
80
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noAccessStateInSetState=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noAccessStateInSetState=(0,eslint_devkit_1.createRule)({name:"no-access-state-in-setstate",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-access-state-in-setstate.md",description:"Disallow accessing this.state inside setState calls"},schema:[],messages:{noAccessStateInSetState:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"State Access in setState",description:"Accessing this.state inside setState call",severity:"HIGH",fix:"Use functional setState: this.setState(prevState => ({...prevState, ...updates}))",documentationLink:"https://react.dev/reference/react/Component#setstate"})}},defaultOptions:[],create(context){return{CallExpression(node){if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="setState"&&node.arguments.length>0){const[firstArg]=node.arguments;if(firstArg&&containsThisStateAccess(firstArg)){context.report({node:node.callee.property,messageId:"noAccessStateInSetState"})}}}}}});function containsThisStateAccess(node,visited=new Set){if(visited.has(node)){return false}visited.add(node);if(node.type==="MemberExpression"){if(node.object.type==="ThisExpression"&&node.property.type==="Identifier"&&node.property.name==="state"){return true}}for(const key in node){if(key==="parent"||key==="loc"||key==="range")continue;const child=node[key];if(child&&typeof child==="object"){if(Array.isArray(child)){for(const item of child){if(item&&typeof item==="object"&&"type"in item){if(containsThisStateAccess(item,visited)){return true}}}}else if("type"in child&&child.type!=="Program"){if(containsThisStateAccess(child,visited)){return true}}}}return false}
@@ -1,72 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noAdjacentInlineElements = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- const INLINE_ELEMENTS = new Set([
7
- 'span', 'a', 'strong', 'em', 'b', 'i', 'u', 'small', 'big', 'sub', 'sup',
8
- 'code', 'kbd', 'samp', 'var', 'cite', 'abbr', 'acronym', 'dfn', 'q', 'time',
9
- 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'wbr', 'ins', 'del', 's', 'strike'
10
- ]);
11
- exports.noAdjacentInlineElements = (0, eslint_devkit_1.createRule)({
12
- name: 'no-adjacent-inline-elements',
13
- meta: {
14
- type: 'problem',
15
- docs: {
16
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-adjacent-inline-elements.md',
17
- description: 'Prevent adjacent inline elements',
18
- },
19
- schema: [],
20
- messages: {
21
- noAdjacentInlineElements: (0, eslint_devkit_2.formatLLMMessage)({
22
- icon: eslint_devkit_2.MessageIcons.WARNING,
23
- issueName: 'Adjacent Inline Elements',
24
- description: 'Adjacent inline elements can cause layout issues',
25
- severity: 'MEDIUM',
26
- fix: 'Wrap adjacent inline elements in a block-level container',
27
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements',
28
- }),
29
- },
30
- },
31
- defaultOptions: [],
32
- create(context) {
33
- return {
34
- JSXElement(node) {
35
- if (node.children.length < 2)
36
- return;
37
- let consecutiveInlineCount = 0;
38
- let lastInlineElement = null;
39
- for (const child of node.children) {
40
- if (child.type === 'JSXElement') {
41
- const elementName = getElementName(child);
42
- if (elementName && INLINE_ELEMENTS.has(elementName)) {
43
- consecutiveInlineCount++;
44
- lastInlineElement = child;
45
- if (consecutiveInlineCount >= 2) {
46
- context.report({
47
- node: lastInlineElement.openingElement.name,
48
- messageId: 'noAdjacentInlineElements',
49
- });
50
- }
51
- }
52
- else {
53
- consecutiveInlineCount = 0;
54
- lastInlineElement = null;
55
- }
56
- }
57
- else if (child.type === 'JSXText') {
58
- consecutiveInlineCount = 0;
59
- lastInlineElement = null;
60
- }
61
- }
62
- },
63
- };
64
- },
65
- });
66
- function getElementName(node) {
67
- const openingElement = node.openingElement;
68
- if (openingElement.name.type === 'JSXIdentifier') {
69
- return openingElement.name.name;
70
- }
71
- return null;
72
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noAdjacentInlineElements=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const INLINE_ELEMENTS=new Set(["span","a","strong","em","b","i","u","small","big","sub","sup","code","kbd","samp","var","cite","abbr","acronym","dfn","q","time","mark","ruby","rt","rp","bdi","bdo","wbr","ins","del","s","strike"]);exports.noAdjacentInlineElements=(0,eslint_devkit_1.createRule)({name:"no-adjacent-inline-elements",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-adjacent-inline-elements.md",description:"Prevent adjacent inline elements"},schema:[],messages:{noAdjacentInlineElements:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Adjacent Inline Elements",description:"Adjacent inline elements can cause layout issues",severity:"MEDIUM",fix:"Wrap adjacent inline elements in a block-level container",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements"})}},defaultOptions:[],create(context){return{JSXElement(node){if(node.children.length<2)return;let consecutiveInlineCount=0;let lastInlineElement=null;for(const child of node.children){if(child.type==="JSXElement"){const elementName=getElementName(child);if(elementName&&INLINE_ELEMENTS.has(elementName)){consecutiveInlineCount++;lastInlineElement=child;if(consecutiveInlineCount>=2){context.report({node:lastInlineElement.openingElement.name,messageId:"noAdjacentInlineElements"})}}else{consecutiveInlineCount=0;lastInlineElement=null}}else if(child.type==="JSXText"){consecutiveInlineCount=0;lastInlineElement=null}}}}}});function getElementName(node){const openingElement=node.openingElement;if(openingElement.name.type==="JSXIdentifier"){return openingElement.name.name}return null}
@@ -1,57 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noArrowFunctionLifecycle = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- const LIFECYCLE_METHODS = new Set([
7
- 'componentDidMount',
8
- 'componentDidUpdate',
9
- 'componentWillUnmount',
10
- 'componentWillMount',
11
- 'componentWillReceiveProps',
12
- 'componentWillUpdate',
13
- 'shouldComponentUpdate',
14
- 'getDerivedStateFromProps',
15
- 'getSnapshotBeforeUpdate',
16
- 'componentDidCatch',
17
- 'UNSAFE_componentWillMount',
18
- 'UNSAFE_componentWillReceiveProps',
19
- 'UNSAFE_componentWillUpdate',
20
- ]);
21
- exports.noArrowFunctionLifecycle = (0, eslint_devkit_1.createRule)({
22
- name: 'no-arrow-function-lifecycle',
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-arrow-function-lifecycle.md',
27
- description: 'Prevent arrow functions in lifecycle methods',
28
- },
29
- messages: {
30
- noArrowFunctionLifecycle: (0, eslint_devkit_2.formatLLMMessage)({
31
- icon: eslint_devkit_2.MessageIcons.WARNING,
32
- issueName: 'Arrow Function Lifecycle',
33
- description: 'Arrow function used in lifecycle method',
34
- severity: 'HIGH',
35
- fix: 'Use regular method syntax for lifecycle methods',
36
- documentationLink: 'https://react.dev/reference/react/Component#defining-a-class-component',
37
- }),
38
- },
39
- schema: [],
40
- },
41
- defaultOptions: [],
42
- create(context) {
43
- return {
44
- PropertyDefinition(node) {
45
- if (node.key.type === 'Identifier' &&
46
- LIFECYCLE_METHODS.has(node.key.name) &&
47
- node.value &&
48
- node.value.type === 'ArrowFunctionExpression') {
49
- context.report({
50
- node: node.key,
51
- messageId: 'noArrowFunctionLifecycle',
52
- });
53
- }
54
- },
55
- };
56
- },
57
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noArrowFunctionLifecycle=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const LIFECYCLE_METHODS=new Set(["componentDidMount","componentDidUpdate","componentWillUnmount","componentWillMount","componentWillReceiveProps","componentWillUpdate","shouldComponentUpdate","getDerivedStateFromProps","getSnapshotBeforeUpdate","componentDidCatch","UNSAFE_componentWillMount","UNSAFE_componentWillReceiveProps","UNSAFE_componentWillUpdate"]);exports.noArrowFunctionLifecycle=(0,eslint_devkit_1.createRule)({name:"no-arrow-function-lifecycle",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-arrow-function-lifecycle.md",description:"Prevent arrow functions in lifecycle methods"},messages:{noArrowFunctionLifecycle:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Arrow Function Lifecycle",description:"Arrow function used in lifecycle method",severity:"HIGH",fix:"Use regular method syntax for lifecycle methods",documentationLink:"https://react.dev/reference/react/Component#defining-a-class-component"})},schema:[]},defaultOptions:[],create(context){return{PropertyDefinition(node){if(node.key.type==="Identifier"&&LIFECYCLE_METHODS.has(node.key.name)&&node.value&&node.value.type==="ArrowFunctionExpression"){context.report({node:node.key,messageId:"noArrowFunctionLifecycle"})}}}}});