@pandacss/eslint-plugin 0.3.2 → 2.0.0-beta.10

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.mjs DELETED
@@ -1,2834 +0,0 @@
1
- import {
2
- __commonJS,
3
- __esm,
4
- init_esm_shims
5
- } from "./chunk-KBOB3H6E.mjs";
6
-
7
- // package.json
8
- var name, version;
9
- var init_package = __esm({
10
- "package.json"() {
11
- name = "@pandacss/eslint-plugin";
12
- version = "0.3.2";
13
- }
14
- });
15
-
16
- // src/utils/cache.ts
17
- import "@typescript-eslint/scope-manager";
18
- function ruleStarted() {
19
- numRulesRunning++;
20
- if (!resetMicrotaskScheduled) {
21
- queueMicrotask(resetCacheMicrotask);
22
- resetMicrotaskScheduled = true;
23
- }
24
- }
25
- function ruleFinished() {
26
- numRulesRunning--;
27
- if (numRulesRunning === 0) {
28
- resetCache();
29
- }
30
- }
31
- function resetCache() {
32
- cache.imports = null;
33
- cache.scopeAnalysis = null;
34
- }
35
- function resetCacheMicrotask() {
36
- resetCache();
37
- numRulesRunning = 0;
38
- resetMicrotaskScheduled = false;
39
- }
40
- var cache, numRulesRunning, resetMicrotaskScheduled;
41
- var init_cache = __esm({
42
- "src/utils/cache.ts"() {
43
- "use strict";
44
- init_esm_shims();
45
- cache = {
46
- imports: null,
47
- scopeAnalysis: null
48
- };
49
- numRulesRunning = 0;
50
- resetMicrotaskScheduled = false;
51
- }
52
- });
53
-
54
- // src/utils/index.ts
55
- import { ESLintUtils } from "@typescript-eslint/utils";
56
- import { createSyncFn } from "synckit";
57
- import { join } from "node:path";
58
- import { fileURLToPath } from "node:url";
59
- var _createRule, createRule, isBase, distDir, _syncAction, syncAction;
60
- var init_utils = __esm({
61
- "src/utils/index.ts"() {
62
- "use strict";
63
- init_esm_shims();
64
- init_cache();
65
- _createRule = ESLintUtils.RuleCreator(
66
- (name2) => `https://github.com/chakra-ui/eslint-plugin-panda/blob/main/docs/rules/${name2}.md`
67
- );
68
- createRule = (...args) => {
69
- const rule20 = _createRule(...args);
70
- const originalCreate = rule20.create;
71
- rule20.create = (context) => {
72
- ruleStarted();
73
- const visitor = originalCreate(context);
74
- const existingExit = visitor["Program:exit"];
75
- if (existingExit) {
76
- visitor["Program:exit"] = (node) => {
77
- existingExit(node);
78
- ruleFinished();
79
- };
80
- } else {
81
- visitor["Program:exit"] = (_node) => ruleFinished();
82
- }
83
- return visitor;
84
- };
85
- return rule20;
86
- };
87
- isBase = process.env.NODE_ENV !== "test" || import.meta.url.includes("/dist/index");
88
- distDir = fileURLToPath(new URL(isBase ? "./" : "../../dist", import.meta.url));
89
- _syncAction = createSyncFn(join(distDir, "utils/worker.mjs"));
90
- syncAction = (...args) => {
91
- try {
92
- return _syncAction(...args);
93
- } catch (error) {
94
- console.error("syncAction error:", error);
95
- return void 0;
96
- }
97
- };
98
- }
99
- });
100
-
101
- // src/utils/nodes.ts
102
- import { isNodeOfType } from "@typescript-eslint/utils/ast-utils";
103
- import { AST_NODE_TYPES } from "@typescript-eslint/utils";
104
- var isIdentifier, isLiteral, isTemplateLiteral, isArrayExpression, isObjectExpression, isMemberExpression, isVariableDeclarator, isVariableDeclaration, isJSXMemberExpression, isJSXOpeningElement, isJSXExpressionContainer, isJSXAttribute, isJSXIdentifier, isCallExpression, isImportDeclaration, isImportSpecifier, isProperty;
105
- var init_nodes = __esm({
106
- "src/utils/nodes.ts"() {
107
- "use strict";
108
- init_esm_shims();
109
- isIdentifier = isNodeOfType(AST_NODE_TYPES.Identifier);
110
- isLiteral = isNodeOfType(AST_NODE_TYPES.Literal);
111
- isTemplateLiteral = isNodeOfType(AST_NODE_TYPES.TemplateLiteral);
112
- isArrayExpression = isNodeOfType(AST_NODE_TYPES.ArrayExpression);
113
- isObjectExpression = isNodeOfType(AST_NODE_TYPES.ObjectExpression);
114
- isMemberExpression = isNodeOfType(AST_NODE_TYPES.MemberExpression);
115
- isVariableDeclarator = isNodeOfType(AST_NODE_TYPES.VariableDeclarator);
116
- isVariableDeclaration = isNodeOfType(AST_NODE_TYPES.VariableDeclaration);
117
- isJSXMemberExpression = isNodeOfType(AST_NODE_TYPES.JSXMemberExpression);
118
- isJSXOpeningElement = isNodeOfType(AST_NODE_TYPES.JSXOpeningElement);
119
- isJSXExpressionContainer = isNodeOfType(AST_NODE_TYPES.JSXExpressionContainer);
120
- isJSXAttribute = isNodeOfType(AST_NODE_TYPES.JSXAttribute);
121
- isJSXIdentifier = isNodeOfType(AST_NODE_TYPES.JSXIdentifier);
122
- isCallExpression = isNodeOfType(AST_NODE_TYPES.CallExpression);
123
- isImportDeclaration = isNodeOfType(AST_NODE_TYPES.ImportDeclaration);
124
- isImportSpecifier = isNodeOfType(AST_NODE_TYPES.ImportSpecifier);
125
- isProperty = isNodeOfType(AST_NODE_TYPES.Property);
126
- }
127
- });
128
-
129
- // src/utils/helpers.ts
130
- import { analyze } from "@typescript-eslint/scope-manager";
131
- function isRecipeVariant(node, context) {
132
- const caller = isInPandaFunction(node, context);
133
- if (!caller) return;
134
- const recipe = getImports(context).find((imp) => ["cva", "sva"].includes(imp.name) && imp.alias === caller);
135
- if (!recipe) return;
136
- let currentNode = node;
137
- let length = 0;
138
- let styleObjectParent = null;
139
- while (currentNode) {
140
- const keyName = currentNode?.key?.name;
141
- if (keyName && ["base", "variants"].includes(keyName)) {
142
- styleObjectParent = keyName;
143
- }
144
- currentNode = currentNode.parent;
145
- if (!styleObjectParent) length++;
146
- }
147
- const isCvaCaller = caller === "cva";
148
- const requiredLength = isCvaCaller ? 2 : 4;
149
- const extraLength = styleObjectParent === "base" ? 0 : 4;
150
- if (length < requiredLength + extraLength) return true;
151
- }
152
- var getAncestor, getSyncOpts, getImportSpecifiers, hasPkgImport, isPandaConfigFunction, _getImports, getImports, isValidStyledProp, isPandaIsh, findDeclaration, isLocalStyledFactory, isValidFile, isValidProperty, isPandaImport, isPandaProp, isStyledProperty, isInPandaFunction, isInJSXProp, isPandaAttribute, resolveLonghand, resolveShorthands, isColorAttribute, isColorToken, extractTokens, invalidTokensCache, getInvalidTokens, deprecatedTokensCache, getDeprecatedTokens, getTokenImport, getTaggedTemplateCaller;
153
- var init_helpers = __esm({
154
- "src/utils/helpers.ts"() {
155
- "use strict";
156
- init_esm_shims();
157
- init_utils();
158
- init_cache();
159
- init_nodes();
160
- getAncestor = (ofType, for_) => {
161
- let current = for_.parent;
162
- while (current) {
163
- if (ofType(current)) return current;
164
- current = current.parent;
165
- }
166
- return;
167
- };
168
- getSyncOpts = (context) => {
169
- return {
170
- currentFile: context.filename,
171
- configPath: context.settings["@pandacss/configPath"]
172
- };
173
- };
174
- getImportSpecifiers = (context) => {
175
- const specifiers = [];
176
- context.sourceCode?.ast.body.forEach((node) => {
177
- if (!isImportDeclaration(node)) return;
178
- const mod = node.source.value;
179
- if (!mod) return;
180
- node.specifiers.forEach((specifier) => {
181
- if (!isImportSpecifier(specifier)) return;
182
- specifiers.push({ specifier, mod });
183
- });
184
- });
185
- return specifiers;
186
- };
187
- hasPkgImport = (context) => {
188
- const imports = _getImports(context);
189
- return imports.some(({ mod }) => mod === "@pandacss/dev");
190
- };
191
- isPandaConfigFunction = (context, name2) => {
192
- const imports = _getImports(context);
193
- return imports.some(({ alias, mod }) => alias === name2 && mod === "@pandacss/dev");
194
- };
195
- _getImports = (context) => {
196
- const specifiers = getImportSpecifiers(context);
197
- const imports = specifiers.map(({ specifier, mod }) => ({
198
- name: specifier.imported.name,
199
- alias: specifier.local.name,
200
- mod
201
- }));
202
- return imports;
203
- };
204
- getImports = (context) => {
205
- if (cache.imports) {
206
- return cache.imports;
207
- }
208
- const imports = _getImports(context);
209
- const filteredImports = imports.filter((imp) => syncAction("matchImports", getSyncOpts(context), imp));
210
- cache.imports = filteredImports;
211
- return filteredImports;
212
- };
213
- isValidStyledProp = (node, context) => {
214
- return isJSXIdentifier(node) && isValidProperty(node.name, context);
215
- };
216
- isPandaIsh = (name2, context) => {
217
- const imports = getImports(context);
218
- if (imports.length === 0) return false;
219
- const jsxFactory = syncAction("getJsxFactory", getSyncOpts(context));
220
- if (jsxFactory && name2 === jsxFactory) {
221
- return imports.some((imp) => imp.name === name2 || imp.alias === name2);
222
- }
223
- return syncAction("matchFile", getSyncOpts(context), name2, imports);
224
- };
225
- findDeclaration = (name2, context) => {
226
- try {
227
- const src = context.sourceCode;
228
- if (!src) {
229
- console.warn("\u26A0\uFE0F ESLint's sourceCode is not available. Ensure that the rule is invoked with valid code.");
230
- return void 0;
231
- }
232
- let scope;
233
- if (cache.scopeAnalysis) {
234
- scope = cache.scopeAnalysis;
235
- } else {
236
- scope = analyze(src.ast, {
237
- sourceType: "module"
238
- });
239
- cache.scopeAnalysis = scope;
240
- }
241
- const decl = scope.variables.find((v) => v.name === name2)?.defs.find((d) => isIdentifier(d.name) && d.name.name === name2)?.node;
242
- if (isVariableDeclarator(decl)) return decl;
243
- } catch (error) {
244
- console.error("Error in findDeclaration:", error);
245
- return void 0;
246
- }
247
- };
248
- isLocalStyledFactory = (node, context) => {
249
- if (!isJSXIdentifier(node.name)) return;
250
- const decl = findDeclaration(node.name.name, context);
251
- if (!decl) return;
252
- if (!isCallExpression(decl.init)) return;
253
- if (!isIdentifier(decl.init.callee)) return;
254
- if (!isPandaIsh(decl.init.callee.name, context)) return;
255
- return true;
256
- };
257
- isValidFile = (context) => {
258
- return syncAction("isValidFile", getSyncOpts(context));
259
- };
260
- isValidProperty = (name2, context, calleName) => {
261
- return syncAction("isValidProperty", getSyncOpts(context), name2, calleName);
262
- };
263
- isPandaImport = (node, context) => {
264
- const imports = getImports(context);
265
- return imports.some((imp) => imp.mod === node.source.value);
266
- };
267
- isPandaProp = (node, context) => {
268
- const jsxAncestor = getAncestor(isJSXOpeningElement, node);
269
- if (!jsxAncestor) return;
270
- if (!isJSXMemberExpression(jsxAncestor.name) && !isJSXIdentifier(jsxAncestor.name)) return;
271
- const name2 = isJSXMemberExpression(jsxAncestor.name) ? jsxAncestor.name.object.name : jsxAncestor.name.name;
272
- const prop = node.name.name;
273
- const isPandaComponent = isPandaIsh(name2, context) || isLocalStyledFactory(jsxAncestor, context);
274
- if (!isPandaComponent) return;
275
- const patternName = isJSXMemberExpression(jsxAncestor.name) ? void 0 : name2;
276
- if (typeof prop !== "string" || !isValidProperty(prop, context, patternName)) return;
277
- return true;
278
- };
279
- isStyledProperty = (node, context, calleeName) => {
280
- if (!isIdentifier(node.key) && !isLiteral(node.key) && !isTemplateLiteral(node.key)) return;
281
- if (isIdentifier(node.key) && !isValidProperty(node.key.name, context, calleeName)) return;
282
- if (isLiteral(node.key) && typeof node.key.value === "string" && !isValidProperty(node.key.value, context, calleeName))
283
- return;
284
- if (isTemplateLiteral(node.key) && !isValidProperty(node.key.quasis[0].value.raw, context, calleeName)) return;
285
- return true;
286
- };
287
- isInPandaFunction = (node, context) => {
288
- const callAncestor = getAncestor(isCallExpression, node);
289
- if (!callAncestor) return;
290
- let calleeName;
291
- if (isIdentifier(callAncestor.callee)) {
292
- calleeName = callAncestor.callee.name;
293
- }
294
- if (isMemberExpression(callAncestor.callee) && isIdentifier(callAncestor.callee.object)) {
295
- calleeName = callAncestor.callee.object.name;
296
- }
297
- if (!calleeName) return;
298
- if (!isPandaIsh(calleeName, context)) return;
299
- return calleeName;
300
- };
301
- isInJSXProp = (node, context) => {
302
- const jsxExprAncestor = getAncestor(isJSXExpressionContainer, node);
303
- const jsxAttrAncestor = getAncestor(isJSXAttribute, node);
304
- if (!jsxExprAncestor || !jsxAttrAncestor) return;
305
- if (!isPandaProp(jsxAttrAncestor, context)) return;
306
- if (typeof jsxAttrAncestor.name === "string") return;
307
- if (!isValidStyledProp(jsxAttrAncestor.name, context)) return;
308
- return true;
309
- };
310
- isPandaAttribute = (node, context) => {
311
- const callAncestor = getAncestor(isCallExpression, node);
312
- if (callAncestor) {
313
- const callee = isInPandaFunction(node, context);
314
- if (!callee) return;
315
- return isStyledProperty(node, context, callee);
316
- }
317
- return isInJSXProp(node, context) && isStyledProperty(node, context);
318
- };
319
- resolveLonghand = (name2, context) => {
320
- return syncAction("resolveLongHand", getSyncOpts(context), name2);
321
- };
322
- resolveShorthands = (name2, context) => {
323
- return syncAction("resolveShorthands", getSyncOpts(context), name2);
324
- };
325
- isColorAttribute = (attr, context) => {
326
- return syncAction("isColorAttribute", getSyncOpts(context), attr);
327
- };
328
- isColorToken = (value, context) => {
329
- if (!value) return;
330
- return syncAction("isColorToken", getSyncOpts(context), value);
331
- };
332
- extractTokens = (value) => {
333
- const regex = /token\(([^"'(),]+)(?:,\s*([^"'(),]+))?\)|\{([^{\r\n}]+)\}/g;
334
- const matches = [];
335
- let match;
336
- while ((match = regex.exec(value)) !== null) {
337
- const tokenFromFirstSyntax = match[1] || match[2] || match[3];
338
- const tokensFromSecondSyntax = match[4] && match[4].match(/(\w+\.\w+(\.\w+)?)/g);
339
- if (tokenFromFirstSyntax) {
340
- matches.push(tokenFromFirstSyntax);
341
- }
342
- if (tokensFromSecondSyntax) {
343
- matches.push(...tokensFromSecondSyntax);
344
- }
345
- }
346
- return matches.filter(Boolean);
347
- };
348
- invalidTokensCache = /* @__PURE__ */ new Map();
349
- getInvalidTokens = (value, context) => {
350
- if (invalidTokensCache.has(value)) {
351
- return invalidTokensCache.get(value);
352
- }
353
- const tokens = extractTokens(value);
354
- if (!tokens.length) return [];
355
- const invalidTokens = syncAction("filterInvalidTokens", getSyncOpts(context), tokens);
356
- invalidTokensCache.set(value, invalidTokens);
357
- return invalidTokens;
358
- };
359
- deprecatedTokensCache = /* @__PURE__ */ new Map();
360
- getDeprecatedTokens = (prop, value, context) => {
361
- if (deprecatedTokensCache.has(value)) {
362
- return deprecatedTokensCache.get(value);
363
- }
364
- const propCategory = syncAction("getPropCategory", getSyncOpts(context), prop);
365
- const tokens = extractTokens(value);
366
- if (!propCategory && !tokens.length) return [];
367
- const values = tokens.length ? tokens : [{ category: propCategory, value: value.split("/")[0] }];
368
- const deprecatedTokens = syncAction("filterDeprecatedTokens", getSyncOpts(context), values);
369
- deprecatedTokensCache.set(value, deprecatedTokens);
370
- return deprecatedTokens;
371
- };
372
- getTokenImport = (context) => {
373
- const imports = _getImports(context);
374
- return imports.find((imp) => imp.name === "token");
375
- };
376
- getTaggedTemplateCaller = (node) => {
377
- if (isIdentifier(node.tag)) {
378
- return node.tag.name;
379
- }
380
- if (isMemberExpression(node.tag)) {
381
- if (!isIdentifier(node.tag.object)) return;
382
- return node.tag.object.name;
383
- }
384
- if (isCallExpression(node.tag)) {
385
- if (!isIdentifier(node.tag.callee)) return;
386
- return node.tag.callee.name;
387
- }
388
- };
389
- }
390
- });
391
-
392
- // src/rules/file-not-included.ts
393
- import "@typescript-eslint/utils";
394
- var RULE_NAME, rule, file_not_included_default;
395
- var init_file_not_included = __esm({
396
- "src/rules/file-not-included.ts"() {
397
- "use strict";
398
- init_esm_shims();
399
- init_utils();
400
- init_helpers();
401
- RULE_NAME = "file-not-included";
402
- rule = createRule({
403
- name: RULE_NAME,
404
- meta: {
405
- docs: {
406
- description: "Disallow the use of Panda CSS in files that are not included in the specified Panda CSS `include` config."
407
- },
408
- messages: {
409
- include: "The use of Panda CSS is not allowed in this file. Please ensure the file is included in the Panda CSS `include` configuration."
410
- },
411
- type: "problem",
412
- schema: []
413
- },
414
- defaultOptions: [],
415
- create(context) {
416
- const isFileIncluded = isValidFile(context);
417
- if (isFileIncluded) {
418
- return {};
419
- }
420
- let hasReported = false;
421
- return {
422
- ImportDeclaration(node) {
423
- if (hasReported) return;
424
- if (!isPandaImport(node, context)) return;
425
- context.report({
426
- node,
427
- messageId: "include"
428
- });
429
- hasReported = true;
430
- }
431
- };
432
- }
433
- });
434
- file_not_included_default = rule;
435
- }
436
- });
437
-
438
- // src/rules/no-config-function-in-source.ts
439
- import "@typescript-eslint/utils";
440
- var RULE_NAME2, CONFIG_FUNCTIONS, rule2, no_config_function_in_source_default;
441
- var init_no_config_function_in_source = __esm({
442
- "src/rules/no-config-function-in-source.ts"() {
443
- "use strict";
444
- init_esm_shims();
445
- init_nodes();
446
- init_utils();
447
- init_helpers();
448
- RULE_NAME2 = "no-config-function-in-source";
449
- CONFIG_FUNCTIONS = /* @__PURE__ */ new Set([
450
- "defineConfig",
451
- "defineRecipe",
452
- "defineSlotRecipe",
453
- "defineParts",
454
- "definePattern",
455
- "definePreset",
456
- "defineKeyframes",
457
- "defineGlobalStyles",
458
- "defineUtility",
459
- "defineTextStyles",
460
- "defineLayerStyles",
461
- "defineStyles",
462
- "defineTokens",
463
- "defineSemanticTokens"
464
- ]);
465
- rule2 = createRule({
466
- name: RULE_NAME2,
467
- meta: {
468
- docs: {
469
- description: "Prohibit the use of config functions outside the Panda config file."
470
- },
471
- messages: {
472
- configFunction: "Unnecessary `{{name}}` call. Config functions should only be used in the Panda config file.",
473
- delete: "Delete `{{name}}` call."
474
- },
475
- type: "problem",
476
- hasSuggestions: true,
477
- schema: []
478
- },
479
- defaultOptions: [],
480
- create(context) {
481
- if (!hasPkgImport(context)) {
482
- return {};
483
- }
484
- const isPandaFile = isValidFile(context);
485
- if (!isPandaFile) {
486
- return {};
487
- }
488
- return {
489
- CallExpression(node) {
490
- if (!isIdentifier(node.callee)) return;
491
- const functionName = node.callee.name;
492
- if (!CONFIG_FUNCTIONS.has(functionName)) return;
493
- if (!isPandaConfigFunction(context, functionName)) return;
494
- context.report({
495
- node,
496
- messageId: "configFunction",
497
- data: {
498
- name: functionName
499
- },
500
- suggest: [
501
- {
502
- messageId: "delete",
503
- data: {
504
- name: functionName
505
- },
506
- fix(fixer) {
507
- const declaration = getAncestor(isVariableDeclaration, node);
508
- const importSpecifiers = getImportSpecifiers(context);
509
- const importSpec = importSpecifiers.find((s) => s.specifier.local.name === functionName);
510
- const fixes = [];
511
- if (declaration) {
512
- fixes.push(fixer.remove(declaration));
513
- } else {
514
- fixes.push(fixer.remove(node));
515
- }
516
- if (importSpec?.specifier) {
517
- fixes.push(fixer.remove(importSpec.specifier));
518
- }
519
- return fixes;
520
- }
521
- }
522
- ]
523
- });
524
- }
525
- };
526
- }
527
- });
528
- no_config_function_in_source_default = rule2;
529
- }
530
- });
531
-
532
- // src/rules/no-debug.ts
533
- import "@typescript-eslint/utils";
534
- var RULE_NAME3, rule3, no_debug_default;
535
- var init_no_debug = __esm({
536
- "src/rules/no-debug.ts"() {
537
- "use strict";
538
- init_esm_shims();
539
- init_utils();
540
- init_helpers();
541
- RULE_NAME3 = "no-debug";
542
- rule3 = createRule({
543
- name: RULE_NAME3,
544
- meta: {
545
- docs: {
546
- description: "Disallow the inclusion of the debug attribute when shipping code to the production environment."
547
- },
548
- messages: {
549
- debug: "Unnecessary debug utility.",
550
- prop: "Remove the debug prop.",
551
- property: "Remove the debug property."
552
- },
553
- type: "problem",
554
- hasSuggestions: true,
555
- schema: []
556
- },
557
- defaultOptions: [],
558
- create(context) {
559
- return {
560
- 'JSXAttribute[name.name="debug"]'(node) {
561
- if (!isPandaProp(node, context)) return;
562
- context.report({
563
- node,
564
- messageId: "debug",
565
- suggest: [
566
- {
567
- messageId: "prop",
568
- fix: (fixer) => fixer.remove(node)
569
- }
570
- ]
571
- });
572
- },
573
- 'Property[key.name="debug"]'(node) {
574
- if (!isPandaAttribute(node, context)) return;
575
- if (isRecipeVariant(node, context)) return;
576
- context.report({
577
- node: node.key,
578
- messageId: "debug",
579
- suggest: [
580
- {
581
- messageId: "property",
582
- fix: (fixer) => fixer.removeRange([node.range[0], node.range[1] + 1])
583
- }
584
- ]
585
- });
586
- }
587
- };
588
- }
589
- });
590
- no_debug_default = rule3;
591
- }
592
- });
593
-
594
- // src/rules/no-deprecated-tokens.ts
595
- import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
596
- import { isNodeOfTypes } from "@typescript-eslint/utils/ast-utils";
597
- var RULE_NAME4, rule4, no_deprecated_tokens_default;
598
- var init_no_deprecated_tokens = __esm({
599
- "src/rules/no-deprecated-tokens.ts"() {
600
- "use strict";
601
- init_esm_shims();
602
- init_helpers();
603
- init_utils();
604
- init_nodes();
605
- RULE_NAME4 = "no-deprecated-tokens";
606
- rule4 = createRule({
607
- name: RULE_NAME4,
608
- meta: {
609
- docs: {
610
- description: "Disallow the use of deprecated tokens within token function syntax."
611
- },
612
- messages: {
613
- noDeprecatedTokenPaths: "`{{token}}` is a deprecated token.",
614
- noDeprecatedTokens: "`{{token}}` is a deprecated {{category}} token."
615
- },
616
- type: "problem",
617
- schema: []
618
- },
619
- defaultOptions: [],
620
- create(context) {
621
- const deprecatedTokensCache2 = /* @__PURE__ */ new Map();
622
- const sendReport = (prop, node, value) => {
623
- if (!value) return;
624
- let tokens = deprecatedTokensCache2.get(value);
625
- if (!tokens) {
626
- tokens = getDeprecatedTokens(prop, value, context);
627
- deprecatedTokensCache2.set(value, tokens);
628
- }
629
- if (tokens.length === 0) return;
630
- tokens.forEach((token) => {
631
- context.report({
632
- node,
633
- messageId: typeof token === "string" ? "noDeprecatedTokenPaths" : "noDeprecatedTokens",
634
- data: {
635
- token: typeof token === "string" ? token : token.value,
636
- category: typeof token === "string" ? void 0 : token.category
637
- }
638
- });
639
- });
640
- };
641
- const handleLiteralOrTemplate = (prop, node) => {
642
- if (!node) return;
643
- if (isLiteral(node)) {
644
- const value = node.value?.toString();
645
- sendReport(prop, node, value);
646
- } else if (isTemplateLiteral(node) && node.expressions.length === 0) {
647
- const value = node.quasis[0].value.raw;
648
- sendReport(prop, node.quasis[0], value);
649
- }
650
- };
651
- return {
652
- JSXAttribute(node) {
653
- if (!node.value || !isPandaProp(node, context)) return;
654
- const prop = node.name.name;
655
- if (isLiteral(node.value)) {
656
- handleLiteralOrTemplate(prop, node.value);
657
- } else if (isJSXExpressionContainer(node.value)) {
658
- handleLiteralOrTemplate(prop, node.value.expression);
659
- }
660
- },
661
- Property(node) {
662
- if (!isIdentifier(node.key) || !isNodeOfTypes([AST_NODE_TYPES2.Literal, AST_NODE_TYPES2.TemplateLiteral])(node.value) || !isPandaAttribute(node, context) || isRecipeVariant(node, context)) {
663
- return;
664
- }
665
- const prop = node.key.name;
666
- handleLiteralOrTemplate(prop, node.value);
667
- },
668
- TaggedTemplateExpression(node) {
669
- const caller = getTaggedTemplateCaller(node);
670
- if (!caller || !isPandaIsh(caller, context)) return;
671
- const quasis = node.quasi.quasis;
672
- quasis.forEach((quasi) => {
673
- const styles = quasi.value.raw;
674
- if (!styles) return;
675
- let tokens = deprecatedTokensCache2.get(styles);
676
- if (!tokens) {
677
- tokens = getDeprecatedTokens("", styles, context);
678
- deprecatedTokensCache2.set(styles, tokens);
679
- }
680
- if (tokens.length === 0) return;
681
- tokens.forEach((token) => {
682
- const tokenValue = typeof token === "string" ? token : token.value;
683
- let index = styles.indexOf(tokenValue);
684
- while (index !== -1) {
685
- const start = quasi.range[0] + index + 1;
686
- const end = start + tokenValue.length;
687
- context.report({
688
- loc: {
689
- start: context.sourceCode.getLocFromIndex(start),
690
- end: context.sourceCode.getLocFromIndex(end)
691
- },
692
- messageId: typeof token === "string" ? "noDeprecatedTokenPaths" : "noDeprecatedTokens",
693
- data: {
694
- token: tokenValue,
695
- category: typeof token === "string" ? void 0 : token.category
696
- }
697
- });
698
- index = styles.indexOf(tokenValue, index + tokenValue.length);
699
- }
700
- });
701
- });
702
- }
703
- };
704
- }
705
- });
706
- no_deprecated_tokens_default = rule4;
707
- }
708
- });
709
-
710
- // src/rules/no-dynamic-styling.ts
711
- import "@typescript-eslint/utils";
712
- var RULE_NAME5, rule5, no_dynamic_styling_default;
713
- var init_no_dynamic_styling = __esm({
714
- "src/rules/no-dynamic-styling.ts"() {
715
- "use strict";
716
- init_esm_shims();
717
- init_utils();
718
- init_helpers();
719
- init_nodes();
720
- RULE_NAME5 = "no-dynamic-styling";
721
- rule5 = createRule({
722
- name: RULE_NAME5,
723
- meta: {
724
- docs: {
725
- description: "Ensure users don't use dynamic styling. Prefer static styles, leverage CSS variables, or recipes for known dynamic styles."
726
- },
727
- messages: {
728
- dynamic: "Remove dynamic value. Prefer static styles.",
729
- dynamicProperty: "Remove dynamic property. Prefer static style property.",
730
- dynamicRecipeVariant: "Remove dynamic variant. Prefer static variant definition."
731
- },
732
- type: "problem",
733
- schema: []
734
- },
735
- defaultOptions: [],
736
- create(context) {
737
- function isStaticValue(node) {
738
- if (!node) return false;
739
- if (isLiteral(node)) return true;
740
- if (isTemplateLiteral(node) && node.expressions.length === 0) return true;
741
- if (isObjectExpression(node)) return true;
742
- return false;
743
- }
744
- function checkArrayElements(array) {
745
- array.elements.forEach((element) => {
746
- if (!element) return;
747
- if (isStaticValue(element)) return;
748
- context.report({
749
- node: element,
750
- messageId: "dynamic"
751
- });
752
- });
753
- }
754
- return {
755
- // JSX Attributes
756
- JSXAttribute(node) {
757
- if (!node.value) return;
758
- if (isLiteral(node.value)) return;
759
- if (!isPandaProp(node, context)) return;
760
- if (isJSXExpressionContainer(node.value)) {
761
- const expr = node.value.expression;
762
- if (isStaticValue(expr)) return;
763
- if (isArrayExpression(expr)) {
764
- checkArrayElements(expr);
765
- return;
766
- }
767
- }
768
- context.report({
769
- node: node.value,
770
- messageId: "dynamic"
771
- });
772
- },
773
- // Dynamic properties with computed keys
774
- "Property[computed=true]": (node) => {
775
- if (!isInPandaFunction(node, context)) return;
776
- context.report({
777
- node: node.key,
778
- messageId: isRecipeVariant(node, context) ? "dynamicRecipeVariant" : "dynamicProperty"
779
- });
780
- },
781
- // Object Properties
782
- Property(node) {
783
- if (!isIdentifier(node.key)) return;
784
- if (!isPandaAttribute(node, context)) return;
785
- if (isRecipeVariant(node, context)) return;
786
- if (isStaticValue(node.value)) return;
787
- if (isArrayExpression(node.value)) {
788
- checkArrayElements(node.value);
789
- return;
790
- }
791
- context.report({
792
- node: node.value,
793
- messageId: "dynamic"
794
- });
795
- }
796
- };
797
- }
798
- });
799
- no_dynamic_styling_default = rule5;
800
- }
801
- });
802
-
803
- // src/rules/no-escape-hatch.ts
804
- import { getArbitraryValue } from "@pandacss/shared";
805
- import "@typescript-eslint/utils";
806
- var RULE_NAME6, rule6, no_escape_hatch_default;
807
- var init_no_escape_hatch = __esm({
808
- "src/rules/no-escape-hatch.ts"() {
809
- "use strict";
810
- init_esm_shims();
811
- init_helpers();
812
- init_utils();
813
- init_nodes();
814
- RULE_NAME6 = "no-escape-hatch";
815
- rule6 = createRule({
816
- name: RULE_NAME6,
817
- meta: {
818
- docs: {
819
- description: "Prohibit the use of escape hatch syntax in the code."
820
- },
821
- messages: {
822
- escapeHatch: "Avoid using the escape hatch [value] for undefined tokens. Define a corresponding token in your design system for better consistency and maintainability.",
823
- remove: "Remove the square brackets (`[]`)."
824
- },
825
- type: "problem",
826
- hasSuggestions: true,
827
- schema: []
828
- },
829
- defaultOptions: [],
830
- create(context) {
831
- const removeBrackets = (range) => {
832
- const [start, end] = range;
833
- return [start + 1, end - 1];
834
- };
835
- const hasEscapeHatch = (value) => {
836
- if (!value) return false;
837
- if (!value.includes("[")) return false;
838
- return getArbitraryValue(value) !== value.trim();
839
- };
840
- const handleNodeValue = (node, value) => {
841
- if (!hasEscapeHatch(value)) return;
842
- context.report({
843
- node,
844
- messageId: "escapeHatch",
845
- suggest: [
846
- {
847
- messageId: "remove",
848
- fix: (fixer) => {
849
- return fixer.replaceTextRange(removeBrackets(node.range), getArbitraryValue(value));
850
- }
851
- }
852
- ]
853
- });
854
- };
855
- return {
856
- JSXAttribute(node) {
857
- if (!node.value) return;
858
- if (!isPandaProp(node, context)) return;
859
- const { value } = node;
860
- if (isLiteral(value)) {
861
- const val = value.value?.toString() ?? "";
862
- handleNodeValue(value, val);
863
- } else if (isJSXExpressionContainer(value)) {
864
- const expr = value.expression;
865
- if (isLiteral(expr)) {
866
- const val = expr.value?.toString() ?? "";
867
- handleNodeValue(expr, val);
868
- } else if (isTemplateLiteral(expr) && expr.expressions.length === 0) {
869
- const val = expr.quasis[0].value.raw;
870
- handleNodeValue(expr.quasis[0], val);
871
- }
872
- }
873
- },
874
- Property(node) {
875
- if (!isIdentifier(node.key)) return;
876
- if (!isPandaAttribute(node, context)) return;
877
- if (isRecipeVariant(node, context)) return;
878
- const value = node.value;
879
- if (isLiteral(value)) {
880
- const val = value.value?.toString() ?? "";
881
- handleNodeValue(value, val);
882
- } else if (isTemplateLiteral(value) && value.expressions.length === 0) {
883
- const val = value.quasis[0].value.raw;
884
- handleNodeValue(value.quasis[0], val);
885
- }
886
- }
887
- };
888
- }
889
- });
890
- no_escape_hatch_default = rule6;
891
- }
892
- });
893
-
894
- // src/rules/no-hardcoded-color.ts
895
- import "@typescript-eslint/utils";
896
- var RULE_NAME7, rule7, no_hardcoded_color_default;
897
- var init_no_hardcoded_color = __esm({
898
- "src/rules/no-hardcoded-color.ts"() {
899
- "use strict";
900
- init_esm_shims();
901
- init_helpers();
902
- init_utils();
903
- init_nodes();
904
- RULE_NAME7 = "no-hardcoded-color";
905
- rule7 = createRule({
906
- name: RULE_NAME7,
907
- meta: {
908
- docs: {
909
- description: "Enforce the exclusive use of design tokens as values for colors within the codebase."
910
- },
911
- messages: {
912
- invalidColor: "`{{color}}` is not a valid color token."
913
- },
914
- type: "problem",
915
- schema: [
916
- {
917
- type: "object",
918
- properties: {
919
- noOpacity: {
920
- type: "boolean"
921
- },
922
- whitelist: {
923
- type: "array",
924
- items: {
925
- type: "string",
926
- minLength: 0
927
- },
928
- uniqueItems: true
929
- }
930
- },
931
- additionalProperties: false
932
- }
933
- ]
934
- },
935
- defaultOptions: [
936
- {
937
- noOpacity: false,
938
- whitelist: []
939
- }
940
- ],
941
- create(context) {
942
- const noOpacity = context.options[0]?.noOpacity;
943
- const whitelist = context.options[0]?.whitelist ?? [];
944
- const colorTokenCache = new Map(whitelist?.map((item) => [item, true]));
945
- const colorAttributeCache = /* @__PURE__ */ new Map();
946
- const isColorToken2 = (token) => {
947
- if (colorTokenCache.has(token)) {
948
- return colorTokenCache.get(token);
949
- }
950
- const result = isColorToken(token, context);
951
- colorTokenCache.set(token, result);
952
- return !!result;
953
- };
954
- const isColorAttribute2 = (attribute) => {
955
- if (colorAttributeCache.has(attribute)) {
956
- return colorAttributeCache.get(attribute);
957
- }
958
- const result = isColorAttribute(attribute, context);
959
- colorAttributeCache.set(attribute, result);
960
- return result;
961
- };
962
- const isTokenFunctionUsed = (value) => {
963
- if (!value) return false;
964
- const tokens = extractTokens(value);
965
- return tokens.length > 0;
966
- };
967
- const isCssVariable = (value) => {
968
- if (!value) return false;
969
- return value.trim().startsWith("var(");
970
- };
971
- const isValidColorToken = (value) => {
972
- if (!value) return false;
973
- const [colorToken, opacity] = value.split("/");
974
- const hasOpacity = opacity !== void 0 && opacity.length > 0;
975
- const isValidToken = isColorToken2(colorToken);
976
- return noOpacity ? isValidToken && !hasOpacity : isValidToken;
977
- };
978
- const reportInvalidColor = (node, color) => {
979
- context.report({
980
- node,
981
- messageId: "invalidColor",
982
- data: {
983
- color
984
- }
985
- });
986
- };
987
- const checkColorValue = (node, value, attributeName) => {
988
- if (!isColorAttribute2(attributeName)) return;
989
- if (isTokenFunctionUsed(value)) return;
990
- if (isCssVariable(value)) return;
991
- if (isValidColorToken(value)) return;
992
- reportInvalidColor(node, value);
993
- };
994
- return {
995
- JSXAttribute(node) {
996
- if (!isJSXIdentifier(node.name)) return;
997
- if (!isPandaProp(node, context) || !node.value) return;
998
- const attributeName = node.name.name;
999
- const valueNode = node.value;
1000
- if (isLiteral(valueNode)) {
1001
- const value = valueNode.value?.toString() || "";
1002
- checkColorValue(valueNode, value, attributeName);
1003
- } else if (isJSXExpressionContainer(valueNode)) {
1004
- const expression = valueNode.expression;
1005
- if (isLiteral(expression)) {
1006
- const value = expression.value?.toString() || "";
1007
- checkColorValue(expression, value, attributeName);
1008
- } else if (isTemplateLiteral(expression) && expression.expressions.length === 0) {
1009
- const value = expression.quasis[0].value.raw;
1010
- checkColorValue(expression.quasis[0], value, attributeName);
1011
- }
1012
- }
1013
- },
1014
- Property(node) {
1015
- if (!isIdentifier(node.key)) return;
1016
- if (!isPandaAttribute(node, context)) return;
1017
- if (isRecipeVariant(node, context)) return;
1018
- const attributeName = node.key.name;
1019
- const valueNode = node.value;
1020
- if (isLiteral(valueNode)) {
1021
- const value = valueNode.value?.toString() || "";
1022
- checkColorValue(valueNode, value, attributeName);
1023
- } else if (isTemplateLiteral(valueNode) && valueNode.expressions.length === 0) {
1024
- const value = valueNode.quasis[0].value.raw;
1025
- checkColorValue(valueNode.quasis[0], value, attributeName);
1026
- }
1027
- }
1028
- };
1029
- }
1030
- });
1031
- no_hardcoded_color_default = rule7;
1032
- }
1033
- });
1034
-
1035
- // src/rules/no-important.ts
1036
- import { getArbitraryValue as getArbitraryValue2 } from "@pandacss/shared";
1037
- import "@typescript-eslint/utils";
1038
- var exclamationRegex, importantRegex, RULE_NAME8, rule8, no_important_default;
1039
- var init_no_important = __esm({
1040
- "src/rules/no-important.ts"() {
1041
- "use strict";
1042
- init_esm_shims();
1043
- init_helpers();
1044
- init_utils();
1045
- init_nodes();
1046
- exclamationRegex = /\s*!$/;
1047
- importantRegex = /\s*!important\s*$/;
1048
- RULE_NAME8 = "no-important";
1049
- rule8 = createRule({
1050
- name: RULE_NAME8,
1051
- meta: {
1052
- docs: {
1053
- description: "Disallow usage of !important keyword. Prioritize specificity for a maintainable and predictable styling structure."
1054
- },
1055
- messages: {
1056
- important: "Avoid using the {{keyword}} keyword. Refactor your code to prioritize specificity for predictable styling.",
1057
- remove: "Remove the `{{keyword}}` keyword."
1058
- },
1059
- type: "problem",
1060
- hasSuggestions: true,
1061
- schema: []
1062
- },
1063
- defaultOptions: [],
1064
- create(context) {
1065
- const removeQuotes = (range) => {
1066
- const [start, end] = range;
1067
- return [start + 1, end - 1];
1068
- };
1069
- const pandaPropCache = /* @__PURE__ */ new WeakMap();
1070
- const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
1071
- const recipeVariantCache = /* @__PURE__ */ new WeakMap();
1072
- const isCachedPandaProp = (node) => {
1073
- if (pandaPropCache.has(node)) {
1074
- return pandaPropCache.get(node);
1075
- }
1076
- const result = isPandaProp(node, context);
1077
- pandaPropCache.set(node, result);
1078
- return !!result;
1079
- };
1080
- const isCachedPandaAttribute = (node) => {
1081
- if (pandaAttributeCache.has(node)) {
1082
- return pandaAttributeCache.get(node);
1083
- }
1084
- const result = isPandaAttribute(node, context);
1085
- pandaAttributeCache.set(node, result);
1086
- return !!result;
1087
- };
1088
- const isCachedRecipeVariant = (node) => {
1089
- if (recipeVariantCache.has(node)) {
1090
- return recipeVariantCache.get(node);
1091
- }
1092
- const result = isRecipeVariant(node, context);
1093
- recipeVariantCache.set(node, result);
1094
- return !!result;
1095
- };
1096
- const hasImportantKeyword = (value) => {
1097
- if (!value) return false;
1098
- const arbitraryValue = getArbitraryValue2(value);
1099
- return exclamationRegex.test(arbitraryValue) || importantRegex.test(arbitraryValue);
1100
- };
1101
- const removeImportantKeyword = (input) => {
1102
- if (importantRegex.test(input)) {
1103
- return { fixed: input.replace(importantRegex, "").trimEnd(), keyword: "!important" };
1104
- } else if (exclamationRegex.test(input)) {
1105
- return { fixed: input.replace(exclamationRegex, "").trimEnd(), keyword: "!" };
1106
- } else {
1107
- return { fixed: input, keyword: null };
1108
- }
1109
- };
1110
- const handleNodeValue = (node, value) => {
1111
- if (!hasImportantKeyword(value)) return;
1112
- const { fixed, keyword } = removeImportantKeyword(value);
1113
- context.report({
1114
- node,
1115
- messageId: "important",
1116
- data: { keyword },
1117
- suggest: [
1118
- {
1119
- messageId: "remove",
1120
- data: { keyword },
1121
- fix: (fixer) => {
1122
- return fixer.replaceTextRange(removeQuotes(node.range), fixed);
1123
- }
1124
- }
1125
- ]
1126
- });
1127
- };
1128
- return {
1129
- // JSX Attributes
1130
- JSXAttribute(node) {
1131
- if (!node.value) return;
1132
- if (!isCachedPandaProp(node)) return;
1133
- const valueNode = node.value;
1134
- if (isLiteral(valueNode)) {
1135
- const val = valueNode.value?.toString() ?? "";
1136
- handleNodeValue(valueNode, val);
1137
- } else if (isJSXExpressionContainer(valueNode)) {
1138
- const expr = valueNode.expression;
1139
- if (isLiteral(expr)) {
1140
- const val = expr.value?.toString() ?? "";
1141
- handleNodeValue(expr, val);
1142
- } else if (isTemplateLiteral(expr) && expr.expressions.length === 0) {
1143
- const val = expr.quasis[0].value.raw;
1144
- handleNodeValue(expr.quasis[0], val);
1145
- }
1146
- }
1147
- },
1148
- // Object Properties
1149
- Property(node) {
1150
- if (!isIdentifier(node.key)) return;
1151
- if (!isCachedPandaAttribute(node)) return;
1152
- if (isCachedRecipeVariant(node)) return;
1153
- const valueNode = node.value;
1154
- if (isLiteral(valueNode)) {
1155
- const val = valueNode.value?.toString() ?? "";
1156
- handleNodeValue(valueNode, val);
1157
- } else if (isTemplateLiteral(valueNode) && valueNode.expressions.length === 0) {
1158
- const val = valueNode.quasis[0].value.raw;
1159
- handleNodeValue(valueNode.quasis[0], val);
1160
- }
1161
- }
1162
- };
1163
- }
1164
- });
1165
- no_important_default = rule8;
1166
- }
1167
- });
1168
-
1169
- // src/rules/no-invalid-nesting.ts
1170
- import "@typescript-eslint/utils";
1171
- var RULE_NAME9, rule9, no_invalid_nesting_default;
1172
- var init_no_invalid_nesting = __esm({
1173
- "src/rules/no-invalid-nesting.ts"() {
1174
- "use strict";
1175
- init_esm_shims();
1176
- init_nodes();
1177
- init_utils();
1178
- init_helpers();
1179
- RULE_NAME9 = "no-invalid-nesting";
1180
- rule9 = createRule({
1181
- name: RULE_NAME9,
1182
- meta: {
1183
- docs: {
1184
- description: "Warn against invalid nesting. Nested styles must contain the `&` character."
1185
- },
1186
- messages: {
1187
- nesting: "Invalid style nesting. Nested styles must contain the `&` character."
1188
- },
1189
- type: "problem",
1190
- schema: []
1191
- },
1192
- defaultOptions: [],
1193
- create(context) {
1194
- const pandaFunctionCache = /* @__PURE__ */ new WeakMap();
1195
- const jsxPropCache = /* @__PURE__ */ new WeakMap();
1196
- const recipeVariantCache = /* @__PURE__ */ new WeakMap();
1197
- const styledPropertyCache = /* @__PURE__ */ new WeakMap();
1198
- const isCachedInPandaFunction = (node) => {
1199
- if (pandaFunctionCache.has(node)) {
1200
- return pandaFunctionCache.get(node);
1201
- }
1202
- const result = !!isInPandaFunction(node, context);
1203
- pandaFunctionCache.set(node, result);
1204
- return !!result;
1205
- };
1206
- const isCachedInJSXProp = (node) => {
1207
- if (jsxPropCache.has(node)) {
1208
- return jsxPropCache.get(node);
1209
- }
1210
- const result = isInJSXProp(node, context);
1211
- jsxPropCache.set(node, result);
1212
- return !!result;
1213
- };
1214
- const isCachedRecipeVariant = (node) => {
1215
- if (recipeVariantCache.has(node)) {
1216
- return recipeVariantCache.get(node);
1217
- }
1218
- const result = isRecipeVariant(node, context);
1219
- recipeVariantCache.set(node, result);
1220
- return !!result;
1221
- };
1222
- const isCachedStyledProperty = (node) => {
1223
- if (styledPropertyCache.has(node)) {
1224
- return styledPropertyCache.get(node);
1225
- }
1226
- const result = isStyledProperty(node, context);
1227
- styledPropertyCache.set(node, result);
1228
- return !!result;
1229
- };
1230
- const isInvalidNestingSelector = (node) => {
1231
- if (isLiteral(node) && typeof node.value === "string") {
1232
- return !node.value.includes("&");
1233
- } else if (isTemplateLiteral(node) && node.expressions.length === 0) {
1234
- return !node.quasis[0].value.raw.includes("&");
1235
- }
1236
- return false;
1237
- };
1238
- return {
1239
- // Use AST selector to target Property nodes with non-Identifier keys whose value is an ObjectExpression
1240
- 'Property[key.type!=/Identifier/][value.type="ObjectExpression"]'(node) {
1241
- const inPandaFunction = isCachedInPandaFunction(node);
1242
- const inJSXProp = isCachedInJSXProp(node);
1243
- if (!inPandaFunction && !inJSXProp) return;
1244
- if (isCachedRecipeVariant(node)) return;
1245
- if (isCachedStyledProperty(node)) return;
1246
- const keyNode = node.key;
1247
- if (isInvalidNestingSelector(keyNode)) {
1248
- context.report({
1249
- node: keyNode,
1250
- messageId: "nesting"
1251
- });
1252
- }
1253
- }
1254
- };
1255
- }
1256
- });
1257
- no_invalid_nesting_default = rule9;
1258
- }
1259
- });
1260
-
1261
- // src/rules/no-invalid-token-paths.ts
1262
- import { AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/utils";
1263
- import { isNodeOfTypes as isNodeOfTypes2 } from "@typescript-eslint/utils/ast-utils";
1264
- var RULE_NAME10, rule10, no_invalid_token_paths_default;
1265
- var init_no_invalid_token_paths = __esm({
1266
- "src/rules/no-invalid-token-paths.ts"() {
1267
- "use strict";
1268
- init_esm_shims();
1269
- init_helpers();
1270
- init_utils();
1271
- init_nodes();
1272
- RULE_NAME10 = "no-invalid-token-paths";
1273
- rule10 = createRule({
1274
- name: RULE_NAME10,
1275
- meta: {
1276
- docs: {
1277
- description: "Disallow the use of invalid token paths within token function syntax."
1278
- },
1279
- messages: {
1280
- noInvalidTokenPaths: "`{{token}}` is an invalid token path."
1281
- },
1282
- type: "problem",
1283
- schema: []
1284
- },
1285
- defaultOptions: [],
1286
- create(context) {
1287
- const invalidTokensCache2 = /* @__PURE__ */ new Map();
1288
- const sendReport = (node, value) => {
1289
- if (!value) return;
1290
- let tokens = invalidTokensCache2.get(value);
1291
- if (!tokens) {
1292
- tokens = getInvalidTokens(value, context);
1293
- invalidTokensCache2.set(value, tokens);
1294
- }
1295
- if (tokens.length === 0) return;
1296
- tokens.forEach((token) => {
1297
- context.report({
1298
- node,
1299
- messageId: "noInvalidTokenPaths",
1300
- data: { token }
1301
- });
1302
- });
1303
- };
1304
- const handleLiteralOrTemplate = (node) => {
1305
- if (!node) return;
1306
- if (isLiteral(node)) {
1307
- const value = node.value?.toString();
1308
- sendReport(node, value);
1309
- } else if (isTemplateLiteral(node) && node.expressions.length === 0) {
1310
- const value = node.quasis[0].value.raw;
1311
- sendReport(node.quasis[0], value);
1312
- }
1313
- };
1314
- return {
1315
- JSXAttribute(node) {
1316
- if (!node.value || !isPandaProp(node, context)) return;
1317
- if (isLiteral(node.value)) {
1318
- handleLiteralOrTemplate(node.value);
1319
- } else if (isJSXExpressionContainer(node.value)) {
1320
- handleLiteralOrTemplate(node.value.expression);
1321
- }
1322
- },
1323
- Property(node) {
1324
- if (!isIdentifier(node.key) || !isNodeOfTypes2([AST_NODE_TYPES3.Literal, AST_NODE_TYPES3.TemplateLiteral])(node.value) || !isPandaAttribute(node, context) || isRecipeVariant(node, context)) {
1325
- return;
1326
- }
1327
- handleLiteralOrTemplate(node.value);
1328
- },
1329
- TaggedTemplateExpression(node) {
1330
- const caller = getTaggedTemplateCaller(node);
1331
- if (!caller || !isPandaIsh(caller, context)) return;
1332
- const quasis = node.quasi.quasis;
1333
- quasis.forEach((quasi) => {
1334
- const styles = quasi.value.raw;
1335
- if (!styles) return;
1336
- let tokens = invalidTokensCache2.get(styles);
1337
- if (!tokens) {
1338
- tokens = getInvalidTokens(styles, context);
1339
- invalidTokensCache2.set(styles, tokens);
1340
- }
1341
- if (tokens.length === 0) return;
1342
- tokens.forEach((token) => {
1343
- let index = styles.indexOf(token);
1344
- while (index !== -1) {
1345
- const start = quasi.range[0] + index + 1;
1346
- const end = start + token.length;
1347
- context.report({
1348
- loc: {
1349
- start: context.sourceCode.getLocFromIndex(start),
1350
- end: context.sourceCode.getLocFromIndex(end)
1351
- },
1352
- messageId: "noInvalidTokenPaths",
1353
- data: { token }
1354
- });
1355
- index = styles.indexOf(token, index + token.length);
1356
- }
1357
- });
1358
- });
1359
- }
1360
- };
1361
- }
1362
- });
1363
- no_invalid_token_paths_default = rule10;
1364
- }
1365
- });
1366
-
1367
- // src/rules/no-margin-properties.ts
1368
- var RULE_NAME11, rule11, no_margin_properties_default;
1369
- var init_no_margin_properties = __esm({
1370
- "src/rules/no-margin-properties.ts"() {
1371
- "use strict";
1372
- init_esm_shims();
1373
- init_helpers();
1374
- init_utils();
1375
- init_nodes();
1376
- RULE_NAME11 = "no-margin-properties";
1377
- rule11 = createRule({
1378
- name: RULE_NAME11,
1379
- meta: {
1380
- docs: {
1381
- description: "Discourage using margin properties for spacing; prefer defining spacing in parent elements with `flex` or `grid` using the `gap` property for a more resilient layout. Margins make components less reusable in other contexts."
1382
- },
1383
- messages: {
1384
- noMargin: "Use flex or grid with the `gap` property to define spacing in parent elements for a more resilient layout."
1385
- },
1386
- type: "suggestion",
1387
- schema: [
1388
- {
1389
- type: "object",
1390
- properties: {
1391
- whitelist: {
1392
- type: "array",
1393
- items: {
1394
- type: "string",
1395
- minLength: 0
1396
- },
1397
- uniqueItems: true
1398
- }
1399
- },
1400
- additionalProperties: false
1401
- }
1402
- ]
1403
- },
1404
- defaultOptions: [
1405
- {
1406
- whitelist: []
1407
- }
1408
- ],
1409
- create(context) {
1410
- const whitelist = context.options[0]?.whitelist ?? [];
1411
- const longhandCache = /* @__PURE__ */ new Map();
1412
- const getLonghand = (name2) => {
1413
- if (longhandCache.has(name2)) {
1414
- return longhandCache.get(name2);
1415
- }
1416
- const longhand = resolveLonghand(name2, context) ?? name2;
1417
- longhandCache.set(name2, longhand);
1418
- return longhand;
1419
- };
1420
- const marginRegex = /margin/i;
1421
- const isMarginProperty = (name2) => {
1422
- const longhand = getLonghand(name2).toLowerCase();
1423
- return marginRegex.test(longhand);
1424
- };
1425
- const sendReport = (node) => {
1426
- if (whitelist.includes(node.name)) return;
1427
- if (!isMarginProperty(node.name)) return;
1428
- context.report({
1429
- node,
1430
- messageId: "noMargin"
1431
- });
1432
- };
1433
- const pandaPropCache = /* @__PURE__ */ new WeakMap();
1434
- const isCachedPandaProp = (node) => {
1435
- if (pandaPropCache.has(node)) {
1436
- return pandaPropCache.get(node);
1437
- }
1438
- const result = isPandaProp(node, context);
1439
- pandaPropCache.set(node, result);
1440
- return !!result;
1441
- };
1442
- const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
1443
- const isCachedPandaAttribute = (node) => {
1444
- if (pandaAttributeCache.has(node)) {
1445
- return pandaAttributeCache.get(node);
1446
- }
1447
- const result = isPandaAttribute(node, context);
1448
- pandaAttributeCache.set(node, result);
1449
- return !!result;
1450
- };
1451
- const recipeVariantCache = /* @__PURE__ */ new WeakMap();
1452
- const isCachedRecipeVariant = (node) => {
1453
- if (recipeVariantCache.has(node)) {
1454
- return recipeVariantCache.get(node);
1455
- }
1456
- const result = isRecipeVariant(node, context);
1457
- recipeVariantCache.set(node, result);
1458
- return !!result;
1459
- };
1460
- return {
1461
- JSXAttribute(node) {
1462
- if (!isJSXIdentifier(node.name)) return;
1463
- if (!isCachedPandaProp(node)) return;
1464
- sendReport(node.name);
1465
- },
1466
- Property(node) {
1467
- if (!isIdentifier(node.key)) return;
1468
- if (!isCachedPandaAttribute(node)) return;
1469
- if (isCachedRecipeVariant(node)) return;
1470
- sendReport(node.key);
1471
- }
1472
- };
1473
- }
1474
- });
1475
- no_margin_properties_default = rule11;
1476
- }
1477
- });
1478
-
1479
- // src/utils/physical-properties.ts
1480
- var physicalProperties, physicalPropertyValues;
1481
- var init_physical_properties = __esm({
1482
- "src/utils/physical-properties.ts"() {
1483
- "use strict";
1484
- init_esm_shims();
1485
- physicalProperties = {
1486
- borderBottom: "borderBlockEnd",
1487
- borderBottomColor: "borderBlockEndColor",
1488
- borderBottomStyle: "borderBlockEndStyle",
1489
- borderBottomWidth: "borderBlockEndWidth",
1490
- borderTop: "borderBlockStart",
1491
- borderTopColor: "borderBlockStartColor",
1492
- borderTopStyle: "borderBlockStartStyle",
1493
- borderTopWidth: "borderBlockStartWidth",
1494
- borderRight: "borderInlineEnd",
1495
- borderRightColor: "borderInlineEndColor",
1496
- borderRightStyle: "borderInlineEndStyle",
1497
- borderRightWidth: "borderInlineEndWidth",
1498
- borderLeft: "borderInlineStart",
1499
- borderLeftColor: "borderInlineStartColor",
1500
- borderLeftStyle: "borderInlineStartStyle",
1501
- borderLeftWidth: "borderInlineStartWidth",
1502
- borderTopLeftRadius: "borderStartStartRadius",
1503
- borderBottomLeftRadius: "borderEndStartRadius",
1504
- borderTopRightRadius: "borderStartEndRadius",
1505
- borderBottomRightRadius: "borderEndEndRadius",
1506
- marginBottom: "marginBlockEnd",
1507
- marginTop: "marginBlockStart",
1508
- marginRight: "marginInlineEnd",
1509
- marginLeft: "marginInlineStart",
1510
- paddingBottom: "paddingBlockEnd",
1511
- paddingTop: "paddingBlockStart",
1512
- paddingRight: "paddingInlineEnd",
1513
- paddingLeft: "paddingInlineStart",
1514
- left: "insetInlineStart",
1515
- right: "insetInlineEnd",
1516
- top: "insetBlockStart",
1517
- bottom: "insetBlockEnd"
1518
- };
1519
- physicalPropertyValues = {
1520
- // text-align physical values mapped to logical values
1521
- textAlign: {
1522
- left: "start",
1523
- right: "end"
1524
- }
1525
- };
1526
- }
1527
- });
1528
-
1529
- // src/rules/no-physical-properties.ts
1530
- var RULE_NAME12, MESSAGES, PropertyCache, extractStringLiteralValue, createPropertyReport, createValueReport, rule12, no_physical_properties_default;
1531
- var init_no_physical_properties = __esm({
1532
- "src/rules/no-physical-properties.ts"() {
1533
- "use strict";
1534
- init_esm_shims();
1535
- init_helpers();
1536
- init_utils();
1537
- init_nodes();
1538
- init_physical_properties();
1539
- RULE_NAME12 = "no-physical-properties";
1540
- MESSAGES = {
1541
- physical: "Use logical property instead of {{physical}}. Prefer `{{logical}}`.",
1542
- physicalValue: "Use logical value instead of {{physical}}. Prefer `{{logical}}`.",
1543
- replace: "Replace `{{physical}}` with `{{logical}}`."
1544
- };
1545
- PropertyCache = class {
1546
- longhandCache = /* @__PURE__ */ new Map();
1547
- pandaPropCache = /* @__PURE__ */ new WeakMap();
1548
- pandaAttributeCache = /* @__PURE__ */ new WeakMap();
1549
- recipeVariantCache = /* @__PURE__ */ new WeakMap();
1550
- getLonghand(name2, context) {
1551
- if (this.longhandCache.has(name2)) {
1552
- return this.longhandCache.get(name2);
1553
- }
1554
- const longhand = resolveLonghand(name2, context) ?? name2;
1555
- this.longhandCache.set(name2, longhand);
1556
- return longhand;
1557
- }
1558
- isPandaProp(node, context) {
1559
- if (this.pandaPropCache.has(node)) {
1560
- return this.pandaPropCache.get(node);
1561
- }
1562
- const result = isPandaProp(node, context);
1563
- this.pandaPropCache.set(node, result);
1564
- return !!result;
1565
- }
1566
- isPandaAttribute(node, context) {
1567
- if (this.pandaAttributeCache.has(node)) {
1568
- return this.pandaAttributeCache.get(node);
1569
- }
1570
- const result = isPandaAttribute(node, context);
1571
- this.pandaAttributeCache.set(node, result);
1572
- return !!result;
1573
- }
1574
- isRecipeVariant(node, context) {
1575
- if (this.recipeVariantCache.has(node)) {
1576
- return this.recipeVariantCache.get(node);
1577
- }
1578
- const result = isRecipeVariant(node, context);
1579
- this.recipeVariantCache.set(node, result);
1580
- return !!result;
1581
- }
1582
- };
1583
- extractStringLiteralValue = (valueNode) => {
1584
- if (isLiteral(valueNode) && typeof valueNode.value === "string") {
1585
- return valueNode.value;
1586
- }
1587
- if (isJSXExpressionContainer(valueNode) && isLiteral(valueNode.expression) && typeof valueNode.expression.value === "string") {
1588
- return valueNode.expression.value;
1589
- }
1590
- return null;
1591
- };
1592
- createPropertyReport = (node, longhandName, logical, context) => {
1593
- const physicalName = `\`${node.name}\`${longhandName !== node.name ? ` (resolved to \`${longhandName}\`)` : ""}`;
1594
- context.report({
1595
- node,
1596
- messageId: "physical",
1597
- data: { physical: physicalName, logical },
1598
- suggest: [
1599
- {
1600
- messageId: "replace",
1601
- data: { physical: node.name, logical },
1602
- fix: (fixer) => fixer.replaceText(node, logical)
1603
- }
1604
- ]
1605
- });
1606
- };
1607
- createValueReport = (valueNode, valueText, logical, context) => {
1608
- context.report({
1609
- node: valueNode,
1610
- messageId: "physicalValue",
1611
- data: { physical: `"${valueText}"`, logical: `"${logical}"` },
1612
- suggest: [
1613
- {
1614
- messageId: "replace",
1615
- data: { physical: `"${valueText}"`, logical: `"${logical}"` },
1616
- fix: (fixer) => {
1617
- if (isLiteral(valueNode)) {
1618
- return fixer.replaceText(valueNode, `"${logical}"`);
1619
- }
1620
- if (isJSXExpressionContainer(valueNode) && isLiteral(valueNode.expression)) {
1621
- return fixer.replaceText(valueNode.expression, `"${logical}"`);
1622
- }
1623
- return null;
1624
- }
1625
- }
1626
- ]
1627
- });
1628
- };
1629
- rule12 = createRule({
1630
- name: RULE_NAME12,
1631
- meta: {
1632
- docs: {
1633
- description: "Encourage the use of logical properties over physical properties to foster a responsive and adaptable user interface."
1634
- },
1635
- messages: MESSAGES,
1636
- type: "suggestion",
1637
- hasSuggestions: true,
1638
- schema: [
1639
- {
1640
- type: "object",
1641
- properties: {
1642
- whitelist: {
1643
- type: "array",
1644
- items: {
1645
- type: "string",
1646
- minLength: 0
1647
- },
1648
- uniqueItems: true
1649
- }
1650
- },
1651
- additionalProperties: false
1652
- }
1653
- ]
1654
- },
1655
- defaultOptions: [{ whitelist: [] }],
1656
- create(context) {
1657
- const whitelist = context.options[0]?.whitelist ?? [];
1658
- const cache2 = new PropertyCache();
1659
- const checkPropertyName = (node) => {
1660
- if (whitelist.includes(node.name)) return;
1661
- const longhandName = cache2.getLonghand(node.name, context);
1662
- if (!(longhandName in physicalProperties)) return;
1663
- const logical = physicalProperties[longhandName];
1664
- createPropertyReport(node, longhandName, logical, context);
1665
- };
1666
- const checkPropertyValue = (keyNode, valueNode) => {
1667
- const propName = keyNode.name;
1668
- if (!(propName in physicalPropertyValues)) return false;
1669
- const valueText = extractStringLiteralValue(valueNode);
1670
- if (valueText === null) return false;
1671
- const valueMap = physicalPropertyValues[propName];
1672
- if (!valueMap[valueText]) return false;
1673
- createValueReport(valueNode, valueText, valueMap[valueText], context);
1674
- return true;
1675
- };
1676
- return {
1677
- JSXAttribute(node) {
1678
- if (!isJSXIdentifier(node.name)) return;
1679
- if (!cache2.isPandaProp(node, context)) return;
1680
- checkPropertyName(node.name);
1681
- if (node.value) {
1682
- checkPropertyValue(node.name, node.value);
1683
- }
1684
- },
1685
- Property(node) {
1686
- if (!isIdentifier(node.key)) return;
1687
- if (!cache2.isPandaAttribute(node, context)) return;
1688
- if (cache2.isRecipeVariant(node, context)) return;
1689
- checkPropertyName(node.key);
1690
- if (node.value) {
1691
- checkPropertyValue(node.key, node.value);
1692
- }
1693
- }
1694
- };
1695
- }
1696
- });
1697
- no_physical_properties_default = rule12;
1698
- }
1699
- });
1700
-
1701
- // src/rules/no-property-renaming.ts
1702
- var RULE_NAME13, rule13, no_property_renaming_default;
1703
- var init_no_property_renaming = __esm({
1704
- "src/rules/no-property-renaming.ts"() {
1705
- "use strict";
1706
- init_esm_shims();
1707
- init_utils();
1708
- init_helpers();
1709
- init_nodes();
1710
- RULE_NAME13 = "no-property-renaming";
1711
- rule13 = createRule({
1712
- name: RULE_NAME13,
1713
- meta: {
1714
- docs: {
1715
- description: "Ensure that properties for patterns or style props are not renamed, as it prevents proper tracking."
1716
- },
1717
- messages: {
1718
- noRenaming: "Incoming `{{prop}}` prop is different from the expected `{{expected}}` attribute. Panda will not track this prop."
1719
- },
1720
- type: "problem",
1721
- schema: []
1722
- },
1723
- defaultOptions: [],
1724
- create(context) {
1725
- const pandaPropCache = /* @__PURE__ */ new WeakMap();
1726
- const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
1727
- const recipeVariantCache = /* @__PURE__ */ new WeakMap();
1728
- const isCachedPandaProp = (node) => {
1729
- if (pandaPropCache.has(node)) {
1730
- return pandaPropCache.get(node);
1731
- }
1732
- const result = isPandaProp(node, context);
1733
- pandaPropCache.set(node, result);
1734
- return !!result;
1735
- };
1736
- const isCachedPandaAttribute = (node) => {
1737
- if (pandaAttributeCache.has(node)) {
1738
- return pandaAttributeCache.get(node);
1739
- }
1740
- const result = isPandaAttribute(node, context);
1741
- pandaAttributeCache.set(node, result);
1742
- return !!result;
1743
- };
1744
- const isCachedRecipeVariant = (node) => {
1745
- if (recipeVariantCache.has(node)) {
1746
- return recipeVariantCache.get(node);
1747
- }
1748
- const result = isRecipeVariant(node, context);
1749
- recipeVariantCache.set(node, result);
1750
- return !!result;
1751
- };
1752
- const sendReport = (node, expected, prop) => {
1753
- context.report({
1754
- node,
1755
- messageId: "noRenaming",
1756
- data: {
1757
- expected,
1758
- prop
1759
- }
1760
- });
1761
- };
1762
- const handleReport = (node, value, attr) => {
1763
- if (isIdentifier(value) && attr !== value.name) {
1764
- sendReport(node, attr, value.name);
1765
- } else if (isMemberExpression(value) && isIdentifier(value.property) && attr !== value.property.name) {
1766
- sendReport(node, attr, value.property.name);
1767
- }
1768
- };
1769
- return {
1770
- JSXAttribute(node) {
1771
- if (!node.value) return;
1772
- if (!isJSXExpressionContainer(node.value)) return;
1773
- if (!isCachedPandaProp(node)) return;
1774
- const attr = node.name.name.toString();
1775
- const expression = node.value.expression;
1776
- handleReport(node.value, expression, attr);
1777
- },
1778
- Property(node) {
1779
- if (!isIdentifier(node.key)) return;
1780
- if (!isIdentifier(node.value) && !isMemberExpression(node.value)) return;
1781
- if (!isCachedPandaAttribute(node)) return;
1782
- if (isCachedRecipeVariant(node)) return;
1783
- const attr = node.key.name;
1784
- const value = node.value;
1785
- handleReport(node.value, value, attr);
1786
- }
1787
- };
1788
- }
1789
- });
1790
- no_property_renaming_default = rule13;
1791
- }
1792
- });
1793
-
1794
- // src/rules/no-unsafe-token-fn-usage.ts
1795
- import "@typescript-eslint/utils";
1796
- import { getArbitraryValue as getArbitraryValue3 } from "@pandacss/shared";
1797
- var RULE_NAME14, rule14, no_unsafe_token_fn_usage_default;
1798
- var init_no_unsafe_token_fn_usage = __esm({
1799
- "src/rules/no-unsafe-token-fn-usage.ts"() {
1800
- "use strict";
1801
- init_esm_shims();
1802
- init_helpers();
1803
- init_utils();
1804
- init_nodes();
1805
- RULE_NAME14 = "no-unsafe-token-fn-usage";
1806
- rule14 = createRule({
1807
- name: RULE_NAME14,
1808
- meta: {
1809
- docs: {
1810
- description: "Prevent users from using the token function in situations where they could simply use the raw design token."
1811
- },
1812
- messages: {
1813
- noUnsafeTokenFnUsage: "Unnecessary token function usage. Prefer design token.",
1814
- replace: "Replace token function with `{{safe}}`."
1815
- },
1816
- type: "suggestion",
1817
- hasSuggestions: true,
1818
- schema: []
1819
- },
1820
- defaultOptions: [],
1821
- create(context) {
1822
- let tokenImportCache;
1823
- const getCachedTokenImport = () => {
1824
- if (tokenImportCache !== void 0) {
1825
- return tokenImportCache;
1826
- }
1827
- tokenImportCache = getTokenImport(context);
1828
- return tokenImportCache;
1829
- };
1830
- const isUnsafeCallExpression = (node) => {
1831
- const tkImport = getCachedTokenImport();
1832
- return isIdentifier(node.callee) && node.callee.name === tkImport?.alias;
1833
- };
1834
- const tokenWrap = (value) => value ? `token(${value})` : "";
1835
- const isCompositeValue = (input) => {
1836
- if (!input) return false;
1837
- const tokenRegex = /^(?:token\([^)]*\)|\{[^}]*\})$/;
1838
- return !tokenRegex.test(input);
1839
- };
1840
- const sendReport = (node, value) => {
1841
- const tkImports = extractTokens(value);
1842
- if (!tkImports.length) return;
1843
- const token = tkImports[0].replace(/^[^.]*\./, "");
1844
- context.report({
1845
- node,
1846
- messageId: "noUnsafeTokenFnUsage",
1847
- suggest: [
1848
- {
1849
- messageId: "replace",
1850
- data: { safe: token },
1851
- fix: (fixer) => fixer.replaceText(node, `'${token}'`)
1852
- }
1853
- ]
1854
- });
1855
- };
1856
- const handleRuntimeFn = (node) => {
1857
- if (!isCallExpression(node)) return;
1858
- if (!isUnsafeCallExpression(node)) return;
1859
- const value = node.arguments[0];
1860
- if (isLiteral(value)) {
1861
- const val = getArbitraryValue3(value.value?.toString() ?? "");
1862
- sendReport(node, tokenWrap(val));
1863
- } else if (isTemplateLiteral(value) && value.expressions.length === 0) {
1864
- const val = getArbitraryValue3(value.quasis[0].value.raw);
1865
- sendReport(node, tokenWrap(val));
1866
- }
1867
- };
1868
- const handleLiteral = (node) => {
1869
- if (!isLiteral(node)) return;
1870
- const value = getArbitraryValue3(node.value?.toString() ?? "");
1871
- if (isCompositeValue(value)) return;
1872
- sendReport(node, value);
1873
- };
1874
- const handleTemplateLiteral = (node) => {
1875
- if (!isTemplateLiteral(node) || node.expressions.length > 0) return;
1876
- const value = getArbitraryValue3(node.quasis[0].value.raw);
1877
- if (isCompositeValue(value)) return;
1878
- sendReport(node, value);
1879
- };
1880
- const pandaPropCache = /* @__PURE__ */ new WeakMap();
1881
- const isCachedPandaProp = (node) => {
1882
- if (pandaPropCache.has(node)) {
1883
- return pandaPropCache.get(node);
1884
- }
1885
- const result = isPandaProp(node, context);
1886
- pandaPropCache.set(node, result);
1887
- return !!result;
1888
- };
1889
- const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
1890
- const isCachedPandaAttribute = (node) => {
1891
- if (pandaAttributeCache.has(node)) {
1892
- return pandaAttributeCache.get(node);
1893
- }
1894
- const result = isPandaAttribute(node, context);
1895
- pandaAttributeCache.set(node, result);
1896
- return !!result;
1897
- };
1898
- const recipeVariantCache = /* @__PURE__ */ new WeakMap();
1899
- const isCachedRecipeVariant = (node) => {
1900
- if (recipeVariantCache.has(node)) {
1901
- return recipeVariantCache.get(node);
1902
- }
1903
- const result = isRecipeVariant(node, context);
1904
- recipeVariantCache.set(node, result);
1905
- return !!result;
1906
- };
1907
- return {
1908
- JSXAttribute(node) {
1909
- if (!node.value) return;
1910
- if (!isCachedPandaProp(node)) return;
1911
- handleLiteral(node.value);
1912
- if (isJSXExpressionContainer(node.value)) {
1913
- const expression = node.value.expression;
1914
- handleLiteral(expression);
1915
- handleTemplateLiteral(expression);
1916
- handleRuntimeFn(expression);
1917
- }
1918
- },
1919
- Property(node) {
1920
- if (!isCachedPandaAttribute(node)) return;
1921
- if (isCachedRecipeVariant(node)) return;
1922
- const valueNode = node.value;
1923
- if (isCallExpression(valueNode) || isLiteral(valueNode) || isTemplateLiteral(valueNode)) {
1924
- handleRuntimeFn(valueNode);
1925
- handleLiteral(valueNode);
1926
- handleTemplateLiteral(valueNode);
1927
- }
1928
- }
1929
- };
1930
- }
1931
- });
1932
- no_unsafe_token_fn_usage_default = rule14;
1933
- }
1934
- });
1935
-
1936
- // src/rules/prefer-longhand-properties.ts
1937
- var RULE_NAME15, rule15, prefer_longhand_properties_default;
1938
- var init_prefer_longhand_properties = __esm({
1939
- "src/rules/prefer-longhand-properties.ts"() {
1940
- "use strict";
1941
- init_esm_shims();
1942
- init_helpers();
1943
- init_utils();
1944
- init_nodes();
1945
- RULE_NAME15 = "prefer-longhand-properties";
1946
- rule15 = createRule({
1947
- name: RULE_NAME15,
1948
- meta: {
1949
- docs: {
1950
- description: "Discourage the use of shorthand properties and promote the preference for longhand properties in the codebase."
1951
- },
1952
- messages: {
1953
- longhand: "Use longhand property instead of `{{shorthand}}`. Prefer `{{longhand}}`.",
1954
- replace: "Replace `{{shorthand}}` with `{{longhand}}`."
1955
- },
1956
- type: "suggestion",
1957
- hasSuggestions: true,
1958
- schema: [
1959
- {
1960
- type: "object",
1961
- properties: {
1962
- whitelist: {
1963
- type: "array",
1964
- items: {
1965
- type: "string",
1966
- minLength: 0
1967
- },
1968
- uniqueItems: true
1969
- }
1970
- },
1971
- additionalProperties: false
1972
- }
1973
- ]
1974
- },
1975
- defaultOptions: [
1976
- {
1977
- whitelist: []
1978
- }
1979
- ],
1980
- create(context) {
1981
- const whitelist = context.options[0]?.whitelist ?? [];
1982
- const longhandCache = /* @__PURE__ */ new Map();
1983
- const getLonghand = (name2) => {
1984
- if (longhandCache.has(name2)) {
1985
- return longhandCache.get(name2);
1986
- }
1987
- const longhand = resolveLonghand(name2, context);
1988
- longhandCache.set(name2, longhand);
1989
- return longhand;
1990
- };
1991
- const pandaPropCache = /* @__PURE__ */ new WeakMap();
1992
- const isCachedPandaProp = (node) => {
1993
- if (pandaPropCache.has(node)) {
1994
- return pandaPropCache.get(node);
1995
- }
1996
- const result = isPandaProp(node, context);
1997
- pandaPropCache.set(node, result);
1998
- return !!result;
1999
- };
2000
- const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
2001
- const isCachedPandaAttribute = (node) => {
2002
- if (pandaAttributeCache.has(node)) {
2003
- return pandaAttributeCache.get(node);
2004
- }
2005
- const result = isPandaAttribute(node, context);
2006
- pandaAttributeCache.set(node, result);
2007
- return !!result;
2008
- };
2009
- const recipeVariantCache = /* @__PURE__ */ new WeakMap();
2010
- const isCachedRecipeVariant = (node) => {
2011
- if (recipeVariantCache.has(node)) {
2012
- return recipeVariantCache.get(node);
2013
- }
2014
- const result = isRecipeVariant(node, context);
2015
- recipeVariantCache.set(node, result);
2016
- return !!result;
2017
- };
2018
- const sendReport = (node) => {
2019
- if (whitelist.includes(node.name)) return;
2020
- const longhand = getLonghand(node.name);
2021
- if (!longhand || longhand === node.name) return;
2022
- const data = {
2023
- shorthand: node.name,
2024
- longhand
2025
- };
2026
- context.report({
2027
- node,
2028
- messageId: "longhand",
2029
- data,
2030
- suggest: [
2031
- {
2032
- messageId: "replace",
2033
- data,
2034
- fix: (fixer) => fixer.replaceText(node, longhand)
2035
- }
2036
- ]
2037
- });
2038
- };
2039
- return {
2040
- JSXAttribute(node) {
2041
- if (!isJSXIdentifier(node.name)) return;
2042
- if (!isCachedPandaProp(node)) return;
2043
- sendReport(node.name);
2044
- },
2045
- Property(node) {
2046
- if (!isIdentifier(node.key)) return;
2047
- if (!isCachedPandaAttribute(node)) return;
2048
- if (isCachedRecipeVariant(node)) return;
2049
- sendReport(node.key);
2050
- }
2051
- };
2052
- }
2053
- });
2054
- prefer_longhand_properties_default = rule15;
2055
- }
2056
- });
2057
-
2058
- // src/rules/prefer-shorthand-properties.ts
2059
- var RULE_NAME16, rule16, prefer_shorthand_properties_default;
2060
- var init_prefer_shorthand_properties = __esm({
2061
- "src/rules/prefer-shorthand-properties.ts"() {
2062
- "use strict";
2063
- init_esm_shims();
2064
- init_helpers();
2065
- init_utils();
2066
- init_nodes();
2067
- RULE_NAME16 = "prefer-shorthand-properties";
2068
- rule16 = createRule({
2069
- name: RULE_NAME16,
2070
- meta: {
2071
- docs: {
2072
- description: "Discourage the use of longhand properties and promote the preference for shorthand properties in the codebase."
2073
- },
2074
- messages: {
2075
- shorthand: "Use shorthand property instead of `{{longhand}}`. Prefer `{{shorthand}}`.",
2076
- replace: "Replace `{{longhand}}` with `{{shorthand}}`."
2077
- },
2078
- type: "suggestion",
2079
- hasSuggestions: true,
2080
- schema: [
2081
- {
2082
- type: "object",
2083
- properties: {
2084
- whitelist: {
2085
- type: "array",
2086
- items: {
2087
- type: "string",
2088
- minLength: 0
2089
- },
2090
- uniqueItems: true
2091
- }
2092
- },
2093
- additionalProperties: false
2094
- }
2095
- ]
2096
- },
2097
- defaultOptions: [
2098
- {
2099
- whitelist: []
2100
- }
2101
- ],
2102
- create(context) {
2103
- const whitelist = context.options[0]?.whitelist ?? [];
2104
- const longhandCache = /* @__PURE__ */ new Map();
2105
- const getLonghand = (name2) => {
2106
- if (longhandCache.has(name2)) {
2107
- return longhandCache.get(name2);
2108
- }
2109
- const longhand = resolveLonghand(name2, context);
2110
- longhandCache.set(name2, longhand);
2111
- return longhand;
2112
- };
2113
- const shorthandsCache = /* @__PURE__ */ new Map();
2114
- const getShorthands = (name2) => {
2115
- if (shorthandsCache.has(name2)) {
2116
- return shorthandsCache.get(name2);
2117
- }
2118
- const shorthands = resolveShorthands(name2, context);
2119
- shorthandsCache.set(name2, shorthands);
2120
- return shorthands;
2121
- };
2122
- const pandaPropCache = /* @__PURE__ */ new WeakMap();
2123
- const isCachedPandaProp = (node) => {
2124
- if (pandaPropCache.has(node)) {
2125
- return pandaPropCache.get(node);
2126
- }
2127
- const result = isPandaProp(node, context);
2128
- pandaPropCache.set(node, result);
2129
- return !!result;
2130
- };
2131
- const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
2132
- const isCachedPandaAttribute = (node) => {
2133
- if (pandaAttributeCache.has(node)) {
2134
- return pandaAttributeCache.get(node);
2135
- }
2136
- const result = isPandaAttribute(node, context);
2137
- pandaAttributeCache.set(node, result);
2138
- return !!result;
2139
- };
2140
- const recipeVariantCache = /* @__PURE__ */ new WeakMap();
2141
- const isCachedRecipeVariant = (node) => {
2142
- if (recipeVariantCache.has(node)) {
2143
- return recipeVariantCache.get(node);
2144
- }
2145
- const result = isRecipeVariant(node, context);
2146
- recipeVariantCache.set(node, result);
2147
- return !!result;
2148
- };
2149
- const sendReport = (node) => {
2150
- if (whitelist.includes(node.name)) return;
2151
- const longhand = getLonghand(node.name);
2152
- if (longhand) return;
2153
- const shorthands = getShorthands(node.name);
2154
- if (!shorthands || shorthands.length === 0) return;
2155
- const shorthandList = shorthands.map((s) => `\`${s}\``).join(", ");
2156
- const data = {
2157
- longhand: node.name,
2158
- shorthand: shorthandList
2159
- };
2160
- context.report({
2161
- node,
2162
- messageId: "shorthand",
2163
- data,
2164
- suggest: [
2165
- {
2166
- messageId: "replace",
2167
- data,
2168
- fix: (fixer) => fixer.replaceText(node, shorthands[0])
2169
- }
2170
- ]
2171
- });
2172
- };
2173
- return {
2174
- JSXAttribute(node) {
2175
- if (!isJSXIdentifier(node.name)) return;
2176
- if (!isCachedPandaProp(node)) return;
2177
- sendReport(node.name);
2178
- },
2179
- Property(node) {
2180
- if (!isIdentifier(node.key)) return;
2181
- if (!isCachedPandaAttribute(node)) return;
2182
- if (isCachedRecipeVariant(node)) return;
2183
- sendReport(node.key);
2184
- }
2185
- };
2186
- }
2187
- });
2188
- prefer_shorthand_properties_default = rule16;
2189
- }
2190
- });
2191
-
2192
- // src/utils/composite-properties.ts
2193
- var compositeProperties;
2194
- var init_composite_properties = __esm({
2195
- "src/utils/composite-properties.ts"() {
2196
- "use strict";
2197
- init_esm_shims();
2198
- compositeProperties = {
2199
- animation: [
2200
- "animationName",
2201
- "animationDuration",
2202
- "animationTimingFunction",
2203
- "animationDelay",
2204
- "animationIterationCount",
2205
- "animationDirection",
2206
- "animationFillMode",
2207
- "animationPlayState"
2208
- ],
2209
- background: [
2210
- "backgroundImage",
2211
- "backgroundPosition",
2212
- "backgroundSize",
2213
- "backgroundRepeat",
2214
- "backgroundAttachment",
2215
- "backgroundOrigin",
2216
- "backgroundClip",
2217
- "backgroundColor"
2218
- ],
2219
- backgroundPosition: ["backgroundPositionX", "backgroundPositionY"],
2220
- border: ["borderWidth", "borderStyle", "borderColor"],
2221
- borderBlock: ["borderBlockWidth", "borderBlockStyle", "borderBlockColor"],
2222
- borderBlockColor: ["borderBlockStartColor", "borderBlockEndColor"],
2223
- borderBlockEnd: ["borderBlockEndWidth", "borderBlockEndStyle", "borderBlockEndColor"],
2224
- borderBlockStart: ["borderBlockStartWidth", "borderBlockStartStyle", "borderBlockStartColor"],
2225
- borderBlockStyle: ["borderBlockStartStyle", "borderBlockEndStyle"],
2226
- borderBlockWidth: ["borderBlockStartWidth", "borderBlockEndWidth"],
2227
- borderBottom: ["borderBottomWidth", "borderBottomStyle", "borderBottomColor"],
2228
- borderColor: ["borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"],
2229
- borderImage: ["borderImageSource", "borderImageSlice", "borderImageWidth", "borderImageOutset", "borderImageRepeat"],
2230
- borderInline: ["borderInlineWidth", "borderInlineStyle", "borderInlineColor"],
2231
- borderInlineColor: ["borderInlineStartColor", "borderInlineEndColor"],
2232
- borderInlineEnd: ["borderInlineEndWidth", "borderInlineEndStyle", "borderInlineEndColor"],
2233
- borderInlineStart: ["borderInlineStartWidth", "borderInlineStartStyle", "borderInlineStartColor"],
2234
- borderInlineStyle: ["borderInlineStartStyle", "borderInlineEndStyle"],
2235
- borderInlineWidth: ["borderInlineStartWidth", "borderInlineEndWidth"],
2236
- borderLeft: ["borderLeftWidth", "borderLeftStyle", "borderLeftColor"],
2237
- borderRadius: ["borderTopLeftRadius", "borderTopRightRadius", "borderBottomRightRadius", "borderBottomLeftRadius"],
2238
- borderRight: ["borderRightWidth", "borderRightStyle", "borderRightColor"],
2239
- borderStyle: ["borderTopStyle", "borderRightStyle", "borderBottomStyle", "borderLeftStyle"],
2240
- borderTop: ["borderTopWidth", "borderTopStyle", "borderTopColor"],
2241
- borderWidth: ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"],
2242
- columnRule: ["columnRuleWidth", "columnRuleStyle", "columnRuleColor"],
2243
- columns: ["columnWidth", "columnCount"],
2244
- container: ["contain", "content"],
2245
- containIntrinsicSize: ["containIntrinsicSizeInline", "containIntrinsicSizeBlock"],
2246
- cue: ["cueBefore", "cueAfter"],
2247
- flex: ["flexGrow", "flexShrink", "flexBasis"],
2248
- flexFlow: ["flexDirection", "flexWrap"],
2249
- font: [
2250
- "fontStyle",
2251
- "fontVariantCaps",
2252
- "fontVariantEastAsian",
2253
- "fontVariantLigatures",
2254
- "fontVariantNumeric",
2255
- "fontVariantPosition",
2256
- "fontWeight",
2257
- "fontStretch",
2258
- "fontSize",
2259
- "lineHeight",
2260
- "fontFamily"
2261
- ],
2262
- fontSynthesis: ["fontSynthesisWeight", "fontSynthesisStyle", "fontSynthesisSmallCaps"],
2263
- fontVariant: [
2264
- "fontVariantCaps",
2265
- "fontVariantEastAsian",
2266
- "fontVariantLigatures",
2267
- "fontVariantNumeric",
2268
- "fontVariantPosition"
2269
- ],
2270
- gap: ["columnGap", "rowGap"],
2271
- grid: [
2272
- "gridTemplateColumns",
2273
- "gridTemplateRows",
2274
- "gridTemplateAreas",
2275
- "gridAutoColumns",
2276
- "gridAutoRows",
2277
- "gridAutoFlow"
2278
- ],
2279
- gridArea: ["gridRowStart", "gridColumnStart", "gridRowEnd", "gridColumnEnd"],
2280
- gridColumn: ["gridColumnStart", "gridColumnEnd"],
2281
- gridGap: ["gridColumnGap", "gridRowGap"],
2282
- gridRow: ["gridRowStart", "gridRowEnd"],
2283
- gridTemplate: ["gridTemplateColumns", "gridTemplateRows", "gridTemplateAreas"],
2284
- inset: ["top", "right", "bottom", "left"],
2285
- insetBlock: ["insetBlockStart", "insetBlockEnd"],
2286
- insetInline: ["insetInlineStart", "insetInlineEnd"],
2287
- listStyle: ["listStyleType", "listStylePosition", "listStyleImage"],
2288
- margin: ["marginTop", "marginRight", "marginBottom", "marginLeft"],
2289
- marginBlock: ["marginBlockStart", "marginBlockEnd"],
2290
- marginInline: ["marginInlineStart", "marginInlineEnd"],
2291
- mask: ["maskImage", "maskMode", "maskRepeat", "maskPosition", "maskClip", "maskOrigin", "maskSize", "maskComposite"],
2292
- maskBorder: [
2293
- "maskBorderSource",
2294
- "maskBorderMode",
2295
- "maskBorderSlice",
2296
- "maskBorderWidth",
2297
- "maskBorderOutset",
2298
- "maskBorderRepeat"
2299
- ],
2300
- offset: ["offsetPosition", "offsetPath", "offsetDistance", "offsetRotate", "offsetAnchor"],
2301
- outline: ["outlineWidth", "outlineStyle", "outlineColor"],
2302
- overflow: ["overflowX", "overflowY"],
2303
- padding: ["paddingTop", "paddingRight", "paddingBottom", "paddingLeft"],
2304
- paddingBlock: ["paddingBlockStart", "paddingBlockEnd"],
2305
- paddingInline: ["paddingInlineStart", "paddingInlineEnd"],
2306
- pause: ["pauseBefore", "pauseAfter"],
2307
- placeContent: ["alignContent", "justifyContent"],
2308
- placeItems: ["alignItems", "justifyItems"],
2309
- placeSelf: ["alignSelf", "justifySelf"],
2310
- rest: ["restBefore", "restAfter"],
2311
- scrollMargin: ["scrollMarginTop", "scrollMarginRight", "scrollMarginBottom", "scrollMarginLeft"],
2312
- scrollMarginBlock: ["scrollMarginBlockStart", "scrollMarginBlockEnd"],
2313
- scrollMarginInline: ["scrollMarginInlineStart", "scrollMarginInlineEnd"],
2314
- scrollPadding: ["scrollPaddingTop", "scrollPaddingRight", "scrollPaddingBottom", "scrollPaddingLeft"],
2315
- scrollPaddingBlock: ["scrollPaddingBlockStart", "scrollPaddingBlockEnd"],
2316
- scrollPaddingInline: ["scrollPaddingInlineStart", "scrollPaddingInlineEnd"],
2317
- scrollSnapMargin: ["scrollSnapMarginTop", "scrollSnapMarginRight", "scrollSnapMarginBottom", "scrollSnapMarginLeft"],
2318
- scrollSnapMarginBlock: ["scrollSnapMarginBlockStart", "scrollSnapMarginBlockEnd"],
2319
- scrollSnapMarginInline: ["scrollSnapMarginInlineStart", "scrollSnapMarginInlineEnd"],
2320
- scrollTimeline: ["scrollTimelineSource", "scrollTimelineOrientation"],
2321
- textDecoration: ["textDecorationLine", "textDecorationStyle", "textDecorationColor"],
2322
- textEmphasis: ["textEmphasisStyle", "textEmphasisColor"],
2323
- transition: ["transitionProperty", "transitionDuration", "transitionTimingFunction", "transitionDelay"]
2324
- };
2325
- }
2326
- });
2327
-
2328
- // src/rules/prefer-atomic-properties.ts
2329
- var RULE_NAME17, rule17, prefer_atomic_properties_default;
2330
- var init_prefer_atomic_properties = __esm({
2331
- "src/rules/prefer-atomic-properties.ts"() {
2332
- "use strict";
2333
- init_esm_shims();
2334
- init_utils();
2335
- init_helpers();
2336
- init_composite_properties();
2337
- init_nodes();
2338
- RULE_NAME17 = "prefer-atomic-properties";
2339
- rule17 = createRule({
2340
- name: RULE_NAME17,
2341
- meta: {
2342
- docs: {
2343
- description: "Encourage the use of atomic properties instead of composite properties in the codebase."
2344
- },
2345
- messages: {
2346
- atomic: "Use atomic properties instead of `{{composite}}`. Prefer: \n{{atomics}}"
2347
- },
2348
- type: "suggestion",
2349
- schema: [
2350
- {
2351
- type: "object",
2352
- properties: {
2353
- whitelist: {
2354
- type: "array",
2355
- items: {
2356
- type: "string",
2357
- minLength: 0
2358
- },
2359
- uniqueItems: true
2360
- }
2361
- },
2362
- additionalProperties: false
2363
- }
2364
- ]
2365
- },
2366
- defaultOptions: [
2367
- {
2368
- whitelist: []
2369
- }
2370
- ],
2371
- create(context) {
2372
- const whitelist = context.options[0]?.whitelist ?? [];
2373
- const longhandCache = /* @__PURE__ */ new Map();
2374
- const getLonghand = (name2) => {
2375
- if (longhandCache.has(name2)) {
2376
- return longhandCache.get(name2);
2377
- }
2378
- const longhand = resolveLonghand(name2, context) ?? name2;
2379
- longhandCache.set(name2, longhand);
2380
- return longhand;
2381
- };
2382
- const compositePropertyCache = /* @__PURE__ */ new Map();
2383
- const resolveCompositeProperty = (name2) => {
2384
- if (compositePropertyCache.has(name2)) {
2385
- return compositePropertyCache.get(name2);
2386
- }
2387
- if (Object.hasOwn(compositeProperties, name2)) {
2388
- compositePropertyCache.set(name2, name2);
2389
- return name2;
2390
- }
2391
- const longhand = getLonghand(name2);
2392
- if (isValidProperty(longhand, context) && Object.hasOwn(compositeProperties, longhand)) {
2393
- compositePropertyCache.set(name2, longhand);
2394
- return longhand;
2395
- }
2396
- compositePropertyCache.set(name2, void 0);
2397
- return void 0;
2398
- };
2399
- const pandaPropCache = /* @__PURE__ */ new WeakMap();
2400
- const isCachedPandaProp = (node) => {
2401
- if (pandaPropCache.has(node)) {
2402
- return pandaPropCache.get(node);
2403
- }
2404
- const result = isPandaProp(node, context);
2405
- pandaPropCache.set(node, result);
2406
- return !!result;
2407
- };
2408
- const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
2409
- const isCachedPandaAttribute = (node) => {
2410
- if (pandaAttributeCache.has(node)) {
2411
- return pandaAttributeCache.get(node);
2412
- }
2413
- const result = isPandaAttribute(node, context);
2414
- pandaAttributeCache.set(node, result);
2415
- return !!result;
2416
- };
2417
- const recipeVariantCache = /* @__PURE__ */ new WeakMap();
2418
- const isCachedRecipeVariant = (node) => {
2419
- if (recipeVariantCache.has(node)) {
2420
- return recipeVariantCache.get(node);
2421
- }
2422
- const result = isRecipeVariant(node, context);
2423
- recipeVariantCache.set(node, result);
2424
- return !!result;
2425
- };
2426
- const sendReport = (node, composite) => {
2427
- if (whitelist.includes(node.name)) return;
2428
- const atomics = compositeProperties[composite].map((name2) => `\`${name2}\``).join(",\n");
2429
- context.report({
2430
- node,
2431
- messageId: "atomic",
2432
- data: {
2433
- composite: node.name,
2434
- atomics
2435
- }
2436
- });
2437
- };
2438
- return {
2439
- JSXAttribute(node) {
2440
- if (!isJSXIdentifier(node.name)) return;
2441
- if (!isCachedPandaProp(node)) return;
2442
- const composite = resolveCompositeProperty(node.name.name);
2443
- if (!composite) return;
2444
- sendReport(node.name, composite);
2445
- },
2446
- Property(node) {
2447
- if (!isIdentifier(node.key)) return;
2448
- if (!isCachedPandaAttribute(node)) return;
2449
- if (isCachedRecipeVariant(node)) return;
2450
- const composite = resolveCompositeProperty(node.key.name);
2451
- if (!composite) return;
2452
- sendReport(node.key, composite);
2453
- }
2454
- };
2455
- }
2456
- });
2457
- prefer_atomic_properties_default = rule17;
2458
- }
2459
- });
2460
-
2461
- // src/rules/prefer-composite-properties.ts
2462
- var RULE_NAME18, rule18, prefer_composite_properties_default;
2463
- var init_prefer_composite_properties = __esm({
2464
- "src/rules/prefer-composite-properties.ts"() {
2465
- "use strict";
2466
- init_esm_shims();
2467
- init_helpers();
2468
- init_utils();
2469
- init_composite_properties();
2470
- init_nodes();
2471
- RULE_NAME18 = "prefer-composite-properties";
2472
- rule18 = createRule({
2473
- name: RULE_NAME18,
2474
- meta: {
2475
- docs: {
2476
- description: "Encourage the use of composite properties instead of atomic properties in the codebase."
2477
- },
2478
- messages: {
2479
- composite: "Use composite property instead of `{{atomic}}`. Prefer: `{{composite}}`."
2480
- },
2481
- type: "suggestion",
2482
- schema: [
2483
- {
2484
- type: "object",
2485
- properties: {
2486
- whitelist: {
2487
- type: "array",
2488
- items: {
2489
- type: "string",
2490
- minLength: 0
2491
- },
2492
- uniqueItems: true
2493
- }
2494
- },
2495
- additionalProperties: false
2496
- }
2497
- ]
2498
- },
2499
- defaultOptions: [
2500
- {
2501
- whitelist: []
2502
- }
2503
- ],
2504
- create(context) {
2505
- const whitelist = context.options[0]?.whitelist ?? [];
2506
- const longhandCache = /* @__PURE__ */ new Map();
2507
- const getLonghand = (name2) => {
2508
- if (longhandCache.has(name2)) {
2509
- return longhandCache.get(name2);
2510
- }
2511
- const longhand = resolveLonghand(name2, context) ?? name2;
2512
- longhandCache.set(name2, longhand);
2513
- return longhand;
2514
- };
2515
- const compositePropertyCache = /* @__PURE__ */ new Map();
2516
- const resolveCompositeProperty = (name2) => {
2517
- if (compositePropertyCache.has(name2)) {
2518
- return compositePropertyCache.get(name2);
2519
- }
2520
- const longhand = getLonghand(name2);
2521
- if (!isValidProperty(longhand, context)) {
2522
- compositePropertyCache.set(name2, void 0);
2523
- return void 0;
2524
- }
2525
- const composite = Object.keys(compositeProperties).find((cpd) => compositeProperties[cpd].includes(longhand));
2526
- compositePropertyCache.set(name2, composite);
2527
- return composite;
2528
- };
2529
- const pandaPropCache = /* @__PURE__ */ new WeakMap();
2530
- const isCachedPandaProp = (node) => {
2531
- if (pandaPropCache.has(node)) {
2532
- return pandaPropCache.get(node);
2533
- }
2534
- const result = isPandaProp(node, context);
2535
- pandaPropCache.set(node, result);
2536
- return !!result;
2537
- };
2538
- const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
2539
- const isCachedPandaAttribute = (node) => {
2540
- if (pandaAttributeCache.has(node)) {
2541
- return pandaAttributeCache.get(node);
2542
- }
2543
- const result = isPandaAttribute(node, context);
2544
- pandaAttributeCache.set(node, result);
2545
- return !!result;
2546
- };
2547
- const recipeVariantCache = /* @__PURE__ */ new WeakMap();
2548
- const isCachedRecipeVariant = (node) => {
2549
- if (recipeVariantCache.has(node)) {
2550
- return recipeVariantCache.get(node);
2551
- }
2552
- const result = isRecipeVariant(node, context);
2553
- recipeVariantCache.set(node, result);
2554
- return !!result;
2555
- };
2556
- const sendReport = (node, composite) => {
2557
- if (whitelist.includes(node.name)) return;
2558
- context.report({
2559
- node,
2560
- messageId: "composite",
2561
- data: {
2562
- composite,
2563
- atomic: node.name
2564
- }
2565
- });
2566
- };
2567
- return {
2568
- JSXAttribute(node) {
2569
- if (!isJSXIdentifier(node.name)) return;
2570
- if (!isCachedPandaProp(node)) return;
2571
- const composite = resolveCompositeProperty(node.name.name);
2572
- if (!composite) return;
2573
- sendReport(node.name, composite);
2574
- },
2575
- Property(node) {
2576
- if (!isIdentifier(node.key)) return;
2577
- if (!isCachedPandaAttribute(node)) return;
2578
- if (isCachedRecipeVariant(node)) return;
2579
- const composite = resolveCompositeProperty(node.key.name);
2580
- if (!composite) return;
2581
- sendReport(node.key, composite);
2582
- }
2583
- };
2584
- }
2585
- });
2586
- prefer_composite_properties_default = rule18;
2587
- }
2588
- });
2589
-
2590
- // src/rules/prefer-unified-property-style.ts
2591
- var RULE_NAME19, rule19, prefer_unified_property_style_default;
2592
- var init_prefer_unified_property_style = __esm({
2593
- "src/rules/prefer-unified-property-style.ts"() {
2594
- "use strict";
2595
- init_esm_shims();
2596
- init_helpers();
2597
- init_utils();
2598
- init_composite_properties();
2599
- init_nodes();
2600
- RULE_NAME19 = "prefer-unified-property-style";
2601
- rule19 = createRule({
2602
- name: RULE_NAME19,
2603
- meta: {
2604
- docs: {
2605
- description: "Discourage mixing atomic and composite forms of the same property in a style declaration. Atomic styles give more consistent results."
2606
- },
2607
- messages: {
2608
- 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."
2609
- },
2610
- type: "suggestion",
2611
- schema: []
2612
- },
2613
- defaultOptions: [],
2614
- create(context) {
2615
- const longhandCache = /* @__PURE__ */ new Map();
2616
- const getLonghand = (name2) => {
2617
- if (longhandCache.has(name2)) {
2618
- return longhandCache.get(name2);
2619
- }
2620
- const longhand = resolveLonghand(name2, context) ?? name2;
2621
- longhandCache.set(name2, longhand);
2622
- return longhand;
2623
- };
2624
- const compositePropertyCache = /* @__PURE__ */ new Map();
2625
- const resolveCompositeProperty = (name2) => {
2626
- if (compositePropertyCache.has(name2)) {
2627
- return compositePropertyCache.get(name2);
2628
- }
2629
- if (name2 in compositeProperties) {
2630
- compositePropertyCache.set(name2, name2);
2631
- return name2;
2632
- }
2633
- const longhand = getLonghand(name2);
2634
- if (isValidProperty(longhand, context) && longhand in compositeProperties) {
2635
- compositePropertyCache.set(name2, longhand);
2636
- return longhand;
2637
- }
2638
- compositePropertyCache.set(name2, void 0);
2639
- return void 0;
2640
- };
2641
- const pandaPropCache = /* @__PURE__ */ new WeakMap();
2642
- const isCachedPandaProp = (node) => {
2643
- if (pandaPropCache.has(node)) {
2644
- return pandaPropCache.get(node);
2645
- }
2646
- const result = isPandaProp(node, context);
2647
- pandaPropCache.set(node, result);
2648
- return !!result;
2649
- };
2650
- const pandaAttributeCache = /* @__PURE__ */ new WeakMap();
2651
- const isCachedPandaAttribute = (node) => {
2652
- if (pandaAttributeCache.has(node)) {
2653
- return pandaAttributeCache.get(node);
2654
- }
2655
- const result = isPandaAttribute(node, context);
2656
- pandaAttributeCache.set(node, result);
2657
- return !!result;
2658
- };
2659
- const recipeVariantCache = /* @__PURE__ */ new WeakMap();
2660
- const isCachedRecipeVariant = (node) => {
2661
- if (recipeVariantCache.has(node)) {
2662
- return recipeVariantCache.get(node);
2663
- }
2664
- const result = isRecipeVariant(node, context);
2665
- recipeVariantCache.set(node, result);
2666
- return !!result;
2667
- };
2668
- const sendReport = (node, composite, siblings) => {
2669
- const atomicPropertiesSet = new Set(
2670
- siblings.filter((prop) => compositeProperties[composite].includes(getLonghand(prop)))
2671
- );
2672
- if (atomicPropertiesSet.size === 0) return;
2673
- const atomicProperties = Array.from(atomicPropertiesSet).map((prop) => `\`${prop}\``).join(", ");
2674
- const atomics = compositeProperties[composite].map((name2) => `\`${name2}\``).join(", ");
2675
- context.report({
2676
- node,
2677
- messageId: "unify",
2678
- data: {
2679
- composite,
2680
- atomicProperties,
2681
- atomics
2682
- }
2683
- });
2684
- };
2685
- return {
2686
- JSXAttribute(node) {
2687
- if (!isJSXIdentifier(node.name)) return;
2688
- if (!isCachedPandaProp(node)) return;
2689
- const composite = resolveCompositeProperty(node.name.name);
2690
- if (!composite) return;
2691
- if (!isJSXOpeningElement(node.parent)) return;
2692
- const siblings = node.parent.attributes.map((attr) => attr.name.name);
2693
- sendReport(node, composite, siblings);
2694
- },
2695
- Property(node) {
2696
- if (!isIdentifier(node.key)) return;
2697
- if (!isCachedPandaAttribute(node)) return;
2698
- if (isCachedRecipeVariant(node)) return;
2699
- const composite = resolveCompositeProperty(node.key.name);
2700
- if (!composite) return;
2701
- if (!isObjectExpression(node.parent)) return;
2702
- const siblings = node.parent.properties.filter((prop) => prop.type === "Property").map((prop) => isIdentifier(prop.key) ? prop.key.name : "");
2703
- sendReport(node.key, composite, siblings);
2704
- }
2705
- };
2706
- }
2707
- });
2708
- prefer_unified_property_style_default = rule19;
2709
- }
2710
- });
2711
-
2712
- // src/rules/index.ts
2713
- var rules;
2714
- var init_rules = __esm({
2715
- "src/rules/index.ts"() {
2716
- "use strict";
2717
- init_esm_shims();
2718
- init_file_not_included();
2719
- init_no_config_function_in_source();
2720
- init_no_debug();
2721
- init_no_deprecated_tokens();
2722
- init_no_dynamic_styling();
2723
- init_no_escape_hatch();
2724
- init_no_hardcoded_color();
2725
- init_no_important();
2726
- init_no_invalid_nesting();
2727
- init_no_invalid_token_paths();
2728
- init_no_margin_properties();
2729
- init_no_physical_properties();
2730
- init_no_property_renaming();
2731
- init_no_unsafe_token_fn_usage();
2732
- init_prefer_longhand_properties();
2733
- init_prefer_shorthand_properties();
2734
- init_prefer_atomic_properties();
2735
- init_prefer_composite_properties();
2736
- init_prefer_unified_property_style();
2737
- rules = {
2738
- [RULE_NAME]: file_not_included_default,
2739
- [RULE_NAME2]: no_config_function_in_source_default,
2740
- [RULE_NAME3]: no_debug_default,
2741
- [RULE_NAME4]: no_deprecated_tokens_default,
2742
- [RULE_NAME5]: no_dynamic_styling_default,
2743
- [RULE_NAME6]: no_escape_hatch_default,
2744
- [RULE_NAME7]: no_hardcoded_color_default,
2745
- [RULE_NAME8]: no_important_default,
2746
- [RULE_NAME10]: no_invalid_token_paths_default,
2747
- [RULE_NAME9]: no_invalid_nesting_default,
2748
- [RULE_NAME11]: no_margin_properties_default,
2749
- [RULE_NAME12]: no_physical_properties_default,
2750
- [RULE_NAME13]: no_property_renaming_default,
2751
- [RULE_NAME14]: no_unsafe_token_fn_usage_default,
2752
- [RULE_NAME15]: prefer_longhand_properties_default,
2753
- [RULE_NAME16]: prefer_shorthand_properties_default,
2754
- [RULE_NAME17]: prefer_atomic_properties_default,
2755
- [RULE_NAME18]: prefer_composite_properties_default,
2756
- [RULE_NAME19]: prefer_unified_property_style_default
2757
- };
2758
- }
2759
- });
2760
-
2761
- // src/configs/all.ts
2762
- var errorRules, allRules, all_default;
2763
- var init_all = __esm({
2764
- "src/configs/all.ts"() {
2765
- "use strict";
2766
- init_esm_shims();
2767
- init_rules();
2768
- init_file_not_included();
2769
- init_no_config_function_in_source();
2770
- init_no_invalid_token_paths();
2771
- errorRules = [RULE_NAME, RULE_NAME2, RULE_NAME10];
2772
- allRules = Object.fromEntries(
2773
- Object.entries(rules).map(([name2]) => {
2774
- return [`@pandacss/${name2}`, errorRules.includes(name2) ? "error" : "warn"];
2775
- })
2776
- );
2777
- all_default = {
2778
- parser: "@typescript-eslint/parser",
2779
- parserOptions: { sourceType: "module" },
2780
- plugins: ["@pandacss"],
2781
- rules: allRules
2782
- };
2783
- }
2784
- });
2785
-
2786
- // src/configs/recommended.ts
2787
- var recommended_default;
2788
- var init_recommended = __esm({
2789
- "src/configs/recommended.ts"() {
2790
- "use strict";
2791
- init_esm_shims();
2792
- recommended_default = {
2793
- parser: "@typescript-eslint/parser",
2794
- parserOptions: { sourceType: "module" },
2795
- plugins: ["@pandacss"],
2796
- rules: {
2797
- "@pandacss/file-not-included": "error",
2798
- "@pandacss/no-config-function-in-source": "error",
2799
- "@pandacss/no-debug": "warn",
2800
- "@pandacss/no-dynamic-styling": "warn",
2801
- "@pandacss/no-hardcoded-color": "warn",
2802
- "@pandacss/no-invalid-nesting": "error",
2803
- "@pandacss/no-invalid-token-paths": "error",
2804
- "@pandacss/no-property-renaming": "warn",
2805
- "@pandacss/no-unsafe-token-fn-usage": "warn",
2806
- "@pandacss/no-deprecated-tokens": "warn"
2807
- }
2808
- };
2809
- }
2810
- });
2811
-
2812
- // src/index.ts
2813
- var require_index = __commonJS({
2814
- "src/index.ts"(exports, module) {
2815
- init_esm_shims();
2816
- init_package();
2817
- init_all();
2818
- init_recommended();
2819
- init_rules();
2820
- var plugin = {
2821
- meta: {
2822
- name,
2823
- version
2824
- },
2825
- rules,
2826
- configs: {
2827
- all: all_default,
2828
- recommended: recommended_default
2829
- }
2830
- };
2831
- module.exports = plugin;
2832
- }
2833
- });
2834
- export default require_index();