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