@agilebot/eslint-plugin 0.8.10 → 0.9.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.
- package/dist/index.js +146 -214
- package/package.json +6 -7
- package/dist/index.mjs +0 -2763
package/dist/index.js
CHANGED
|
@@ -1,41 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path$1 from "node:path";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { isCamelCase, isPascalCase, tsImport } from "@agilebot/eslint-utils";
|
|
7
|
+
import * as Components from "eslint-plugin-react/lib/util/Components.js";
|
|
9
8
|
|
|
10
9
|
//#region rolldown:runtime
|
|
11
|
-
var
|
|
12
|
-
var __defProp = Object.defineProperty;
|
|
13
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
16
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
-
var __copyProps = (to, from, except, desc) => {
|
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
-
key = keys[i];
|
|
20
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
-
get: ((k) => from[k]).bind(null, key),
|
|
22
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
10
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
31
11
|
|
|
32
12
|
//#endregion
|
|
33
|
-
const __typescript_eslint_utils = __toESM(require("@typescript-eslint/utils"));
|
|
34
|
-
const node_fs = __toESM(require("node:fs"));
|
|
35
|
-
const node_path = __toESM(require("node:path"));
|
|
36
|
-
const __agilebot_eslint_utils = __toESM(require("@agilebot/eslint-utils"));
|
|
37
|
-
const eslint_plugin_react_lib_util_Components_js = __toESM(require("eslint-plugin-react/lib/util/Components.js"));
|
|
38
|
-
|
|
39
13
|
//#region src/util/rule.js
|
|
40
14
|
const docBaseUrl = "https://github.com/sh-agilebot/frontend-toolkit/blob/master/packages/eslint-plugin/src/rules/";
|
|
41
15
|
const hasDocs = [
|
|
@@ -45,7 +19,7 @@ const hasDocs = [
|
|
|
45
19
|
"intl-no-default",
|
|
46
20
|
"react-better-exhaustive-deps"
|
|
47
21
|
];
|
|
48
|
-
const createRule =
|
|
22
|
+
const createRule = ESLintUtils.RuleCreator((name) => hasDocs.includes(name) ? `${docBaseUrl}${name}.md` : `${docBaseUrl}${name}.test.js`);
|
|
49
23
|
|
|
50
24
|
//#endregion
|
|
51
25
|
//#region src/rules/enforce-mui-icon-alias.js
|
|
@@ -67,7 +41,7 @@ var enforce_mui_icon_alias_default = createRule({
|
|
|
67
41
|
return { ImportDeclaration(node) {
|
|
68
42
|
if (node.source.value !== "@mui/icons-material" && node.source.value !== "mdi-material-ui") return;
|
|
69
43
|
for (const specifier of node.specifiers) {
|
|
70
|
-
if (specifier.type !==
|
|
44
|
+
if (specifier.type !== AST_NODE_TYPES.ImportSpecifier) return;
|
|
71
45
|
if (specifier.imported.name === specifier.local.name || !specifier.local.name.endsWith("Icon")) context.report({
|
|
72
46
|
node,
|
|
73
47
|
messageId: "iconAlias",
|
|
@@ -82,15 +56,10 @@ var enforce_mui_icon_alias_default = createRule({
|
|
|
82
56
|
//#endregion
|
|
83
57
|
//#region src/util/context.js
|
|
84
58
|
/**
|
|
85
|
-
|
|
86
59
|
* Get a setting from eslint config
|
|
87
|
-
|
|
88
60
|
* @param {import('eslint').Rule.RuleContext} context - Context
|
|
89
|
-
|
|
90
61
|
* @param {string} name - Name
|
|
91
|
-
|
|
92
62
|
* @returns {*} - result
|
|
93
|
-
|
|
94
63
|
*/
|
|
95
64
|
function getSetting(context, name) {
|
|
96
65
|
return context.settings[`agilebot/${name}`];
|
|
@@ -142,8 +111,8 @@ var import_monorepo_default = createRule({
|
|
|
142
111
|
* @returns {*} node - returns node if it finds the attribute.
|
|
143
112
|
*/
|
|
144
113
|
function findFormatMessageAttrNode(node, attrName) {
|
|
145
|
-
if (node.type ===
|
|
146
|
-
if (node.type ===
|
|
114
|
+
if (node.type === AST_NODE_TYPES.CallExpression && (node.callee.name === "formatMessage" || node.callee.name === "$t") && node.arguments.length > 0 && node.arguments[0].properties) return node.arguments[0].properties.find((a) => a.key && a.key.name === attrName);
|
|
115
|
+
if (node.type === AST_NODE_TYPES.CallExpression && node.callee.type === AST_NODE_TYPES.MemberExpression && (node.callee.object.name === "intl" || node.callee.object.name && node.callee.object.name.endsWith("Intl")) && (node.callee.property.name === "formatMessage" || node.callee.property.name === "$t")) return node.arguments[0].properties.find((a) => a.key && a.key.name === attrName);
|
|
147
116
|
}
|
|
148
117
|
/**
|
|
149
118
|
* Finds an attribute in FormattedMessage using attribute name.
|
|
@@ -152,7 +121,7 @@ function findFormatMessageAttrNode(node, attrName) {
|
|
|
152
121
|
* @returns {*} node - returns node if it finds the attribute.
|
|
153
122
|
*/
|
|
154
123
|
function findFormattedMessageAttrNode(node, attrName) {
|
|
155
|
-
if (node.type ===
|
|
124
|
+
if (node.type === AST_NODE_TYPES.JSXIdentifier && node.name === "FormattedMessage" && node.parent && node.parent.type === AST_NODE_TYPES.JSXOpeningElement) return node.parent.attributes.find((a) => a.name && a.name.name === attrName);
|
|
156
125
|
}
|
|
157
126
|
/**
|
|
158
127
|
* Finds an attribute in defineMessages using attribute name.
|
|
@@ -161,7 +130,7 @@ function findFormattedMessageAttrNode(node, attrName) {
|
|
|
161
130
|
* @returns {*} node - returns node if it finds the attribute.
|
|
162
131
|
*/
|
|
163
132
|
function findAttrNodeInDefineMessages(node, attrName) {
|
|
164
|
-
if (node.type === "Property" && node.key.name === attrName && node.parent && node.parent.parent && node.parent.parent.parent && node.parent.parent.parent.parent && node.parent.parent.parent.parent.type ===
|
|
133
|
+
if (node.type === "Property" && node.key.name === attrName && node.parent && node.parent.parent && node.parent.parent.parent && node.parent.parent.parent.parent && node.parent.parent.parent.parent.type === AST_NODE_TYPES.CallExpression && node.parent.parent.parent.parent.callee.name === "defineMessages") return node;
|
|
165
134
|
}
|
|
166
135
|
/**
|
|
167
136
|
* Finds an attribute in defineMessages using attribute name.
|
|
@@ -170,7 +139,7 @@ function findAttrNodeInDefineMessages(node, attrName) {
|
|
|
170
139
|
* @returns {*} node - returns node if it finds the attribute.
|
|
171
140
|
*/
|
|
172
141
|
function findAttrNodeInDefineMessage(node, attrName) {
|
|
173
|
-
if (node.type === "Property" && node.key.name === attrName && node.parent && node.parent.parent && node.parent.parent.type ===
|
|
142
|
+
if (node.type === "Property" && node.key.name === attrName && node.parent && node.parent.parent && node.parent.parent.type === AST_NODE_TYPES.CallExpression && node.parent.parent.callee.name === "defineMessage") return node;
|
|
174
143
|
}
|
|
175
144
|
/**
|
|
176
145
|
* Returns a sorted array of nodes, based on their starting posting in the locale id.
|
|
@@ -192,23 +161,15 @@ function templateLiteralDisplayStr(node) {
|
|
|
192
161
|
//#endregion
|
|
193
162
|
//#region src/util/translations.js
|
|
194
163
|
/**
|
|
195
|
-
|
|
196
164
|
* Map of locale file paths to keys and modified time
|
|
197
|
-
|
|
198
165
|
* @type {Record<string, {keys: Array<string>, mtime: number}>}
|
|
199
|
-
|
|
200
166
|
*/
|
|
201
167
|
const localeFilesKeys = {};
|
|
202
168
|
/**
|
|
203
|
-
|
|
204
169
|
* Get a list of ids keys from reading locale files
|
|
205
|
-
|
|
206
170
|
* Keeps track of modified times and reloads if changed,; useful for realtime eslint in-editor
|
|
207
|
-
|
|
208
171
|
* @param {import('eslint').Rule.RuleContext} context - Context
|
|
209
|
-
|
|
210
172
|
* @returns {string[]} results - Array of ids
|
|
211
|
-
|
|
212
173
|
*/
|
|
213
174
|
function getIntlIds(context) {
|
|
214
175
|
const projectRoot = getSetting(context, "project-root");
|
|
@@ -216,16 +177,16 @@ function getIntlIds(context) {
|
|
|
216
177
|
if (!localeFiles) throw new Error("localeFiles not in settings");
|
|
217
178
|
const results = [];
|
|
218
179
|
localeFiles.forEach((f) => {
|
|
219
|
-
const fullPath = projectRoot ?
|
|
220
|
-
const mtime =
|
|
180
|
+
const fullPath = projectRoot ? path$1.join(projectRoot, f) : f;
|
|
181
|
+
const mtime = fs.lstatSync(fullPath).mtime.getTime();
|
|
221
182
|
if (!localeFilesKeys[fullPath] || mtime !== localeFilesKeys[fullPath].mtime) {
|
|
222
183
|
let json;
|
|
223
|
-
if (fullPath.endsWith(".json")) json = JSON.parse(
|
|
184
|
+
if (fullPath.endsWith(".json")) json = JSON.parse(fs.readFileSync(fullPath, "utf8"));
|
|
224
185
|
else if (fullPath.endsWith(".ts")) {
|
|
225
|
-
json =
|
|
186
|
+
json = tsImport(fullPath);
|
|
226
187
|
if (typeof json === "object" && json.default) json = json.default;
|
|
227
188
|
} else if (fullPath.endsWith(".js")) {
|
|
228
|
-
json =
|
|
189
|
+
json = __require(fullPath);
|
|
229
190
|
if (typeof json === "object" && json.default) json = json.default;
|
|
230
191
|
} else throw new Error("unsupported file extension");
|
|
231
192
|
localeFilesKeys[fullPath] = {
|
|
@@ -272,17 +233,16 @@ var intl_id_missing_default = createRule({
|
|
|
272
233
|
}
|
|
273
234
|
function processTemplateLiteral(node) {
|
|
274
235
|
const exStr = sortedTemplateElements(node).map((e) => !e.value ? ".*" : e.value.raw).join("");
|
|
275
|
-
|
|
276
|
-
if (!isTemplateTranslated(re)) context.report({
|
|
236
|
+
if (!isTemplateTranslated(new RegExp(exStr))) context.report({
|
|
277
237
|
node,
|
|
278
238
|
messageId: "missingIdPattern",
|
|
279
239
|
data: { value: templateLiteralDisplayStr(node) }
|
|
280
240
|
});
|
|
281
241
|
}
|
|
282
242
|
function processAttrNode(node) {
|
|
283
|
-
if (node.value.type ===
|
|
284
|
-
if (node.value.type ===
|
|
285
|
-
if (node.value.type ===
|
|
243
|
+
if (node.value.type === AST_NODE_TYPES.Literal) return processLiteral(node.value);
|
|
244
|
+
if (node.value.type === AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === AST_NODE_TYPES.TemplateLiteral) return processTemplateLiteral(node.value.expression);
|
|
245
|
+
if (node.value.type === AST_NODE_TYPES.TemplateLiteral) return processTemplateLiteral(node.value);
|
|
286
246
|
context.report({
|
|
287
247
|
node,
|
|
288
248
|
messageId: "disallowInvoke",
|
|
@@ -332,10 +292,10 @@ var intl_id_naming_default = createRule({
|
|
|
332
292
|
let isPass;
|
|
333
293
|
for (const v of values) switch (format) {
|
|
334
294
|
case "camelCase":
|
|
335
|
-
if (!
|
|
295
|
+
if (!isCamelCase(v)) isPass = false;
|
|
336
296
|
break;
|
|
337
297
|
case "PascalCase":
|
|
338
|
-
if (!
|
|
298
|
+
if (!isPascalCase(v)) isPass = false;
|
|
339
299
|
break;
|
|
340
300
|
}
|
|
341
301
|
if (isPass === false) context.report({
|
|
@@ -348,13 +308,12 @@ var intl_id_naming_default = createRule({
|
|
|
348
308
|
report(node, node.value);
|
|
349
309
|
}
|
|
350
310
|
function processTemplateLiteral(node) {
|
|
351
|
-
|
|
352
|
-
report(node, displayStr);
|
|
311
|
+
report(node, templateLiteralDisplayStr(node));
|
|
353
312
|
}
|
|
354
313
|
function processAttrNode(node) {
|
|
355
|
-
if (node.value.type ===
|
|
356
|
-
if (node.value.type ===
|
|
357
|
-
if (node.value.type ===
|
|
314
|
+
if (node.value.type === AST_NODE_TYPES.Literal) return processLiteral(node.value);
|
|
315
|
+
if (node.value.type === AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === AST_NODE_TYPES.TemplateLiteral) return processTemplateLiteral(node.value.expression);
|
|
316
|
+
if (node.value.type === AST_NODE_TYPES.TemplateLiteral) return processTemplateLiteral(node.value);
|
|
358
317
|
}
|
|
359
318
|
return {
|
|
360
319
|
JSXIdentifier: function(node) {
|
|
@@ -402,13 +361,12 @@ var intl_id_prefix_default = createRule({
|
|
|
402
361
|
report(node, node.value);
|
|
403
362
|
}
|
|
404
363
|
function processTemplateLiteral(node) {
|
|
405
|
-
|
|
406
|
-
report(node, displayStr);
|
|
364
|
+
report(node, templateLiteralDisplayStr(node));
|
|
407
365
|
}
|
|
408
366
|
function processAttrNode(node) {
|
|
409
|
-
if (node.value.type ===
|
|
410
|
-
if (node.value.type ===
|
|
411
|
-
if (node.value.type ===
|
|
367
|
+
if (node.value.type === AST_NODE_TYPES.Literal) return processLiteral(node.value);
|
|
368
|
+
if (node.value.type === AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === AST_NODE_TYPES.TemplateLiteral) return processTemplateLiteral(node.value.expression);
|
|
369
|
+
if (node.value.type === AST_NODE_TYPES.TemplateLiteral) return processTemplateLiteral(node.value);
|
|
412
370
|
}
|
|
413
371
|
return {
|
|
414
372
|
JSXIdentifier: function(node) {
|
|
@@ -458,13 +416,12 @@ var intl_id_unused_default = createRule({
|
|
|
458
416
|
}
|
|
459
417
|
function processTemplateLiteral(node) {
|
|
460
418
|
const exStr = sortedTemplateElements(node).map((e) => !e.value ? ".*" : e.value.raw).join("");
|
|
461
|
-
|
|
462
|
-
if (isTemplateTranslated(re)) {}
|
|
419
|
+
if (isTemplateTranslated(new RegExp(exStr))) {}
|
|
463
420
|
}
|
|
464
421
|
function processAttrNode(node) {
|
|
465
|
-
if (node.value.type ===
|
|
466
|
-
if (node.value.type ===
|
|
467
|
-
if (node.value.type ===
|
|
422
|
+
if (node.value.type === AST_NODE_TYPES.Literal) return processLiteral(node.value);
|
|
423
|
+
if (node.value.type === AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === AST_NODE_TYPES.TemplateLiteral) return processTemplateLiteral(node.value.expression);
|
|
424
|
+
if (node.value.type === AST_NODE_TYPES.TemplateLiteral) return processTemplateLiteral(node.value);
|
|
468
425
|
}
|
|
469
426
|
return {
|
|
470
427
|
JSXIdentifier: function(node) {
|
|
@@ -481,8 +438,8 @@ var intl_id_unused_default = createRule({
|
|
|
481
438
|
},
|
|
482
439
|
"Program:exit": function() {
|
|
483
440
|
const unusedIds = [...translatedIdSet].filter((id) => !usedIdSet.has(id));
|
|
484
|
-
const jsonPath =
|
|
485
|
-
|
|
441
|
+
const jsonPath = path$1.join(projectRoot, "intl-unused.json");
|
|
442
|
+
fs.writeFileSync(jsonPath, JSON.stringify(unusedIds, null, 2));
|
|
486
443
|
}
|
|
487
444
|
};
|
|
488
445
|
}
|
|
@@ -559,7 +516,7 @@ var no_async_array_methods_default = createRule({
|
|
|
559
516
|
if (!callee || !callee.property || !callee.property.name) return;
|
|
560
517
|
if (notAllowedArrayMethods.includes(callee.property.name)) {
|
|
561
518
|
const functionArguments = node.expression.arguments.find((n) => {
|
|
562
|
-
return [
|
|
519
|
+
return [AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression].includes(n.type);
|
|
563
520
|
});
|
|
564
521
|
if (functionArguments && functionArguments.async) context.report({
|
|
565
522
|
node,
|
|
@@ -588,7 +545,7 @@ var no_extends_error_default = createRule({
|
|
|
588
545
|
defaultOptions: [],
|
|
589
546
|
create(context) {
|
|
590
547
|
return { ClassDeclaration(node) {
|
|
591
|
-
if (node.superClass && node.superClass.type ===
|
|
548
|
+
if (node.superClass && node.superClass.type === AST_NODE_TYPES.Identifier && node.superClass.name === "Error") context.report({
|
|
592
549
|
node: node.superClass,
|
|
593
550
|
messageId: "noExtendsError"
|
|
594
551
|
});
|
|
@@ -613,7 +570,7 @@ var no_import_css_default = createRule({
|
|
|
613
570
|
defaultOptions: [],
|
|
614
571
|
create(context) {
|
|
615
572
|
return { ImportDeclaration(node) {
|
|
616
|
-
const ext =
|
|
573
|
+
const ext = path.extname(node.source.value);
|
|
617
574
|
if (ext.startsWith(".css") || ext.startsWith(".scss") || ext.startsWith(".sass") || ext.startsWith(".less") || ext.startsWith(".styl")) context.report({
|
|
618
575
|
node,
|
|
619
576
|
messageId: "noImportCSS",
|
|
@@ -643,8 +600,7 @@ var no_then_catch_finally_default = createRule({
|
|
|
643
600
|
},
|
|
644
601
|
defaultOptions: [],
|
|
645
602
|
create(context) {
|
|
646
|
-
const
|
|
647
|
-
const restrictedFunctions = configuration.restrictedFunctions || [];
|
|
603
|
+
const restrictedFunctions = (context.options[0] || {}).restrictedFunctions || [];
|
|
648
604
|
const getScope = typeof context.getScope === "function" ? () => {
|
|
649
605
|
return context.getScope();
|
|
650
606
|
} : (node) => {
|
|
@@ -665,11 +621,11 @@ var no_then_catch_finally_default = createRule({
|
|
|
665
621
|
function isThenCatchFinally(node) {
|
|
666
622
|
return node.property && (node.property.name === "then" || node.property.name === "catch" || node.property.name === "finally");
|
|
667
623
|
}
|
|
668
|
-
return { [`${
|
|
624
|
+
return { [`${AST_NODE_TYPES.CallExpression} > ${AST_NODE_TYPES.MemberExpression}.callee`]: (node) => {
|
|
669
625
|
if (isTopLevelScoped(node)) return;
|
|
670
626
|
if (!isThenCatchFinally(node)) return;
|
|
671
627
|
const callExpression = node.object;
|
|
672
|
-
if (callExpression.type ===
|
|
628
|
+
if (callExpression.type === AST_NODE_TYPES.CallExpression && callExpression.callee.type === AST_NODE_TYPES.Identifier && restrictedFunctions.includes(callExpression.callee.name)) context.report({
|
|
673
629
|
node: node.property,
|
|
674
630
|
messageId: "forbiddenThenCatchFinally",
|
|
675
631
|
data: { name: callExpression.callee.name }
|
|
@@ -759,15 +715,12 @@ var react_better_exhaustive_deps_default = {
|
|
|
759
715
|
create(context) {
|
|
760
716
|
const additionalHooks = context.options && context.options[0] && context.options[0].additionalHooks ? new RegExp(context.options[0].additionalHooks) : void 0;
|
|
761
717
|
const enableDangerousAutofixThisMayCauseInfiniteLoops = context.options && context.options[0] && context.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops || false;
|
|
762
|
-
const customHooks = context.options && context.options[0] && context.options[0].customHooks || {};
|
|
763
|
-
const staticHooks = context.options && context.options[0] && context.options[0].staticHooks || {};
|
|
764
|
-
const checkMemoizedVariableIsStatic = context.options && context.options[0] && context.options[0].checkMemoizedVariableIsStatic || false;
|
|
765
718
|
const options = {
|
|
766
719
|
additionalHooks,
|
|
767
720
|
enableDangerousAutofixThisMayCauseInfiniteLoops,
|
|
768
|
-
customHooks,
|
|
769
|
-
staticHooks,
|
|
770
|
-
checkMemoizedVariableIsStatic
|
|
721
|
+
customHooks: context.options && context.options[0] && context.options[0].customHooks || {},
|
|
722
|
+
staticHooks: context.options && context.options[0] && context.options[0].staticHooks || {},
|
|
723
|
+
checkMemoizedVariableIsStatic: context.options && context.options[0] && context.options[0].checkMemoizedVariableIsStatic || false
|
|
771
724
|
};
|
|
772
725
|
function reportProblem(problem) {
|
|
773
726
|
if (enableDangerousAutofixThisMayCauseInfiniteLoops && Array.isArray(problem.suggest) && problem.suggest.length > 0) problem.fix = problem.suggest[0].fix;
|
|
@@ -951,8 +904,7 @@ var react_better_exhaustive_deps_default = {
|
|
|
951
904
|
for (const reference of currentScope.references) {
|
|
952
905
|
if (!reference.resolved) continue;
|
|
953
906
|
if (!pureScopes.has(reference.resolved.scope)) continue;
|
|
954
|
-
const
|
|
955
|
-
const dependencyNode = getDependency(referenceNode);
|
|
907
|
+
const dependencyNode = getDependency(fastFindReferenceWithParent(node, reference.identifier));
|
|
956
908
|
const dependency = analyzePropertyChain(dependencyNode, optionalChains);
|
|
957
909
|
if (isEffect && dependencyNode.type === "Identifier" && (dependencyNode.parent.type === "MemberExpression" || dependencyNode.parent.type === "OptionalMemberExpression") && !dependencyNode.parent.computed && dependencyNode.parent.property.type === "Identifier" && dependencyNode.parent.property.name === "current" && isInsideEffectCleanup(reference)) currentRefsInEffectCleanup.set(dependency, {
|
|
958
910
|
reference,
|
|
@@ -1014,12 +966,10 @@ var react_better_exhaustive_deps_default = {
|
|
|
1014
966
|
references.forEach((reference) => {
|
|
1015
967
|
if (setStateInsideEffectWithoutDeps) return;
|
|
1016
968
|
const id = reference.identifier;
|
|
1017
|
-
|
|
1018
|
-
if (!isSetState) return;
|
|
969
|
+
if (!setStateCallSites.has(id)) return;
|
|
1019
970
|
let fnScope = reference.from;
|
|
1020
971
|
while (fnScope.type !== "function") fnScope = fnScope.upper;
|
|
1021
|
-
|
|
1022
|
-
if (isDirectlyInsideEffect) setStateInsideEffectWithoutDeps = key;
|
|
972
|
+
if (fnScope.block === node) setStateInsideEffectWithoutDeps = key;
|
|
1023
973
|
});
|
|
1024
974
|
});
|
|
1025
975
|
if (setStateInsideEffectWithoutDeps) {
|
|
@@ -1051,58 +1001,55 @@ var react_better_exhaustive_deps_default = {
|
|
|
1051
1001
|
node: declaredDependenciesNode,
|
|
1052
1002
|
message: `React Hook ${getSource(reactiveHook)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`
|
|
1053
1003
|
});
|
|
1054
|
-
else {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
if (declaredDependencyNode.type === "SpreadElement") {
|
|
1059
|
-
reportProblem({
|
|
1060
|
-
node: declaredDependencyNode,
|
|
1061
|
-
message: `React Hook ${getSource(reactiveHook)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`
|
|
1062
|
-
});
|
|
1063
|
-
return;
|
|
1064
|
-
}
|
|
1065
|
-
if (useEffectEventVariables.has(declaredDependencyNode)) reportProblem({
|
|
1004
|
+
else (isTSAsArrayExpression ? declaredDependenciesNode.expression : declaredDependenciesNode).elements.forEach((declaredDependencyNode) => {
|
|
1005
|
+
if (declaredDependencyNode == null) return;
|
|
1006
|
+
if (declaredDependencyNode.type === "SpreadElement") {
|
|
1007
|
+
reportProblem({
|
|
1066
1008
|
node: declaredDependencyNode,
|
|
1067
|
-
message: `
|
|
1068
|
-
suggest: [{
|
|
1069
|
-
desc: `Remove the dependency \`${getSource(declaredDependencyNode)}\``,
|
|
1070
|
-
fix(fixer) {
|
|
1071
|
-
return fixer.removeRange(declaredDependencyNode.range);
|
|
1072
|
-
}
|
|
1073
|
-
}]
|
|
1009
|
+
message: `React Hook ${getSource(reactiveHook)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`
|
|
1074
1010
|
});
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
else reportProblem({
|
|
1085
|
-
node: declaredDependencyNode,
|
|
1086
|
-
message: `The ${declaredDependencyNode.raw} literal is not a valid dependency because it never changes. You can safely remove it.`
|
|
1087
|
-
});
|
|
1088
|
-
else reportProblem({
|
|
1089
|
-
node: declaredDependencyNode,
|
|
1090
|
-
message: `React Hook ${getSource(reactiveHook)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`
|
|
1091
|
-
});
|
|
1092
|
-
return;
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
if (useEffectEventVariables.has(declaredDependencyNode)) reportProblem({
|
|
1014
|
+
node: declaredDependencyNode,
|
|
1015
|
+
message: `Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${getSource(declaredDependencyNode)}\` from the list.`,
|
|
1016
|
+
suggest: [{
|
|
1017
|
+
desc: `Remove the dependency \`${getSource(declaredDependencyNode)}\``,
|
|
1018
|
+
fix(fixer) {
|
|
1019
|
+
return fixer.removeRange(declaredDependencyNode.range);
|
|
1093
1020
|
}
|
|
1094
|
-
|
|
1021
|
+
}]
|
|
1022
|
+
});
|
|
1023
|
+
let declaredDependency;
|
|
1024
|
+
try {
|
|
1025
|
+
declaredDependency = analyzePropertyChain(declaredDependencyNode, null);
|
|
1026
|
+
} catch (err) {
|
|
1027
|
+
if (/Unsupported node type/.test(err.message)) {
|
|
1028
|
+
if (declaredDependencyNode.type === "Literal") if (dependencies.has(declaredDependencyNode.value)) reportProblem({
|
|
1029
|
+
node: declaredDependencyNode,
|
|
1030
|
+
message: `The ${declaredDependencyNode.raw} literal is not a valid dependency because it never changes. Did you mean to include ${declaredDependencyNode.value} in the array instead?`
|
|
1031
|
+
});
|
|
1032
|
+
else reportProblem({
|
|
1033
|
+
node: declaredDependencyNode,
|
|
1034
|
+
message: `The ${declaredDependencyNode.raw} literal is not a valid dependency because it never changes. You can safely remove it.`
|
|
1035
|
+
});
|
|
1036
|
+
else reportProblem({
|
|
1037
|
+
node: declaredDependencyNode,
|
|
1038
|
+
message: `React Hook ${getSource(reactiveHook)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`
|
|
1039
|
+
});
|
|
1040
|
+
return;
|
|
1095
1041
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1042
|
+
throw err;
|
|
1043
|
+
}
|
|
1044
|
+
let maybeID = declaredDependencyNode;
|
|
1045
|
+
while (maybeID.type === "MemberExpression" || maybeID.type === "OptionalMemberExpression" || maybeID.type === "ChainExpression") maybeID = maybeID.object || maybeID.expression.object;
|
|
1046
|
+
const isDeclaredInComponent = !componentScope.through.some((ref) => ref.identifier === maybeID);
|
|
1047
|
+
declaredDependencies.push({
|
|
1048
|
+
key: declaredDependency,
|
|
1049
|
+
node: declaredDependencyNode
|
|
1104
1050
|
});
|
|
1105
|
-
|
|
1051
|
+
if (!isDeclaredInComponent) externalDependencies.add(declaredDependency);
|
|
1052
|
+
});
|
|
1106
1053
|
const { suggestedDependencies, unnecessaryDependencies, missingDependencies, duplicateDependencies } = collectRecommendations({
|
|
1107
1054
|
dependencies,
|
|
1108
1055
|
declaredDependencies,
|
|
@@ -1111,15 +1058,13 @@ var react_better_exhaustive_deps_default = {
|
|
|
1111
1058
|
isEffect
|
|
1112
1059
|
});
|
|
1113
1060
|
let suggestedDeps = suggestedDependencies;
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
const constructions = scanForConstructions({
|
|
1061
|
+
if (duplicateDependencies.size + missingDependencies.size + unnecessaryDependencies.size === 0) {
|
|
1062
|
+
scanForConstructions({
|
|
1117
1063
|
declaredDependencies,
|
|
1118
1064
|
declaredDependenciesNode,
|
|
1119
1065
|
componentScope,
|
|
1120
1066
|
scope
|
|
1121
|
-
})
|
|
1122
|
-
constructions.forEach(({ construction, isUsedOutsideOfHook, depType }) => {
|
|
1067
|
+
}).forEach(({ construction, isUsedOutsideOfHook, depType }) => {
|
|
1123
1068
|
const wrapperHook = depType === "function" ? "useCallback" : "useMemo";
|
|
1124
1069
|
const constructionType = depType === "function" ? "definition" : "initialization";
|
|
1125
1070
|
const defaultAdvice = `wrap the ${constructionType} of '${construction.name.name}' in its own ${wrapperHook}() Hook.`;
|
|
@@ -1156,8 +1101,8 @@ var react_better_exhaustive_deps_default = {
|
|
|
1156
1101
|
return declaredDepKeys.join(",") === sortedDeclaredDepKeys.join(",");
|
|
1157
1102
|
}
|
|
1158
1103
|
if (areDeclaredDepsAlphabetized()) suggestedDeps.sort();
|
|
1159
|
-
function formatDependency(path$
|
|
1160
|
-
const members = path$
|
|
1104
|
+
function formatDependency(path$2) {
|
|
1105
|
+
const members = path$2.split(".");
|
|
1161
1106
|
let finalPath = "";
|
|
1162
1107
|
for (let i = 0; i < members.length; i++) {
|
|
1163
1108
|
if (i !== 0) {
|
|
@@ -1237,8 +1182,7 @@ var react_better_exhaustive_deps_default = {
|
|
|
1237
1182
|
let setStateRecommendation = null;
|
|
1238
1183
|
missingDependencies.forEach((missingDep) => {
|
|
1239
1184
|
if (setStateRecommendation != null) return;
|
|
1240
|
-
const
|
|
1241
|
-
const references = usedDep.references;
|
|
1185
|
+
const references = dependencies.get(missingDep).references;
|
|
1242
1186
|
let id;
|
|
1243
1187
|
let maybeCall;
|
|
1244
1188
|
for (const reference of references) {
|
|
@@ -1402,8 +1346,8 @@ function collectRecommendations({ dependencies, declaredDependencies, stableDepe
|
|
|
1402
1346
|
const node = getOrCreateNodeByPath(depTree, key);
|
|
1403
1347
|
node.isSatisfiedRecursively = true;
|
|
1404
1348
|
});
|
|
1405
|
-
function getOrCreateNodeByPath(rootNode, path$
|
|
1406
|
-
const keys = path$
|
|
1349
|
+
function getOrCreateNodeByPath(rootNode, path$2) {
|
|
1350
|
+
const keys = path$2.split(".");
|
|
1407
1351
|
let node = rootNode;
|
|
1408
1352
|
for (const key of keys) {
|
|
1409
1353
|
let child = node.children.get(key);
|
|
@@ -1415,8 +1359,8 @@ function collectRecommendations({ dependencies, declaredDependencies, stableDepe
|
|
|
1415
1359
|
}
|
|
1416
1360
|
return node;
|
|
1417
1361
|
}
|
|
1418
|
-
function markAllParentsByPath(rootNode, path$
|
|
1419
|
-
const keys = path$
|
|
1362
|
+
function markAllParentsByPath(rootNode, path$2, fn) {
|
|
1363
|
+
const keys = path$2.split(".");
|
|
1420
1364
|
let node = rootNode;
|
|
1421
1365
|
for (const key of keys) {
|
|
1422
1366
|
const child = node.children.get(key);
|
|
@@ -1430,16 +1374,16 @@ function collectRecommendations({ dependencies, declaredDependencies, stableDepe
|
|
|
1430
1374
|
scanTreeRecursively(depTree, missingDependencies, satisfyingDependencies, (key) => key);
|
|
1431
1375
|
function scanTreeRecursively(node, missingPaths, satisfyingPaths, keyToPath) {
|
|
1432
1376
|
node.children.forEach((child, key) => {
|
|
1433
|
-
const path$
|
|
1377
|
+
const path$2 = keyToPath(key);
|
|
1434
1378
|
if (child.isSatisfiedRecursively) {
|
|
1435
|
-
if (child.isSubtreeUsed) satisfyingPaths.add(path$
|
|
1379
|
+
if (child.isSubtreeUsed) satisfyingPaths.add(path$2);
|
|
1436
1380
|
return;
|
|
1437
1381
|
}
|
|
1438
1382
|
if (child.isUsed) {
|
|
1439
|
-
missingPaths.add(path$
|
|
1383
|
+
missingPaths.add(path$2);
|
|
1440
1384
|
return;
|
|
1441
1385
|
}
|
|
1442
|
-
scanTreeRecursively(child, missingPaths, satisfyingPaths, (childKey) => path$
|
|
1386
|
+
scanTreeRecursively(child, missingPaths, satisfyingPaths, (childKey) => path$2 + "." + childKey);
|
|
1443
1387
|
});
|
|
1444
1388
|
}
|
|
1445
1389
|
const suggestedDependencies = [];
|
|
@@ -1559,23 +1503,17 @@ function analyzePropertyChain(node, optionalChains) {
|
|
|
1559
1503
|
if (optionalChains) optionalChains.set(result, false);
|
|
1560
1504
|
return result;
|
|
1561
1505
|
} else if (node.type === "MemberExpression" && !node.computed) {
|
|
1562
|
-
const
|
|
1563
|
-
const property = analyzePropertyChain(node.property, null);
|
|
1564
|
-
const result = `${object}.${property}`;
|
|
1506
|
+
const result = `${analyzePropertyChain(node.object, optionalChains)}.${analyzePropertyChain(node.property, null)}`;
|
|
1565
1507
|
markNode(node, optionalChains, result);
|
|
1566
1508
|
return result;
|
|
1567
1509
|
} else if (node.type === "OptionalMemberExpression" && !node.computed) {
|
|
1568
|
-
const
|
|
1569
|
-
const property = analyzePropertyChain(node.property, null);
|
|
1570
|
-
const result = `${object}.${property}`;
|
|
1510
|
+
const result = `${analyzePropertyChain(node.object, optionalChains)}.${analyzePropertyChain(node.property, null)}`;
|
|
1571
1511
|
markNode(node, optionalChains, result);
|
|
1572
1512
|
return result;
|
|
1573
1513
|
} else if (node.type === "ChainExpression" && !node.computed) {
|
|
1574
1514
|
const expression = node.expression;
|
|
1575
1515
|
if (expression.type === "CallExpression") throw new Error(`Unsupported node type: ${expression.type}`);
|
|
1576
|
-
const
|
|
1577
|
-
const property = analyzePropertyChain(expression.property, null);
|
|
1578
|
-
const result = `${object}.${property}`;
|
|
1516
|
+
const result = `${analyzePropertyChain(expression.object, optionalChains)}.${analyzePropertyChain(expression.property, null)}`;
|
|
1579
1517
|
markNode(expression, optionalChains, result);
|
|
1580
1518
|
return result;
|
|
1581
1519
|
}
|
|
@@ -1691,12 +1629,10 @@ var react_hook_use_ref_default = createRule({
|
|
|
1691
1629
|
messages: { useRefName: "useRef call is not end with \"Ref\"" }
|
|
1692
1630
|
},
|
|
1693
1631
|
defaultOptions: [],
|
|
1694
|
-
create:
|
|
1695
|
-
|
|
1696
|
-
if (
|
|
1697
|
-
if (node.parent.id.
|
|
1698
|
-
const variable = node.parent.id.name;
|
|
1699
|
-
if (!variable.endsWith("Ref")) context.report({
|
|
1632
|
+
create: Components.default.detect((context, component, util) => ({ CallExpression(node) {
|
|
1633
|
+
if (node.parent && node.parent.type === AST_NODE_TYPES.ReturnStatement || !util.isReactHookCall(node, ["useRef"])) return;
|
|
1634
|
+
if (node.parent.id.type !== AST_NODE_TYPES.Identifier) return;
|
|
1635
|
+
if (!node.parent.id.name.endsWith("Ref")) context.report({
|
|
1700
1636
|
node,
|
|
1701
1637
|
messageId: "useRefName"
|
|
1702
1638
|
});
|
|
@@ -1726,16 +1662,14 @@ var react_prefer_sx_prop_default = createRule({
|
|
|
1726
1662
|
},
|
|
1727
1663
|
defaultOptions: [],
|
|
1728
1664
|
create(context) {
|
|
1729
|
-
const
|
|
1730
|
-
const allowedFor = configuration.allowedFor || [];
|
|
1665
|
+
const allowedFor = (context.options[0] || {}).allowedFor || [];
|
|
1731
1666
|
function checkComponent(node) {
|
|
1732
1667
|
const parentName = node.parent.name;
|
|
1733
1668
|
const tag = parentName.name || `${parentName.object.name}.${parentName.property.name}`;
|
|
1734
1669
|
const componentName = parentName.name || parentName.property.name;
|
|
1735
1670
|
if (componentName && typeof componentName[0] === "string" && componentName[0] !== componentName[0].toUpperCase()) return;
|
|
1736
1671
|
if (allowedFor.includes(tag)) return;
|
|
1737
|
-
|
|
1738
|
-
if (prop === "style") context.report({
|
|
1672
|
+
if (node.name.name === "style") context.report({
|
|
1739
1673
|
node,
|
|
1740
1674
|
messageId: "preferSxProp"
|
|
1741
1675
|
});
|
|
@@ -1744,8 +1678,7 @@ var react_prefer_sx_prop_default = createRule({
|
|
|
1744
1678
|
const tag = node.parent.name.name;
|
|
1745
1679
|
if (!(tag && typeof tag === "string" && tag[0] !== tag[0].toUpperCase())) return;
|
|
1746
1680
|
if (allowedFor.includes(tag)) return;
|
|
1747
|
-
|
|
1748
|
-
if (prop === "style") context.report({
|
|
1681
|
+
if (node.name.name === "style") context.report({
|
|
1749
1682
|
node,
|
|
1750
1683
|
messageId: "preferSxProp"
|
|
1751
1684
|
});
|
|
@@ -1765,9 +1698,9 @@ var react_prefer_sx_prop_default = createRule({
|
|
|
1765
1698
|
* @returns {string | null} The identifier name or null if it can't be determined
|
|
1766
1699
|
*/
|
|
1767
1700
|
function getBasicIdentifier(node) {
|
|
1768
|
-
if (node.type ===
|
|
1769
|
-
if (node.type ===
|
|
1770
|
-
if (node.type ===
|
|
1701
|
+
if (node.type === AST_NODE_TYPES.Identifier) return node.name;
|
|
1702
|
+
if (node.type === AST_NODE_TYPES.Literal) return node.value;
|
|
1703
|
+
if (node.type === AST_NODE_TYPES.TemplateLiteral) {
|
|
1771
1704
|
if (node.expressions.length > 0) return null;
|
|
1772
1705
|
return node.quasis[0].value.raw;
|
|
1773
1706
|
}
|
|
@@ -1780,9 +1713,9 @@ function getBasicIdentifier(node) {
|
|
|
1780
1713
|
*/
|
|
1781
1714
|
function getBaseIdentifier(node) {
|
|
1782
1715
|
switch (node.type) {
|
|
1783
|
-
case
|
|
1784
|
-
case
|
|
1785
|
-
case
|
|
1716
|
+
case AST_NODE_TYPES.Identifier: return node;
|
|
1717
|
+
case AST_NODE_TYPES.CallExpression: return getBaseIdentifier(node.callee);
|
|
1718
|
+
case AST_NODE_TYPES.MemberExpression: return getBaseIdentifier(node.object);
|
|
1786
1719
|
}
|
|
1787
1720
|
return null;
|
|
1788
1721
|
}
|
|
@@ -1793,7 +1726,7 @@ function getBaseIdentifier(node) {
|
|
|
1793
1726
|
*/
|
|
1794
1727
|
function getStyesObj(node) {
|
|
1795
1728
|
const isMakeStyles = node.callee.name === "makeStyles";
|
|
1796
|
-
const isModernApi = node.callee.type ===
|
|
1729
|
+
const isModernApi = node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.name === "create" && getBaseIdentifier(node.callee.object) && getBaseIdentifier(node.callee.object).name === "tss";
|
|
1797
1730
|
if (!isMakeStyles && !isModernApi) return;
|
|
1798
1731
|
const styles = (() => {
|
|
1799
1732
|
if (isMakeStyles) return node.parent.arguments[0];
|
|
@@ -1801,16 +1734,16 @@ function getStyesObj(node) {
|
|
|
1801
1734
|
})();
|
|
1802
1735
|
if (!styles) return;
|
|
1803
1736
|
switch (styles.type) {
|
|
1804
|
-
case
|
|
1805
|
-
case
|
|
1737
|
+
case AST_NODE_TYPES.ObjectExpression: return styles;
|
|
1738
|
+
case AST_NODE_TYPES.ArrowFunctionExpression:
|
|
1806
1739
|
{
|
|
1807
1740
|
const { body } = styles;
|
|
1808
1741
|
switch (body.type) {
|
|
1809
|
-
case
|
|
1810
|
-
case
|
|
1742
|
+
case AST_NODE_TYPES.ObjectExpression: return body;
|
|
1743
|
+
case AST_NODE_TYPES.BlockStatement: {
|
|
1811
1744
|
let stylesObj;
|
|
1812
1745
|
body.body.forEach((bodyNode) => {
|
|
1813
|
-
if (bodyNode.type ===
|
|
1746
|
+
if (bodyNode.type === AST_NODE_TYPES.ReturnStatement && bodyNode.argument.type === AST_NODE_TYPES.ObjectExpression) stylesObj = bodyNode.argument;
|
|
1814
1747
|
});
|
|
1815
1748
|
return stylesObj;
|
|
1816
1749
|
}
|
|
@@ -1826,8 +1759,8 @@ function getStyesObj(node) {
|
|
|
1826
1759
|
* @returns - The styles object or null if it can't be determined
|
|
1827
1760
|
*/
|
|
1828
1761
|
function loopStylesObj(node, callback) {
|
|
1829
|
-
if (node && node.type ===
|
|
1830
|
-
if (property.type ===
|
|
1762
|
+
if (node && node.type === AST_NODE_TYPES.ObjectExpression) node.properties.forEach((property) => {
|
|
1763
|
+
if (property.type === AST_NODE_TYPES.Property && property.value) if (property.value.type === AST_NODE_TYPES.ObjectExpression) loopStylesObj(property.value, callback);
|
|
1831
1764
|
else callback(property.value);
|
|
1832
1765
|
});
|
|
1833
1766
|
}
|
|
@@ -1853,9 +1786,9 @@ var tss_class_naming_default = createRule({
|
|
|
1853
1786
|
if (stylesObj === void 0) return;
|
|
1854
1787
|
stylesObj.properties.forEach((property) => {
|
|
1855
1788
|
if (property.computed) return;
|
|
1856
|
-
if (property.type === "ExperimentalSpreadProperty" || property.type ===
|
|
1789
|
+
if (property.type === "ExperimentalSpreadProperty" || property.type === AST_NODE_TYPES.SpreadElement) return;
|
|
1857
1790
|
const className = property.key.value || property.key.name;
|
|
1858
|
-
if (!
|
|
1791
|
+
if (!isCamelCase(className)) context.report({
|
|
1859
1792
|
node: property,
|
|
1860
1793
|
messageId: "camelCase",
|
|
1861
1794
|
data: { className }
|
|
@@ -2630,7 +2563,7 @@ var tss_no_color_name_default = createRule({
|
|
|
2630
2563
|
const stylesObj = getStyesObj(node);
|
|
2631
2564
|
if (!stylesObj) return;
|
|
2632
2565
|
function checkColorLiteral(value) {
|
|
2633
|
-
if (value.type ===
|
|
2566
|
+
if (value.type === AST_NODE_TYPES.Literal && typeof value.value === "string" && Object.keys(color_name_default).includes(value.value.toLowerCase())) context.report({
|
|
2634
2567
|
node: value,
|
|
2635
2568
|
messageId: "disallowColorName"
|
|
2636
2569
|
});
|
|
@@ -2660,9 +2593,8 @@ var tss_no_color_value_default = createRule({
|
|
|
2660
2593
|
const stylesObj = getStyesObj(node);
|
|
2661
2594
|
if (!stylesObj) return;
|
|
2662
2595
|
function checkColorLiteral(value) {
|
|
2663
|
-
if (value.type ===
|
|
2664
|
-
|
|
2665
|
-
if (colorCodePattern.test(value.value)) context.report({
|
|
2596
|
+
if (value.type === AST_NODE_TYPES.Literal && typeof value.value === "string") {
|
|
2597
|
+
if (/#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|rgb\?\(\s*(\d{1,3}\s*,\s*){2}\d{1,3}(?:\s*,\s*\d*(?:\.\d+)?)?\s*\)/g.test(value.value)) context.report({
|
|
2666
2598
|
node: value,
|
|
2667
2599
|
messageId: "preferMuiColor"
|
|
2668
2600
|
});
|
|
@@ -2697,12 +2629,12 @@ var tss_unused_classes_default = createRule({
|
|
|
2697
2629
|
if (stylesObj === void 0) return;
|
|
2698
2630
|
stylesObj.properties.forEach((property) => {
|
|
2699
2631
|
if (property.computed) return;
|
|
2700
|
-
if (property.type === "ExperimentalSpreadProperty" || property.type ===
|
|
2632
|
+
if (property.type === "ExperimentalSpreadProperty" || property.type === AST_NODE_TYPES.SpreadElement) return;
|
|
2701
2633
|
definedClasses[property.key.value || property.key.name] = property;
|
|
2702
2634
|
});
|
|
2703
2635
|
},
|
|
2704
2636
|
MemberExpression(node) {
|
|
2705
|
-
if (node.object.type ===
|
|
2637
|
+
if (node.object.type === AST_NODE_TYPES.Identifier && node.object.name === "classes") {
|
|
2706
2638
|
const whichClass = getBasicIdentifier(node.property);
|
|
2707
2639
|
if (whichClass) usedClasses[whichClass] = true;
|
|
2708
2640
|
return;
|
|
@@ -2711,12 +2643,12 @@ var tss_unused_classes_default = createRule({
|
|
|
2711
2643
|
if (!classIdentifier) return;
|
|
2712
2644
|
if (classIdentifier !== "classes") return;
|
|
2713
2645
|
const { parent } = node;
|
|
2714
|
-
if (parent.type !==
|
|
2715
|
-
if (node.object.object && node.object.object.type !==
|
|
2646
|
+
if (parent.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
2647
|
+
if (node.object.object && node.object.object.type !== AST_NODE_TYPES.ThisExpression) return;
|
|
2716
2648
|
const propsIdentifier = getBasicIdentifier(parent.object);
|
|
2717
2649
|
if (propsIdentifier && propsIdentifier !== "props") return;
|
|
2718
|
-
if (!propsIdentifier && parent.object.type !==
|
|
2719
|
-
if (parent.parent.type ===
|
|
2650
|
+
if (!propsIdentifier && parent.object.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
2651
|
+
if (parent.parent.type === AST_NODE_TYPES.MemberExpression) return;
|
|
2720
2652
|
const parentClassIdentifier = getBasicIdentifier(parent.property);
|
|
2721
2653
|
if (parentClassIdentifier) usedClasses[parentClassIdentifier] = true;
|
|
2722
2654
|
},
|
|
@@ -2775,4 +2707,4 @@ Object.keys(rules).forEach((name) => {
|
|
|
2775
2707
|
var src_default = plugin;
|
|
2776
2708
|
|
|
2777
2709
|
//#endregion
|
|
2778
|
-
|
|
2710
|
+
export { src_default as default };
|