@blumintinc/eslint-plugin-blumint 1.7.3 → 1.8.1

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 (70) hide show
  1. package/README.md +83 -61
  2. package/lib/index.js +85 -1
  3. package/lib/rules/enforce-assert-throws.js +48 -3
  4. package/lib/rules/enforce-assertSafe-object-key.d.ts +2 -0
  5. package/lib/rules/enforce-assertSafe-object-key.js +284 -0
  6. package/lib/rules/enforce-centralized-mock-firestore.js +192 -14
  7. package/lib/rules/enforce-css-media-queries.d.ts +5 -0
  8. package/lib/rules/enforce-css-media-queries.js +87 -0
  9. package/lib/rules/enforce-dynamic-imports.d.ts +9 -0
  10. package/lib/rules/enforce-dynamic-imports.js +84 -0
  11. package/lib/rules/enforce-firestore-facade.js +8 -0
  12. package/lib/rules/enforce-id-capitalization.d.ts +6 -0
  13. package/lib/rules/enforce-id-capitalization.js +78 -0
  14. package/lib/rules/enforce-microdiff.d.ts +3 -0
  15. package/lib/rules/enforce-microdiff.js +379 -0
  16. package/lib/rules/enforce-mui-rounded-icons.d.ts +1 -0
  17. package/lib/rules/enforce-mui-rounded-icons.js +54 -0
  18. package/lib/rules/enforce-object-literal-as-const.d.ts +4 -0
  19. package/lib/rules/enforce-object-literal-as-const.js +88 -0
  20. package/lib/rules/enforce-positive-naming.d.ts +1 -0
  21. package/lib/rules/enforce-positive-naming.js +387 -0
  22. package/lib/rules/enforce-props-argument-name.d.ts +8 -0
  23. package/lib/rules/enforce-props-argument-name.js +182 -0
  24. package/lib/rules/enforce-react-type-naming.d.ts +3 -0
  25. package/lib/rules/enforce-react-type-naming.js +191 -0
  26. package/lib/rules/enforce-render-hits-memoization.js +155 -26
  27. package/lib/rules/enforce-singular-type-names.d.ts +2 -0
  28. package/lib/rules/enforce-singular-type-names.js +112 -0
  29. package/lib/rules/enforce-timestamp-now.d.ts +1 -0
  30. package/lib/rules/enforce-timestamp-now.js +223 -0
  31. package/lib/rules/enforce-verb-noun-naming.js +5 -2
  32. package/lib/rules/ensure-pointer-events-none.d.ts +1 -0
  33. package/lib/rules/ensure-pointer-events-none.js +211 -0
  34. package/lib/rules/extract-global-constants.d.ts +1 -1
  35. package/lib/rules/extract-global-constants.js +109 -1
  36. package/lib/rules/global-const-style.js +3 -2
  37. package/lib/rules/key-only-outermost-element.d.ts +3 -0
  38. package/lib/rules/key-only-outermost-element.js +152 -0
  39. package/lib/rules/no-always-true-false-conditions.d.ts +3 -0
  40. package/lib/rules/no-always-true-false-conditions.js +1221 -0
  41. package/lib/rules/no-circular-references.d.ts +1 -0
  42. package/lib/rules/no-circular-references.js +523 -0
  43. package/lib/rules/no-firestore-jest-mock.js +27 -4
  44. package/lib/rules/no-hungarian.d.ts +5 -0
  45. package/lib/rules/no-hungarian.js +223 -0
  46. package/lib/rules/no-mock-firebase-admin.js +20 -7
  47. package/lib/rules/no-object-values-on-strings.d.ts +2 -0
  48. package/lib/rules/no-object-values-on-strings.js +294 -0
  49. package/lib/rules/no-type-assertion-returns.d.ts +9 -0
  50. package/lib/rules/no-type-assertion-returns.js +299 -0
  51. package/lib/rules/no-unnecessary-destructuring.d.ts +5 -0
  52. package/lib/rules/no-unnecessary-destructuring.js +69 -0
  53. package/lib/rules/no-unnecessary-verb-suffix.d.ts +1 -0
  54. package/lib/rules/no-unnecessary-verb-suffix.js +203 -0
  55. package/lib/rules/no-unused-props.js +10 -5
  56. package/lib/rules/no-unused-usestate.d.ts +8 -0
  57. package/lib/rules/no-unused-usestate.js +84 -0
  58. package/lib/rules/omit-index-html.d.ts +7 -0
  59. package/lib/rules/omit-index-html.js +91 -0
  60. package/lib/rules/prefer-clone-deep.js +294 -22
  61. package/lib/rules/prefer-fragment-component.js +265 -34
  62. package/lib/rules/prefer-global-router-state-key.d.ts +5 -0
  63. package/lib/rules/prefer-global-router-state-key.js +89 -0
  64. package/lib/rules/prefer-usememo-over-useeffect-usestate.d.ts +5 -0
  65. package/lib/rules/prefer-usememo-over-useeffect-usestate.js +129 -0
  66. package/lib/rules/prefer-utility-function-over-private-static.d.ts +1 -0
  67. package/lib/rules/prefer-utility-function-over-private-static.js +77 -0
  68. package/lib/rules/react-usememo-should-be-component.d.ts +1 -0
  69. package/lib/rules/react-usememo-should-be-component.js +623 -0
  70. package/package.json +10 -7
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enforceTimestampNow = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const createRule_1 = require("../utils/createRule");
6
+ exports.enforceTimestampNow = (0, createRule_1.createRule)({
7
+ name: 'enforce-timestamp-now',
8
+ meta: {
9
+ type: 'suggestion',
10
+ docs: {
11
+ description: 'Enforce the use of Timestamp.now() for getting the current timestamp in backend code. This rule prevents using alternatives like Timestamp.fromDate(new Date()) or other date creation patterns that could lead to inconsistency.',
12
+ recommended: 'error',
13
+ requiresTypeChecking: false,
14
+ extendsBaseRule: false,
15
+ },
16
+ fixable: 'code',
17
+ schema: [],
18
+ messages: {
19
+ preferTimestampNow: 'Use Timestamp.now() instead of creating a Date object and converting it. This is more efficient and idiomatic for Firestore.',
20
+ },
21
+ },
22
+ defaultOptions: [],
23
+ create(context) {
24
+ // Only apply this rule to backend code (functions/src/)
25
+ const filename = context.getFilename();
26
+ if (!filename.includes('functions/src/')) {
27
+ return {};
28
+ }
29
+ // Skip test files
30
+ if (filename.includes('.test.') || filename.includes('.spec.')) {
31
+ return {};
32
+ }
33
+ // Track Timestamp imports and aliases
34
+ const timestampAliases = new Set(['Timestamp']);
35
+ function isTimestampFromDateWithNewDate(node) {
36
+ // Check if it's a Timestamp.fromDate(new Date()) call
37
+ if (node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
38
+ const property = node.callee.property;
39
+ const object = node.callee.object;
40
+ if (property.type === utils_1.AST_NODE_TYPES.Identifier &&
41
+ property.name === 'fromDate' &&
42
+ object.type === utils_1.AST_NODE_TYPES.Identifier &&
43
+ timestampAliases.has(object.name)) {
44
+ // Check if the argument is new Date()
45
+ const arg = node.arguments[0];
46
+ if (arg &&
47
+ arg.type === utils_1.AST_NODE_TYPES.NewExpression &&
48
+ arg.callee.type === utils_1.AST_NODE_TYPES.Identifier &&
49
+ arg.callee.name === 'Date' &&
50
+ arg.arguments.length === 0) {
51
+ return true;
52
+ }
53
+ // Check if the argument is a variable reference to a Date object
54
+ if (arg &&
55
+ arg.type === utils_1.AST_NODE_TYPES.Identifier) {
56
+ // If it's a variable, we need to check if it's a Date that's being modified
57
+ // If it's modified, we shouldn't flag it
58
+ return false;
59
+ }
60
+ }
61
+ }
62
+ return false;
63
+ }
64
+ function isTimestampFromMillisWithDateNow(node) {
65
+ // Check if it's a Timestamp.fromMillis(Date.now()) call
66
+ if (node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
67
+ const property = node.callee.property;
68
+ const object = node.callee.object;
69
+ if (property.type === utils_1.AST_NODE_TYPES.Identifier &&
70
+ property.name === 'fromMillis' &&
71
+ object.type === utils_1.AST_NODE_TYPES.Identifier &&
72
+ timestampAliases.has(object.name)) {
73
+ // Check if the argument is Date.now()
74
+ const arg = node.arguments[0];
75
+ if (arg &&
76
+ arg.type === utils_1.AST_NODE_TYPES.CallExpression &&
77
+ arg.callee.type === utils_1.AST_NODE_TYPES.MemberExpression &&
78
+ arg.callee.object.type === utils_1.AST_NODE_TYPES.Identifier &&
79
+ arg.callee.object.name === 'Date' &&
80
+ arg.callee.property.type === utils_1.AST_NODE_TYPES.Identifier &&
81
+ arg.callee.property.name === 'now') {
82
+ return true;
83
+ }
84
+ }
85
+ }
86
+ return false;
87
+ }
88
+ function isNewDateDirectUsage(node) {
89
+ // Check if it's a new Date() with no arguments
90
+ return (node.callee.type === utils_1.AST_NODE_TYPES.Identifier &&
91
+ node.callee.name === 'Date' &&
92
+ node.arguments.length === 0);
93
+ }
94
+ // Check if a Date object is being modified (e.g., futureDate.setDate())
95
+ function isDateBeingModified(dateVar) {
96
+ // Look through the scope to find if this variable is modified
97
+ const scope = context.getScope();
98
+ const variable = scope.variables.find(v => v.name === dateVar);
99
+ if (!variable)
100
+ return false;
101
+ // Check if any references to this variable are followed by property access and modification
102
+ return variable.references.some(ref => {
103
+ const id = ref.identifier;
104
+ const parent = id.parent;
105
+ // Check for patterns like dateVar.setDate(), dateVar.setHours(), etc.
106
+ return (parent &&
107
+ parent.type === utils_1.AST_NODE_TYPES.MemberExpression &&
108
+ parent.object === id &&
109
+ parent.property.type === utils_1.AST_NODE_TYPES.Identifier &&
110
+ (parent.property.name.startsWith('set') ||
111
+ parent.property.name === 'toISOString' ||
112
+ parent.property.name === 'toLocaleString' ||
113
+ parent.property.name === 'toString'));
114
+ });
115
+ }
116
+ return {
117
+ ImportDeclaration(node) {
118
+ // Track Timestamp imports from Firebase
119
+ if (node.source.value === 'firebase-admin/firestore' ||
120
+ node.source.value === 'firebase/firestore') {
121
+ node.specifiers.forEach((specifier) => {
122
+ if (specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier &&
123
+ specifier.imported.type === utils_1.AST_NODE_TYPES.Identifier &&
124
+ specifier.imported.name === 'Timestamp') {
125
+ timestampAliases.add(specifier.local.name);
126
+ }
127
+ });
128
+ }
129
+ },
130
+ VariableDeclarator(node) {
131
+ // Track dynamic imports of Timestamp
132
+ if (node.init?.type === utils_1.AST_NODE_TYPES.AwaitExpression &&
133
+ node.init.argument.type === utils_1.AST_NODE_TYPES.ImportExpression) {
134
+ const importSource = node.init.argument.source;
135
+ if (importSource.type === utils_1.AST_NODE_TYPES.Literal &&
136
+ (importSource.value === 'firebase-admin/firestore' ||
137
+ importSource.value === 'firebase/firestore')) {
138
+ // Handle destructured imports
139
+ if (node.id.type === utils_1.AST_NODE_TYPES.ObjectPattern) {
140
+ node.id.properties.forEach((prop) => {
141
+ if (prop.type === utils_1.AST_NODE_TYPES.Property &&
142
+ prop.key.type === utils_1.AST_NODE_TYPES.Identifier &&
143
+ prop.key.name === 'Timestamp') {
144
+ if (prop.value.type === utils_1.AST_NODE_TYPES.Identifier) {
145
+ timestampAliases.add(prop.value.name);
146
+ }
147
+ }
148
+ });
149
+ }
150
+ }
151
+ }
152
+ },
153
+ CallExpression(node) {
154
+ if (isTimestampFromDateWithNewDate(node)) {
155
+ context.report({
156
+ node,
157
+ messageId: 'preferTimestampNow',
158
+ fix(fixer) {
159
+ if (node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
160
+ const timestampObj = context
161
+ .getSourceCode()
162
+ .getText(node.callee.object);
163
+ return fixer.replaceText(node, `${timestampObj}.now()`);
164
+ }
165
+ return null;
166
+ },
167
+ });
168
+ }
169
+ else if (isTimestampFromMillisWithDateNow(node)) {
170
+ context.report({
171
+ node,
172
+ messageId: 'preferTimestampNow',
173
+ fix(fixer) {
174
+ if (node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
175
+ const timestampObj = context
176
+ .getSourceCode()
177
+ .getText(node.callee.object);
178
+ return fixer.replaceText(node, `${timestampObj}.now()`);
179
+ }
180
+ return null;
181
+ },
182
+ });
183
+ }
184
+ },
185
+ NewExpression(node) {
186
+ // Only flag direct new Date() usage if it's assigned to a variable named timestamp or similar
187
+ if (isNewDateDirectUsage(node)) {
188
+ const parent = node.parent;
189
+ if (parent &&
190
+ parent.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
191
+ parent.id.type === utils_1.AST_NODE_TYPES.Identifier) {
192
+ const varName = parent.id.name.toLowerCase();
193
+ // Check if the variable name suggests it's a timestamp
194
+ if (varName.includes('timestamp') ||
195
+ varName.includes('time') ||
196
+ varName.includes('now') ||
197
+ varName.includes('date') ||
198
+ varName.includes('created') ||
199
+ varName.includes('updated')) {
200
+ // Check if the Date object is being modified
201
+ if (isDateBeingModified(parent.id.name)) {
202
+ // If the Date is being modified, don't flag it
203
+ return;
204
+ }
205
+ // Check if we have a Timestamp import before suggesting
206
+ if (timestampAliases.size > 0) {
207
+ const timestampName = Array.from(timestampAliases)[0];
208
+ context.report({
209
+ node,
210
+ messageId: 'preferTimestampNow',
211
+ fix(fixer) {
212
+ return fixer.replaceText(node, `${timestampName}.now()`);
213
+ },
214
+ });
215
+ }
216
+ }
217
+ }
218
+ }
219
+ },
220
+ };
221
+ },
222
+ });
223
+ //# sourceMappingURL=enforce-timestamp-now.js.map
@@ -4651,10 +4651,13 @@ exports.enforceVerbNounNaming = (0, createRule_1.createRule)({
4651
4651
  }
4652
4652
  }
4653
4653
  return false;
4654
- })()
4654
+ })(),
4655
+ // 5. Component name ends with "Unmemoized" (common React pattern)
4656
+ functionName && functionName.endsWith('Unmemoized')
4655
4657
  ];
4656
4658
  // Consider it a React component if it matches at least 2 indicators
4657
- return indicators.filter(Boolean).length >= 2;
4659
+ // OR if it has the Unmemoized suffix (strong indicator of a React component)
4660
+ return indicators.filter(Boolean).length >= 2 || (!!functionName && functionName.endsWith('Unmemoized'));
4658
4661
  }
4659
4662
  return {
4660
4663
  FunctionDeclaration(node) {
@@ -0,0 +1 @@
1
+ export declare const ensurePointerEventsNone: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"missingPointerEventsNone", [], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensurePointerEventsNone = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const createRule_1 = require("../utils/createRule");
6
+ /**
7
+ * Checks if a string contains a pseudo-element selector (::before or ::after)
8
+ */
9
+ function hasPseudoElementSelector(selector) {
10
+ return /::?(before|after)\b/i.test(selector);
11
+ }
12
+ /**
13
+ * Checks if a property name is position with absolute or fixed value
14
+ */
15
+ function isAbsoluteOrFixedPosition(propertyName, propertyValue) {
16
+ if (propertyName !== 'position')
17
+ return false;
18
+ return propertyValue === 'absolute' || propertyValue === 'fixed';
19
+ }
20
+ /**
21
+ * Checks if a property is pointer-events with a value
22
+ */
23
+ function isPointerEventsProperty(propertyName) {
24
+ return propertyName === 'pointerEvents' || propertyName === 'pointer-events';
25
+ }
26
+ exports.ensurePointerEventsNone = (0, createRule_1.createRule)({
27
+ name: 'ensure-pointer-events-none',
28
+ meta: {
29
+ type: 'suggestion',
30
+ docs: {
31
+ description: 'Ensure pointer-events: none is added to non-interactive pseudo-elements',
32
+ recommended: 'error',
33
+ },
34
+ fixable: 'code',
35
+ schema: [],
36
+ messages: {
37
+ missingPointerEventsNone: 'Pseudo-elements (::before, ::after) with position: absolute or fixed should have pointer-events: none to prevent blocking interactions with underlying elements',
38
+ },
39
+ },
40
+ defaultOptions: [],
41
+ create(context) {
42
+ // Track style objects that have position: absolute or fixed
43
+ const absolutePositionedStyles = new Map();
44
+ // Track style objects that already have pointer-events defined
45
+ const stylesWithPointerEvents = new Map();
46
+ /**
47
+ * Process a CSS-in-JS style object to check for position: absolute/fixed and pointer-events
48
+ */
49
+ function processStyleObject(node) {
50
+ let hasAbsolutePosition = false;
51
+ let pointerEventsValue;
52
+ // Check each property in the style object
53
+ for (const property of node.properties) {
54
+ if (property.type !== utils_1.AST_NODE_TYPES.Property)
55
+ continue;
56
+ let propertyName = '';
57
+ let propertyValue;
58
+ // Get property name
59
+ if (property.key.type === utils_1.AST_NODE_TYPES.Identifier) {
60
+ propertyName = property.key.name;
61
+ }
62
+ else if (property.key.type === utils_1.AST_NODE_TYPES.Literal && typeof property.key.value === 'string') {
63
+ propertyName = property.key.value;
64
+ }
65
+ // Get property value if it's a string literal
66
+ if (property.value.type === utils_1.AST_NODE_TYPES.Literal) {
67
+ propertyValue = String(property.value.value);
68
+ }
69
+ else if (property.value.type === utils_1.AST_NODE_TYPES.Identifier) {
70
+ propertyValue = property.value.name;
71
+ }
72
+ // Check if this is position: absolute/fixed
73
+ if (isAbsoluteOrFixedPosition(propertyName, propertyValue)) {
74
+ hasAbsolutePosition = true;
75
+ }
76
+ // Check if this is pointer-events property
77
+ if (isPointerEventsProperty(propertyName)) {
78
+ if (property.value.type === utils_1.AST_NODE_TYPES.Literal) {
79
+ pointerEventsValue = String(property.value.value);
80
+ }
81
+ else if (property.value.type === utils_1.AST_NODE_TYPES.Identifier) {
82
+ pointerEventsValue = property.value.name;
83
+ }
84
+ }
85
+ }
86
+ // Store the results for this style object
87
+ absolutePositionedStyles.set(node, hasAbsolutePosition);
88
+ if (pointerEventsValue !== undefined) {
89
+ stylesWithPointerEvents.set(node, pointerEventsValue);
90
+ }
91
+ }
92
+ /**
93
+ * Check if a style object needs pointer-events: none
94
+ */
95
+ function checkStyleObject(node, selector) {
96
+ const isPseudoElement = selector && hasPseudoElementSelector(selector);
97
+ const isAbsolutePositioned = absolutePositionedStyles.get(node) || false;
98
+ const pointerEventsValue = stylesWithPointerEvents.get(node);
99
+ // If this is a pseudo-element with absolute positioning but no pointer-events
100
+ if (isPseudoElement && isAbsolutePositioned && pointerEventsValue === undefined) {
101
+ context.report({
102
+ node,
103
+ messageId: 'missingPointerEventsNone',
104
+ fix(fixer) {
105
+ // Find the last property in the object
106
+ const sourceCode = context.getSourceCode();
107
+ const properties = node.properties;
108
+ if (properties.length === 0)
109
+ return null;
110
+ const lastProperty = properties[properties.length - 1];
111
+ const lastPropertyToken = sourceCode.getLastToken(lastProperty);
112
+ if (lastPropertyToken) {
113
+ return fixer.insertTextAfter(lastPropertyToken, `, pointerEvents: 'none'`);
114
+ }
115
+ return null;
116
+ }
117
+ });
118
+ }
119
+ // If this is a pseudo-element with absolute positioning and pointer-events: auto
120
+ if (isPseudoElement && isAbsolutePositioned && pointerEventsValue === 'auto') {
121
+ // Don't report an error if pointer-events is explicitly set to 'auto'
122
+ // This is an intentional choice by the developer
123
+ }
124
+ }
125
+ return {
126
+ // Check for pseudo-element selectors in styled-components and similar libraries
127
+ TaggedTemplateExpression(node) {
128
+ // Check if this is a styled-components template
129
+ const tag = node.tag;
130
+ let isStyledComponent = false;
131
+ if (tag.type === utils_1.AST_NODE_TYPES.MemberExpression &&
132
+ tag.object.type === utils_1.AST_NODE_TYPES.Identifier &&
133
+ tag.object.name === 'styled') {
134
+ isStyledComponent = true;
135
+ }
136
+ else if (tag.type === utils_1.AST_NODE_TYPES.Identifier &&
137
+ (tag.name === 'styled' || tag.name === 'css')) {
138
+ isStyledComponent = true;
139
+ }
140
+ if (isStyledComponent) {
141
+ // For styled-components, we need to check the template content
142
+ const template = node.quasi.quasis.map(q => q.value.raw).join('');
143
+ // Check if it contains a pseudo-element with position: absolute/fixed
144
+ if (hasPseudoElementSelector(template) &&
145
+ (template.includes('position: absolute') || template.includes('position: fixed'))) {
146
+ // Check if it's missing pointer-events: none
147
+ if (!template.includes('pointer-events: none') && !template.includes('pointer-events:none')) {
148
+ context.report({
149
+ node,
150
+ messageId: 'missingPointerEventsNone'
151
+ });
152
+ }
153
+ }
154
+ }
155
+ },
156
+ // Process style objects in JSX
157
+ JSXAttribute(node) {
158
+ if (node.name.type !== utils_1.AST_NODE_TYPES.JSXIdentifier || node.name.name !== 'style')
159
+ return;
160
+ if (node.value?.type === utils_1.AST_NODE_TYPES.JSXExpressionContainer &&
161
+ node.value.expression.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
162
+ processStyleObject(node.value.expression);
163
+ checkStyleObject(node.value.expression);
164
+ }
165
+ },
166
+ // Process style objects in regular JavaScript/TypeScript
167
+ ObjectExpression(node) {
168
+ // Skip if parent is not a variable declaration or assignment
169
+ const parent = node.parent;
170
+ if (!parent)
171
+ return;
172
+ // Check if this might be a style object
173
+ let isStyleObject = false;
174
+ let selector;
175
+ if (parent.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
176
+ parent.id.type === utils_1.AST_NODE_TYPES.Identifier &&
177
+ /style/i.test(parent.id.name)) {
178
+ isStyleObject = true;
179
+ }
180
+ else if (parent.type === utils_1.AST_NODE_TYPES.Property &&
181
+ parent.key.type === utils_1.AST_NODE_TYPES.Identifier &&
182
+ /style/i.test(parent.key.name)) {
183
+ isStyleObject = true;
184
+ }
185
+ else if (parent.type === utils_1.AST_NODE_TYPES.CallExpression) {
186
+ // Check for CSS-in-JS libraries like emotion's css() function
187
+ const callee = parent.callee;
188
+ if (callee.type === utils_1.AST_NODE_TYPES.Identifier && callee.name === 'css') {
189
+ isStyleObject = true;
190
+ }
191
+ }
192
+ if (isStyleObject) {
193
+ processStyleObject(node);
194
+ checkStyleObject(node, selector);
195
+ }
196
+ },
197
+ // Process CSS-in-JS libraries that use objects with selectors
198
+ Property(node) {
199
+ // Check for patterns like { '&::before': { ... } }
200
+ if (node.key.type === utils_1.AST_NODE_TYPES.Literal &&
201
+ typeof node.key.value === 'string' &&
202
+ hasPseudoElementSelector(node.key.value) &&
203
+ node.value.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
204
+ processStyleObject(node.value);
205
+ checkStyleObject(node.value, node.key.value);
206
+ }
207
+ }
208
+ };
209
+ },
210
+ });
211
+ //# sourceMappingURL=ensure-pointer-events-none.js.map
@@ -1,2 +1,2 @@
1
1
  import { TSESLint } from '@typescript-eslint/utils';
2
- export declare const extractGlobalConstants: TSESLint.RuleModule<'extractGlobalConstants', never[]>;
2
+ export declare const extractGlobalConstants: TSESLint.RuleModule<'extractGlobalConstants' | 'requireAsConst', never[]>;
@@ -90,6 +90,29 @@ function isMutableValue(node) {
90
90
  }
91
91
  return false;
92
92
  }
93
+ function isNumericLiteral(node) {
94
+ if (!node)
95
+ return false;
96
+ return node.type === 'Literal' && typeof node.value === 'number';
97
+ }
98
+ function isZeroOrOne(node) {
99
+ if (!isNumericLiteral(node))
100
+ return false;
101
+ const value = node.value;
102
+ return value === 0 || value === 1;
103
+ }
104
+ function isAsConstExpression(node) {
105
+ if (!node)
106
+ return false;
107
+ if (node.type === 'TSAsExpression') {
108
+ if (node.typeAnnotation.type === 'TSTypeReference' &&
109
+ node.typeAnnotation.typeName.type === 'Identifier' &&
110
+ node.typeAnnotation.typeName.name === 'const') {
111
+ return true;
112
+ }
113
+ }
114
+ return false;
115
+ }
93
116
  exports.extractGlobalConstants = (0, createRule_1.createRule)({
94
117
  create(context) {
95
118
  return {
@@ -104,8 +127,11 @@ exports.extractGlobalConstants = (0, createRule_1.createRule)({
104
127
  const scope = context.getScope();
105
128
  const hasDependencies = node.declarations.some((declaration) => declaration.init &&
106
129
  ASTHelpers_1.ASTHelpers.declarationIncludesIdentifier(declaration.init));
130
+ // Skip constants with 'as const' type assertions used in loops
131
+ const hasAsConstAssertion = node.declarations.some((declaration) => declaration.init && isAsConstExpression(declaration.init));
107
132
  // Only check function/block scoped constants without dependencies
108
133
  if (!hasDependencies &&
134
+ !hasAsConstAssertion &&
109
135
  (scope.type === 'function' || scope.type === 'block') &&
110
136
  isInsideFunction(node)) {
111
137
  const constName = node.declarations[0].id
@@ -138,18 +164,100 @@ exports.extractGlobalConstants = (0, createRule_1.createRule)({
138
164
  }
139
165
  }
140
166
  },
167
+ ForStatement(node) {
168
+ // Check initialization
169
+ if (node.init && node.init.type === 'VariableDeclaration') {
170
+ for (const decl of node.init.declarations) {
171
+ if (decl.init && isNumericLiteral(decl.init) && !isZeroOrOne(decl.init) && !isAsConstExpression(decl.init)) {
172
+ context.report({
173
+ node: decl.init,
174
+ messageId: 'requireAsConst',
175
+ data: {
176
+ value: decl.init.value,
177
+ },
178
+ });
179
+ }
180
+ }
181
+ }
182
+ // Check test condition
183
+ if (node.test && node.test.type === 'BinaryExpression') {
184
+ if (isNumericLiteral(node.test.right) && !isZeroOrOne(node.test.right) && !isAsConstExpression(node.test.right)) {
185
+ context.report({
186
+ node: node.test.right,
187
+ messageId: 'requireAsConst',
188
+ data: {
189
+ value: node.test.right.value,
190
+ },
191
+ });
192
+ }
193
+ }
194
+ // Check update expression
195
+ if (node.update) {
196
+ if (node.update.type === 'AssignmentExpression') {
197
+ if (node.update.right && isNumericLiteral(node.update.right) && !isZeroOrOne(node.update.right) && !isAsConstExpression(node.update.right)) {
198
+ context.report({
199
+ node: node.update.right,
200
+ messageId: 'requireAsConst',
201
+ data: {
202
+ value: node.update.right.value,
203
+ },
204
+ });
205
+ }
206
+ }
207
+ else if (node.update.type === 'BinaryExpression') {
208
+ if (isNumericLiteral(node.update.right) && !isZeroOrOne(node.update.right) && !isAsConstExpression(node.update.right)) {
209
+ context.report({
210
+ node: node.update.right,
211
+ messageId: 'requireAsConst',
212
+ data: {
213
+ value: node.update.right.value,
214
+ },
215
+ });
216
+ }
217
+ }
218
+ }
219
+ },
220
+ WhileStatement(node) {
221
+ // Check test condition
222
+ if (node.test.type === 'BinaryExpression') {
223
+ if (isNumericLiteral(node.test.right) && !isZeroOrOne(node.test.right) && !isAsConstExpression(node.test.right)) {
224
+ context.report({
225
+ node: node.test.right,
226
+ messageId: 'requireAsConst',
227
+ data: {
228
+ value: node.test.right.value,
229
+ },
230
+ });
231
+ }
232
+ }
233
+ },
234
+ DoWhileStatement(node) {
235
+ // Check test condition
236
+ if (node.test.type === 'BinaryExpression') {
237
+ if (isNumericLiteral(node.test.right) && !isZeroOrOne(node.test.right) && !isAsConstExpression(node.test.right)) {
238
+ context.report({
239
+ node: node.test.right,
240
+ messageId: 'requireAsConst',
241
+ data: {
242
+ value: node.test.right.value,
243
+ },
244
+ });
245
+ }
246
+ }
247
+ },
141
248
  };
142
249
  },
143
250
  name: 'extract-global-constants',
144
251
  meta: {
145
252
  type: 'suggestion',
146
253
  docs: {
147
- description: 'Extract static constants and functions to the global scope when possible',
254
+ description: 'Extract static constants and functions to the global scope when possible, and enforce type narrowing with as const for numeric literals in loops',
148
255
  recommended: 'error',
149
256
  },
150
257
  schema: [],
151
258
  messages: {
152
259
  extractGlobalConstants: 'Move this declaration {{ declarationName }} to the global scope and rename it to UPPER_SNAKE_CASE if necessary.',
260
+ requireAsConst: 'Numeric literal {{ value }} in loop expression should be extracted to a constant with "as const" type assertion.',
153
261
  },
154
262
  },
155
263
  defaultOptions: [],
@@ -29,8 +29,9 @@ exports.default = (0, createRule_1.createRule)({
29
29
  if (node.kind !== 'const') {
30
30
  return;
31
31
  }
32
- // Skip if not at program level
33
- if (node.parent?.type !== utils_1.AST_NODE_TYPES.Program) {
32
+ // Skip if not at program level or not an exported declaration
33
+ if (node.parent?.type !== utils_1.AST_NODE_TYPES.Program &&
34
+ node.parent?.type !== utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
34
35
  return;
35
36
  }
36
37
  // Skip if any declaration is a function component, arrow function, forwardRef, or memo
@@ -0,0 +1,3 @@
1
+ type MessageIds = 'keyOnlyOutermostElement' | 'fragmentShouldHaveKey';
2
+ export declare const keyOnlyOutermostElement: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<MessageIds, [], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
3
+ export {};