@pandacss/eslint-plugin 0.1.15 → 0.2.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/{chunk-65XWD4AU.mjs → chunk-YLUMOAQM.mjs} +2 -2
- package/dist/index.js +953 -443
- package/dist/index.mjs +953 -444
- package/dist/utils/worker.js +5 -8
- package/dist/utils/worker.mjs +6 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,10 +28,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
mod
|
|
29
29
|
));
|
|
30
30
|
|
|
31
|
-
// ../node_modules/.pnpm/tsup@8.0.2_postcss@8.4.38_typescript@5.
|
|
31
|
+
// ../node_modules/.pnpm/tsup@8.0.2_postcss@8.4.38_typescript@5.6.3/node_modules/tsup/assets/cjs_shims.js
|
|
32
32
|
var getImportMetaUrl, importMetaUrl;
|
|
33
33
|
var init_cjs_shims = __esm({
|
|
34
|
-
"../node_modules/.pnpm/tsup@8.0.2_postcss@8.4.38_typescript@5.
|
|
34
|
+
"../node_modules/.pnpm/tsup@8.0.2_postcss@8.4.38_typescript@5.6.3/node_modules/tsup/assets/cjs_shims.js"() {
|
|
35
35
|
"use strict";
|
|
36
36
|
getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
37
37
|
importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
@@ -7957,7 +7957,7 @@ init_cjs_shims();
|
|
|
7957
7957
|
|
|
7958
7958
|
// package.json
|
|
7959
7959
|
var name = "@pandacss/eslint-plugin";
|
|
7960
|
-
var version = "0.1
|
|
7960
|
+
var version = "0.2.1";
|
|
7961
7961
|
|
|
7962
7962
|
// src/configs/all.ts
|
|
7963
7963
|
init_cjs_shims();
|
|
@@ -7984,7 +7984,8 @@ var syncAction = (...args) => {
|
|
|
7984
7984
|
try {
|
|
7985
7985
|
return _syncAction(...args);
|
|
7986
7986
|
} catch (error) {
|
|
7987
|
-
|
|
7987
|
+
console.error("syncAction error:", error);
|
|
7988
|
+
return void 0;
|
|
7988
7989
|
}
|
|
7989
7990
|
};
|
|
7990
7991
|
|
|
@@ -8063,13 +8064,17 @@ var _getImports = (context) => {
|
|
|
8063
8064
|
}));
|
|
8064
8065
|
return imports;
|
|
8065
8066
|
};
|
|
8067
|
+
var importsCache = /* @__PURE__ */ new WeakMap();
|
|
8066
8068
|
var getImports = (context) => {
|
|
8069
|
+
if (importsCache.has(context)) {
|
|
8070
|
+
return importsCache.get(context);
|
|
8071
|
+
}
|
|
8067
8072
|
const imports = _getImports(context);
|
|
8068
|
-
|
|
8073
|
+
const filteredImports = imports.filter((imp) => syncAction("matchImports", getSyncOpts(context), imp));
|
|
8074
|
+
importsCache.set(context, filteredImports);
|
|
8075
|
+
return filteredImports;
|
|
8069
8076
|
};
|
|
8070
8077
|
var isValidStyledProp = (node, context) => {
|
|
8071
|
-
if (typeof node === "string")
|
|
8072
|
-
return;
|
|
8073
8078
|
return isJSXIdentifier(node) && isValidProperty(node.name, context);
|
|
8074
8079
|
};
|
|
8075
8080
|
var isPandaIsh = (name2, context) => {
|
|
@@ -8080,14 +8085,20 @@ var isPandaIsh = (name2, context) => {
|
|
|
8080
8085
|
};
|
|
8081
8086
|
var findDeclaration = (name2, context) => {
|
|
8082
8087
|
try {
|
|
8083
|
-
const
|
|
8088
|
+
const src = context.sourceCode;
|
|
8089
|
+
if (!src) {
|
|
8090
|
+
console.warn("\u26A0\uFE0F ESLint's sourceCode is not available. Ensure that the rule is invoked with valid code.");
|
|
8091
|
+
return void 0;
|
|
8092
|
+
}
|
|
8093
|
+
const scope = (0, import_scope_manager.analyze)(src.ast, {
|
|
8084
8094
|
sourceType: "module"
|
|
8085
8095
|
});
|
|
8086
8096
|
const decl = scope.variables.find((v) => v.name === name2)?.defs.find((d) => isIdentifier(d.name) && d.name.name === name2)?.node;
|
|
8087
8097
|
if (isVariableDeclarator(decl))
|
|
8088
8098
|
return decl;
|
|
8089
8099
|
} catch (error) {
|
|
8090
|
-
|
|
8100
|
+
console.error("Error in findDeclaration:", error);
|
|
8101
|
+
return void 0;
|
|
8091
8102
|
}
|
|
8092
8103
|
};
|
|
8093
8104
|
var isLocalStyledFactory = (node, context) => {
|
|
@@ -8163,6 +8174,8 @@ var isInJSXProp = (node, context) => {
|
|
|
8163
8174
|
return;
|
|
8164
8175
|
if (!isPandaProp(jsxAttrAncestor, context))
|
|
8165
8176
|
return;
|
|
8177
|
+
if (typeof jsxAttrAncestor.name === "string")
|
|
8178
|
+
return;
|
|
8166
8179
|
if (!isValidStyledProp(jsxAttrAncestor.name, context))
|
|
8167
8180
|
return;
|
|
8168
8181
|
return true;
|
|
@@ -8191,6 +8204,7 @@ var isColorToken = (value, context) => {
|
|
|
8191
8204
|
return;
|
|
8192
8205
|
return syncAction("isColorToken", getSyncOpts(context), value);
|
|
8193
8206
|
};
|
|
8207
|
+
var invalidTokensCache = /* @__PURE__ */ new Map();
|
|
8194
8208
|
var extractTokens = (value) => {
|
|
8195
8209
|
const regex = /token\(([^"'(),]+)(?:,\s*([^"'(),]+))?\)|\{([^{}]+)\}/g;
|
|
8196
8210
|
const matches = [];
|
|
@@ -8208,10 +8222,15 @@ var extractTokens = (value) => {
|
|
|
8208
8222
|
return matches.filter(Boolean);
|
|
8209
8223
|
};
|
|
8210
8224
|
var getInvalidTokens = (value, context) => {
|
|
8225
|
+
if (invalidTokensCache.has(value)) {
|
|
8226
|
+
return invalidTokensCache.get(value);
|
|
8227
|
+
}
|
|
8211
8228
|
const tokens = extractTokens(value);
|
|
8212
8229
|
if (!tokens.length)
|
|
8213
8230
|
return [];
|
|
8214
|
-
|
|
8231
|
+
const invalidTokens = syncAction("filterInvalidTokens", getSyncOpts(context), tokens);
|
|
8232
|
+
invalidTokensCache.set(value, invalidTokens);
|
|
8233
|
+
return invalidTokens;
|
|
8215
8234
|
};
|
|
8216
8235
|
var getTokenImport = (context) => {
|
|
8217
8236
|
const imports = _getImports(context);
|
|
@@ -8259,31 +8278,38 @@ function isRecipeVariant(node, context) {
|
|
|
8259
8278
|
}
|
|
8260
8279
|
|
|
8261
8280
|
// src/rules/file-not-included.ts
|
|
8281
|
+
var import_utils4 = require("@typescript-eslint/utils");
|
|
8262
8282
|
var RULE_NAME = "file-not-included";
|
|
8263
8283
|
var rule = createRule({
|
|
8264
8284
|
name: RULE_NAME,
|
|
8265
8285
|
meta: {
|
|
8266
8286
|
docs: {
|
|
8267
|
-
description: "Disallow the use of
|
|
8287
|
+
description: "Disallow the use of Panda CSS in files that are not included in the specified Panda CSS `include` config."
|
|
8268
8288
|
},
|
|
8269
8289
|
messages: {
|
|
8270
|
-
include: "The use of Panda CSS is not allowed in this file. Please
|
|
8290
|
+
include: "The use of Panda CSS is not allowed in this file. Please ensure the file is included in the Panda CSS `include` configuration."
|
|
8271
8291
|
},
|
|
8272
|
-
type: "
|
|
8292
|
+
type: "problem",
|
|
8273
8293
|
schema: []
|
|
8274
8294
|
},
|
|
8275
8295
|
defaultOptions: [],
|
|
8276
8296
|
create(context) {
|
|
8297
|
+
const isFileIncluded = isValidFile(context);
|
|
8298
|
+
if (isFileIncluded) {
|
|
8299
|
+
return {};
|
|
8300
|
+
}
|
|
8301
|
+
let hasReported = false;
|
|
8277
8302
|
return {
|
|
8278
8303
|
ImportDeclaration(node) {
|
|
8279
|
-
if (
|
|
8304
|
+
if (hasReported)
|
|
8280
8305
|
return;
|
|
8281
|
-
if (
|
|
8306
|
+
if (!isPandaImport(node, context))
|
|
8282
8307
|
return;
|
|
8283
8308
|
context.report({
|
|
8284
8309
|
node,
|
|
8285
8310
|
messageId: "include"
|
|
8286
8311
|
});
|
|
8312
|
+
hasReported = true;
|
|
8287
8313
|
}
|
|
8288
8314
|
};
|
|
8289
8315
|
}
|
|
@@ -8292,56 +8318,82 @@ var file_not_included_default = rule;
|
|
|
8292
8318
|
|
|
8293
8319
|
// src/rules/no-config-function-in-source.ts
|
|
8294
8320
|
init_cjs_shims();
|
|
8321
|
+
var import_utils6 = require("@typescript-eslint/utils");
|
|
8295
8322
|
var RULE_NAME2 = "no-config-function-in-source";
|
|
8323
|
+
var CONFIG_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
8324
|
+
"defineConfig",
|
|
8325
|
+
"defineRecipe",
|
|
8326
|
+
"defineSlotRecipe",
|
|
8327
|
+
"defineParts",
|
|
8328
|
+
"definePattern",
|
|
8329
|
+
"definePreset",
|
|
8330
|
+
"defineKeyframes",
|
|
8331
|
+
"defineGlobalStyles",
|
|
8332
|
+
"defineUtility",
|
|
8333
|
+
"defineTextStyles",
|
|
8334
|
+
"defineLayerStyles",
|
|
8335
|
+
"defineStyles",
|
|
8336
|
+
"defineTokens",
|
|
8337
|
+
"defineSemanticTokens"
|
|
8338
|
+
]);
|
|
8296
8339
|
var rule2 = createRule({
|
|
8297
8340
|
name: RULE_NAME2,
|
|
8298
8341
|
meta: {
|
|
8299
8342
|
docs: {
|
|
8300
|
-
description: "Prohibit the use of config functions outside the Panda config."
|
|
8343
|
+
description: "Prohibit the use of config functions outside the Panda config file."
|
|
8301
8344
|
},
|
|
8302
8345
|
messages: {
|
|
8303
|
-
configFunction: "Unnecessary`{{name}}` call.
|
|
8346
|
+
configFunction: "Unnecessary `{{name}}` call. Config functions should only be used in the Panda config file.",
|
|
8304
8347
|
delete: "Delete `{{name}}` call."
|
|
8305
8348
|
},
|
|
8306
|
-
type: "
|
|
8349
|
+
type: "problem",
|
|
8307
8350
|
hasSuggestions: true,
|
|
8308
8351
|
schema: []
|
|
8309
8352
|
},
|
|
8310
8353
|
defaultOptions: [],
|
|
8311
8354
|
create(context) {
|
|
8312
|
-
if (!hasPkgImport(context))
|
|
8355
|
+
if (!hasPkgImport(context)) {
|
|
8356
|
+
return {};
|
|
8357
|
+
}
|
|
8358
|
+
const isPandaFile = isValidFile(context);
|
|
8359
|
+
if (!isPandaFile) {
|
|
8313
8360
|
return {};
|
|
8361
|
+
}
|
|
8314
8362
|
return {
|
|
8315
8363
|
CallExpression(node) {
|
|
8316
|
-
if (!isValidFile(context))
|
|
8317
|
-
return;
|
|
8318
8364
|
if (!isIdentifier(node.callee))
|
|
8319
8365
|
return;
|
|
8320
|
-
|
|
8366
|
+
const functionName = node.callee.name;
|
|
8367
|
+
if (!CONFIG_FUNCTIONS.has(functionName))
|
|
8321
8368
|
return;
|
|
8322
|
-
if (!isPandaConfigFunction(context,
|
|
8369
|
+
if (!isPandaConfigFunction(context, functionName))
|
|
8323
8370
|
return;
|
|
8324
8371
|
context.report({
|
|
8325
8372
|
node,
|
|
8326
8373
|
messageId: "configFunction",
|
|
8327
8374
|
data: {
|
|
8328
|
-
name:
|
|
8375
|
+
name: functionName
|
|
8329
8376
|
},
|
|
8330
8377
|
suggest: [
|
|
8331
8378
|
{
|
|
8332
8379
|
messageId: "delete",
|
|
8333
8380
|
data: {
|
|
8334
|
-
name:
|
|
8381
|
+
name: functionName
|
|
8335
8382
|
},
|
|
8336
8383
|
fix(fixer) {
|
|
8337
8384
|
const declaration = getAncestor(isVariableDeclaration, node);
|
|
8338
|
-
const
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
fixer.remove(declaration
|
|
8343
|
-
|
|
8344
|
-
|
|
8385
|
+
const importSpecifiers = getImportSpecifiers(context);
|
|
8386
|
+
const importSpec = importSpecifiers.find((s) => s.specifier.local.name === functionName);
|
|
8387
|
+
const fixes = [];
|
|
8388
|
+
if (declaration) {
|
|
8389
|
+
fixes.push(fixer.remove(declaration));
|
|
8390
|
+
} else {
|
|
8391
|
+
fixes.push(fixer.remove(node));
|
|
8392
|
+
}
|
|
8393
|
+
if (importSpec?.specifier) {
|
|
8394
|
+
fixes.push(fixer.remove(importSpec.specifier));
|
|
8395
|
+
}
|
|
8396
|
+
return fixes;
|
|
8345
8397
|
}
|
|
8346
8398
|
}
|
|
8347
8399
|
]
|
|
@@ -8351,25 +8403,10 @@ var rule2 = createRule({
|
|
|
8351
8403
|
}
|
|
8352
8404
|
});
|
|
8353
8405
|
var no_config_function_in_source_default = rule2;
|
|
8354
|
-
var CONFIG_FUNCTIONS = [
|
|
8355
|
-
"defineConfig",
|
|
8356
|
-
"defineRecipe",
|
|
8357
|
-
"defineSlotRecipe",
|
|
8358
|
-
"defineParts",
|
|
8359
|
-
"definePattern",
|
|
8360
|
-
"definePreset",
|
|
8361
|
-
"defineKeyframes",
|
|
8362
|
-
"defineGlobalStyles",
|
|
8363
|
-
"defineUtility",
|
|
8364
|
-
"defineTextStyles",
|
|
8365
|
-
"defineLayerStyles",
|
|
8366
|
-
"defineStyles",
|
|
8367
|
-
"defineTokens",
|
|
8368
|
-
"defineSemanticTokens"
|
|
8369
|
-
];
|
|
8370
8406
|
|
|
8371
8407
|
// src/rules/no-debug.ts
|
|
8372
8408
|
init_cjs_shims();
|
|
8409
|
+
var import_utils8 = require("@typescript-eslint/utils");
|
|
8373
8410
|
var RULE_NAME3 = "no-debug";
|
|
8374
8411
|
var rule3 = createRule({
|
|
8375
8412
|
name: RULE_NAME3,
|
|
@@ -8382,16 +8419,14 @@ var rule3 = createRule({
|
|
|
8382
8419
|
prop: "Remove the debug prop.",
|
|
8383
8420
|
property: "Remove the debug property."
|
|
8384
8421
|
},
|
|
8385
|
-
type: "
|
|
8422
|
+
type: "problem",
|
|
8386
8423
|
hasSuggestions: true,
|
|
8387
8424
|
schema: []
|
|
8388
8425
|
},
|
|
8389
8426
|
defaultOptions: [],
|
|
8390
8427
|
create(context) {
|
|
8391
8428
|
return {
|
|
8392
|
-
JSXAttribute(node) {
|
|
8393
|
-
if (!isJSXIdentifier(node.name) || node.name.name !== "debug")
|
|
8394
|
-
return;
|
|
8429
|
+
'JSXAttribute[name.name="debug"]'(node) {
|
|
8395
8430
|
if (!isPandaProp(node, context))
|
|
8396
8431
|
return;
|
|
8397
8432
|
context.report({
|
|
@@ -8405,9 +8440,7 @@ var rule3 = createRule({
|
|
|
8405
8440
|
]
|
|
8406
8441
|
});
|
|
8407
8442
|
},
|
|
8408
|
-
Property(node) {
|
|
8409
|
-
if (!isIdentifier(node.key) || node.key.name !== "debug")
|
|
8410
|
-
return;
|
|
8443
|
+
'Property[key.name="debug"]'(node) {
|
|
8411
8444
|
if (!isPandaAttribute(node, context))
|
|
8412
8445
|
return;
|
|
8413
8446
|
if (isRecipeVariant(node, context))
|
|
@@ -8430,47 +8463,72 @@ var no_debug_default = rule3;
|
|
|
8430
8463
|
|
|
8431
8464
|
// src/rules/no-dynamic-styling.ts
|
|
8432
8465
|
init_cjs_shims();
|
|
8466
|
+
var import_utils9 = require("@typescript-eslint/utils");
|
|
8433
8467
|
var RULE_NAME4 = "no-dynamic-styling";
|
|
8434
8468
|
var rule4 = createRule({
|
|
8435
8469
|
name: RULE_NAME4,
|
|
8436
8470
|
meta: {
|
|
8437
8471
|
docs: {
|
|
8438
|
-
description: "Ensure
|
|
8472
|
+
description: "Ensure users don't use dynamic styling. Prefer static styles, leverage CSS variables, or recipes for known dynamic styles."
|
|
8439
8473
|
},
|
|
8440
8474
|
messages: {
|
|
8441
|
-
dynamic: "Remove dynamic value. Prefer static styles",
|
|
8442
|
-
dynamicProperty: "Remove dynamic property. Prefer static style property",
|
|
8443
|
-
dynamicRecipeVariant: "Remove dynamic variant. Prefer static variant definition"
|
|
8475
|
+
dynamic: "Remove dynamic value. Prefer static styles.",
|
|
8476
|
+
dynamicProperty: "Remove dynamic property. Prefer static style property.",
|
|
8477
|
+
dynamicRecipeVariant: "Remove dynamic variant. Prefer static variant definition."
|
|
8444
8478
|
},
|
|
8445
|
-
type: "
|
|
8479
|
+
type: "problem",
|
|
8446
8480
|
schema: []
|
|
8447
8481
|
},
|
|
8448
8482
|
defaultOptions: [],
|
|
8449
8483
|
create(context) {
|
|
8484
|
+
function isStaticValue(node) {
|
|
8485
|
+
if (!node)
|
|
8486
|
+
return false;
|
|
8487
|
+
if (isLiteral(node))
|
|
8488
|
+
return true;
|
|
8489
|
+
if (isTemplateLiteral(node) && node.expressions.length === 0)
|
|
8490
|
+
return true;
|
|
8491
|
+
if (isObjectExpression(node))
|
|
8492
|
+
return true;
|
|
8493
|
+
return false;
|
|
8494
|
+
}
|
|
8495
|
+
function checkArrayElements(array) {
|
|
8496
|
+
array.elements.forEach((element) => {
|
|
8497
|
+
if (!element)
|
|
8498
|
+
return;
|
|
8499
|
+
if (isStaticValue(element))
|
|
8500
|
+
return;
|
|
8501
|
+
context.report({
|
|
8502
|
+
node: element,
|
|
8503
|
+
messageId: "dynamic"
|
|
8504
|
+
});
|
|
8505
|
+
});
|
|
8506
|
+
}
|
|
8450
8507
|
return {
|
|
8508
|
+
// JSX Attributes
|
|
8451
8509
|
JSXAttribute(node) {
|
|
8452
8510
|
if (!node.value)
|
|
8453
8511
|
return;
|
|
8454
8512
|
if (isLiteral(node.value))
|
|
8455
8513
|
return;
|
|
8456
|
-
if (isJSXExpressionContainer(node.value) && isLiteral(node.value.expression))
|
|
8457
|
-
return;
|
|
8458
|
-
if (isJSXExpressionContainer(node.value) && isTemplateLiteral(node.value.expression) && node.value.expression.expressions.length === 0)
|
|
8459
|
-
return;
|
|
8460
|
-
if (isObjectExpression(node.value.expression))
|
|
8461
|
-
return;
|
|
8462
8514
|
if (!isPandaProp(node, context))
|
|
8463
8515
|
return;
|
|
8464
|
-
if (
|
|
8465
|
-
|
|
8516
|
+
if (isJSXExpressionContainer(node.value)) {
|
|
8517
|
+
const expr = node.value.expression;
|
|
8518
|
+
if (isStaticValue(expr))
|
|
8519
|
+
return;
|
|
8520
|
+
if (isArrayExpression(expr)) {
|
|
8521
|
+
checkArrayElements(expr);
|
|
8522
|
+
return;
|
|
8523
|
+
}
|
|
8466
8524
|
}
|
|
8467
8525
|
context.report({
|
|
8468
8526
|
node: node.value,
|
|
8469
8527
|
messageId: "dynamic"
|
|
8470
8528
|
});
|
|
8471
8529
|
},
|
|
8472
|
-
// Dynamic properties
|
|
8473
|
-
"Property[computed=true]"(node) {
|
|
8530
|
+
// Dynamic properties with computed keys
|
|
8531
|
+
"Property[computed=true]": (node) => {
|
|
8474
8532
|
if (!isInPandaFunction(node, context))
|
|
8475
8533
|
return;
|
|
8476
8534
|
context.report({
|
|
@@ -8478,19 +8536,19 @@ var rule4 = createRule({
|
|
|
8478
8536
|
messageId: isRecipeVariant(node, context) ? "dynamicRecipeVariant" : "dynamicProperty"
|
|
8479
8537
|
});
|
|
8480
8538
|
},
|
|
8539
|
+
// Object Properties
|
|
8481
8540
|
Property(node) {
|
|
8482
8541
|
if (!isIdentifier(node.key))
|
|
8483
8542
|
return;
|
|
8484
|
-
if (
|
|
8543
|
+
if (!isPandaAttribute(node, context))
|
|
8485
8544
|
return;
|
|
8486
|
-
if (
|
|
8545
|
+
if (isRecipeVariant(node, context))
|
|
8487
8546
|
return;
|
|
8488
|
-
if (
|
|
8489
|
-
return;
|
|
8490
|
-
if (!isPandaAttribute(node, context))
|
|
8547
|
+
if (isStaticValue(node.value))
|
|
8491
8548
|
return;
|
|
8492
8549
|
if (isArrayExpression(node.value)) {
|
|
8493
|
-
|
|
8550
|
+
checkArrayElements(node.value);
|
|
8551
|
+
return;
|
|
8494
8552
|
}
|
|
8495
8553
|
context.report({
|
|
8496
8554
|
node: node.value,
|
|
@@ -8500,25 +8558,12 @@ var rule4 = createRule({
|
|
|
8500
8558
|
};
|
|
8501
8559
|
}
|
|
8502
8560
|
});
|
|
8503
|
-
function checkArrayElements(array, context) {
|
|
8504
|
-
array.elements.forEach((node) => {
|
|
8505
|
-
if (!node)
|
|
8506
|
-
return;
|
|
8507
|
-
if (isLiteral(node))
|
|
8508
|
-
return;
|
|
8509
|
-
if (isTemplateLiteral(node) && node.expressions.length === 0)
|
|
8510
|
-
return;
|
|
8511
|
-
context.report({
|
|
8512
|
-
node,
|
|
8513
|
-
messageId: "dynamic"
|
|
8514
|
-
});
|
|
8515
|
-
});
|
|
8516
|
-
}
|
|
8517
8561
|
var no_dynamic_styling_default = rule4;
|
|
8518
8562
|
|
|
8519
8563
|
// src/rules/no-escape-hatch.ts
|
|
8520
8564
|
init_cjs_shims();
|
|
8521
8565
|
var import_shared = require("@pandacss/shared");
|
|
8566
|
+
var import_utils12 = require("@typescript-eslint/utils");
|
|
8522
8567
|
var RULE_NAME5 = "no-escape-hatch";
|
|
8523
8568
|
var rule5 = createRule({
|
|
8524
8569
|
name: RULE_NAME5,
|
|
@@ -8527,47 +8572,37 @@ var rule5 = createRule({
|
|
|
8527
8572
|
description: "Prohibit the use of escape hatch syntax in the code."
|
|
8528
8573
|
},
|
|
8529
8574
|
messages: {
|
|
8530
|
-
escapeHatch: "Avoid using the escape hatch [value] for undefined tokens.
|
|
8575
|
+
escapeHatch: "Avoid using the escape hatch [value] for undefined tokens. Define a corresponding token in your design system for better consistency and maintainability.",
|
|
8531
8576
|
remove: "Remove the square brackets (`[]`)."
|
|
8532
8577
|
},
|
|
8533
|
-
type: "
|
|
8578
|
+
type: "problem",
|
|
8534
8579
|
hasSuggestions: true,
|
|
8535
8580
|
schema: []
|
|
8536
8581
|
},
|
|
8537
8582
|
defaultOptions: [],
|
|
8538
8583
|
create(context) {
|
|
8539
|
-
const
|
|
8584
|
+
const removeBrackets = (range) => {
|
|
8585
|
+
const [start, end] = range;
|
|
8586
|
+
return [start + 1, end - 1];
|
|
8587
|
+
};
|
|
8540
8588
|
const hasEscapeHatch = (value) => {
|
|
8541
8589
|
if (!value)
|
|
8542
8590
|
return false;
|
|
8591
|
+
if (!value.includes("["))
|
|
8592
|
+
return false;
|
|
8543
8593
|
return (0, import_shared.getArbitraryValue)(value) !== value.trim();
|
|
8544
8594
|
};
|
|
8545
|
-
const
|
|
8546
|
-
if (!
|
|
8547
|
-
return;
|
|
8548
|
-
if (!hasEscapeHatch(node.value?.toString()))
|
|
8549
|
-
return;
|
|
8550
|
-
sendReport(node);
|
|
8551
|
-
};
|
|
8552
|
-
const handleTemplateLiteral = (node) => {
|
|
8553
|
-
if (!isTemplateLiteral(node))
|
|
8595
|
+
const handleNodeValue = (node, value) => {
|
|
8596
|
+
if (!hasEscapeHatch(value))
|
|
8554
8597
|
return;
|
|
8555
|
-
|
|
8556
|
-
return;
|
|
8557
|
-
if (!hasEscapeHatch(node.quasis[0].value.raw))
|
|
8558
|
-
return;
|
|
8559
|
-
sendReport(node.quasis[0], node.quasis[0].value.raw);
|
|
8560
|
-
};
|
|
8561
|
-
const sendReport = (node, _value) => {
|
|
8562
|
-
const value = _value ?? node.value?.toString();
|
|
8563
|
-
return context.report({
|
|
8598
|
+
context.report({
|
|
8564
8599
|
node,
|
|
8565
8600
|
messageId: "escapeHatch",
|
|
8566
8601
|
suggest: [
|
|
8567
8602
|
{
|
|
8568
8603
|
messageId: "remove",
|
|
8569
8604
|
fix: (fixer) => {
|
|
8570
|
-
return fixer.replaceTextRange(
|
|
8605
|
+
return fixer.replaceTextRange(removeBrackets(node.range), (0, import_shared.getArbitraryValue)(value));
|
|
8571
8606
|
}
|
|
8572
8607
|
}
|
|
8573
8608
|
]
|
|
@@ -8579,23 +8614,36 @@ var rule5 = createRule({
|
|
|
8579
8614
|
return;
|
|
8580
8615
|
if (!isPandaProp(node, context))
|
|
8581
8616
|
return;
|
|
8582
|
-
|
|
8583
|
-
if (
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8617
|
+
const { value } = node;
|
|
8618
|
+
if (isLiteral(value)) {
|
|
8619
|
+
const val = value.value?.toString() ?? "";
|
|
8620
|
+
handleNodeValue(value, val);
|
|
8621
|
+
} else if (isJSXExpressionContainer(value)) {
|
|
8622
|
+
const expr = value.expression;
|
|
8623
|
+
if (isLiteral(expr)) {
|
|
8624
|
+
const val = expr.value?.toString() ?? "";
|
|
8625
|
+
handleNodeValue(expr, val);
|
|
8626
|
+
} else if (isTemplateLiteral(expr) && expr.expressions.length === 0) {
|
|
8627
|
+
const val = expr.quasis[0].value.raw;
|
|
8628
|
+
handleNodeValue(expr.quasis[0], val);
|
|
8629
|
+
}
|
|
8630
|
+
}
|
|
8587
8631
|
},
|
|
8588
8632
|
Property(node) {
|
|
8589
8633
|
if (!isIdentifier(node.key))
|
|
8590
8634
|
return;
|
|
8591
|
-
if (!isLiteral(node.value) && !isTemplateLiteral(node.value))
|
|
8592
|
-
return;
|
|
8593
8635
|
if (!isPandaAttribute(node, context))
|
|
8594
8636
|
return;
|
|
8595
8637
|
if (isRecipeVariant(node, context))
|
|
8596
8638
|
return;
|
|
8597
|
-
|
|
8598
|
-
|
|
8639
|
+
const value = node.value;
|
|
8640
|
+
if (isLiteral(value)) {
|
|
8641
|
+
const val = value.value?.toString() ?? "";
|
|
8642
|
+
handleNodeValue(value, val);
|
|
8643
|
+
} else if (isTemplateLiteral(value) && value.expressions.length === 0) {
|
|
8644
|
+
const val = value.quasis[0].value.raw;
|
|
8645
|
+
handleNodeValue(value.quasis[0], val);
|
|
8646
|
+
}
|
|
8599
8647
|
}
|
|
8600
8648
|
};
|
|
8601
8649
|
}
|
|
@@ -8604,6 +8652,7 @@ var no_escape_hatch_default = rule5;
|
|
|
8604
8652
|
|
|
8605
8653
|
// src/rules/no-hardcoded-color.ts
|
|
8606
8654
|
init_cjs_shims();
|
|
8655
|
+
var import_utils14 = require("@typescript-eslint/utils");
|
|
8607
8656
|
var RULE_NAME6 = "no-hardcoded-color";
|
|
8608
8657
|
var rule6 = createRule({
|
|
8609
8658
|
name: RULE_NAME6,
|
|
@@ -8614,7 +8663,7 @@ var rule6 = createRule({
|
|
|
8614
8663
|
messages: {
|
|
8615
8664
|
invalidColor: "`{{color}}` is not a valid color token."
|
|
8616
8665
|
},
|
|
8617
|
-
type: "
|
|
8666
|
+
type: "problem",
|
|
8618
8667
|
schema: [
|
|
8619
8668
|
{
|
|
8620
8669
|
type: "object",
|
|
@@ -8622,7 +8671,8 @@ var rule6 = createRule({
|
|
|
8622
8671
|
noOpacity: {
|
|
8623
8672
|
type: "boolean"
|
|
8624
8673
|
}
|
|
8625
|
-
}
|
|
8674
|
+
},
|
|
8675
|
+
additionalProperties: false
|
|
8626
8676
|
}
|
|
8627
8677
|
]
|
|
8628
8678
|
},
|
|
@@ -8633,19 +8683,55 @@ var rule6 = createRule({
|
|
|
8633
8683
|
],
|
|
8634
8684
|
create(context) {
|
|
8635
8685
|
const noOpacity = context.options[0]?.noOpacity;
|
|
8636
|
-
const
|
|
8686
|
+
const colorTokenCache = /* @__PURE__ */ new Map();
|
|
8687
|
+
const colorAttributeCache = /* @__PURE__ */ new Map();
|
|
8688
|
+
const isColorToken2 = (token) => {
|
|
8689
|
+
if (colorTokenCache.has(token)) {
|
|
8690
|
+
return colorTokenCache.get(token);
|
|
8691
|
+
}
|
|
8692
|
+
const result = isColorToken(token, context);
|
|
8693
|
+
colorTokenCache.set(token, result);
|
|
8694
|
+
return !!result;
|
|
8695
|
+
};
|
|
8696
|
+
const isColorAttribute2 = (attribute) => {
|
|
8697
|
+
if (colorAttributeCache.has(attribute)) {
|
|
8698
|
+
return colorAttributeCache.get(attribute);
|
|
8699
|
+
}
|
|
8700
|
+
const result = isColorAttribute(attribute, context);
|
|
8701
|
+
colorAttributeCache.set(attribute, result);
|
|
8702
|
+
return result;
|
|
8703
|
+
};
|
|
8704
|
+
const isTokenFunctionUsed = (value) => {
|
|
8637
8705
|
if (!value)
|
|
8638
8706
|
return false;
|
|
8639
8707
|
const tokens = extractTokens(value);
|
|
8640
8708
|
return tokens.length > 0;
|
|
8641
8709
|
};
|
|
8642
|
-
const
|
|
8710
|
+
const isValidColorToken = (value) => {
|
|
8643
8711
|
if (!value)
|
|
8644
8712
|
return false;
|
|
8645
|
-
const
|
|
8646
|
-
const
|
|
8647
|
-
const isValidToken =
|
|
8648
|
-
return noOpacity ? isValidToken && !
|
|
8713
|
+
const [colorToken, opacity] = value.split("/");
|
|
8714
|
+
const hasOpacity = opacity !== void 0 && opacity.length > 0;
|
|
8715
|
+
const isValidToken = isColorToken2(colorToken);
|
|
8716
|
+
return noOpacity ? isValidToken && !hasOpacity : isValidToken;
|
|
8717
|
+
};
|
|
8718
|
+
const reportInvalidColor = (node, color) => {
|
|
8719
|
+
context.report({
|
|
8720
|
+
node,
|
|
8721
|
+
messageId: "invalidColor",
|
|
8722
|
+
data: {
|
|
8723
|
+
color
|
|
8724
|
+
}
|
|
8725
|
+
});
|
|
8726
|
+
};
|
|
8727
|
+
const checkColorValue = (node, value, attributeName) => {
|
|
8728
|
+
if (!isColorAttribute2(attributeName))
|
|
8729
|
+
return;
|
|
8730
|
+
if (isTokenFunctionUsed(value))
|
|
8731
|
+
return;
|
|
8732
|
+
if (isValidColorToken(value))
|
|
8733
|
+
return;
|
|
8734
|
+
reportInvalidColor(node, value);
|
|
8649
8735
|
};
|
|
8650
8736
|
return {
|
|
8651
8737
|
JSXAttribute(node) {
|
|
@@ -8653,49 +8739,38 @@ var rule6 = createRule({
|
|
|
8653
8739
|
return;
|
|
8654
8740
|
if (!isPandaProp(node, context) || !node.value)
|
|
8655
8741
|
return;
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
messageId: "invalidColor",
|
|
8671
|
-
data: {
|
|
8672
|
-
color: node.value.expression.value?.toString()
|
|
8673
|
-
}
|
|
8674
|
-
});
|
|
8742
|
+
const attributeName = node.name.name;
|
|
8743
|
+
const valueNode = node.value;
|
|
8744
|
+
if (isLiteral(valueNode)) {
|
|
8745
|
+
const value = valueNode.value?.toString() || "";
|
|
8746
|
+
checkColorValue(valueNode, value, attributeName);
|
|
8747
|
+
} else if (isJSXExpressionContainer(valueNode)) {
|
|
8748
|
+
const expression = valueNode.expression;
|
|
8749
|
+
if (isLiteral(expression)) {
|
|
8750
|
+
const value = expression.value?.toString() || "";
|
|
8751
|
+
checkColorValue(expression, value, attributeName);
|
|
8752
|
+
} else if (isTemplateLiteral(expression) && expression.expressions.length === 0) {
|
|
8753
|
+
const value = expression.quasis[0].value.raw;
|
|
8754
|
+
checkColorValue(expression.quasis[0], value, attributeName);
|
|
8755
|
+
}
|
|
8675
8756
|
}
|
|
8676
8757
|
},
|
|
8677
8758
|
Property(node) {
|
|
8678
8759
|
if (!isIdentifier(node.key))
|
|
8679
8760
|
return;
|
|
8680
|
-
if (!isLiteral(node.value))
|
|
8681
|
-
return;
|
|
8682
8761
|
if (!isPandaAttribute(node, context))
|
|
8683
8762
|
return;
|
|
8684
8763
|
if (isRecipeVariant(node, context))
|
|
8685
8764
|
return;
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
if (
|
|
8689
|
-
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
data: {
|
|
8696
|
-
color: node.value.value?.toString()
|
|
8697
|
-
}
|
|
8698
|
-
});
|
|
8765
|
+
const attributeName = node.key.name;
|
|
8766
|
+
const valueNode = node.value;
|
|
8767
|
+
if (isLiteral(valueNode)) {
|
|
8768
|
+
const value = valueNode.value?.toString() || "";
|
|
8769
|
+
checkColorValue(valueNode, value, attributeName);
|
|
8770
|
+
} else if (isTemplateLiteral(valueNode) && valueNode.expressions.length === 0) {
|
|
8771
|
+
const value = valueNode.quasis[0].value.raw;
|
|
8772
|
+
checkColorValue(valueNode.quasis[0], value, attributeName);
|
|
8773
|
+
}
|
|
8699
8774
|
}
|
|
8700
8775
|
};
|
|
8701
8776
|
}
|
|
@@ -8705,6 +8780,7 @@ var no_hardcoded_color_default = rule6;
|
|
|
8705
8780
|
// src/rules/no-important.ts
|
|
8706
8781
|
init_cjs_shims();
|
|
8707
8782
|
var import_shared2 = require("@pandacss/shared");
|
|
8783
|
+
var import_utils16 = require("@typescript-eslint/utils");
|
|
8708
8784
|
var exclamationRegex = /\s*!$/;
|
|
8709
8785
|
var importantRegex = /\s*!important\s*$/;
|
|
8710
8786
|
var RULE_NAME7 = "no-important";
|
|
@@ -8712,56 +8788,72 @@ var rule7 = createRule({
|
|
|
8712
8788
|
name: RULE_NAME7,
|
|
8713
8789
|
meta: {
|
|
8714
8790
|
docs: {
|
|
8715
|
-
description: "Disallow usage of important keyword.
|
|
8791
|
+
description: "Disallow usage of !important keyword. Prioritize specificity for a maintainable and predictable styling structure."
|
|
8716
8792
|
},
|
|
8717
8793
|
messages: {
|
|
8718
|
-
important: "Avoid using the
|
|
8794
|
+
important: "Avoid using the {{keyword}} keyword. Refactor your code to prioritize specificity for predictable styling.",
|
|
8719
8795
|
remove: "Remove the `{{keyword}}` keyword."
|
|
8720
8796
|
},
|
|
8721
|
-
type: "
|
|
8797
|
+
type: "problem",
|
|
8722
8798
|
hasSuggestions: true,
|
|
8723
8799
|
schema: []
|
|
8724
8800
|
},
|
|
8725
8801
|
defaultOptions: [],
|
|
8726
8802
|
create(context) {
|
|
8727
|
-
const removeQuotes = (
|
|
8728
|
-
|
|
8729
|
-
|
|
8803
|
+
const removeQuotes = (range) => {
|
|
8804
|
+
const [start, end] = range;
|
|
8805
|
+
return [start + 1, end - 1];
|
|
8806
|
+
};
|
|
8807
|
+
const pandaPropCache = /* @__PURE__ */ new WeakMap();
|
|
8808
|
+
const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
8809
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
8810
|
+
const isCachedPandaProp = (node) => {
|
|
8811
|
+
if (pandaPropCache.has(node)) {
|
|
8812
|
+
return pandaPropCache.get(node);
|
|
8813
|
+
}
|
|
8814
|
+
const result = isPandaProp(node, context);
|
|
8815
|
+
pandaPropCache.set(node, result);
|
|
8816
|
+
return !!result;
|
|
8817
|
+
};
|
|
8818
|
+
const isCachedPandaAttribute = (node) => {
|
|
8819
|
+
if (pandaAttributeCache.has(node)) {
|
|
8820
|
+
return pandaAttributeCache.get(node);
|
|
8821
|
+
}
|
|
8822
|
+
const result = isPandaAttribute(node, context);
|
|
8823
|
+
pandaAttributeCache.set(node, result);
|
|
8824
|
+
return !!result;
|
|
8825
|
+
};
|
|
8826
|
+
const isCachedRecipeVariant = (node) => {
|
|
8827
|
+
if (recipeVariantCache.has(node)) {
|
|
8828
|
+
return recipeVariantCache.get(node);
|
|
8829
|
+
}
|
|
8830
|
+
const result = isRecipeVariant(node, context);
|
|
8831
|
+
recipeVariantCache.set(node, result);
|
|
8832
|
+
return !!result;
|
|
8833
|
+
};
|
|
8834
|
+
const hasImportantKeyword = (value) => {
|
|
8835
|
+
if (!value)
|
|
8730
8836
|
return false;
|
|
8731
|
-
const
|
|
8732
|
-
return exclamationRegex.test(
|
|
8837
|
+
const arbitraryValue = (0, import_shared2.getArbitraryValue)(value);
|
|
8838
|
+
return exclamationRegex.test(arbitraryValue) || importantRegex.test(arbitraryValue);
|
|
8733
8839
|
};
|
|
8734
8840
|
const removeImportantKeyword = (input) => {
|
|
8735
|
-
if (
|
|
8736
|
-
return { fixed: input.replace(
|
|
8737
|
-
} else if (
|
|
8738
|
-
return { fixed: input.replace(
|
|
8841
|
+
if (importantRegex.test(input)) {
|
|
8842
|
+
return { fixed: input.replace(importantRegex, "").trimEnd(), keyword: "!important" };
|
|
8843
|
+
} else if (exclamationRegex.test(input)) {
|
|
8844
|
+
return { fixed: input.replace(exclamationRegex, "").trimEnd(), keyword: "!" };
|
|
8739
8845
|
} else {
|
|
8740
8846
|
return { fixed: input, keyword: null };
|
|
8741
8847
|
}
|
|
8742
8848
|
};
|
|
8743
|
-
const
|
|
8744
|
-
if (!
|
|
8745
|
-
return;
|
|
8746
|
-
if (!hasImportantKeyword(node.value?.toString()))
|
|
8849
|
+
const handleNodeValue = (node, value) => {
|
|
8850
|
+
if (!hasImportantKeyword(value))
|
|
8747
8851
|
return;
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
const handleTemplateLiteral = (node) => {
|
|
8751
|
-
if (!isTemplateLiteral(node))
|
|
8752
|
-
return;
|
|
8753
|
-
if (node.expressions.length > 0)
|
|
8754
|
-
return;
|
|
8755
|
-
if (!hasImportantKeyword(node.quasis[0].value.raw))
|
|
8756
|
-
return;
|
|
8757
|
-
sendReport(node.quasis[0], node.quasis[0].value.raw);
|
|
8758
|
-
};
|
|
8759
|
-
const sendReport = (node, _value) => {
|
|
8760
|
-
const value = _value ?? node.value?.toString();
|
|
8761
|
-
const { keyword, fixed } = removeImportantKeyword(value);
|
|
8762
|
-
return context.report({
|
|
8852
|
+
const { fixed, keyword } = removeImportantKeyword(value);
|
|
8853
|
+
context.report({
|
|
8763
8854
|
node,
|
|
8764
8855
|
messageId: "important",
|
|
8856
|
+
data: { keyword },
|
|
8765
8857
|
suggest: [
|
|
8766
8858
|
{
|
|
8767
8859
|
messageId: "remove",
|
|
@@ -8774,28 +8866,43 @@ var rule7 = createRule({
|
|
|
8774
8866
|
});
|
|
8775
8867
|
};
|
|
8776
8868
|
return {
|
|
8869
|
+
// JSX Attributes
|
|
8777
8870
|
JSXAttribute(node) {
|
|
8778
8871
|
if (!node.value)
|
|
8779
8872
|
return;
|
|
8780
|
-
if (!
|
|
8781
|
-
return;
|
|
8782
|
-
handleLiteral(node.value);
|
|
8783
|
-
if (!isJSXExpressionContainer(node.value))
|
|
8873
|
+
if (!isCachedPandaProp(node))
|
|
8784
8874
|
return;
|
|
8785
|
-
|
|
8786
|
-
|
|
8875
|
+
const valueNode = node.value;
|
|
8876
|
+
if (isLiteral(valueNode)) {
|
|
8877
|
+
const val = valueNode.value?.toString() ?? "";
|
|
8878
|
+
handleNodeValue(valueNode, val);
|
|
8879
|
+
} else if (isJSXExpressionContainer(valueNode)) {
|
|
8880
|
+
const expr = valueNode.expression;
|
|
8881
|
+
if (isLiteral(expr)) {
|
|
8882
|
+
const val = expr.value?.toString() ?? "";
|
|
8883
|
+
handleNodeValue(expr, val);
|
|
8884
|
+
} else if (isTemplateLiteral(expr) && expr.expressions.length === 0) {
|
|
8885
|
+
const val = expr.quasis[0].value.raw;
|
|
8886
|
+
handleNodeValue(expr.quasis[0], val);
|
|
8887
|
+
}
|
|
8888
|
+
}
|
|
8787
8889
|
},
|
|
8890
|
+
// Object Properties
|
|
8788
8891
|
Property(node) {
|
|
8789
8892
|
if (!isIdentifier(node.key))
|
|
8790
8893
|
return;
|
|
8791
|
-
if (!
|
|
8792
|
-
return;
|
|
8793
|
-
if (!isPandaAttribute(node, context))
|
|
8894
|
+
if (!isCachedPandaAttribute(node))
|
|
8794
8895
|
return;
|
|
8795
|
-
if (
|
|
8896
|
+
if (isCachedRecipeVariant(node))
|
|
8796
8897
|
return;
|
|
8797
|
-
|
|
8798
|
-
|
|
8898
|
+
const valueNode = node.value;
|
|
8899
|
+
if (isLiteral(valueNode)) {
|
|
8900
|
+
const val = valueNode.value?.toString() ?? "";
|
|
8901
|
+
handleNodeValue(valueNode, val);
|
|
8902
|
+
} else if (isTemplateLiteral(valueNode) && valueNode.expressions.length === 0) {
|
|
8903
|
+
const val = valueNode.quasis[0].value.raw;
|
|
8904
|
+
handleNodeValue(valueNode.quasis[0], val);
|
|
8905
|
+
}
|
|
8799
8906
|
}
|
|
8800
8907
|
};
|
|
8801
8908
|
}
|
|
@@ -8804,40 +8911,84 @@ var no_important_default = rule7;
|
|
|
8804
8911
|
|
|
8805
8912
|
// src/rules/no-invalid-nesting.ts
|
|
8806
8913
|
init_cjs_shims();
|
|
8914
|
+
var import_utils18 = require("@typescript-eslint/utils");
|
|
8807
8915
|
var RULE_NAME8 = "no-invalid-nesting";
|
|
8808
8916
|
var rule8 = createRule({
|
|
8809
8917
|
name: RULE_NAME8,
|
|
8810
8918
|
meta: {
|
|
8811
8919
|
docs: {
|
|
8812
|
-
description: "Warn against invalid nesting.
|
|
8920
|
+
description: "Warn against invalid nesting. Nested styles must contain the `&` character."
|
|
8813
8921
|
},
|
|
8814
8922
|
messages: {
|
|
8815
8923
|
nesting: "Invalid style nesting. Nested styles must contain the `&` character."
|
|
8816
8924
|
},
|
|
8817
|
-
type: "
|
|
8925
|
+
type: "problem",
|
|
8818
8926
|
schema: []
|
|
8819
8927
|
},
|
|
8820
8928
|
defaultOptions: [],
|
|
8821
8929
|
create(context) {
|
|
8930
|
+
const pandaFunctionCache = /* @__PURE__ */ new WeakMap();
|
|
8931
|
+
const jsxPropCache = /* @__PURE__ */ new WeakMap();
|
|
8932
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
8933
|
+
const styledPropertyCache = /* @__PURE__ */ new WeakMap();
|
|
8934
|
+
const isCachedInPandaFunction = (node) => {
|
|
8935
|
+
if (pandaFunctionCache.has(node)) {
|
|
8936
|
+
return pandaFunctionCache.get(node);
|
|
8937
|
+
}
|
|
8938
|
+
const result = !!isInPandaFunction(node, context);
|
|
8939
|
+
pandaFunctionCache.set(node, result);
|
|
8940
|
+
return !!result;
|
|
8941
|
+
};
|
|
8942
|
+
const isCachedInJSXProp = (node) => {
|
|
8943
|
+
if (jsxPropCache.has(node)) {
|
|
8944
|
+
return jsxPropCache.get(node);
|
|
8945
|
+
}
|
|
8946
|
+
const result = isInJSXProp(node, context);
|
|
8947
|
+
jsxPropCache.set(node, result);
|
|
8948
|
+
return !!result;
|
|
8949
|
+
};
|
|
8950
|
+
const isCachedRecipeVariant = (node) => {
|
|
8951
|
+
if (recipeVariantCache.has(node)) {
|
|
8952
|
+
return recipeVariantCache.get(node);
|
|
8953
|
+
}
|
|
8954
|
+
const result = isRecipeVariant(node, context);
|
|
8955
|
+
recipeVariantCache.set(node, result);
|
|
8956
|
+
return !!result;
|
|
8957
|
+
};
|
|
8958
|
+
const isCachedStyledProperty = (node) => {
|
|
8959
|
+
if (styledPropertyCache.has(node)) {
|
|
8960
|
+
return styledPropertyCache.get(node);
|
|
8961
|
+
}
|
|
8962
|
+
const result = isStyledProperty(node, context);
|
|
8963
|
+
styledPropertyCache.set(node, result);
|
|
8964
|
+
return !!result;
|
|
8965
|
+
};
|
|
8966
|
+
const isInvalidNestingSelector = (node) => {
|
|
8967
|
+
if (isLiteral(node) && typeof node.value === "string") {
|
|
8968
|
+
return !node.value.includes("&");
|
|
8969
|
+
} else if (isTemplateLiteral(node) && node.expressions.length === 0) {
|
|
8970
|
+
return !node.quasis[0].value.raw.includes("&");
|
|
8971
|
+
}
|
|
8972
|
+
return false;
|
|
8973
|
+
};
|
|
8822
8974
|
return {
|
|
8823
|
-
Property
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
const
|
|
8827
|
-
if (!
|
|
8975
|
+
// Use AST selector to target Property nodes with non-Identifier keys whose value is an ObjectExpression
|
|
8976
|
+
'Property[key.type!=/Identifier/][value.type="ObjectExpression"]'(node) {
|
|
8977
|
+
const inPandaFunction = isCachedInPandaFunction(node);
|
|
8978
|
+
const inJSXProp = isCachedInJSXProp(node);
|
|
8979
|
+
if (!inPandaFunction && !inJSXProp)
|
|
8828
8980
|
return;
|
|
8829
|
-
if (
|
|
8830
|
-
return;
|
|
8831
|
-
if (isStyledProperty(node, context))
|
|
8981
|
+
if (isCachedRecipeVariant(node))
|
|
8832
8982
|
return;
|
|
8833
|
-
|
|
8834
|
-
const invalidTemplateLiteral = isTemplateLiteral(node.key) && !node.key.quasis[0].value.raw.includes("&");
|
|
8835
|
-
if (!(invalidLiteral || invalidTemplateLiteral))
|
|
8983
|
+
if (isCachedStyledProperty(node))
|
|
8836
8984
|
return;
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8985
|
+
const keyNode = node.key;
|
|
8986
|
+
if (isInvalidNestingSelector(keyNode)) {
|
|
8987
|
+
context.report({
|
|
8988
|
+
node: keyNode,
|
|
8989
|
+
messageId: "nesting"
|
|
8990
|
+
});
|
|
8991
|
+
}
|
|
8841
8992
|
}
|
|
8842
8993
|
};
|
|
8843
8994
|
}
|
|
@@ -8846,7 +8997,7 @@ var no_invalid_nesting_default = rule8;
|
|
|
8846
8997
|
|
|
8847
8998
|
// src/rules/no-invalid-token-paths.ts
|
|
8848
8999
|
init_cjs_shims();
|
|
8849
|
-
var
|
|
9000
|
+
var import_utils20 = require("@typescript-eslint/utils");
|
|
8850
9001
|
var import_ast_utils2 = require("@typescript-eslint/utils/ast-utils");
|
|
8851
9002
|
var RULE_NAME9 = "no-invalid-token-paths";
|
|
8852
9003
|
var rule9 = createRule({
|
|
@@ -8858,87 +9009,89 @@ var rule9 = createRule({
|
|
|
8858
9009
|
messages: {
|
|
8859
9010
|
noInvalidTokenPaths: "`{{token}}` is an invalid token path."
|
|
8860
9011
|
},
|
|
8861
|
-
type: "
|
|
9012
|
+
type: "problem",
|
|
8862
9013
|
schema: []
|
|
8863
9014
|
},
|
|
8864
9015
|
defaultOptions: [],
|
|
8865
9016
|
create(context) {
|
|
8866
|
-
const
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
sendReport(node);
|
|
8870
|
-
};
|
|
8871
|
-
const handleTemplateLiteral = (node) => {
|
|
8872
|
-
if (!isTemplateLiteral(node))
|
|
9017
|
+
const invalidTokensCache2 = /* @__PURE__ */ new Map();
|
|
9018
|
+
const sendReport = (node, value) => {
|
|
9019
|
+
if (!value)
|
|
8873
9020
|
return;
|
|
8874
|
-
|
|
9021
|
+
let tokens = invalidTokensCache2.get(value);
|
|
9022
|
+
if (!tokens) {
|
|
9023
|
+
tokens = getInvalidTokens(value, context);
|
|
9024
|
+
invalidTokensCache2.set(value, tokens);
|
|
9025
|
+
}
|
|
9026
|
+
if (tokens.length === 0)
|
|
8875
9027
|
return;
|
|
8876
|
-
|
|
9028
|
+
tokens.forEach((token) => {
|
|
9029
|
+
context.report({
|
|
9030
|
+
node,
|
|
9031
|
+
messageId: "noInvalidTokenPaths",
|
|
9032
|
+
data: { token }
|
|
9033
|
+
});
|
|
9034
|
+
});
|
|
8877
9035
|
};
|
|
8878
|
-
const
|
|
8879
|
-
|
|
8880
|
-
const tokens = getInvalidTokens(value, context);
|
|
8881
|
-
if (!tokens)
|
|
9036
|
+
const handleLiteralOrTemplate = (node) => {
|
|
9037
|
+
if (!node)
|
|
8882
9038
|
return;
|
|
8883
|
-
if (
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
});
|
|
8890
|
-
});
|
|
9039
|
+
if (isLiteral(node)) {
|
|
9040
|
+
const value = node.value?.toString();
|
|
9041
|
+
sendReport(node, value);
|
|
9042
|
+
} else if (isTemplateLiteral(node) && node.expressions.length === 0) {
|
|
9043
|
+
const value = node.quasis[0].value.raw;
|
|
9044
|
+
sendReport(node.quasis[0], value);
|
|
8891
9045
|
}
|
|
8892
9046
|
};
|
|
8893
9047
|
return {
|
|
8894
9048
|
JSXAttribute(node) {
|
|
8895
|
-
if (!node.value)
|
|
8896
|
-
return;
|
|
8897
|
-
if (!isPandaProp(node, context))
|
|
8898
|
-
return;
|
|
8899
|
-
handleLiteral(node.value);
|
|
8900
|
-
if (!isJSXExpressionContainer(node.value))
|
|
9049
|
+
if (!node.value || !isPandaProp(node, context))
|
|
8901
9050
|
return;
|
|
8902
|
-
|
|
8903
|
-
|
|
9051
|
+
if (isLiteral(node.value)) {
|
|
9052
|
+
handleLiteralOrTemplate(node.value);
|
|
9053
|
+
} else if (isJSXExpressionContainer(node.value)) {
|
|
9054
|
+
handleLiteralOrTemplate(node.value.expression);
|
|
9055
|
+
}
|
|
8904
9056
|
},
|
|
8905
9057
|
Property(node) {
|
|
8906
|
-
if (!isIdentifier(node.key))
|
|
8907
|
-
return;
|
|
8908
|
-
if (!(0, import_ast_utils2.isNodeOfTypes)([import_utils12.AST_NODE_TYPES.Literal, import_utils12.AST_NODE_TYPES.TemplateLiteral])(node.value))
|
|
9058
|
+
if (!isIdentifier(node.key) || !(0, import_ast_utils2.isNodeOfTypes)([import_utils20.AST_NODE_TYPES.Literal, import_utils20.AST_NODE_TYPES.TemplateLiteral])(node.value) || !isPandaAttribute(node, context) || isRecipeVariant(node, context)) {
|
|
8909
9059
|
return;
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
if (isRecipeVariant(node, context))
|
|
8913
|
-
return;
|
|
8914
|
-
handleLiteral(node.value);
|
|
8915
|
-
handleTemplateLiteral(node.value);
|
|
9060
|
+
}
|
|
9061
|
+
handleLiteralOrTemplate(node.value);
|
|
8916
9062
|
},
|
|
8917
9063
|
TaggedTemplateExpression(node) {
|
|
8918
9064
|
const caller = getTaggedTemplateCaller(node);
|
|
8919
|
-
if (!caller)
|
|
9065
|
+
if (!caller || !isPandaIsh(caller, context))
|
|
8920
9066
|
return;
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
const tokens = getInvalidTokens(styles, context);
|
|
8926
|
-
if (!tokens)
|
|
8927
|
-
return;
|
|
8928
|
-
tokens.forEach((token, i, arr) => {
|
|
8929
|
-
if (arr.indexOf(token) < i)
|
|
9067
|
+
const quasis = node.quasi.quasis;
|
|
9068
|
+
quasis.forEach((quasi) => {
|
|
9069
|
+
const styles = quasi.value.raw;
|
|
9070
|
+
if (!styles)
|
|
8930
9071
|
return;
|
|
8931
|
-
let
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
context.report({
|
|
8936
|
-
loc: { start: context.sourceCode.getLocFromIndex(start), end: context.sourceCode.getLocFromIndex(end) },
|
|
8937
|
-
messageId: "noInvalidTokenPaths",
|
|
8938
|
-
data: { token }
|
|
8939
|
-
});
|
|
8940
|
-
index = styles.indexOf(token, index + 1);
|
|
9072
|
+
let tokens = invalidTokensCache2.get(styles);
|
|
9073
|
+
if (!tokens) {
|
|
9074
|
+
tokens = getInvalidTokens(styles, context);
|
|
9075
|
+
invalidTokensCache2.set(styles, tokens);
|
|
8941
9076
|
}
|
|
9077
|
+
if (tokens.length === 0)
|
|
9078
|
+
return;
|
|
9079
|
+
tokens.forEach((token) => {
|
|
9080
|
+
let index = styles.indexOf(token);
|
|
9081
|
+
while (index !== -1) {
|
|
9082
|
+
const start = quasi.range[0] + index + 1;
|
|
9083
|
+
const end = start + token.length;
|
|
9084
|
+
context.report({
|
|
9085
|
+
loc: {
|
|
9086
|
+
start: context.sourceCode.getLocFromIndex(start),
|
|
9087
|
+
end: context.sourceCode.getLocFromIndex(end)
|
|
9088
|
+
},
|
|
9089
|
+
messageId: "noInvalidTokenPaths",
|
|
9090
|
+
data: { token }
|
|
9091
|
+
});
|
|
9092
|
+
index = styles.indexOf(token, index + token.length);
|
|
9093
|
+
}
|
|
9094
|
+
});
|
|
8942
9095
|
});
|
|
8943
9096
|
}
|
|
8944
9097
|
};
|
|
@@ -8963,29 +9116,69 @@ var rule10 = createRule({
|
|
|
8963
9116
|
},
|
|
8964
9117
|
defaultOptions: [],
|
|
8965
9118
|
create(context) {
|
|
8966
|
-
const
|
|
9119
|
+
const longhandCache = /* @__PURE__ */ new Map();
|
|
9120
|
+
const getLonghand = (name2) => {
|
|
9121
|
+
if (longhandCache.has(name2)) {
|
|
9122
|
+
return longhandCache.get(name2);
|
|
9123
|
+
}
|
|
9124
|
+
const longhand = resolveLonghand(name2, context) ?? name2;
|
|
9125
|
+
longhandCache.set(name2, longhand);
|
|
9126
|
+
return longhand;
|
|
9127
|
+
};
|
|
9128
|
+
const marginRegex = /margin/i;
|
|
9129
|
+
const isMarginProperty = (name2) => {
|
|
9130
|
+
const longhand = getLonghand(name2).toLowerCase();
|
|
9131
|
+
return marginRegex.test(longhand);
|
|
9132
|
+
};
|
|
8967
9133
|
const sendReport = (node) => {
|
|
8968
|
-
if (!
|
|
9134
|
+
if (!isMarginProperty(node.name))
|
|
8969
9135
|
return;
|
|
8970
|
-
|
|
9136
|
+
context.report({
|
|
8971
9137
|
node,
|
|
8972
9138
|
messageId: "noMargin"
|
|
8973
9139
|
});
|
|
8974
9140
|
};
|
|
9141
|
+
const pandaPropCache = /* @__PURE__ */ new WeakMap();
|
|
9142
|
+
const isCachedPandaProp = (node) => {
|
|
9143
|
+
if (pandaPropCache.has(node)) {
|
|
9144
|
+
return pandaPropCache.get(node);
|
|
9145
|
+
}
|
|
9146
|
+
const result = isPandaProp(node, context);
|
|
9147
|
+
pandaPropCache.set(node, result);
|
|
9148
|
+
return !!result;
|
|
9149
|
+
};
|
|
9150
|
+
const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
9151
|
+
const isCachedPandaAttribute = (node) => {
|
|
9152
|
+
if (pandaAttributeCache.has(node)) {
|
|
9153
|
+
return pandaAttributeCache.get(node);
|
|
9154
|
+
}
|
|
9155
|
+
const result = isPandaAttribute(node, context);
|
|
9156
|
+
pandaAttributeCache.set(node, result);
|
|
9157
|
+
return !!result;
|
|
9158
|
+
};
|
|
9159
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
9160
|
+
const isCachedRecipeVariant = (node) => {
|
|
9161
|
+
if (recipeVariantCache.has(node)) {
|
|
9162
|
+
return recipeVariantCache.get(node);
|
|
9163
|
+
}
|
|
9164
|
+
const result = isRecipeVariant(node, context);
|
|
9165
|
+
recipeVariantCache.set(node, result);
|
|
9166
|
+
return !!result;
|
|
9167
|
+
};
|
|
8975
9168
|
return {
|
|
8976
9169
|
JSXAttribute(node) {
|
|
8977
9170
|
if (!isJSXIdentifier(node.name))
|
|
8978
9171
|
return;
|
|
8979
|
-
if (!
|
|
9172
|
+
if (!isCachedPandaProp(node))
|
|
8980
9173
|
return;
|
|
8981
9174
|
sendReport(node.name);
|
|
8982
9175
|
},
|
|
8983
9176
|
Property(node) {
|
|
8984
9177
|
if (!isIdentifier(node.key))
|
|
8985
9178
|
return;
|
|
8986
|
-
if (!
|
|
9179
|
+
if (!isCachedPandaAttribute(node))
|
|
8987
9180
|
return;
|
|
8988
|
-
if (
|
|
9181
|
+
if (isCachedRecipeVariant(node))
|
|
8989
9182
|
return;
|
|
8990
9183
|
sendReport(node.key);
|
|
8991
9184
|
}
|
|
@@ -9040,11 +9233,11 @@ var rule11 = createRule({
|
|
|
9040
9233
|
name: RULE_NAME11,
|
|
9041
9234
|
meta: {
|
|
9042
9235
|
docs: {
|
|
9043
|
-
description: "Encourage the use of
|
|
9236
|
+
description: "Encourage the use of logical properties over physical properties to foster a responsive and adaptable user interface."
|
|
9044
9237
|
},
|
|
9045
9238
|
messages: {
|
|
9046
|
-
physical: "Use logical property of {{physical}}
|
|
9047
|
-
replace: "Replace `{{physical}}` with `{{logical}}
|
|
9239
|
+
physical: "Use logical property instead of {{physical}}. Prefer `{{logical}}`.",
|
|
9240
|
+
replace: "Replace `{{physical}}` with `{{logical}}`."
|
|
9048
9241
|
},
|
|
9049
9242
|
type: "suggestion",
|
|
9050
9243
|
hasSuggestions: true,
|
|
@@ -9052,17 +9245,53 @@ var rule11 = createRule({
|
|
|
9052
9245
|
},
|
|
9053
9246
|
defaultOptions: [],
|
|
9054
9247
|
create(context) {
|
|
9055
|
-
const
|
|
9248
|
+
const longhandCache = /* @__PURE__ */ new Map();
|
|
9249
|
+
const pandaPropCache = /* @__PURE__ */ new WeakMap();
|
|
9250
|
+
const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
9251
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
9252
|
+
const getLonghand = (name2) => {
|
|
9253
|
+
if (longhandCache.has(name2)) {
|
|
9254
|
+
return longhandCache.get(name2);
|
|
9255
|
+
}
|
|
9256
|
+
const longhand = resolveLonghand(name2, context) ?? name2;
|
|
9257
|
+
longhandCache.set(name2, longhand);
|
|
9258
|
+
return longhand;
|
|
9259
|
+
};
|
|
9260
|
+
const isCachedPandaProp = (node) => {
|
|
9261
|
+
if (pandaPropCache.has(node)) {
|
|
9262
|
+
return pandaPropCache.get(node);
|
|
9263
|
+
}
|
|
9264
|
+
const result = isPandaProp(node, context);
|
|
9265
|
+
pandaPropCache.set(node, result);
|
|
9266
|
+
return !!result;
|
|
9267
|
+
};
|
|
9268
|
+
const isCachedPandaAttribute = (node) => {
|
|
9269
|
+
if (pandaAttributeCache.has(node)) {
|
|
9270
|
+
return pandaAttributeCache.get(node);
|
|
9271
|
+
}
|
|
9272
|
+
const result = isPandaAttribute(node, context);
|
|
9273
|
+
pandaAttributeCache.set(node, result);
|
|
9274
|
+
return !!result;
|
|
9275
|
+
};
|
|
9276
|
+
const isCachedRecipeVariant = (node) => {
|
|
9277
|
+
if (recipeVariantCache.has(node)) {
|
|
9278
|
+
return recipeVariantCache.get(node);
|
|
9279
|
+
}
|
|
9280
|
+
const result = isRecipeVariant(node, context);
|
|
9281
|
+
recipeVariantCache.set(node, result);
|
|
9282
|
+
return !!result;
|
|
9283
|
+
};
|
|
9056
9284
|
const sendReport = (node) => {
|
|
9057
|
-
|
|
9285
|
+
const longhandName = getLonghand(node.name);
|
|
9286
|
+
if (!(longhandName in physicalProperties))
|
|
9058
9287
|
return;
|
|
9059
|
-
const logical = physicalProperties[
|
|
9060
|
-
const
|
|
9061
|
-
|
|
9288
|
+
const logical = physicalProperties[longhandName];
|
|
9289
|
+
const physicalName = `\`${node.name}\`${longhandName !== node.name ? ` (resolved to \`${longhandName}\`)` : ""}`;
|
|
9290
|
+
context.report({
|
|
9062
9291
|
node,
|
|
9063
9292
|
messageId: "physical",
|
|
9064
9293
|
data: {
|
|
9065
|
-
physical:
|
|
9294
|
+
physical: physicalName,
|
|
9066
9295
|
logical
|
|
9067
9296
|
},
|
|
9068
9297
|
suggest: [
|
|
@@ -9073,7 +9302,7 @@ var rule11 = createRule({
|
|
|
9073
9302
|
logical
|
|
9074
9303
|
},
|
|
9075
9304
|
fix: (fixer) => {
|
|
9076
|
-
return fixer.
|
|
9305
|
+
return fixer.replaceText(node, logical);
|
|
9077
9306
|
}
|
|
9078
9307
|
}
|
|
9079
9308
|
]
|
|
@@ -9083,16 +9312,16 @@ var rule11 = createRule({
|
|
|
9083
9312
|
JSXAttribute(node) {
|
|
9084
9313
|
if (!isJSXIdentifier(node.name))
|
|
9085
9314
|
return;
|
|
9086
|
-
if (!
|
|
9315
|
+
if (!isCachedPandaProp(node))
|
|
9087
9316
|
return;
|
|
9088
9317
|
sendReport(node.name);
|
|
9089
9318
|
},
|
|
9090
9319
|
Property(node) {
|
|
9091
9320
|
if (!isIdentifier(node.key))
|
|
9092
9321
|
return;
|
|
9093
|
-
if (!
|
|
9322
|
+
if (!isCachedPandaAttribute(node))
|
|
9094
9323
|
return;
|
|
9095
|
-
if (
|
|
9324
|
+
if (isCachedRecipeVariant(node))
|
|
9096
9325
|
return;
|
|
9097
9326
|
sendReport(node.key);
|
|
9098
9327
|
}
|
|
@@ -9108,19 +9337,46 @@ var rule12 = createRule({
|
|
|
9108
9337
|
name: RULE_NAME12,
|
|
9109
9338
|
meta: {
|
|
9110
9339
|
docs: {
|
|
9111
|
-
description: "Ensure
|
|
9340
|
+
description: "Ensure that properties for patterns or style props are not renamed, as it prevents proper tracking."
|
|
9112
9341
|
},
|
|
9113
9342
|
messages: {
|
|
9114
|
-
noRenaming: "Incoming `{{prop}}` prop is different from the expected `{{expected}}` attribute.
|
|
9343
|
+
noRenaming: "Incoming `{{prop}}` prop is different from the expected `{{expected}}` attribute. Panda will not track this prop."
|
|
9115
9344
|
},
|
|
9116
|
-
type: "
|
|
9345
|
+
type: "problem",
|
|
9117
9346
|
schema: []
|
|
9118
9347
|
},
|
|
9119
9348
|
defaultOptions: [],
|
|
9120
9349
|
create(context) {
|
|
9350
|
+
const pandaPropCache = /* @__PURE__ */ new WeakMap();
|
|
9351
|
+
const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
9352
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
9353
|
+
const isCachedPandaProp = (node) => {
|
|
9354
|
+
if (pandaPropCache.has(node)) {
|
|
9355
|
+
return pandaPropCache.get(node);
|
|
9356
|
+
}
|
|
9357
|
+
const result = isPandaProp(node, context);
|
|
9358
|
+
pandaPropCache.set(node, result);
|
|
9359
|
+
return !!result;
|
|
9360
|
+
};
|
|
9361
|
+
const isCachedPandaAttribute = (node) => {
|
|
9362
|
+
if (pandaAttributeCache.has(node)) {
|
|
9363
|
+
return pandaAttributeCache.get(node);
|
|
9364
|
+
}
|
|
9365
|
+
const result = isPandaAttribute(node, context);
|
|
9366
|
+
pandaAttributeCache.set(node, result);
|
|
9367
|
+
return !!result;
|
|
9368
|
+
};
|
|
9369
|
+
const isCachedRecipeVariant = (node) => {
|
|
9370
|
+
if (recipeVariantCache.has(node)) {
|
|
9371
|
+
return recipeVariantCache.get(node);
|
|
9372
|
+
}
|
|
9373
|
+
const result = isRecipeVariant(node, context);
|
|
9374
|
+
recipeVariantCache.set(node, result);
|
|
9375
|
+
return !!result;
|
|
9376
|
+
};
|
|
9121
9377
|
const sendReport = (node, expected, prop) => {
|
|
9122
|
-
|
|
9123
|
-
node
|
|
9378
|
+
context.report({
|
|
9379
|
+
node,
|
|
9124
9380
|
messageId: "noRenaming",
|
|
9125
9381
|
data: {
|
|
9126
9382
|
expected,
|
|
@@ -9130,10 +9386,9 @@ var rule12 = createRule({
|
|
|
9130
9386
|
};
|
|
9131
9387
|
const handleReport = (node, value, attr) => {
|
|
9132
9388
|
if (isIdentifier(value) && attr !== value.name) {
|
|
9133
|
-
|
|
9134
|
-
}
|
|
9135
|
-
|
|
9136
|
-
return sendReport(node, attr, value.property.name);
|
|
9389
|
+
sendReport(node, attr, value.name);
|
|
9390
|
+
} else if (isMemberExpression(value) && isIdentifier(value.property) && attr !== value.property.name) {
|
|
9391
|
+
sendReport(node, attr, value.property.name);
|
|
9137
9392
|
}
|
|
9138
9393
|
};
|
|
9139
9394
|
return {
|
|
@@ -9142,24 +9397,24 @@ var rule12 = createRule({
|
|
|
9142
9397
|
return;
|
|
9143
9398
|
if (!isJSXExpressionContainer(node.value))
|
|
9144
9399
|
return;
|
|
9145
|
-
if (!
|
|
9400
|
+
if (!isCachedPandaProp(node))
|
|
9146
9401
|
return;
|
|
9147
9402
|
const attr = node.name.name.toString();
|
|
9148
9403
|
const expression = node.value.expression;
|
|
9149
|
-
handleReport(node, expression, attr);
|
|
9404
|
+
handleReport(node.value, expression, attr);
|
|
9150
9405
|
},
|
|
9151
9406
|
Property(node) {
|
|
9152
9407
|
if (!isIdentifier(node.key))
|
|
9153
9408
|
return;
|
|
9154
9409
|
if (!isIdentifier(node.value) && !isMemberExpression(node.value))
|
|
9155
9410
|
return;
|
|
9156
|
-
if (!
|
|
9411
|
+
if (!isCachedPandaAttribute(node))
|
|
9157
9412
|
return;
|
|
9158
|
-
if (
|
|
9413
|
+
if (isCachedRecipeVariant(node))
|
|
9159
9414
|
return;
|
|
9160
|
-
const attr = node.key.name
|
|
9415
|
+
const attr = node.key.name;
|
|
9161
9416
|
const value = node.value;
|
|
9162
|
-
handleReport(node, value, attr);
|
|
9417
|
+
handleReport(node.value, value, attr);
|
|
9163
9418
|
}
|
|
9164
9419
|
};
|
|
9165
9420
|
}
|
|
@@ -9168,7 +9423,7 @@ var no_property_renaming_default = rule12;
|
|
|
9168
9423
|
|
|
9169
9424
|
// src/rules/no-unsafe-token-fn-usage.ts
|
|
9170
9425
|
init_cjs_shims();
|
|
9171
|
-
var
|
|
9426
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
9172
9427
|
var import_shared3 = require("@pandacss/shared");
|
|
9173
9428
|
var RULE_NAME13 = "no-unsafe-token-fn-usage";
|
|
9174
9429
|
var rule13 = createRule({
|
|
@@ -9178,8 +9433,8 @@ var rule13 = createRule({
|
|
|
9178
9433
|
description: "Prevent users from using the token function in situations where they could simply use the raw design token."
|
|
9179
9434
|
},
|
|
9180
9435
|
messages: {
|
|
9181
|
-
noUnsafeTokenFnUsage: "
|
|
9182
|
-
replace: "Replace token function with `{{safe}}
|
|
9436
|
+
noUnsafeTokenFnUsage: "Unnecessary token function usage. Prefer design token.",
|
|
9437
|
+
replace: "Replace token function with `{{safe}}`."
|
|
9183
9438
|
},
|
|
9184
9439
|
type: "suggestion",
|
|
9185
9440
|
hasSuggestions: true,
|
|
@@ -9187,11 +9442,42 @@ var rule13 = createRule({
|
|
|
9187
9442
|
},
|
|
9188
9443
|
defaultOptions: [],
|
|
9189
9444
|
create(context) {
|
|
9445
|
+
let tokenImportCache;
|
|
9446
|
+
const getCachedTokenImport = () => {
|
|
9447
|
+
if (tokenImportCache !== void 0) {
|
|
9448
|
+
return tokenImportCache;
|
|
9449
|
+
}
|
|
9450
|
+
tokenImportCache = getTokenImport(context);
|
|
9451
|
+
return tokenImportCache;
|
|
9452
|
+
};
|
|
9190
9453
|
const isUnsafeCallExpression = (node) => {
|
|
9191
|
-
const tkImport =
|
|
9454
|
+
const tkImport = getCachedTokenImport();
|
|
9192
9455
|
return isIdentifier(node.callee) && node.callee.name === tkImport?.alias;
|
|
9193
9456
|
};
|
|
9194
9457
|
const tokenWrap = (value) => value ? `token(${value})` : "";
|
|
9458
|
+
const isCompositeValue = (input) => {
|
|
9459
|
+
if (!input)
|
|
9460
|
+
return false;
|
|
9461
|
+
const tokenRegex = /^(?:token\([^)]*\)|\{[^}]*\})$/;
|
|
9462
|
+
return !tokenRegex.test(input);
|
|
9463
|
+
};
|
|
9464
|
+
const sendReport = (node, value) => {
|
|
9465
|
+
const tkImports = extractTokens(value);
|
|
9466
|
+
if (!tkImports.length)
|
|
9467
|
+
return;
|
|
9468
|
+
const token = tkImports[0].replace(/^[^.]*\./, "");
|
|
9469
|
+
context.report({
|
|
9470
|
+
node,
|
|
9471
|
+
messageId: "noUnsafeTokenFnUsage",
|
|
9472
|
+
suggest: [
|
|
9473
|
+
{
|
|
9474
|
+
messageId: "replace",
|
|
9475
|
+
data: { safe: token },
|
|
9476
|
+
fix: (fixer) => fixer.replaceText(node, `'${token}'`)
|
|
9477
|
+
}
|
|
9478
|
+
]
|
|
9479
|
+
});
|
|
9480
|
+
};
|
|
9195
9481
|
const handleRuntimeFm = (node) => {
|
|
9196
9482
|
if (!isCallExpression(node))
|
|
9197
9483
|
return;
|
|
@@ -9199,17 +9485,12 @@ var rule13 = createRule({
|
|
|
9199
9485
|
return;
|
|
9200
9486
|
const value = node.arguments[0];
|
|
9201
9487
|
if (isLiteral(value)) {
|
|
9202
|
-
|
|
9488
|
+
const val = (0, import_shared3.getArbitraryValue)(value.value?.toString() ?? "");
|
|
9489
|
+
sendReport(node, tokenWrap(val));
|
|
9490
|
+
} else if (isTemplateLiteral(value) && value.expressions.length === 0) {
|
|
9491
|
+
const val = (0, import_shared3.getArbitraryValue)(value.quasis[0].value.raw);
|
|
9492
|
+
sendReport(node, tokenWrap(val));
|
|
9203
9493
|
}
|
|
9204
|
-
if (isTemplateLiteral(value)) {
|
|
9205
|
-
sendReport(node, tokenWrap((0, import_shared3.getArbitraryValue)(value.quasis[0].value.raw)));
|
|
9206
|
-
}
|
|
9207
|
-
};
|
|
9208
|
-
const isCompositeValue = (input) => {
|
|
9209
|
-
if (!input)
|
|
9210
|
-
return;
|
|
9211
|
-
const tokenRegex = /^(?:token\([^)]*\)|\{[^}]*\})$/;
|
|
9212
|
-
return !tokenRegex.test(input);
|
|
9213
9494
|
};
|
|
9214
9495
|
const handleLiteral = (node) => {
|
|
9215
9496
|
if (!isLiteral(node))
|
|
@@ -9220,54 +9501,63 @@ var rule13 = createRule({
|
|
|
9220
9501
|
sendReport(node, value);
|
|
9221
9502
|
};
|
|
9222
9503
|
const handleTemplateLiteral = (node) => {
|
|
9223
|
-
if (!isTemplateLiteral(node))
|
|
9224
|
-
return;
|
|
9225
|
-
if (node.expressions.length > 0)
|
|
9504
|
+
if (!isTemplateLiteral(node) || node.expressions.length > 0)
|
|
9226
9505
|
return;
|
|
9227
|
-
|
|
9506
|
+
const value = (0, import_shared3.getArbitraryValue)(node.quasis[0].value.raw);
|
|
9507
|
+
sendReport(node, value);
|
|
9228
9508
|
};
|
|
9229
|
-
const
|
|
9230
|
-
|
|
9231
|
-
if (
|
|
9232
|
-
return;
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9509
|
+
const pandaPropCache = /* @__PURE__ */ new WeakMap();
|
|
9510
|
+
const isCachedPandaProp = (node) => {
|
|
9511
|
+
if (pandaPropCache.has(node)) {
|
|
9512
|
+
return pandaPropCache.get(node);
|
|
9513
|
+
}
|
|
9514
|
+
const result = isPandaProp(node, context);
|
|
9515
|
+
pandaPropCache.set(node, result);
|
|
9516
|
+
return !!result;
|
|
9517
|
+
};
|
|
9518
|
+
const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
9519
|
+
const isCachedPandaAttribute = (node) => {
|
|
9520
|
+
if (pandaAttributeCache.has(node)) {
|
|
9521
|
+
return pandaAttributeCache.get(node);
|
|
9522
|
+
}
|
|
9523
|
+
const result = isPandaAttribute(node, context);
|
|
9524
|
+
pandaAttributeCache.set(node, result);
|
|
9525
|
+
return !!result;
|
|
9526
|
+
};
|
|
9527
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
9528
|
+
const isCachedRecipeVariant = (node) => {
|
|
9529
|
+
if (recipeVariantCache.has(node)) {
|
|
9530
|
+
return recipeVariantCache.get(node);
|
|
9531
|
+
}
|
|
9532
|
+
const result = isRecipeVariant(node, context);
|
|
9533
|
+
recipeVariantCache.set(node, result);
|
|
9534
|
+
return !!result;
|
|
9247
9535
|
};
|
|
9248
9536
|
return {
|
|
9249
9537
|
JSXAttribute(node) {
|
|
9250
9538
|
if (!node.value)
|
|
9251
9539
|
return;
|
|
9252
|
-
if (!
|
|
9540
|
+
if (!isCachedPandaProp(node))
|
|
9253
9541
|
return;
|
|
9254
9542
|
handleLiteral(node.value);
|
|
9255
|
-
if (
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9543
|
+
if (isJSXExpressionContainer(node.value)) {
|
|
9544
|
+
const expression = node.value.expression;
|
|
9545
|
+
handleLiteral(expression);
|
|
9546
|
+
handleTemplateLiteral(expression);
|
|
9547
|
+
handleRuntimeFm(expression);
|
|
9548
|
+
}
|
|
9260
9549
|
},
|
|
9261
9550
|
Property(node) {
|
|
9262
|
-
if (!
|
|
9551
|
+
if (!isCachedPandaAttribute(node))
|
|
9263
9552
|
return;
|
|
9264
|
-
if (
|
|
9265
|
-
return;
|
|
9266
|
-
if (isRecipeVariant(node, context))
|
|
9553
|
+
if (isCachedRecipeVariant(node))
|
|
9267
9554
|
return;
|
|
9268
|
-
|
|
9269
|
-
|
|
9270
|
-
|
|
9555
|
+
const valueNode = node.value;
|
|
9556
|
+
if (isCallExpression(valueNode) || isLiteral(valueNode) || isTemplateLiteral(valueNode)) {
|
|
9557
|
+
handleRuntimeFm(valueNode);
|
|
9558
|
+
handleLiteral(valueNode);
|
|
9559
|
+
handleTemplateLiteral(valueNode);
|
|
9560
|
+
}
|
|
9271
9561
|
}
|
|
9272
9562
|
};
|
|
9273
9563
|
}
|
|
@@ -9284,8 +9574,8 @@ var rule14 = createRule({
|
|
|
9284
9574
|
description: "Discourage the use of shorthand properties and promote the preference for longhand properties in the codebase."
|
|
9285
9575
|
},
|
|
9286
9576
|
messages: {
|
|
9287
|
-
longhand: "Use longhand property of `{{shorthand}}
|
|
9288
|
-
replace: "Replace `{{shorthand}}` with `{{longhand}}
|
|
9577
|
+
longhand: "Use longhand property instead of `{{shorthand}}`. Prefer `{{longhand}}`.",
|
|
9578
|
+
replace: "Replace `{{shorthand}}` with `{{longhand}}`."
|
|
9289
9579
|
},
|
|
9290
9580
|
type: "suggestion",
|
|
9291
9581
|
hasSuggestions: true,
|
|
@@ -9293,15 +9583,51 @@ var rule14 = createRule({
|
|
|
9293
9583
|
},
|
|
9294
9584
|
defaultOptions: [],
|
|
9295
9585
|
create(context) {
|
|
9586
|
+
const longhandCache = /* @__PURE__ */ new Map();
|
|
9587
|
+
const getLonghand = (name2) => {
|
|
9588
|
+
if (longhandCache.has(name2)) {
|
|
9589
|
+
return longhandCache.get(name2);
|
|
9590
|
+
}
|
|
9591
|
+
const longhand = resolveLonghand(name2, context);
|
|
9592
|
+
longhandCache.set(name2, longhand);
|
|
9593
|
+
return longhand;
|
|
9594
|
+
};
|
|
9595
|
+
const pandaPropCache = /* @__PURE__ */ new WeakMap();
|
|
9596
|
+
const isCachedPandaProp = (node) => {
|
|
9597
|
+
if (pandaPropCache.has(node)) {
|
|
9598
|
+
return pandaPropCache.get(node);
|
|
9599
|
+
}
|
|
9600
|
+
const result = isPandaProp(node, context);
|
|
9601
|
+
pandaPropCache.set(node, result);
|
|
9602
|
+
return !!result;
|
|
9603
|
+
};
|
|
9604
|
+
const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
9605
|
+
const isCachedPandaAttribute = (node) => {
|
|
9606
|
+
if (pandaAttributeCache.has(node)) {
|
|
9607
|
+
return pandaAttributeCache.get(node);
|
|
9608
|
+
}
|
|
9609
|
+
const result = isPandaAttribute(node, context);
|
|
9610
|
+
pandaAttributeCache.set(node, result);
|
|
9611
|
+
return !!result;
|
|
9612
|
+
};
|
|
9613
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
9614
|
+
const isCachedRecipeVariant = (node) => {
|
|
9615
|
+
if (recipeVariantCache.has(node)) {
|
|
9616
|
+
return recipeVariantCache.get(node);
|
|
9617
|
+
}
|
|
9618
|
+
const result = isRecipeVariant(node, context);
|
|
9619
|
+
recipeVariantCache.set(node, result);
|
|
9620
|
+
return !!result;
|
|
9621
|
+
};
|
|
9296
9622
|
const sendReport = (node) => {
|
|
9297
|
-
const longhand =
|
|
9298
|
-
if (!longhand)
|
|
9623
|
+
const longhand = getLonghand(node.name);
|
|
9624
|
+
if (!longhand || longhand === node.name)
|
|
9299
9625
|
return;
|
|
9300
9626
|
const data = {
|
|
9301
9627
|
shorthand: node.name,
|
|
9302
9628
|
longhand
|
|
9303
9629
|
};
|
|
9304
|
-
|
|
9630
|
+
context.report({
|
|
9305
9631
|
node,
|
|
9306
9632
|
messageId: "longhand",
|
|
9307
9633
|
data,
|
|
@@ -9309,9 +9635,7 @@ var rule14 = createRule({
|
|
|
9309
9635
|
{
|
|
9310
9636
|
messageId: "replace",
|
|
9311
9637
|
data,
|
|
9312
|
-
fix: (fixer) =>
|
|
9313
|
-
return fixer.replaceTextRange(node.range, longhand);
|
|
9314
|
-
}
|
|
9638
|
+
fix: (fixer) => fixer.replaceText(node, longhand)
|
|
9315
9639
|
}
|
|
9316
9640
|
]
|
|
9317
9641
|
});
|
|
@@ -9320,16 +9644,16 @@ var rule14 = createRule({
|
|
|
9320
9644
|
JSXAttribute(node) {
|
|
9321
9645
|
if (!isJSXIdentifier(node.name))
|
|
9322
9646
|
return;
|
|
9323
|
-
if (!
|
|
9647
|
+
if (!isCachedPandaProp(node))
|
|
9324
9648
|
return;
|
|
9325
9649
|
sendReport(node.name);
|
|
9326
9650
|
},
|
|
9327
9651
|
Property(node) {
|
|
9328
9652
|
if (!isIdentifier(node.key))
|
|
9329
9653
|
return;
|
|
9330
|
-
if (!
|
|
9654
|
+
if (!isCachedPandaAttribute(node))
|
|
9331
9655
|
return;
|
|
9332
|
-
if (
|
|
9656
|
+
if (isCachedRecipeVariant(node))
|
|
9333
9657
|
return;
|
|
9334
9658
|
sendReport(node.key);
|
|
9335
9659
|
}
|
|
@@ -9348,8 +9672,8 @@ var rule15 = createRule({
|
|
|
9348
9672
|
description: "Discourage the use of longhand properties and promote the preference for shorthand properties in the codebase."
|
|
9349
9673
|
},
|
|
9350
9674
|
messages: {
|
|
9351
|
-
shorthand: "Use shorthand property of `{{longhand}}
|
|
9352
|
-
replace: "Replace `{{longhand}}` with `{{shorthand}}
|
|
9675
|
+
shorthand: "Use shorthand property instead of `{{longhand}}`. Prefer `{{shorthand}}`.",
|
|
9676
|
+
replace: "Replace `{{longhand}}` with `{{shorthand}}`."
|
|
9353
9677
|
},
|
|
9354
9678
|
type: "suggestion",
|
|
9355
9679
|
hasSuggestions: true,
|
|
@@ -9357,19 +9681,64 @@ var rule15 = createRule({
|
|
|
9357
9681
|
},
|
|
9358
9682
|
defaultOptions: [],
|
|
9359
9683
|
create(context) {
|
|
9684
|
+
const longhandCache = /* @__PURE__ */ new Map();
|
|
9685
|
+
const getLonghand = (name2) => {
|
|
9686
|
+
if (longhandCache.has(name2)) {
|
|
9687
|
+
return longhandCache.get(name2);
|
|
9688
|
+
}
|
|
9689
|
+
const longhand = resolveLonghand(name2, context);
|
|
9690
|
+
longhandCache.set(name2, longhand);
|
|
9691
|
+
return longhand;
|
|
9692
|
+
};
|
|
9693
|
+
const shorthandsCache = /* @__PURE__ */ new Map();
|
|
9694
|
+
const getShorthands = (name2) => {
|
|
9695
|
+
if (shorthandsCache.has(name2)) {
|
|
9696
|
+
return shorthandsCache.get(name2);
|
|
9697
|
+
}
|
|
9698
|
+
const shorthands = resolveShorthands(name2, context);
|
|
9699
|
+
shorthandsCache.set(name2, shorthands);
|
|
9700
|
+
return shorthands;
|
|
9701
|
+
};
|
|
9702
|
+
const pandaPropCache = /* @__PURE__ */ new WeakMap();
|
|
9703
|
+
const isCachedPandaProp = (node) => {
|
|
9704
|
+
if (pandaPropCache.has(node)) {
|
|
9705
|
+
return pandaPropCache.get(node);
|
|
9706
|
+
}
|
|
9707
|
+
const result = isPandaProp(node, context);
|
|
9708
|
+
pandaPropCache.set(node, result);
|
|
9709
|
+
return !!result;
|
|
9710
|
+
};
|
|
9711
|
+
const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
9712
|
+
const isCachedPandaAttribute = (node) => {
|
|
9713
|
+
if (pandaAttributeCache.has(node)) {
|
|
9714
|
+
return pandaAttributeCache.get(node);
|
|
9715
|
+
}
|
|
9716
|
+
const result = isPandaAttribute(node, context);
|
|
9717
|
+
pandaAttributeCache.set(node, result);
|
|
9718
|
+
return !!result;
|
|
9719
|
+
};
|
|
9720
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
9721
|
+
const isCachedRecipeVariant = (node) => {
|
|
9722
|
+
if (recipeVariantCache.has(node)) {
|
|
9723
|
+
return recipeVariantCache.get(node);
|
|
9724
|
+
}
|
|
9725
|
+
const result = isRecipeVariant(node, context);
|
|
9726
|
+
recipeVariantCache.set(node, result);
|
|
9727
|
+
return !!result;
|
|
9728
|
+
};
|
|
9360
9729
|
const sendReport = (node) => {
|
|
9361
|
-
const longhand =
|
|
9730
|
+
const longhand = getLonghand(node.name);
|
|
9362
9731
|
if (longhand)
|
|
9363
9732
|
return;
|
|
9364
|
-
const shorthands =
|
|
9365
|
-
if (!shorthands)
|
|
9733
|
+
const shorthands = getShorthands(node.name);
|
|
9734
|
+
if (!shorthands || shorthands.length === 0)
|
|
9366
9735
|
return;
|
|
9367
|
-
const
|
|
9736
|
+
const shorthandList = shorthands.map((s) => `\`${s}\``).join(", ");
|
|
9368
9737
|
const data = {
|
|
9369
9738
|
longhand: node.name,
|
|
9370
|
-
shorthand
|
|
9739
|
+
shorthand: shorthandList
|
|
9371
9740
|
};
|
|
9372
|
-
|
|
9741
|
+
context.report({
|
|
9373
9742
|
node,
|
|
9374
9743
|
messageId: "shorthand",
|
|
9375
9744
|
data,
|
|
@@ -9377,9 +9746,7 @@ var rule15 = createRule({
|
|
|
9377
9746
|
{
|
|
9378
9747
|
messageId: "replace",
|
|
9379
9748
|
data,
|
|
9380
|
-
fix: (fixer) =>
|
|
9381
|
-
return fixer.replaceTextRange(node.range, shorthands[0]);
|
|
9382
|
-
}
|
|
9749
|
+
fix: (fixer) => fixer.replaceText(node, shorthands[0])
|
|
9383
9750
|
}
|
|
9384
9751
|
]
|
|
9385
9752
|
});
|
|
@@ -9388,16 +9755,16 @@ var rule15 = createRule({
|
|
|
9388
9755
|
JSXAttribute(node) {
|
|
9389
9756
|
if (!isJSXIdentifier(node.name))
|
|
9390
9757
|
return;
|
|
9391
|
-
if (!
|
|
9758
|
+
if (!isCachedPandaProp(node))
|
|
9392
9759
|
return;
|
|
9393
9760
|
sendReport(node.name);
|
|
9394
9761
|
},
|
|
9395
9762
|
Property(node) {
|
|
9396
9763
|
if (!isIdentifier(node.key))
|
|
9397
9764
|
return;
|
|
9398
|
-
if (!
|
|
9765
|
+
if (!isCachedPandaAttribute(node))
|
|
9399
9766
|
return;
|
|
9400
|
-
if (
|
|
9767
|
+
if (isCachedRecipeVariant(node))
|
|
9401
9768
|
return;
|
|
9402
9769
|
sendReport(node.key);
|
|
9403
9770
|
}
|
|
@@ -9532,26 +9899,69 @@ var rule16 = createRule({
|
|
|
9532
9899
|
description: "Encourage the use of atomic properties instead of composite properties in the codebase."
|
|
9533
9900
|
},
|
|
9534
9901
|
messages: {
|
|
9535
|
-
atomic: "Use atomic properties of `{{composite}}
|
|
9902
|
+
atomic: "Use atomic properties instead of `{{composite}}`. Prefer: \n{{atomics}}"
|
|
9536
9903
|
},
|
|
9537
9904
|
type: "suggestion",
|
|
9538
9905
|
schema: []
|
|
9539
9906
|
},
|
|
9540
9907
|
defaultOptions: [],
|
|
9541
9908
|
create(context) {
|
|
9909
|
+
const longhandCache = /* @__PURE__ */ new Map();
|
|
9910
|
+
const getLonghand = (name2) => {
|
|
9911
|
+
if (longhandCache.has(name2)) {
|
|
9912
|
+
return longhandCache.get(name2);
|
|
9913
|
+
}
|
|
9914
|
+
const longhand = resolveLonghand(name2, context) ?? name2;
|
|
9915
|
+
longhandCache.set(name2, longhand);
|
|
9916
|
+
return longhand;
|
|
9917
|
+
};
|
|
9918
|
+
const compositePropertyCache = /* @__PURE__ */ new Map();
|
|
9542
9919
|
const resolveCompositeProperty = (name2) => {
|
|
9543
|
-
if (
|
|
9920
|
+
if (compositePropertyCache.has(name2)) {
|
|
9921
|
+
return compositePropertyCache.get(name2);
|
|
9922
|
+
}
|
|
9923
|
+
if (Object.hasOwn(compositeProperties, name2)) {
|
|
9924
|
+
compositePropertyCache.set(name2, name2);
|
|
9544
9925
|
return name2;
|
|
9545
|
-
|
|
9546
|
-
|
|
9926
|
+
}
|
|
9927
|
+
const longhand = getLonghand(name2);
|
|
9928
|
+
if (isValidProperty(longhand, context) && Object.hasOwn(compositeProperties, longhand)) {
|
|
9929
|
+
compositePropertyCache.set(name2, longhand);
|
|
9547
9930
|
return longhand;
|
|
9931
|
+
}
|
|
9932
|
+
compositePropertyCache.set(name2, void 0);
|
|
9933
|
+
return void 0;
|
|
9548
9934
|
};
|
|
9549
|
-
const
|
|
9550
|
-
|
|
9551
|
-
if (
|
|
9552
|
-
return;
|
|
9553
|
-
|
|
9554
|
-
|
|
9935
|
+
const pandaPropCache = /* @__PURE__ */ new WeakMap();
|
|
9936
|
+
const isCachedPandaProp = (node) => {
|
|
9937
|
+
if (pandaPropCache.has(node)) {
|
|
9938
|
+
return pandaPropCache.get(node);
|
|
9939
|
+
}
|
|
9940
|
+
const result = isPandaProp(node, context);
|
|
9941
|
+
pandaPropCache.set(node, result);
|
|
9942
|
+
return !!result;
|
|
9943
|
+
};
|
|
9944
|
+
const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
9945
|
+
const isCachedPandaAttribute = (node) => {
|
|
9946
|
+
if (pandaAttributeCache.has(node)) {
|
|
9947
|
+
return pandaAttributeCache.get(node);
|
|
9948
|
+
}
|
|
9949
|
+
const result = isPandaAttribute(node, context);
|
|
9950
|
+
pandaAttributeCache.set(node, result);
|
|
9951
|
+
return !!result;
|
|
9952
|
+
};
|
|
9953
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
9954
|
+
const isCachedRecipeVariant = (node) => {
|
|
9955
|
+
if (recipeVariantCache.has(node)) {
|
|
9956
|
+
return recipeVariantCache.get(node);
|
|
9957
|
+
}
|
|
9958
|
+
const result = isRecipeVariant(node, context);
|
|
9959
|
+
recipeVariantCache.set(node, result);
|
|
9960
|
+
return !!result;
|
|
9961
|
+
};
|
|
9962
|
+
const sendReport = (node, composite) => {
|
|
9963
|
+
const atomics = compositeProperties[composite].map((name2) => `\`${name2}\``).join(",\n");
|
|
9964
|
+
context.report({
|
|
9555
9965
|
node,
|
|
9556
9966
|
messageId: "atomic",
|
|
9557
9967
|
data: {
|
|
@@ -9564,18 +9974,24 @@ var rule16 = createRule({
|
|
|
9564
9974
|
JSXAttribute(node) {
|
|
9565
9975
|
if (!isJSXIdentifier(node.name))
|
|
9566
9976
|
return;
|
|
9567
|
-
if (!
|
|
9977
|
+
if (!isCachedPandaProp(node))
|
|
9568
9978
|
return;
|
|
9569
|
-
|
|
9979
|
+
const composite = resolveCompositeProperty(node.name.name);
|
|
9980
|
+
if (!composite)
|
|
9981
|
+
return;
|
|
9982
|
+
sendReport(node.name, composite);
|
|
9570
9983
|
},
|
|
9571
9984
|
Property(node) {
|
|
9572
9985
|
if (!isIdentifier(node.key))
|
|
9573
9986
|
return;
|
|
9574
|
-
if (!
|
|
9987
|
+
if (!isCachedPandaAttribute(node))
|
|
9575
9988
|
return;
|
|
9576
|
-
if (
|
|
9989
|
+
if (isCachedRecipeVariant(node))
|
|
9577
9990
|
return;
|
|
9578
|
-
|
|
9991
|
+
const composite = resolveCompositeProperty(node.key.name);
|
|
9992
|
+
if (!composite)
|
|
9993
|
+
return;
|
|
9994
|
+
sendReport(node.key, composite);
|
|
9579
9995
|
}
|
|
9580
9996
|
};
|
|
9581
9997
|
}
|
|
@@ -9592,28 +10008,69 @@ var rule17 = createRule({
|
|
|
9592
10008
|
description: "Encourage the use of composite properties instead of atomic properties in the codebase."
|
|
9593
10009
|
},
|
|
9594
10010
|
messages: {
|
|
9595
|
-
composite: "Use composite property of `{{atomic}}
|
|
10011
|
+
composite: "Use composite property instead of `{{atomic}}`. Prefer: `{{composite}}`."
|
|
9596
10012
|
},
|
|
9597
10013
|
type: "suggestion",
|
|
9598
10014
|
schema: []
|
|
9599
10015
|
},
|
|
9600
10016
|
defaultOptions: [],
|
|
9601
10017
|
create(context) {
|
|
9602
|
-
const
|
|
10018
|
+
const longhandCache = /* @__PURE__ */ new Map();
|
|
10019
|
+
const getLonghand = (name2) => {
|
|
10020
|
+
if (longhandCache.has(name2)) {
|
|
10021
|
+
return longhandCache.get(name2);
|
|
10022
|
+
}
|
|
9603
10023
|
const longhand = resolveLonghand(name2, context) ?? name2;
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
return Object.keys(compositeProperties).find((cpd) => compositeProperties[cpd].includes(longhand));
|
|
10024
|
+
longhandCache.set(name2, longhand);
|
|
10025
|
+
return longhand;
|
|
9607
10026
|
};
|
|
9608
|
-
const
|
|
9609
|
-
|
|
9610
|
-
if (
|
|
9611
|
-
return;
|
|
9612
|
-
|
|
10027
|
+
const compositePropertyCache = /* @__PURE__ */ new Map();
|
|
10028
|
+
const resolveCompositeProperty = (name2) => {
|
|
10029
|
+
if (compositePropertyCache.has(name2)) {
|
|
10030
|
+
return compositePropertyCache.get(name2);
|
|
10031
|
+
}
|
|
10032
|
+
const longhand = getLonghand(name2);
|
|
10033
|
+
if (!isValidProperty(longhand, context)) {
|
|
10034
|
+
compositePropertyCache.set(name2, void 0);
|
|
10035
|
+
return void 0;
|
|
10036
|
+
}
|
|
10037
|
+
const composite = Object.keys(compositeProperties).find((cpd) => compositeProperties[cpd].includes(longhand));
|
|
10038
|
+
compositePropertyCache.set(name2, composite);
|
|
10039
|
+
return composite;
|
|
10040
|
+
};
|
|
10041
|
+
const pandaPropCache = /* @__PURE__ */ new WeakMap();
|
|
10042
|
+
const isCachedPandaProp = (node) => {
|
|
10043
|
+
if (pandaPropCache.has(node)) {
|
|
10044
|
+
return pandaPropCache.get(node);
|
|
10045
|
+
}
|
|
10046
|
+
const result = isPandaProp(node, context);
|
|
10047
|
+
pandaPropCache.set(node, result);
|
|
10048
|
+
return !!result;
|
|
10049
|
+
};
|
|
10050
|
+
const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
10051
|
+
const isCachedPandaAttribute = (node) => {
|
|
10052
|
+
if (pandaAttributeCache.has(node)) {
|
|
10053
|
+
return pandaAttributeCache.get(node);
|
|
10054
|
+
}
|
|
10055
|
+
const result = isPandaAttribute(node, context);
|
|
10056
|
+
pandaAttributeCache.set(node, result);
|
|
10057
|
+
return !!result;
|
|
10058
|
+
};
|
|
10059
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
10060
|
+
const isCachedRecipeVariant = (node) => {
|
|
10061
|
+
if (recipeVariantCache.has(node)) {
|
|
10062
|
+
return recipeVariantCache.get(node);
|
|
10063
|
+
}
|
|
10064
|
+
const result = isRecipeVariant(node, context);
|
|
10065
|
+
recipeVariantCache.set(node, result);
|
|
10066
|
+
return !!result;
|
|
10067
|
+
};
|
|
10068
|
+
const sendReport = (node, composite) => {
|
|
10069
|
+
context.report({
|
|
9613
10070
|
node,
|
|
9614
10071
|
messageId: "composite",
|
|
9615
10072
|
data: {
|
|
9616
|
-
composite
|
|
10073
|
+
composite,
|
|
9617
10074
|
atomic: node.name
|
|
9618
10075
|
}
|
|
9619
10076
|
});
|
|
@@ -9622,18 +10079,24 @@ var rule17 = createRule({
|
|
|
9622
10079
|
JSXAttribute(node) {
|
|
9623
10080
|
if (!isJSXIdentifier(node.name))
|
|
9624
10081
|
return;
|
|
9625
|
-
if (!
|
|
10082
|
+
if (!isCachedPandaProp(node))
|
|
9626
10083
|
return;
|
|
9627
|
-
|
|
10084
|
+
const composite = resolveCompositeProperty(node.name.name);
|
|
10085
|
+
if (!composite)
|
|
10086
|
+
return;
|
|
10087
|
+
sendReport(node.name, composite);
|
|
9628
10088
|
},
|
|
9629
10089
|
Property(node) {
|
|
9630
10090
|
if (!isIdentifier(node.key))
|
|
9631
10091
|
return;
|
|
9632
|
-
if (!
|
|
10092
|
+
if (!isCachedPandaAttribute(node))
|
|
9633
10093
|
return;
|
|
9634
|
-
if (
|
|
10094
|
+
if (isCachedRecipeVariant(node))
|
|
9635
10095
|
return;
|
|
9636
|
-
|
|
10096
|
+
const composite = resolveCompositeProperty(node.key.name);
|
|
10097
|
+
if (!composite)
|
|
10098
|
+
return;
|
|
10099
|
+
sendReport(node.key, composite);
|
|
9637
10100
|
}
|
|
9638
10101
|
};
|
|
9639
10102
|
}
|
|
@@ -9647,35 +10110,82 @@ var rule18 = createRule({
|
|
|
9647
10110
|
name: RULE_NAME18,
|
|
9648
10111
|
meta: {
|
|
9649
10112
|
docs: {
|
|
9650
|
-
description: "Discourage
|
|
10113
|
+
description: "Discourage mixing atomic and composite forms of the same property in a style declaration. Atomic styles give more consistent results."
|
|
9651
10114
|
},
|
|
9652
10115
|
messages: {
|
|
9653
|
-
unify: "You're mixing atomic {{atomicProperties}} with composite property {{composite}}
|
|
10116
|
+
unify: "You're mixing atomic {{atomicProperties}} with composite property `{{composite}}`. Prefer atomic styling to mixing atomic and composite properties. Remove `{{composite}}` and use one or more of {{atomics}} instead."
|
|
9654
10117
|
},
|
|
9655
10118
|
type: "suggestion",
|
|
9656
10119
|
schema: []
|
|
9657
10120
|
},
|
|
9658
10121
|
defaultOptions: [],
|
|
9659
10122
|
create(context) {
|
|
9660
|
-
const
|
|
10123
|
+
const longhandCache = /* @__PURE__ */ new Map();
|
|
10124
|
+
const getLonghand = (name2) => {
|
|
10125
|
+
if (longhandCache.has(name2)) {
|
|
10126
|
+
return longhandCache.get(name2);
|
|
10127
|
+
}
|
|
10128
|
+
const longhand = resolveLonghand(name2, context) ?? name2;
|
|
10129
|
+
longhandCache.set(name2, longhand);
|
|
10130
|
+
return longhand;
|
|
10131
|
+
};
|
|
10132
|
+
const compositePropertyCache = /* @__PURE__ */ new Map();
|
|
9661
10133
|
const resolveCompositeProperty = (name2) => {
|
|
9662
|
-
if (name2
|
|
10134
|
+
if (compositePropertyCache.has(name2)) {
|
|
10135
|
+
return compositePropertyCache.get(name2);
|
|
10136
|
+
}
|
|
10137
|
+
if (name2 in compositeProperties) {
|
|
10138
|
+
compositePropertyCache.set(name2, name2);
|
|
9663
10139
|
return name2;
|
|
10140
|
+
}
|
|
9664
10141
|
const longhand = getLonghand(name2);
|
|
9665
|
-
if (isValidProperty(longhand, context) && longhand in compositeProperties)
|
|
10142
|
+
if (isValidProperty(longhand, context) && longhand in compositeProperties) {
|
|
10143
|
+
compositePropertyCache.set(name2, longhand);
|
|
9666
10144
|
return longhand;
|
|
10145
|
+
}
|
|
10146
|
+
compositePropertyCache.set(name2, void 0);
|
|
10147
|
+
return void 0;
|
|
10148
|
+
};
|
|
10149
|
+
const pandaPropCache = /* @__PURE__ */ new WeakMap();
|
|
10150
|
+
const isCachedPandaProp = (node) => {
|
|
10151
|
+
if (pandaPropCache.has(node)) {
|
|
10152
|
+
return pandaPropCache.get(node);
|
|
10153
|
+
}
|
|
10154
|
+
const result = isPandaProp(node, context);
|
|
10155
|
+
pandaPropCache.set(node, result);
|
|
10156
|
+
return !!result;
|
|
10157
|
+
};
|
|
10158
|
+
const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
10159
|
+
const isCachedPandaAttribute = (node) => {
|
|
10160
|
+
if (pandaAttributeCache.has(node)) {
|
|
10161
|
+
return pandaAttributeCache.get(node);
|
|
10162
|
+
}
|
|
10163
|
+
const result = isPandaAttribute(node, context);
|
|
10164
|
+
pandaAttributeCache.set(node, result);
|
|
10165
|
+
return !!result;
|
|
9667
10166
|
};
|
|
9668
|
-
const
|
|
9669
|
-
|
|
9670
|
-
if (
|
|
10167
|
+
const recipeVariantCache = /* @__PURE__ */ new WeakMap();
|
|
10168
|
+
const isCachedRecipeVariant = (node) => {
|
|
10169
|
+
if (recipeVariantCache.has(node)) {
|
|
10170
|
+
return recipeVariantCache.get(node);
|
|
10171
|
+
}
|
|
10172
|
+
const result = isRecipeVariant(node, context);
|
|
10173
|
+
recipeVariantCache.set(node, result);
|
|
10174
|
+
return !!result;
|
|
10175
|
+
};
|
|
10176
|
+
const sendReport = (node, composite, siblings) => {
|
|
10177
|
+
const atomicPropertiesSet = new Set(
|
|
10178
|
+
siblings.filter((prop) => compositeProperties[composite].includes(getLonghand(prop)))
|
|
10179
|
+
);
|
|
10180
|
+
if (atomicPropertiesSet.size === 0)
|
|
9671
10181
|
return;
|
|
9672
|
-
const atomicProperties =
|
|
9673
|
-
const atomics = compositeProperties[
|
|
10182
|
+
const atomicProperties = Array.from(atomicPropertiesSet).map((prop) => `\`${prop}\``).join(", ");
|
|
10183
|
+
const atomics = compositeProperties[composite].map((name2) => `\`${name2}\``).join(", ");
|
|
9674
10184
|
context.report({
|
|
9675
10185
|
node,
|
|
9676
10186
|
messageId: "unify",
|
|
9677
10187
|
data: {
|
|
9678
|
-
composite
|
|
10188
|
+
composite,
|
|
9679
10189
|
atomicProperties,
|
|
9680
10190
|
atomics
|
|
9681
10191
|
}
|
|
@@ -9685,30 +10195,30 @@ var rule18 = createRule({
|
|
|
9685
10195
|
JSXAttribute(node) {
|
|
9686
10196
|
if (!isJSXIdentifier(node.name))
|
|
9687
10197
|
return;
|
|
9688
|
-
if (!
|
|
10198
|
+
if (!isCachedPandaProp(node))
|
|
9689
10199
|
return;
|
|
9690
|
-
const
|
|
9691
|
-
if (!
|
|
10200
|
+
const composite = resolveCompositeProperty(node.name.name);
|
|
10201
|
+
if (!composite)
|
|
9692
10202
|
return;
|
|
9693
10203
|
if (!isJSXOpeningElement(node.parent))
|
|
9694
10204
|
return;
|
|
9695
10205
|
const siblings = node.parent.attributes.map((attr) => attr.name.name);
|
|
9696
|
-
sendReport(node,
|
|
10206
|
+
sendReport(node, composite, siblings);
|
|
9697
10207
|
},
|
|
9698
10208
|
Property(node) {
|
|
9699
10209
|
if (!isIdentifier(node.key))
|
|
9700
10210
|
return;
|
|
9701
|
-
if (!
|
|
10211
|
+
if (!isCachedPandaAttribute(node))
|
|
9702
10212
|
return;
|
|
9703
|
-
if (
|
|
10213
|
+
if (isCachedRecipeVariant(node))
|
|
9704
10214
|
return;
|
|
9705
|
-
const
|
|
9706
|
-
if (!
|
|
10215
|
+
const composite = resolveCompositeProperty(node.key.name);
|
|
10216
|
+
if (!composite)
|
|
9707
10217
|
return;
|
|
9708
10218
|
if (!isObjectExpression(node.parent))
|
|
9709
10219
|
return;
|
|
9710
|
-
const siblings = node.parent.properties.map((prop) => isIdentifier(prop.key)
|
|
9711
|
-
sendReport(node.key,
|
|
10220
|
+
const siblings = node.parent.properties.filter((prop) => prop.type === "Property").map((prop) => isIdentifier(prop.key) ? prop.key.name : "");
|
|
10221
|
+
sendReport(node.key, composite, siblings);
|
|
9712
10222
|
}
|
|
9713
10223
|
};
|
|
9714
10224
|
}
|