eslint-plugin-react-features 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/LICENSE +23 -0
  3. package/README.md +155 -0
  4. package/package.json +65 -0
  5. package/src/index.d.ts +1093 -0
  6. package/src/index.js +212 -0
  7. package/src/rules/migration/react-class-to-hooks.d.ts +22 -0
  8. package/src/rules/migration/react-class-to-hooks.js +178 -0
  9. package/src/rules/performance/no-unnecessary-rerenders.d.ts +26 -0
  10. package/src/rules/performance/no-unnecessary-rerenders.js +212 -0
  11. package/src/rules/performance/react-no-inline-functions.d.ts +24 -0
  12. package/src/rules/performance/react-no-inline-functions.js +211 -0
  13. package/src/rules/performance/react-render-optimization.d.ts +31 -0
  14. package/src/rules/performance/react-render-optimization.js +294 -0
  15. package/src/rules/react/checked-requires-onchange-or-readonly.d.ts +16 -0
  16. package/src/rules/react/checked-requires-onchange-or-readonly.js +74 -0
  17. package/src/rules/react/default-props-match-prop-types.d.ts +13 -0
  18. package/src/rules/react/default-props-match-prop-types.js +119 -0
  19. package/src/rules/react/display-name.d.ts +13 -0
  20. package/src/rules/react/display-name.js +164 -0
  21. package/src/rules/react/hooks-exhaustive-deps.d.ts +25 -0
  22. package/src/rules/react/hooks-exhaustive-deps.js +466 -0
  23. package/src/rules/react/jsx-handler-names.d.ts +13 -0
  24. package/src/rules/react/jsx-handler-names.js +57 -0
  25. package/src/rules/react/jsx-key.d.ts +20 -0
  26. package/src/rules/react/jsx-key.js +421 -0
  27. package/src/rules/react/jsx-max-depth.d.ts +19 -0
  28. package/src/rules/react/jsx-max-depth.js +80 -0
  29. package/src/rules/react/jsx-no-bind.d.ts +13 -0
  30. package/src/rules/react/jsx-no-bind.js +64 -0
  31. package/src/rules/react/jsx-no-duplicate-props.d.ts +21 -0
  32. package/src/rules/react/jsx-no-duplicate-props.js +70 -0
  33. package/src/rules/react/jsx-no-literals.d.ts +20 -0
  34. package/src/rules/react/jsx-no-literals.js +83 -0
  35. package/src/rules/react/jsx-no-script-url.d.ts +25 -0
  36. package/src/rules/react/jsx-no-script-url.js +131 -0
  37. package/src/rules/react/jsx-no-target-blank.d.ts +26 -0
  38. package/src/rules/react/jsx-no-target-blank.js +176 -0
  39. package/src/rules/react/no-access-state-in-setstate.d.ts +13 -0
  40. package/src/rules/react/no-access-state-in-setstate.js +92 -0
  41. package/src/rules/react/no-adjacent-inline-elements.d.ts +13 -0
  42. package/src/rules/react/no-adjacent-inline-elements.js +81 -0
  43. package/src/rules/react/no-arrow-function-lifecycle.d.ts +13 -0
  44. package/src/rules/react/no-arrow-function-lifecycle.js +63 -0
  45. package/src/rules/react/no-children-prop.d.ts +13 -0
  46. package/src/rules/react/no-children-prop.js +60 -0
  47. package/src/rules/react/no-danger-with-children.d.ts +16 -0
  48. package/src/rules/react/no-danger-with-children.js +110 -0
  49. package/src/rules/react/no-danger.d.ts +13 -0
  50. package/src/rules/react/no-danger.js +45 -0
  51. package/src/rules/react/no-deprecated.d.ts +16 -0
  52. package/src/rules/react/no-deprecated.js +140 -0
  53. package/src/rules/react/no-did-mount-set-state.d.ts +13 -0
  54. package/src/rules/react/no-did-mount-set-state.js +55 -0
  55. package/src/rules/react/no-did-update-set-state.d.ts +19 -0
  56. package/src/rules/react/no-did-update-set-state.js +80 -0
  57. package/src/rules/react/no-direct-mutation-state.d.ts +20 -0
  58. package/src/rules/react/no-direct-mutation-state.js +277 -0
  59. package/src/rules/react/no-find-dom-node.d.ts +15 -0
  60. package/src/rules/react/no-find-dom-node.js +56 -0
  61. package/src/rules/react/no-invalid-html-attribute.d.ts +13 -0
  62. package/src/rules/react/no-invalid-html-attribute.js +84 -0
  63. package/src/rules/react/no-is-mounted.d.ts +13 -0
  64. package/src/rules/react/no-is-mounted.js +52 -0
  65. package/src/rules/react/no-multi-comp.d.ts +18 -0
  66. package/src/rules/react/no-multi-comp.js +160 -0
  67. package/src/rules/react/no-namespace.d.ts +13 -0
  68. package/src/rules/react/no-namespace.js +41 -0
  69. package/src/rules/react/no-object-type-as-default-prop.d.ts +13 -0
  70. package/src/rules/react/no-object-type-as-default-prop.js +61 -0
  71. package/src/rules/react/no-redundant-should-component-update.d.ts +13 -0
  72. package/src/rules/react/no-redundant-should-component-update.js +55 -0
  73. package/src/rules/react/no-render-return-value.d.ts +13 -0
  74. package/src/rules/react/no-render-return-value.js +74 -0
  75. package/src/rules/react/no-set-state.d.ts +13 -0
  76. package/src/rules/react/no-set-state.js +50 -0
  77. package/src/rules/react/no-string-refs.d.ts +13 -0
  78. package/src/rules/react/no-string-refs.js +68 -0
  79. package/src/rules/react/no-this-in-sfc.d.ts +13 -0
  80. package/src/rules/react/no-this-in-sfc.js +65 -0
  81. package/src/rules/react/no-typos.d.ts +13 -0
  82. package/src/rules/react/no-typos.js +97 -0
  83. package/src/rules/react/no-unescaped-entities.d.ts +13 -0
  84. package/src/rules/react/no-unescaped-entities.js +50 -0
  85. package/src/rules/react/no-unknown-property.d.ts +13 -0
  86. package/src/rules/react/no-unknown-property.js +130 -0
  87. package/src/rules/react/no-unsafe.d.ts +20 -0
  88. package/src/rules/react/no-unsafe.js +112 -0
  89. package/src/rules/react/prefer-es6-class.d.ts +13 -0
  90. package/src/rules/react/prefer-es6-class.js +56 -0
  91. package/src/rules/react/prefer-stateless-function.d.ts +16 -0
  92. package/src/rules/react/prefer-stateless-function.js +134 -0
  93. package/src/rules/react/prop-types.d.ts +18 -0
  94. package/src/rules/react/prop-types.js +153 -0
  95. package/src/rules/react/react-in-jsx-scope.d.ts +13 -0
  96. package/src/rules/react/react-in-jsx-scope.js +94 -0
  97. package/src/rules/react/require-default-props.d.ts +16 -0
  98. package/src/rules/react/require-default-props.js +146 -0
  99. package/src/rules/react/require-optimization.d.ts +26 -0
  100. package/src/rules/react/require-optimization.js +436 -0
  101. package/src/rules/react/require-render-return.d.ts +13 -0
  102. package/src/rules/react/require-render-return.js +87 -0
  103. package/src/rules/react/required-attributes.d.ts +28 -0
  104. package/src/rules/react/required-attributes.js +212 -0
  105. package/src/rules/react/sort-comp.d.ts +17 -0
  106. package/src/rules/react/sort-comp.js +160 -0
  107. package/src/rules/react/state-in-constructor.d.ts +13 -0
  108. package/src/rules/react/state-in-constructor.js +103 -0
  109. package/src/rules/react/static-property-placement.d.ts +20 -0
  110. package/src/rules/react/static-property-placement.js +166 -0
  111. package/src/rules/react/void-dom-elements-no-children.d.ts +15 -0
  112. package/src/rules/react/void-dom-elements-no-children.js +94 -0
  113. package/src/types/index.d.ts +54 -0
  114. package/src/types/index.js +7 -0
@@ -0,0 +1,70 @@
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.jsxNoDuplicateProps = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.jsxNoDuplicateProps = (0, eslint_devkit_2.createRule)({
12
+ name: 'jsx-no-duplicate-props',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Prevent duplicate props in JSX',
17
+ },
18
+ messages: {
19
+ duplicateProp: (0, eslint_devkit_1.formatLLMMessage)({
20
+ icon: eslint_devkit_1.MessageIcons.WARNING,
21
+ issueName: 'Duplicate Prop',
22
+ description: 'Prop "{{name}}" is duplicated - the last value will be used',
23
+ severity: 'HIGH',
24
+ fix: 'Remove the duplicate prop',
25
+ documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md',
26
+ }),
27
+ },
28
+ schema: [
29
+ {
30
+ type: 'object',
31
+ properties: {
32
+ ignoreCase: { type: 'boolean', default: false },
33
+ },
34
+ additionalProperties: false,
35
+ },
36
+ ],
37
+ },
38
+ defaultOptions: [{}],
39
+ create(context, [options = {}]) {
40
+ const { ignoreCase = false } = options ?? {};
41
+ return {
42
+ JSXOpeningElement(node) {
43
+ const seenProps = new Map();
44
+ for (const attr of node.attributes) {
45
+ if (attr.type !== 'JSXAttribute')
46
+ continue;
47
+ if (attr.name.type !== 'JSXIdentifier')
48
+ continue;
49
+ let propName = attr.name.name;
50
+ if (ignoreCase) {
51
+ propName = propName.toLowerCase();
52
+ }
53
+ const previousAttr = seenProps.get(propName);
54
+ if (previousAttr) {
55
+ context.report({
56
+ node: attr,
57
+ messageId: 'duplicateProp',
58
+ data: {
59
+ name: attr.name.name,
60
+ },
61
+ });
62
+ }
63
+ else {
64
+ seenProps.set(propName, attr);
65
+ }
66
+ }
67
+ },
68
+ };
69
+ },
70
+ });
@@ -0,0 +1,20 @@
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: jsx-no-literals
8
+ * Prevent string literals in JSX
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ export interface Options {
12
+ noStrings?: boolean;
13
+ allowedStrings?: string[];
14
+ ignoreProps?: boolean;
15
+ }
16
+ type RuleOptions = [Options?];
17
+ export declare const jsxNoLiterals: TSESLint.RuleModule<"jsxNoLiterals", RuleOptions, unknown, TSESLint.RuleListener> & {
18
+ name: string;
19
+ };
20
+ export {};
@@ -0,0 +1,83 @@
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.jsxNoLiterals = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.jsxNoLiterals = (0, eslint_devkit_1.createRule)({
12
+ name: 'jsx-no-literals',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Prevent string literals in JSX',
17
+ },
18
+ messages: {
19
+ jsxNoLiterals: (0, eslint_devkit_2.formatLLMMessage)({
20
+ icon: eslint_devkit_2.MessageIcons.WARNING,
21
+ issueName: 'String Literal in JSX',
22
+ description: 'String literal found in JSX',
23
+ severity: 'MEDIUM',
24
+ fix: 'Extract string to variable or use translation key',
25
+ documentationLink: 'https://react.dev/learn/passing-props-to-a-component#passing-jsx-as-children',
26
+ }),
27
+ },
28
+ schema: [
29
+ {
30
+ type: 'object',
31
+ properties: {
32
+ noStrings: {
33
+ type: 'boolean',
34
+ default: true,
35
+ },
36
+ allowedStrings: {
37
+ type: 'array',
38
+ items: { type: 'string' },
39
+ default: [],
40
+ },
41
+ ignoreProps: {
42
+ type: 'boolean',
43
+ default: true,
44
+ },
45
+ },
46
+ additionalProperties: false,
47
+ },
48
+ ],
49
+ },
50
+ defaultOptions: [{}],
51
+ create(context) {
52
+ const [options] = context.options;
53
+ const noStrings = options?.noStrings ?? true;
54
+ const allowedStrings = options?.allowedStrings ?? [];
55
+ const ignoreProps = options?.ignoreProps ?? true;
56
+ return {
57
+ JSXText(node) {
58
+ if (!noStrings)
59
+ return;
60
+ const text = node.value.trim();
61
+ if (text && !allowedStrings.includes(text)) {
62
+ context.report({
63
+ node,
64
+ messageId: 'jsxNoLiterals',
65
+ });
66
+ }
67
+ },
68
+ JSXAttribute(node) {
69
+ if (ignoreProps)
70
+ return;
71
+ if (node.value && node.value.type === 'Literal' && typeof node.value.value === 'string') {
72
+ const text = node.value.value.trim();
73
+ if (text && !allowedStrings.includes(text)) {
74
+ context.report({
75
+ node: node.value,
76
+ messageId: 'jsxNoLiterals',
77
+ });
78
+ }
79
+ }
80
+ },
81
+ };
82
+ },
83
+ });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: jsx-no-script-url
8
+ * Forbid javascript: URLs in JSX
9
+ *
10
+ * Security: Prevents XSS attacks through javascript: protocol (CWE-79)
11
+ * @see https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-script-url.md
12
+ */
13
+ import type { TSESLint } from '@interlace/eslint-devkit';
14
+ type ComponentConfig = {
15
+ name: string;
16
+ props: string[];
17
+ };
18
+ type Options = {
19
+ includeFromSettings?: boolean;
20
+ };
21
+ type RuleOptions = [ComponentConfig[]?, Options?];
22
+ export declare const jsxNoScriptUrl: TSESLint.RuleModule<"noScriptUrl", RuleOptions, unknown, TSESLint.RuleListener> & {
23
+ name: string;
24
+ };
25
+ export {};
@@ -0,0 +1,131 @@
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.jsxNoScriptUrl = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ // Attributes that commonly accept URLs
12
+ const URL_PROPS = ['href', 'src', 'action', 'formAction', 'data', 'poster', 'background'];
13
+ exports.jsxNoScriptUrl = (0, eslint_devkit_2.createRule)({
14
+ name: 'jsx-no-script-url',
15
+ meta: {
16
+ type: 'problem',
17
+ docs: {
18
+ description: 'Forbid javascript: URLs',
19
+ },
20
+ messages: {
21
+ noScriptUrl: (0, eslint_devkit_1.formatLLMMessage)({
22
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
23
+ issueName: 'javascript: URL',
24
+ cwe: 'CWE-79',
25
+ description: 'javascript: URLs are a security risk and can lead to XSS attacks',
26
+ severity: 'CRITICAL',
27
+ fix: 'Use an onClick handler instead or a proper href',
28
+ documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-script-url.md',
29
+ }),
30
+ },
31
+ schema: [
32
+ {
33
+ type: 'array',
34
+ items: {
35
+ type: 'object',
36
+ properties: {
37
+ name: { type: 'string' },
38
+ props: { type: 'array', items: { type: 'string' } },
39
+ },
40
+ required: ['name', 'props'],
41
+ additionalProperties: false,
42
+ },
43
+ },
44
+ {
45
+ type: 'object',
46
+ properties: {
47
+ includeFromSettings: { type: 'boolean' },
48
+ },
49
+ additionalProperties: false,
50
+ },
51
+ ],
52
+ },
53
+ defaultOptions: [[], {}],
54
+ create(context, [componentConfigs = []]) {
55
+ // Build a map of component -> props to check
56
+ const componentPropsMap = new Map();
57
+ // Add custom component configurations
58
+ for (const config of componentConfigs) {
59
+ componentPropsMap.set(config.name, new Set(config.props));
60
+ }
61
+ function isJavaScriptUrl(value) {
62
+ // Match javascript: protocol (case insensitive, with optional whitespace)
63
+ return /^\s*javascript:/i.test(value);
64
+ }
65
+ function checkAttribute(node, elementName) {
66
+ if (node.name.type !== 'JSXIdentifier')
67
+ return;
68
+ const propName = node.name.name;
69
+ // Check if this is a URL prop for standard elements
70
+ const isUrlProp = URL_PROPS.includes(propName);
71
+ // Check if this is a configured custom component prop
72
+ const customProps = componentPropsMap.get(elementName);
73
+ const isCustomProp = customProps?.has(propName);
74
+ if (!isUrlProp && !isCustomProp)
75
+ return;
76
+ if (!node.value)
77
+ return;
78
+ // Check literal string values
79
+ if (node.value.type === 'Literal' && typeof node.value.value === 'string') {
80
+ if (isJavaScriptUrl(node.value.value)) {
81
+ context.report({
82
+ node,
83
+ messageId: 'noScriptUrl',
84
+ });
85
+ }
86
+ }
87
+ // Check JSX expression with template literal or string
88
+ if (node.value.type === 'JSXExpressionContainer') {
89
+ const expr = node.value.expression;
90
+ if (expr.type === 'Literal' && typeof expr.value === 'string') {
91
+ if (isJavaScriptUrl(expr.value)) {
92
+ context.report({
93
+ node,
94
+ messageId: 'noScriptUrl',
95
+ });
96
+ }
97
+ }
98
+ if (expr.type === 'TemplateLiteral' && expr.quasis.length > 0) {
99
+ // Check if the template literal starts with javascript:
100
+ const firstQuasi = expr.quasis[0];
101
+ if (firstQuasi && isJavaScriptUrl(firstQuasi.value.raw)) {
102
+ context.report({
103
+ node,
104
+ messageId: 'noScriptUrl',
105
+ });
106
+ }
107
+ }
108
+ }
109
+ }
110
+ return {
111
+ JSXOpeningElement(node) {
112
+ let elementName;
113
+ if (node.name.type === 'JSXIdentifier') {
114
+ elementName = node.name.name;
115
+ }
116
+ else if (node.name.type === 'JSXMemberExpression') {
117
+ // Handle Component.SubComponent
118
+ elementName = context.sourceCode.getText(node.name);
119
+ }
120
+ else {
121
+ return;
122
+ }
123
+ for (const attr of node.attributes) {
124
+ if (attr.type === 'JSXAttribute') {
125
+ checkAttribute(attr, elementName);
126
+ }
127
+ }
128
+ },
129
+ };
130
+ },
131
+ });
@@ -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: jsx-no-target-blank
8
+ * Enforce rel="noopener noreferrer" on anchor tags with target="_blank"
9
+ *
10
+ * Security: Prevents reverse tabnabbing attacks (CWE-1022)
11
+ * @see https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md
12
+ */
13
+ import type { TSESLint } from '@interlace/eslint-devkit';
14
+ type MessageIds = 'noTargetBlank' | 'noRelWithoutNoopener';
15
+ type Options = {
16
+ allowReferrer?: boolean;
17
+ enforceDynamicLinks?: 'always' | 'never';
18
+ warnOnSpreadAttributes?: boolean;
19
+ links?: boolean;
20
+ forms?: boolean;
21
+ };
22
+ type RuleOptions = [Options?];
23
+ export declare const jsxNoTargetBlank: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
24
+ name: string;
25
+ };
26
+ export {};
@@ -0,0 +1,176 @@
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.jsxNoTargetBlank = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.jsxNoTargetBlank = (0, eslint_devkit_2.createRule)({
12
+ name: 'jsx-no-target-blank',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Forbid target="_blank" without rel="noopener noreferrer"',
17
+ },
18
+ fixable: 'code',
19
+ messages: {
20
+ noTargetBlank: (0, eslint_devkit_1.formatLLMMessage)({
21
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
22
+ issueName: 'Unsafe target="_blank"',
23
+ cwe: 'CWE-1022',
24
+ description: 'Using target="_blank" without rel="noopener noreferrer" is a security risk',
25
+ severity: 'HIGH',
26
+ fix: 'Add rel="noopener noreferrer" to prevent reverse tabnabbing',
27
+ documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md',
28
+ }),
29
+ noRelWithoutNoopener: (0, eslint_devkit_1.formatLLMMessage)({
30
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
31
+ issueName: 'Missing noopener',
32
+ cwe: 'CWE-1022',
33
+ description: 'rel attribute is missing "noopener" value',
34
+ severity: 'MEDIUM',
35
+ fix: 'Add "noopener" to the rel attribute',
36
+ documentationLink: 'https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md',
37
+ }),
38
+ },
39
+ schema: [
40
+ {
41
+ type: 'object',
42
+ properties: {
43
+ allowReferrer: { type: 'boolean', default: false },
44
+ enforceDynamicLinks: {
45
+ type: 'string',
46
+ enum: ['always', 'never'],
47
+ default: 'always'
48
+ },
49
+ warnOnSpreadAttributes: { type: 'boolean', default: false },
50
+ links: { type: 'boolean', default: true },
51
+ forms: { type: 'boolean', default: false },
52
+ },
53
+ additionalProperties: false,
54
+ },
55
+ ],
56
+ },
57
+ defaultOptions: [{}],
58
+ create(context, [options = {}]) {
59
+ const { allowReferrer = false, enforceDynamicLinks = 'always', warnOnSpreadAttributes = false, links = true, forms = false, } = options ?? {};
60
+ const elementsToCheck = [];
61
+ if (links)
62
+ elementsToCheck.push('a');
63
+ if (forms)
64
+ elementsToCheck.push('form');
65
+ function hasTargetBlank(node) {
66
+ const targetAttr = node.attributes.find((attr) => attr.type === 'JSXAttribute' &&
67
+ attr.name.type === 'JSXIdentifier' &&
68
+ attr.name.name === 'target');
69
+ if (!targetAttr || !targetAttr.value)
70
+ return false;
71
+ if (targetAttr.value.type === 'Literal') {
72
+ return targetAttr.value.value === '_blank';
73
+ }
74
+ // Dynamic value - check enforceDynamicLinks option
75
+ if (enforceDynamicLinks === 'always') {
76
+ return true;
77
+ }
78
+ return false;
79
+ }
80
+ function hasExternalHref(node) {
81
+ const hrefAttr = node.attributes.find((attr) => attr.type === 'JSXAttribute' &&
82
+ attr.name.type === 'JSXIdentifier' &&
83
+ attr.name.name === 'href');
84
+ if (!hrefAttr || !hrefAttr.value)
85
+ return false;
86
+ if (hrefAttr.value.type === 'Literal' && typeof hrefAttr.value.value === 'string') {
87
+ const href = hrefAttr.value.value;
88
+ // External if starts with http:// or https:// or //
89
+ return /^(https?:)?\/\//.test(href) || /^\/\//.test(href);
90
+ }
91
+ // Dynamic href - assume external
92
+ return enforceDynamicLinks === 'always';
93
+ }
94
+ function getRelAttribute(node) {
95
+ return node.attributes.find((attr) => attr.type === 'JSXAttribute' &&
96
+ attr.name.type === 'JSXIdentifier' &&
97
+ attr.name.name === 'rel');
98
+ }
99
+ function hasNoopener(relAttr) {
100
+ if (!relAttr.value)
101
+ return false;
102
+ if (relAttr.value.type === 'Literal' && typeof relAttr.value.value === 'string') {
103
+ const relValues = relAttr.value.value.toLowerCase().split(/\s+/);
104
+ return relValues.includes('noopener');
105
+ }
106
+ return false;
107
+ }
108
+ function hasNoreferrer(relAttr) {
109
+ if (!relAttr.value)
110
+ return false;
111
+ if (relAttr.value.type === 'Literal' && typeof relAttr.value.value === 'string') {
112
+ const relValues = relAttr.value.value.toLowerCase().split(/\s+/);
113
+ return relValues.includes('noreferrer');
114
+ }
115
+ return false;
116
+ }
117
+ function hasSpreadAttribute(node) {
118
+ return node.attributes.some(attr => attr.type === 'JSXSpreadAttribute');
119
+ }
120
+ return {
121
+ JSXOpeningElement(node) {
122
+ if (node.name.type !== 'JSXIdentifier' || !elementsToCheck.includes(node.name.name)) {
123
+ return;
124
+ }
125
+ // Skip if spread attributes and not warning on them
126
+ if (hasSpreadAttribute(node) && !warnOnSpreadAttributes) {
127
+ return;
128
+ }
129
+ if (!hasTargetBlank(node)) {
130
+ return;
131
+ }
132
+ // For anchors, only check external links
133
+ if (node.name.name === 'a' && !hasExternalHref(node)) {
134
+ return;
135
+ }
136
+ const relAttr = getRelAttribute(node);
137
+ const hasNoopenerValue = relAttr ? hasNoopener(relAttr) : false;
138
+ const hasNoreferrerValue = relAttr ? hasNoreferrer(relAttr) : false;
139
+ // noreferrer implies noopener in modern browsers
140
+ if (hasNoopenerValue || hasNoreferrerValue) {
141
+ // If allowReferrer is false, we need both noopener and noreferrer (or just noreferrer)
142
+ if (!allowReferrer && !hasNoreferrerValue) {
143
+ // Has noopener but not noreferrer - acceptable if allowReferrer is true
144
+ return; // noopener is sufficient for security
145
+ }
146
+ return;
147
+ }
148
+ // Missing rel or rel doesn't have noopener/noreferrer
149
+ context.report({
150
+ node,
151
+ messageId: relAttr ? 'noRelWithoutNoopener' : 'noTargetBlank',
152
+ fix: (fixer) => {
153
+ if (relAttr && relAttr.value && relAttr.value.type === 'Literal') {
154
+ // Add noopener noreferrer to existing rel
155
+ const currentRel = String(relAttr.value.value);
156
+ const newRel = allowReferrer
157
+ ? `${currentRel} noopener`.trim()
158
+ : `${currentRel} noopener noreferrer`.trim();
159
+ return fixer.replaceText(relAttr.value, `"${newRel}"`);
160
+ }
161
+ else if (!relAttr) {
162
+ // Add rel attribute
163
+ const lastAttr = node.attributes[node.attributes.length - 1];
164
+ const relValue = allowReferrer ? 'noopener' : 'noopener noreferrer';
165
+ if (lastAttr) {
166
+ return fixer.insertTextAfter(lastAttr, ` rel="${relValue}"`);
167
+ }
168
+ return fixer.insertTextAfter(node.name, ` rel="${relValue}"`);
169
+ }
170
+ return null;
171
+ },
172
+ });
173
+ },
174
+ };
175
+ },
176
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-access-state-in-setstate
8
+ * Disallow accessing this.state inside setState calls
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ export declare const noAccessStateInSetState: TSESLint.RuleModule<"noAccessStateInSetState", [], unknown, TSESLint.RuleListener> & {
12
+ name: string;
13
+ };
@@ -0,0 +1,92 @@
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.noAccessStateInSetState = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.noAccessStateInSetState = (0, eslint_devkit_1.createRule)({
12
+ name: 'no-access-state-in-setstate',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Disallow accessing this.state inside setState calls',
17
+ },
18
+ schema: [],
19
+ messages: {
20
+ noAccessStateInSetState: (0, eslint_devkit_2.formatLLMMessage)({
21
+ icon: eslint_devkit_2.MessageIcons.WARNING,
22
+ issueName: 'State Access in setState',
23
+ description: 'Accessing this.state inside setState call',
24
+ severity: 'HIGH',
25
+ fix: 'Use functional setState: this.setState(prevState => ({...prevState, ...updates}))',
26
+ documentationLink: 'https://react.dev/reference/react/Component#setstate',
27
+ }),
28
+ },
29
+ },
30
+ defaultOptions: [],
31
+ create(context) {
32
+ return {
33
+ CallExpression(node) {
34
+ // Check if this is a setState call
35
+ if (node.callee.type === 'MemberExpression' &&
36
+ node.callee.property.type === 'Identifier' &&
37
+ node.callee.property.name === 'setState' &&
38
+ node.arguments.length > 0) {
39
+ const [firstArg] = node.arguments;
40
+ // Check if the first argument accesses this.state
41
+ if (firstArg && containsThisStateAccess(firstArg)) {
42
+ context.report({
43
+ node: node.callee.property,
44
+ messageId: 'noAccessStateInSetState',
45
+ });
46
+ }
47
+ }
48
+ },
49
+ };
50
+ },
51
+ });
52
+ /**
53
+ * Check if a node contains access to this.state
54
+ */
55
+ function containsThisStateAccess(node, visited = new Set()) {
56
+ // Prevent infinite recursion
57
+ if (visited.has(node)) {
58
+ return false;
59
+ }
60
+ visited.add(node);
61
+ if (node.type === 'MemberExpression') {
62
+ // Check for this.state or this.state.someProperty
63
+ if (node.object.type === 'ThisExpression' &&
64
+ node.property.type === 'Identifier' &&
65
+ node.property.name === 'state') {
66
+ return true;
67
+ }
68
+ }
69
+ // Recursively check child nodes
70
+ for (const key in node) {
71
+ if (key === 'parent' || key === 'loc' || key === 'range')
72
+ continue;
73
+ const child = node[key];
74
+ if (child && typeof child === 'object') {
75
+ if (Array.isArray(child)) {
76
+ for (const item of child) {
77
+ if (item && typeof item === 'object' && 'type' in item) {
78
+ if (containsThisStateAccess(item, visited)) {
79
+ return true;
80
+ }
81
+ }
82
+ }
83
+ }
84
+ else if ('type' in child && child.type !== 'Program') {
85
+ if (containsThisStateAccess(child, visited)) {
86
+ return true;
87
+ }
88
+ }
89
+ }
90
+ }
91
+ return false;
92
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: no-adjacent-inline-elements
8
+ * Prevent adjacent inline elements
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ export declare const noAdjacentInlineElements: TSESLint.RuleModule<"noAdjacentInlineElements", [], unknown, TSESLint.RuleListener> & {
12
+ name: string;
13
+ };