@antebudimir/eslint-plugin-vanilla-extract 1.18.0 → 1.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +1 -1
  2. package/dist/css-rules/no-trailing-zero/_tests_/no-trailing-zero.test.js +29 -5
  3. package/dist/css-rules/no-trailing-zero/trailing-zero-processor.js +2 -2
  4. package/dist/css-rules/prefer-logical-properties/logical-properties-processor.js +6 -1
  5. package/dist/css-rules/prefer-theme-tokens/theme-token-processor.js +12 -2
  6. package/dist/css-rules/shared-utils/css-order-fixer.d.ts +7 -3
  7. package/dist/css-rules/shared-utils/css-order-fixer.js +129 -19
  8. package/dist/index.js +1 -1
  9. package/package.json +2 -1
  10. package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.d.ts +0 -2
  11. package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.js +0 -55
  12. package/dist/css-rules/no-px-unit/processor.d.ts +0 -3
  13. package/dist/css-rules/no-px-unit/processor.js +0 -93
  14. package/dist/css-rules/no-px-unit/visitor-creator.d.ts +0 -2
  15. package/dist/css-rules/no-px-unit/visitor-creator.js +0 -55
  16. package/dist/css-rules/sample.css.d.ts +0 -76
  17. package/dist/css-rules/sample.css.js +0 -548
  18. package/dist/demo-bad-example.css.d.ts +0 -4
  19. package/dist/demo-bad-example.css.js +0 -45
  20. package/dist/demo-good-example.css.d.ts +0 -5
  21. package/dist/demo-good-example.css.js +0 -48
  22. package/dist/demo-theme.css.d.ts +0 -37
  23. package/dist/demo-theme.css.js +0 -39
  24. package/dist/sample-bad.css.d.ts +0 -26
  25. package/dist/sample-bad.css.js +0 -85
  26. package/dist/sample-good.css.d.ts +0 -27
  27. package/dist/sample-good.css.js +0 -94
  28. package/dist/sample-theme.css.d.ts +0 -37
  29. package/dist/sample-theme.css.js +0 -38
  30. package/dist/sample.css.d.ts +0 -75
  31. package/dist/sample.css.js +0 -530
package/README.md CHANGED
@@ -694,7 +694,7 @@ export const myStyle = style({
694
694
  padding: '2.5rem',
695
695
  opacity: 1,
696
696
  lineHeight: 2.5,
697
- width: '0',
697
+ width: '0em',
698
698
  transition: 'all 0.3s ease',
699
699
  });
700
700
  ```
@@ -177,11 +177,11 @@ run({
177
177
  import { style } from '@vanilla-extract/css';
178
178
  const myStyle = style({
179
179
  margin: '0',
180
- padding: '0',
181
- width: '0',
180
+ padding: '0px',
181
+ width: '0rem',
182
182
  });
183
183
  `,
184
- name: 'should convert 0.0 to 0',
184
+ name: 'should convert 0.0 to 0, preserving units',
185
185
  },
186
186
  {
187
187
  code: `
@@ -396,7 +396,7 @@ run({
396
396
  const myStyle = style({
397
397
  margin: '-1px',
398
398
  padding: '-2.5rem',
399
- top: '0',
399
+ top: '0vh',
400
400
  });
401
401
  `,
402
402
  name: 'should handle negative values with trailing zeros',
@@ -528,10 +528,34 @@ run({
528
528
  const myStyle = style({
529
529
  margin: '1px',
530
530
  padding: '2.5rem',
531
- width: '0',
531
+ width: '0em',
532
532
  });
533
533
  `,
534
534
  name: 'should handle multiple trailing zeros',
535
535
  },
536
+ {
537
+ code: `
538
+ import { style } from '@vanilla-extract/css';
539
+ const myStyle = style({
540
+ transition: 'all 0.0s ease',
541
+ animation: 'spin 2.0s linear',
542
+ gridTemplateRows: '0.0fr',
543
+ gridTemplateColumns: '1.0fr 0.0fr',
544
+ transform: 'rotate(0.0deg)',
545
+ });
546
+ `,
547
+ errors: 5,
548
+ output: `
549
+ import { style } from '@vanilla-extract/css';
550
+ const myStyle = style({
551
+ transition: 'all 0s ease',
552
+ animation: 'spin 2s linear',
553
+ gridTemplateRows: '0fr',
554
+ gridTemplateColumns: '1fr 0fr',
555
+ transform: 'rotate(0deg)',
556
+ });
557
+ `,
558
+ name: 'should preserve time, fr, and angle units for zero values',
559
+ },
536
560
  ],
537
561
  });
@@ -27,11 +27,11 @@ export const checkTrailingZero = (value) => {
27
27
  return null;
28
28
  }
29
29
  const [, minus = '', integerPart, significantFractional = '', , unit = ''] = match;
30
- // Handle special case: 0.0 or 0.00 etc. should become just "0"
30
+ // Handle special case: 0.0 or 0.00 etc. should become "0" with unit if present
31
31
  if (integerPart === '0' && !significantFractional) {
32
32
  return {
33
33
  hasTrailingZero: true,
34
- fixed: '0',
34
+ fixed: unit ? `0${unit}` : '0',
35
35
  };
36
36
  }
37
37
  // If there's no significant fractional part (e.g., "1.0" -> "1")
@@ -97,7 +97,12 @@ const createPropertyKeyFix = (fixer, property, newPropertyName, context) => {
97
97
  }
98
98
  if (key.type === AST_NODE_TYPES.Literal && typeof key.value === 'string') {
99
99
  // Preserve quote style
100
- const sourceCode = context.getSourceCode();
100
+ // `context.sourceCode` on ESLint v9+/v10+; `getSourceCode()` is the ESLint v8 fallback
101
+ const sourceCode = context.sourceCode ||
102
+ context.getSourceCode?.();
103
+ if (!sourceCode) {
104
+ return null;
105
+ }
101
106
  const originalText = sourceCode.getText(key);
102
107
  const quote = originalText[0];
103
108
  return fixer.replaceText(key, `${quote}${newPropertyName}${quote}`);
@@ -318,7 +318,12 @@ export const processThemeTokensInStyleObject = (context, node, options, analyzer
318
318
  // Check if property value is a TemplateLiteral (e.g., `${rem(4)} ${rem(8)}`)
319
319
  if (checkHelperFunctions && property.value.type === AST_NODE_TYPES.TemplateLiteral) {
320
320
  // Get the source code of the template literal
321
- const sourceCode = context.sourceCode || context.getSourceCode();
321
+ // `context.sourceCode` on ESLint v9+/v10+; `getSourceCode()` is the ESLint v8 fallback
322
+ const sourceCode = context.sourceCode ||
323
+ context.getSourceCode?.();
324
+ if (!sourceCode) {
325
+ return;
326
+ }
322
327
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
323
328
  const templateText = sourceCode.getText(property.value);
324
329
  // Try to evaluate it
@@ -378,7 +383,12 @@ export const processThemeTokensInStyleObject = (context, node, options, analyzer
378
383
  // Check if property value is a CallExpression (e.g., rem(48), clsx(...))
379
384
  if (checkHelperFunctions && property.value.type === AST_NODE_TYPES.CallExpression) {
380
385
  // Get the source code of the call expression
381
- const sourceCode = context.sourceCode || context.getSourceCode();
386
+ // `context.sourceCode` on ESLint v9+/v10+; `getSourceCode()` is the ESLint v8 fallback
387
+ const sourceCode = context.sourceCode ||
388
+ context.getSourceCode?.();
389
+ if (!sourceCode) {
390
+ return;
391
+ }
382
392
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
383
393
  const callExpressionText = sourceCode.getText(property.value);
384
394
  // Try to evaluate it
@@ -10,8 +10,12 @@ import type { Rule } from 'eslint';
10
10
  *
11
11
  * This function performs the following steps:
12
12
  * 1. Sorts the input properties using the provided comparison function.
13
- * 2. Maps the original and sorted properties to their text ranges.
14
- * 3. Creates fix objects for properties whose positions have changed after sorting.
15
- * 4. Returns an array of fixes that, when applied, will reorder the properties correctly.
13
+ * 2. Splits every property into its attachable "chunk" (leading comments,
14
+ * property text, same-line trailing comment).
15
+ * 3. For every file slot whose property changed position, replaces the slot's
16
+ * whole chunk (from its first leading comment to its trailing comma /
17
+ * same-line comment) with the incoming property's chunk, re-adding the
18
+ * trailing comma when required so the result stays syntactically valid.
19
+ * 4. Comments always move together with the property they describe.
16
20
  */
17
21
  export declare const generateFixesForCSSOrder: <T>(eslintFixer: Rule.RuleFixer, ruleContext: Rule.RuleContext, cssProperties: T[], compareProperties: (firstProperty: T, secondProperty: T) => number, extractNode: (property: T) => Rule.Node) => Rule.Fix[];
@@ -1,3 +1,79 @@
1
+ /**
2
+ * Extracts the pieces of source text that belong to a property and should move
3
+ * with it when properties are reordered:
4
+ * 1. The leading comments directly above the property (contiguous block of
5
+ * comments with no blank line separating them from the property).
6
+ * 2. The property node itself.
7
+ * 3. A trailing comment on the same line as the property, if present.
8
+ *
9
+ * Delimiters that belong to the *slot* in the file rather than to the property
10
+ * (the trailing comma, the newlines, the indentation of the first line) are
11
+ * deliberately excluded so that swapping chunk texts between slots always
12
+ * produces valid syntax.
13
+ */
14
+ const createPropertyChunkExtractor = (sourceCode) => {
15
+ // Comments already claimed as trailing comments of an earlier property must
16
+ // not also be claimed as leading comments of the next property.
17
+ const claimedTrailingComments = new Set();
18
+ const extractLeadingComments = (node) => {
19
+ const allCommentsBefore = sourceCode.getCommentsBefore(node);
20
+ if (allCommentsBefore.length === 0) {
21
+ return null;
22
+ }
23
+ // Walk upwards from the property, collecting the contiguous run of
24
+ // comments directly above it (no blank line in between).
25
+ const attachedComments = [];
26
+ let currentEndLine = node.loc.start.line;
27
+ for (let index = allCommentsBefore.length - 1; index >= 0; index--) {
28
+ const comment = allCommentsBefore[index];
29
+ if (!comment || claimedTrailingComments.has(comment)) {
30
+ break;
31
+ }
32
+ // A blank line between the comment and what follows means the comment
33
+ // documents the block, not this specific property.
34
+ if (currentEndLine - comment.loc.end.line > 1) {
35
+ break;
36
+ }
37
+ attachedComments.unshift(comment);
38
+ currentEndLine = comment.loc.start.line;
39
+ }
40
+ if (attachedComments.length === 0) {
41
+ return null;
42
+ }
43
+ // Slice from the first attached comment up to the property start. This
44
+ // includes the newlines and indentation between the comments and before
45
+ // the property, but not the indentation of the first comment's line (the
46
+ // destination slot already provides that indentation).
47
+ const firstComment = attachedComments[0];
48
+ const firstCommentStart = firstComment.range[0];
49
+ const commentsText = sourceCode.text.slice(firstCommentStart, node.range[0]);
50
+ return { start: firstCommentStart, text: commentsText };
51
+ };
52
+ // ESLint attaches a same-line trailing comment to the *following* node's
53
+ // leading comments rather than to this node, so trailing comments are found
54
+ // by scanning all comments for one starting on the property's last line.
55
+ const findTrailingComment = (node) => sourceCode.getAllComments().find((comment) => comment.loc.start.line === node.loc.end.line);
56
+ const extractTrailingCommentText = (node) => {
57
+ const trailingComment = findTrailingComment(node);
58
+ if (!trailingComment) {
59
+ return null;
60
+ }
61
+ claimedTrailingComments.add(trailingComment);
62
+ return sourceCode.text.slice(trailingComment.range[0], trailingComment.range[1]);
63
+ };
64
+ return {
65
+ extractPropertyChunk: (node) => {
66
+ const leadingComments = extractLeadingComments(node);
67
+ return {
68
+ leadingCommentsStart: leadingComments?.start ?? null,
69
+ leadingCommentsText: leadingComments?.text ?? '',
70
+ nodeText: sourceCode.getText(node),
71
+ trailingCommentText: extractTrailingCommentText(node),
72
+ };
73
+ },
74
+ findTrailingComment,
75
+ };
76
+ };
1
77
  /**
2
78
  * Generates ESLint fixes for CSS property ordering violations.
3
79
  * @param eslintFixer The ESLint fixer instance used to create fix objects.
@@ -9,31 +85,65 @@
9
85
  *
10
86
  * This function performs the following steps:
11
87
  * 1. Sorts the input properties using the provided comparison function.
12
- * 2. Maps the original and sorted properties to their text ranges.
13
- * 3. Creates fix objects for properties whose positions have changed after sorting.
14
- * 4. Returns an array of fixes that, when applied, will reorder the properties correctly.
88
+ * 2. Splits every property into its attachable "chunk" (leading comments,
89
+ * property text, same-line trailing comment).
90
+ * 3. For every file slot whose property changed position, replaces the slot's
91
+ * whole chunk (from its first leading comment to its trailing comma /
92
+ * same-line comment) with the incoming property's chunk, re-adding the
93
+ * trailing comma when required so the result stays syntactically valid.
94
+ * 4. Comments always move together with the property they describe.
15
95
  */
16
96
  export const generateFixesForCSSOrder = (eslintFixer, ruleContext, cssProperties, compareProperties, extractNode) => {
17
97
  const sourceCode = ruleContext.sourceCode;
18
98
  // Sort properties using the provided comparison function
19
99
  const sortedProperties = [...cssProperties].sort(compareProperties);
20
- // Map each original property to its text range
21
- const originalPropertyRanges = cssProperties.map((property) => ({
100
+ const { extractPropertyChunk, findTrailingComment } = createPropertyChunkExtractor(sourceCode);
101
+ const chunksByProperty = new Map(cssProperties.map((property) => [
22
102
  property,
23
- range: extractNode(property).range,
24
- }));
25
- // Map sorted properties back to their original range information
26
- const sortedPropertyRanges = sortedProperties.map((property) => originalPropertyRanges.find((rangeInfo) => rangeInfo.property === property));
27
- // Generate fixes for properties that have changed position
28
- return originalPropertyRanges
29
- .map((originalRangeInfo, index) => {
30
- const sortedRangeInfo = sortedPropertyRanges[index];
31
- // Create a fix only if the property's position has changed
32
- if (originalRangeInfo && sortedRangeInfo && originalRangeInfo !== sortedRangeInfo) {
33
- const sortedPropertyText = sourceCode.getText(extractNode(sortedRangeInfo.property));
34
- return eslintFixer.replaceText(extractNode(originalRangeInfo.property), sortedPropertyText);
35
- }
36
- return null;
103
+ extractPropertyChunk(extractNode(property)),
104
+ ]));
105
+ // Generate fixes for slots whose property has changed
106
+ return cssProperties
107
+ .map((slotProperty, slotIndex) => {
108
+ const sortedProperty = sortedProperties[slotIndex];
109
+ if (!sortedProperty || sortedProperty === slotProperty) {
110
+ return null;
111
+ }
112
+ const slotChunk = chunksByProperty.get(slotProperty);
113
+ const sortedChunk = chunksByProperty.get(sortedProperty);
114
+ if (!slotChunk || !sortedChunk) {
115
+ return null;
116
+ }
117
+ const slotNode = extractNode(slotProperty);
118
+ // The replacement range spans the slot's whole attachable chunk: from
119
+ // its first leading comment (if any) to the end of its trailing comma
120
+ // and/or same-line trailing comment. This consumes the original
121
+ // comments and punctuation so they are neither left behind nor doubled.
122
+ const rangeStart = slotChunk.leadingCommentsStart ?? slotNode.range[0];
123
+ let rangeEnd = slotNode.range[1];
124
+ const tokenAfter = sourceCode.getTokenAfter(slotNode);
125
+ if (tokenAfter && tokenAfter.value === ',' && tokenAfter.range[1] > rangeEnd) {
126
+ rangeEnd = tokenAfter.range[1];
127
+ }
128
+ if (slotChunk.trailingCommentText !== null) {
129
+ const trailingComment = findTrailingComment(slotNode);
130
+ if (trailingComment && trailingComment.range[1] > rangeEnd) {
131
+ rangeEnd = trailingComment.range[1];
132
+ }
133
+ }
134
+ // Rebuild the incoming property's text, preserving the slot's comma
135
+ // convention: if the original property in this slot had a trailing
136
+ // comma, keep one; if not (typically the object's last property), don't.
137
+ const slotHadTrailingComma = tokenAfter?.value === ',';
138
+ const replacementText = [
139
+ sortedChunk.leadingCommentsText,
140
+ sortedChunk.nodeText,
141
+ slotHadTrailingComma ? ',' : '',
142
+ sortedChunk.trailingCommentText !== null
143
+ ? `${slotHadTrailingComma ? ' ' : ''}${sortedChunk.trailingCommentText}`
144
+ : '',
145
+ ].join('');
146
+ return eslintFixer.replaceTextRange([rangeStart, rangeEnd], replacementText);
37
147
  })
38
148
  .filter((fix) => fix !== null);
39
149
  };
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import preferThemeTokensRule from './css-rules/prefer-theme-tokens/index.js';
12
12
  const vanillaExtract = {
13
13
  meta: {
14
14
  name: '@antebudimir/eslint-plugin-vanilla-extract',
15
- version: '1.18.0',
15
+ version: '1.18.2',
16
16
  },
17
17
  rules: {
18
18
  'alphabetical-order': alphabeticalOrderRule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antebudimir/eslint-plugin-vanilla-extract",
3
- "version": "1.18.0",
3
+ "version": "1.18.2",
4
4
  "description": "Comprehensive ESLint plugin for vanilla-extract with CSS property ordering, style validation, and best practices enforcement. Supports alphabetical, concentric and custom CSS ordering, auto-fixing, and zero-runtime safety.",
5
5
  "author": "Ante Budimir",
6
6
  "license": "MIT",
@@ -80,6 +80,7 @@
80
80
  "test": "vitest run",
81
81
  "test:watch": "vitest",
82
82
  "test:coverage": "vitest run --coverage",
83
+ "test:integration": "bash scripts/integration-test.sh",
83
84
  "typecheck": "tsc --noEmit",
84
85
  "version:update": "node scripts/update-version.mjs"
85
86
  }
@@ -1,2 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- export declare const createNoPxUnitVisitors: (context: Rule.RuleContext) => Rule.RuleListener;
@@ -1,55 +0,0 @@
1
- import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
- import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
3
- import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
4
- import { processStyleNode } from '../shared-utils/style-node-processor.js';
5
- import { processNoPxUnitInStyleObject } from './processor.js';
6
- export const createNoPxUnitVisitors = (context) => {
7
- const tracker = new ReferenceTracker();
8
- const trackingVisitor = createReferenceTrackingVisitor(tracker);
9
- const options = context.options?.[0] || {};
10
- const allowSet = new Set((options.allow ?? []).map((s) => s));
11
- const process = (ctx, obj) => processNoPxUnitInStyleObject(ctx, obj, allowSet);
12
- return {
13
- ...trackingVisitor,
14
- CallExpression(node) {
15
- if (node.callee.type !== AST_NODE_TYPES.Identifier)
16
- return;
17
- const functionName = node.callee.name;
18
- if (!tracker.isTrackedFunction(functionName))
19
- return;
20
- const originalName = tracker.getOriginalName(functionName);
21
- if (!originalName)
22
- return;
23
- switch (originalName) {
24
- case 'fontFace':
25
- if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
26
- process(context, node.arguments[0]);
27
- }
28
- break;
29
- case 'globalFontFace':
30
- if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
31
- process(context, node.arguments[1]);
32
- }
33
- break;
34
- case 'style':
35
- case 'styleVariants':
36
- case 'keyframes':
37
- if (node.arguments.length > 0) {
38
- processStyleNode(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
39
- }
40
- break;
41
- case 'globalStyle':
42
- case 'globalKeyframes':
43
- if (node.arguments.length >= 2) {
44
- processStyleNode(context, node.arguments[1], (ctx, obj) => process(ctx, obj));
45
- }
46
- break;
47
- case 'recipe':
48
- if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
49
- processRecipeProperties(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
50
- }
51
- break;
52
- }
53
- },
54
- };
55
- };
@@ -1,3 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import { TSESTree } from '@typescript-eslint/utils';
3
- export declare const processNoPxUnitInStyleObject: (context: Rule.RuleContext, node: TSESTree.ObjectExpression, allowSet: Set<string>) => void;
@@ -1,93 +0,0 @@
1
- import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
- const containsPx = (text) => /(^|\W)-?\d*\.?\d*px(?![a-zA-Z])/i.test(text);
3
- const replacePxWith = (text, replacement) => text.replace(/px(?![a-zA-Z])/g, replacement);
4
- const toKebab = (name) => name.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
5
- const getValueText = (node) => {
6
- if (node.type === AST_NODE_TYPES.Literal && typeof node.value === 'string') {
7
- return node.value;
8
- }
9
- if (node.type === AST_NODE_TYPES.TemplateLiteral) {
10
- // Join all quasis (ignore expressions content)
11
- const raw = node.quasis.map((q) => q.value.raw ?? '').join('');
12
- return raw;
13
- }
14
- return null;
15
- };
16
- const canSuggestFix = (node) => {
17
- if (node.type === AST_NODE_TYPES.Literal && typeof node.value === 'string')
18
- return 'literal';
19
- if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0)
20
- return 'simple-template';
21
- return null;
22
- };
23
- export const processNoPxUnitInStyleObject = (context, node, allowSet) => {
24
- for (const property of node.properties) {
25
- if (property.type !== AST_NODE_TYPES.Property)
26
- continue;
27
- // Determine property name when possible
28
- let propertyName = null;
29
- if (property.key.type === AST_NODE_TYPES.Identifier) {
30
- propertyName = property.key.name;
31
- }
32
- else if (property.key.type === AST_NODE_TYPES.Literal && typeof property.key.value === 'string') {
33
- propertyName = property.key.value;
34
- }
35
- // Recurse into known nested containers
36
- if (propertyName === '@media' || propertyName === 'selectors') {
37
- if (property.value.type === AST_NODE_TYPES.ObjectExpression) {
38
- for (const nested of property.value.properties) {
39
- if (nested.type === AST_NODE_TYPES.Property && nested.value.type === AST_NODE_TYPES.ObjectExpression) {
40
- processNoPxUnitInStyleObject(context, nested.value, allowSet);
41
- }
42
- }
43
- }
44
- continue;
45
- }
46
- // Traverse any nested object
47
- if (property.value.type === AST_NODE_TYPES.ObjectExpression) {
48
- processNoPxUnitInStyleObject(context, property.value, allowSet);
49
- continue;
50
- }
51
- // Skip if property is whitelisted (supports both camelCase and kebab-case)
52
- if (propertyName) {
53
- const kebab = toKebab(propertyName);
54
- if (allowSet.has(propertyName) || allowSet.has(kebab)) {
55
- continue;
56
- }
57
- }
58
- // Check string or template literal values
59
- const text = getValueText(property.value);
60
- if (text && containsPx(text)) {
61
- const fixability = canSuggestFix(property.value);
62
- context.report({
63
- node: property.value,
64
- messageId: 'noPxUnit',
65
- suggest: fixability
66
- ? [
67
- {
68
- messageId: 'removePx',
69
- fix: (fixer) => {
70
- const newText = replacePxWith(text, '');
71
- if (fixability === 'literal') {
72
- return fixer.replaceText(property.value, `'${newText}'`);
73
- }
74
- // simple template with no expressions
75
- return fixer.replaceText(property.value, `\`${newText}\``);
76
- },
77
- },
78
- {
79
- messageId: 'replaceWithRem',
80
- fix: (fixer) => {
81
- const newText = replacePxWith(text, 'rem');
82
- if (fixability === 'literal') {
83
- return fixer.replaceText(property.value, `'${newText}'`);
84
- }
85
- return fixer.replaceText(property.value, `\`${newText}\``);
86
- },
87
- },
88
- ]
89
- : undefined,
90
- });
91
- }
92
- }
93
- };
@@ -1,2 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- export declare const createNoPxUnitVisitors: (context: Rule.RuleContext) => Rule.RuleListener;
@@ -1,55 +0,0 @@
1
- import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
- import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
3
- import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
4
- import { processStyleNode } from '../shared-utils/style-node-processor.js';
5
- import { processNoPxUnitInStyleObject } from './processor.js';
6
- export const createNoPxUnitVisitors = (context) => {
7
- const tracker = new ReferenceTracker();
8
- const trackingVisitor = createReferenceTrackingVisitor(tracker);
9
- const options = context.options?.[0] || {};
10
- const allowSet = new Set((options.allow ?? []).map((s) => s));
11
- const process = (ctx, obj) => processNoPxUnitInStyleObject(ctx, obj, allowSet);
12
- return {
13
- ...trackingVisitor,
14
- CallExpression(node) {
15
- if (node.callee.type !== AST_NODE_TYPES.Identifier)
16
- return;
17
- const functionName = node.callee.name;
18
- if (!tracker.isTrackedFunction(functionName))
19
- return;
20
- const originalName = tracker.getOriginalName(functionName);
21
- if (!originalName)
22
- return;
23
- switch (originalName) {
24
- case 'fontFace':
25
- if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
26
- process(context, node.arguments[0]);
27
- }
28
- break;
29
- case 'globalFontFace':
30
- if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
31
- process(context, node.arguments[1]);
32
- }
33
- break;
34
- case 'style':
35
- case 'styleVariants':
36
- case 'keyframes':
37
- if (node.arguments.length > 0) {
38
- processStyleNode(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
39
- }
40
- break;
41
- case 'globalStyle':
42
- case 'globalKeyframes':
43
- if (node.arguments.length >= 2) {
44
- processStyleNode(context, node.arguments[1], (ctx, obj) => process(ctx, obj));
45
- }
46
- break;
47
- case 'recipe':
48
- if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
49
- processRecipeProperties(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
50
- }
51
- break;
52
- }
53
- },
54
- };
55
- };
@@ -1,76 +0,0 @@
1
- export declare const theFont: string;
2
- export declare const spinster: void;
3
- export declare const buttonWrapper: string;
4
- export declare const starter: string;
5
- export declare const accordionContent: import("@vanilla-extract/recipes").RuntimeFn<{
6
- isOpen: {
7
- false: {
8
- boxSizing: "inherit";
9
- position: "relative";
10
- right: "inherit";
11
- display: "flex";
12
- gap: "revert";
13
- transform: "none";
14
- margin: "11rem";
15
- outline: "none";
16
- border: "Background";
17
- borderRight: "ActiveBorder";
18
- borderLeft: "ActiveBorder";
19
- borderRadius: "initial";
20
- borderBottomLeftRadius: "initial";
21
- borderBottomRightRadius: "initial";
22
- boxShadow: "none";
23
- backgroundColor: "initial";
24
- cursor: "pointer";
25
- width: "100%";
26
- color: "red";
27
- fontSize: "large";
28
- };
29
- true: {
30
- boxSizing: "inherit";
31
- position: "relative";
32
- right: "inherit";
33
- display: "flex";
34
- gap: "revert";
35
- transform: "none";
36
- margin: "11rem";
37
- outline: "none";
38
- border: "Background";
39
- borderRight: "ActiveBorder";
40
- borderLeft: "ActiveBorder";
41
- borderRadius: "initial";
42
- borderBottomLeftRadius: "initial";
43
- borderBottomRightRadius: "initial";
44
- boxShadow: "none";
45
- backgroundColor: "initial";
46
- cursor: "pointer";
47
- width: "100%";
48
- color: "red";
49
- fontSize: "large";
50
- ':hover': {
51
- boxSizing: "inherit";
52
- position: "relative";
53
- right: "inherit";
54
- display: "flex";
55
- gap: "revert";
56
- transform: "none";
57
- margin: "11rem";
58
- outline: "none";
59
- border: "Background";
60
- borderRight: "ActiveBorder";
61
- borderLeft: "ActiveBorder";
62
- borderRadius: "initial";
63
- borderBottomLeftRadius: "initial";
64
- borderBottomRightRadius: "initial";
65
- boxShadow: "none";
66
- backgroundColor: "initial";
67
- cursor: "pointer";
68
- width: "100%";
69
- color: "red";
70
- fontSize: "large";
71
- };
72
- };
73
- };
74
- }>;
75
- export declare const item: string;
76
- export declare const selectButtonVariants: Record<"bordered" | "borderless", string>;