@antebudimir/eslint-plugin-vanilla-extract 1.4.0 → 1.4.6

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 (68) hide show
  1. package/README.md +7 -3
  2. package/dist/css-rules/alphabetical-order/__tests__/animation.test.js +108 -0
  3. package/dist/css-rules/alphabetical-order/__tests__/font-face.test.js +138 -0
  4. package/dist/css-rules/alphabetical-order/__tests__/global.test.js +51 -0
  5. package/dist/css-rules/alphabetical-order/__tests__/recipe.test.js +91 -0
  6. package/dist/css-rules/alphabetical-order/__tests__/style.test.d.ts +1 -0
  7. package/dist/css-rules/alphabetical-order/__tests__/style.test.js +108 -0
  8. package/dist/css-rules/alphabetical-order/__tests__/variants.test.d.ts +1 -0
  9. package/dist/css-rules/alphabetical-order/__tests__/variants.test.js +63 -0
  10. package/dist/css-rules/concentric-order/__tests__/animation.test.d.ts +1 -0
  11. package/dist/css-rules/concentric-order/__tests__/animation.test.js +69 -0
  12. package/dist/css-rules/concentric-order/__tests__/font-face.test.d.ts +1 -0
  13. package/dist/css-rules/concentric-order/__tests__/font-face.test.js +94 -0
  14. package/dist/css-rules/concentric-order/__tests__/global.test.d.ts +1 -0
  15. package/dist/css-rules/concentric-order/__tests__/global.test.js +57 -0
  16. package/dist/css-rules/concentric-order/__tests__/recipe.test.d.ts +1 -0
  17. package/dist/css-rules/concentric-order/__tests__/recipe.test.js +100 -0
  18. package/dist/css-rules/concentric-order/__tests__/style.test.d.ts +1 -0
  19. package/dist/css-rules/concentric-order/__tests__/style.test.js +126 -0
  20. package/dist/css-rules/concentric-order/__tests__/variants.test.d.ts +1 -0
  21. package/dist/css-rules/concentric-order/__tests__/variants.test.js +133 -0
  22. package/dist/css-rules/custom-order/__tests__/animation.test.d.ts +1 -0
  23. package/dist/css-rules/custom-order/__tests__/animation.test.js +148 -0
  24. package/dist/css-rules/custom-order/__tests__/font-face.test.d.ts +1 -0
  25. package/dist/css-rules/custom-order/__tests__/font-face.test.js +124 -0
  26. package/dist/css-rules/custom-order/__tests__/global.test.d.ts +1 -0
  27. package/dist/css-rules/custom-order/__tests__/global.test.js +124 -0
  28. package/dist/css-rules/custom-order/__tests__/recipe.test.d.ts +1 -0
  29. package/dist/css-rules/custom-order/__tests__/recipe.test.js +208 -0
  30. package/dist/css-rules/custom-order/__tests__/style.test.d.ts +1 -0
  31. package/dist/css-rules/custom-order/__tests__/style.test.js +249 -0
  32. package/dist/css-rules/custom-order/__tests__/variants.test.d.ts +1 -0
  33. package/dist/css-rules/custom-order/__tests__/variants.test.js +184 -0
  34. package/dist/css-rules/shared-utils/__tests__/css-property-priority-map.test.d.ts +1 -0
  35. package/dist/css-rules/shared-utils/__tests__/css-property-priority-map.test.js +37 -0
  36. package/dist/css-rules/shared-utils/__tests__/font-face-property-order-enforcer.test.d.ts +1 -0
  37. package/dist/css-rules/shared-utils/__tests__/font-face-property-order-enforcer.test.js +58 -0
  38. package/dist/css-rules/shared-utils/__tests__/order-strategy-visitor-creator.test.d.ts +1 -0
  39. package/dist/css-rules/shared-utils/__tests__/order-strategy-visitor-creator.test.js +125 -0
  40. package/dist/css-rules/shared-utils/__tests__/property-name-extractor.test.d.ts +1 -0
  41. package/dist/css-rules/shared-utils/__tests__/property-name-extractor.test.js +53 -0
  42. package/dist/css-rules/shared-utils/__tests__/recipe-property-processor.test.d.ts +1 -0
  43. package/dist/css-rules/shared-utils/__tests__/recipe-property-processor.test.js +116 -0
  44. package/dist/css-rules/shared-utils/__tests__/style-node-processor.test.d.ts +1 -0
  45. package/dist/css-rules/shared-utils/__tests__/style-node-processor.test.js +55 -0
  46. package/dist/css-rules/shared-utils/__tests__/test-property-name-rule.d.ts +3 -0
  47. package/dist/css-rules/shared-utils/__tests__/test-property-name-rule.js +30 -0
  48. package/dist/css-rules/shared-utils/order-strategy-visitor-creator.d.ts +4 -3
  49. package/dist/css-rules/shared-utils/order-strategy-visitor-creator.js +5 -4
  50. package/dist/css-rules/shared-utils/style-node-processor.js +2 -5
  51. package/dist/index.js +1 -1
  52. package/package.json +10 -3
  53. package/dist/css-rules/shared-utils/font-face-style-processor.d.ts +0 -10
  54. package/dist/css-rules/shared-utils/font-face-style-processor.js +0 -17
  55. package/dist/css-rules/theme-tokens/ast-helpers.d.ts +0 -12
  56. package/dist/css-rules/theme-tokens/ast-helpers.js +0 -80
  57. package/dist/css-rules/theme-tokens/index.d.ts +0 -2
  58. package/dist/css-rules/theme-tokens/index.js +0 -2
  59. package/dist/css-rules/theme-tokens/rule-definition.d.ts +0 -3
  60. package/dist/css-rules/theme-tokens/rule-definition.js +0 -29
  61. package/dist/css-rules/theme-tokens/theme-loader.d.ts +0 -10
  62. package/dist/css-rules/theme-tokens/theme-loader.js +0 -71
  63. package/dist/css-rules/theme-tokens/theme-token-visitor.d.ts +0 -2
  64. package/dist/css-rules/theme-tokens/theme-token-visitor.js +0 -113
  65. /package/dist/css-rules/{theme-tokens/theme-tokens-enforcer.d.ts → alphabetical-order/__tests__/animation.test.d.ts} +0 -0
  66. /package/dist/css-rules/{theme-tokens/theme-tokens-enforcer.js → alphabetical-order/__tests__/font-face.test.d.ts} +0 -0
  67. /package/dist/css-rules/{theme-tokens/value-comparison.d.ts → alphabetical-order/__tests__/global.test.d.ts} +0 -0
  68. /package/dist/css-rules/{theme-tokens/value-comparison.js → alphabetical-order/__tests__/recipe.test.d.ts} +0 -0
@@ -0,0 +1,53 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import testRuleForPropertyNameExtractor from './test-property-name-rule.js';
4
+ run({
5
+ name: 'vanilla-extract/property-name-extractor-tests',
6
+ rule: testRuleForPropertyNameExtractor,
7
+ languageOptions: {
8
+ parser: tsParser,
9
+ parserOptions: {
10
+ ecmaVersion: 2022,
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ valid: [
15
+ // Test for identifier and string literal keys (should return names)
16
+ `
17
+ import { style } from '@vanilla-extract/css';
18
+
19
+ const myStyle = style({
20
+ color: 'blue',
21
+ 'background-color': 'white',
22
+ fontSize: '16px'
23
+ });
24
+ `,
25
+ // Test for computed property with non-string literal (should return empty string)
26
+ `
27
+ import { style } from '@vanilla-extract/css';
28
+
29
+ const myStyle = style({
30
+ [42]: 'numeric key',
31
+ [true]: 'boolean key'
32
+ });
33
+ `,
34
+ // Test for computed property with complex expression
35
+ `
36
+ import { style } from '@vanilla-extract/css';
37
+
38
+ const myStyle = style({
39
+ [Math.random() > 0.5 ? 'dynamicKey' : 'otherKey']: 'dynamic value'
40
+ });
41
+ `,
42
+ // Test for property with template literal key
43
+ `
44
+ import { style } from '@vanilla-extract/css';
45
+
46
+ const prefix = 'webkit';
47
+ const myStyle = style({
48
+ [\`-\${prefix}-appearance\`]: 'none'
49
+ });
50
+ `,
51
+ ],
52
+ invalid: [],
53
+ });
@@ -0,0 +1,116 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import alphabeticalOrderRule from '../../alphabetical-order/rule-definition.js';
4
+ run({
5
+ name: 'vanilla-extract/recipe-property-processor-tests',
6
+ rule: alphabeticalOrderRule,
7
+ languageOptions: {
8
+ parser: tsParser,
9
+ parserOptions: {
10
+ ecmaVersion: 2022,
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ valid: [
15
+ // Test for recipe with spread element (should trigger the early return)
16
+ `
17
+ import { recipe } from '@vanilla-extract/recipes';
18
+ import { style } from '@vanilla-extract/css';
19
+
20
+ const baseStyle = style({ backgroundColor: 'blue', color: 'white' });
21
+
22
+ const myRecipe = recipe({
23
+ base: baseStyle,
24
+ ...{ someSpreadProperty: true },
25
+ variants: {
26
+ size: {
27
+ small: style({ fontSize: '1.2rem', padding: '4rem' }),
28
+ large: style({ fontSize: '1.8rem', padding: '12rem' })
29
+ }
30
+ }
31
+ });
32
+ `,
33
+ // Test for recipe with computed property (non-Identifier key)
34
+ `
35
+ import { recipe } from '@vanilla-extract/recipes';
36
+ import { style } from '@vanilla-extract/css';
37
+
38
+ const propName = 'dynamicProp';
39
+ const baseStyle = style({ backgroundColor: 'blue', color: 'white' });
40
+
41
+ const myRecipe = recipe({
42
+ base: baseStyle,
43
+ [propName]: style({ fontSize: '1.4rem' }),
44
+ variants: {
45
+ size: {
46
+ small: style({ fontSize: '1.2rem', padding: '4rem' }),
47
+ large: style({ fontSize: '1.8rem', padding: '12rem' })
48
+ }
49
+ }
50
+ });
51
+ `,
52
+ // Test for recipe with non-object values (should skip processing)
53
+ `
54
+ import { recipe } from '@vanilla-extract/recipes';
55
+ import { style } from '@vanilla-extract/css';
56
+
57
+ const baseStyle = style({ backgroundColor: 'blue', color: 'white' });
58
+
59
+ const myRecipe = recipe({
60
+ base: baseStyle,
61
+ nonObjectProp: 'string value',
62
+ numericProp: 42,
63
+ booleanProp: true,
64
+ nullProp: null,
65
+ variants: {
66
+ size: {
67
+ small: style({ fontSize: '1.2rem', padding: '4rem' }),
68
+ large: style({ fontSize: '1.8rem', padding: '12rem' })
69
+ }
70
+ }
71
+ });
72
+ `,
73
+ ],
74
+ invalid: [
75
+ // Basic recipe with incorrect ordering in style calls
76
+ {
77
+ code: `
78
+ import { recipe } from '@vanilla-extract/recipes';
79
+ import { style } from '@vanilla-extract/css';
80
+
81
+ const baseStyle = style({ color: 'blue', backgroundColor: 'white' });
82
+
83
+ const myRecipe = recipe({
84
+ base: baseStyle,
85
+ variants: {
86
+ size: {
87
+ small: style({ padding: '4rem', fontSize: '1.2rem' }),
88
+ large: style({ padding: '12rem', fontSize: '1.8rem' })
89
+ }
90
+ }
91
+ });
92
+ `,
93
+ errors: [
94
+ { messageId: 'alphabeticalOrder' },
95
+ { messageId: 'alphabeticalOrder' },
96
+ { messageId: 'alphabeticalOrder' },
97
+ ],
98
+ output: `
99
+ import { recipe } from '@vanilla-extract/recipes';
100
+ import { style } from '@vanilla-extract/css';
101
+
102
+ const baseStyle = style({ backgroundColor: 'white', color: 'blue' });
103
+
104
+ const myRecipe = recipe({
105
+ base: baseStyle,
106
+ variants: {
107
+ size: {
108
+ small: style({ fontSize: '1.2rem', padding: '4rem' }),
109
+ large: style({ fontSize: '1.8rem', padding: '12rem' })
110
+ }
111
+ }
112
+ });
113
+ `,
114
+ },
115
+ ],
116
+ });
@@ -0,0 +1,55 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import alphabeticalOrderRule from '../../alphabetical-order/rule-definition.js';
4
+ run({
5
+ name: 'vanilla-extract/style-node-processor-tests',
6
+ rule: alphabeticalOrderRule,
7
+ languageOptions: {
8
+ parser: tsParser,
9
+ parserOptions: {
10
+ ecmaVersion: 2022,
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ valid: [
15
+ // Test for empty array
16
+ `
17
+ import { style } from '@vanilla-extract/css';
18
+
19
+ const emptyStyle = style([]);
20
+ `,
21
+ // Test for null/undefined handling
22
+ `
23
+ import { style } from '@vanilla-extract/css';
24
+
25
+ const dynamicStyle = style(undefined);
26
+ const nullStyle = style(null);
27
+ `,
28
+ ],
29
+ invalid: [
30
+ // Test for array with mixed content
31
+ {
32
+ code: `
33
+ import { style } from '@vanilla-extract/css';
34
+
35
+ const myStyle = style([
36
+ { zIndex: 1, position: 'relative' },
37
+ null,
38
+ undefined,
39
+ { display: 'flex', alignItems: 'center' }
40
+ ]);
41
+ `,
42
+ errors: [{ messageId: 'alphabeticalOrder' }, { messageId: 'alphabeticalOrder' }],
43
+ output: `
44
+ import { style } from '@vanilla-extract/css';
45
+
46
+ const myStyle = style([
47
+ { position: 'relative', zIndex: 1 },
48
+ null,
49
+ undefined,
50
+ { alignItems: 'center', display: 'flex' }
51
+ ]);
52
+ `,
53
+ },
54
+ ],
55
+ });
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const testRuleForPropertyNameExtractor: Rule.RuleModule;
3
+ export default testRuleForPropertyNameExtractor;
@@ -0,0 +1,30 @@
1
+ import { getPropertyName } from '../property-separator.js';
2
+ const testRuleForPropertyNameExtractor = {
3
+ meta: {
4
+ type: 'suggestion',
5
+ docs: {
6
+ description: 'enforce test rule for property name extraction',
7
+ category: 'Stylistic Issues',
8
+ recommended: false,
9
+ },
10
+ fixable: undefined,
11
+ schema: [],
12
+ messages: {
13
+ emptyName: 'Property name extraction returned an empty string for this property',
14
+ },
15
+ },
16
+ create() {
17
+ return {
18
+ ObjectExpression(node) {
19
+ // Extract property names without enforcing any order
20
+ node.properties.forEach((property) => {
21
+ if (property.type === 'Property') {
22
+ // Test the getPropertyName function
23
+ getPropertyName(property);
24
+ }
25
+ });
26
+ },
27
+ };
28
+ },
29
+ };
30
+ export default testRuleForPropertyNameExtractor;
@@ -8,9 +8,10 @@ import type { Rule } from 'eslint';
8
8
  * @returns An object with visitor functions for the ESLint rule.
9
9
  *
10
10
  * This function sets up visitors for the following cases:
11
- * 1. Style-related functions: 'style', 'styleVariants', 'createVar', 'createTheme', 'createThemeContract'
12
- * 2. The 'globalStyle' function
13
- * 3. The 'recipe' function
11
+ * 1. The fontFace and globalFontFace functions.
12
+ * 2. Style-related functions: 'keyframes', 'style', 'styleVariants'.
13
+ * 3. The 'globalStyle' and 'globalKeyframes' function
14
+ * 4. The 'recipe' function
14
15
  *
15
16
  * Each visitor applies the appropriate ordering strategy to the style objects in these function calls.
16
17
  */
@@ -16,9 +16,10 @@ import { processStyleNode } from './style-node-processor.js';
16
16
  * @returns An object with visitor functions for the ESLint rule.
17
17
  *
18
18
  * This function sets up visitors for the following cases:
19
- * 1. Style-related functions: 'style', 'styleVariants', 'createVar', 'createTheme', 'createThemeContract'
20
- * 2. The 'globalStyle' function
21
- * 3. The 'recipe' function
19
+ * 1. The fontFace and globalFontFace functions.
20
+ * 2. Style-related functions: 'keyframes', 'style', 'styleVariants'.
21
+ * 3. The 'globalStyle' and 'globalKeyframes' function
22
+ * 4. The 'recipe' function
22
23
  *
23
24
  * Each visitor applies the appropriate ordering strategy to the style objects in these function calls.
24
25
  */
@@ -58,7 +59,7 @@ export const createNodeVisitors = (ruleContext, orderingStrategy, userDefinedGro
58
59
  return;
59
60
  }
60
61
  // Handle style-related functions
61
- if (['createThemeContract', 'createVar', 'createTheme', 'keyframes', 'style', 'styleVariants'].includes(node.callee.name)) {
62
+ if (['keyframes', 'style', 'styleVariants'].includes(node.callee.name)) {
62
63
  if (node.arguments.length > 0) {
63
64
  const styleArguments = node.arguments[0];
64
65
  processStyleNode(ruleContext, styleArguments, processProperty);
@@ -6,13 +6,10 @@ import { TSESTree } from '@typescript-eslint/utils';
6
6
  * @param processProperty A function to process each object expression.
7
7
  */
8
8
  export const processStyleNode = (ruleContext, node, processProperty) => {
9
- if (!node) {
10
- return;
11
- }
12
- if (node.type === 'ObjectExpression') {
9
+ if (node?.type === 'ObjectExpression') {
13
10
  processProperty(ruleContext, node);
14
11
  }
15
- if (node.type === 'ArrayExpression') {
12
+ if (node?.type === 'ArrayExpression') {
16
13
  node.elements.forEach((element) => {
17
14
  if (element && element.type === 'ObjectExpression') {
18
15
  processProperty(ruleContext, element);
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import customOrderRule from './css-rules/custom-order/rule-definition.js';
4
4
  export const vanillaExtract = {
5
5
  meta: {
6
6
  name: '@antebudimir/eslint-plugin-vanilla-extract',
7
- version: '1.4.0',
7
+ version: '1.4.6',
8
8
  },
9
9
  rules: {
10
10
  'alphabetical-order': alphabeticalOrderRule,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@antebudimir/eslint-plugin-vanilla-extract",
3
- "version": "1.4.0",
4
- "description": "ESLint plugin for enforcing CSS ordering in vanilla-extract styles",
3
+ "version": "1.4.6",
4
+ "description": "ESLint plugin for enforcing best practices in vanilla-extract CSS styles, including CSS property ordering and additional linting rules.",
5
5
  "author": "Ante Budimir",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -51,22 +51,29 @@
51
51
  "@types/node": "^20.17.19",
52
52
  "@typescript-eslint/eslint-plugin": "^8.25.0",
53
53
  "@typescript-eslint/parser": "^8.25.0",
54
+ "@typescript-eslint/rule-tester": "^8.26.0",
54
55
  "@typescript-eslint/utils": "^8.25.0",
55
56
  "@vanilla-extract/css": "^1.17.1",
56
57
  "@vanilla-extract/recipes": "^0.5.5",
58
+ "@vitest/coverage-v8": "3.0.8",
57
59
  "eslint": "^9.21.0",
58
60
  "eslint-config-prettier": "^10.0.2",
59
61
  "eslint-import-resolver-typescript": "^3.8.3",
60
62
  "eslint-plugin-eslint-plugin": "^6.4.0",
61
63
  "eslint-plugin-import": "^2.31.0",
64
+ "eslint-vitest-rule-tester": "^1.1.0",
62
65
  "prettier": "^3.5.2",
63
66
  "typescript": "^5.7.3",
64
- "typescript-eslint": "^8.25.0"
67
+ "typescript-eslint": "^8.25.0",
68
+ "vitest": "^3.0.8"
65
69
  },
66
70
  "scripts": {
67
71
  "build": "tsc",
68
72
  "format": "prettier --write .",
69
73
  "lint": "eslint src --ext .ts --fix --max-warnings 0",
74
+ "test": "vitest run",
75
+ "test:watch": "vitest",
76
+ "test:coverage": "vitest run --coverage",
70
77
  "typecheck": "tsc --noEmit",
71
78
  "version:update": "node scripts/update-version.mjs"
72
79
  }
@@ -1,10 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import { TSESTree } from '@typescript-eslint/utils';
3
- /**
4
- * Processes a font face style object to enforce special ordering:
5
- * 'src' first, then other properties alphabetically.
6
- *
7
- * @param ruleContext The ESLint rule context for reporting and fixing issues.
8
- * @param styleObject The object expression representing the style object.
9
- */
10
- export declare const enforceFontFaceOrderInStyleObject: (ruleContext: Rule.RuleContext, styleObject: TSESTree.ObjectExpression) => void;
@@ -1,17 +0,0 @@
1
- import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
- import { separateProperties } from '../shared-utils/property-separator.js';
3
- import { enforceFontFaceOrder } from './font-face-property-order-enforcer.js';
4
- /**
5
- * Processes a font face style object to enforce special ordering:
6
- * 'src' first, then other properties alphabetically.
7
- *
8
- * @param ruleContext The ESLint rule context for reporting and fixing issues.
9
- * @param styleObject The object expression representing the style object.
10
- */
11
- export const enforceFontFaceOrderInStyleObject = (ruleContext, styleObject) => {
12
- // if (!styleObject || styleObject.type !== AST_NODE_TYPES.ObjectExpression) {
13
- // return;
14
- // }
15
- // const { regularProperties } = separateProperties(styleObject.properties);
16
- // enforceFontFaceOrder(ruleContext, regularProperties);
17
- };
@@ -1,12 +0,0 @@
1
- import { TSESTree } from '@typescript-eslint/utils';
2
- export type ThemeValue = string | number | null;
3
- export type ThemeObject = {
4
- [key: string]: ThemeValue | ThemeObject;
5
- };
6
- export interface ThemeTokenMatch {
7
- token: string;
8
- path: string[];
9
- }
10
- export declare function isVanillaExtractStyleCall(node: TSESTree.CallExpression): boolean;
11
- export declare function findThemeTokenForValue(value: ThemeValue, themeObj: ThemeObject | null, path?: string[]): ThemeTokenMatch | null;
12
- export declare function findThemeTokenForPropertyValue(property: string, value: ThemeValue, themeObj: ThemeObject, path?: string[]): ThemeTokenMatch | null;
@@ -1,80 +0,0 @@
1
- // import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
- // export function isVanillaExtractStyleCall(node: TSESTree.CallExpression): boolean {
3
- // return (
4
- // node.callee.type === AST_NODE_TYPES.Identifier &&
5
- // ['style', 'createVar', 'styleVariants', 'globalStyle'].includes(node.callee.name) &&
6
- // node.arguments.length > 0 &&
7
- // node.arguments[0] !== undefined &&
8
- // node.arguments[0].type === AST_NODE_TYPES.ObjectExpression
9
- // );
10
- // }
11
- // type ThemeValue = string | number | null;
12
- // type ThemeObject = { [key: string]: ThemeValue | ThemeObject };
13
- // interface ThemeTokenMatch {
14
- // token: string;
15
- // path: string[];
16
- // }
17
- // export function findThemeTokenForValue(
18
- // value: ThemeValue,
19
- // themeObj: ThemeObject | null,
20
- // path: string[] = [],
21
- // ): ThemeTokenMatch | null {
22
- // if (!themeObj || typeof themeObj !== 'object') {
23
- // return null;
24
- // }
25
- // for (const [key, val] of Object.entries(themeObj)) {
26
- // const currentPath = [...path, key];
27
- // if (String(val) === String(value)) {
28
- // return { token: currentPath.join('.'), path: currentPath };
29
- // }
30
- // if (typeof val === 'object' && val !== null) {
31
- // const result = findThemeTokenForValue(value, val, currentPath);
32
- // if (result) {
33
- // return result;
34
- // }
35
- // }
36
- // }
37
- // return null;
38
- // }
39
- // TODO 2nd
40
- import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
41
- export function isVanillaExtractStyleCall(node) {
42
- return (node.callee.type === AST_NODE_TYPES.Identifier &&
43
- ['style', 'createVar', 'styleVariants', 'globalStyle', 'createThemeContract', 'createTheme', 'keyframes'].includes(node.callee.name) &&
44
- node.arguments.length > 0 &&
45
- (node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression ||
46
- node.arguments[0]?.type === AST_NODE_TYPES.ArrayExpression));
47
- }
48
- export function findThemeTokenForValue(value, themeObj, path = []) {
49
- if (!themeObj || typeof themeObj !== 'object') {
50
- return null;
51
- }
52
- for (const [key, val] of Object.entries(themeObj)) {
53
- const currentPath = [...path, key];
54
- if (String(val) === String(value)) {
55
- return {
56
- token: currentPath.join('.'),
57
- path: currentPath,
58
- };
59
- }
60
- if (typeof val === 'object' && val !== null) {
61
- const result = findThemeTokenForValue(value, val, currentPath);
62
- if (result) {
63
- return result;
64
- }
65
- }
66
- }
67
- return null;
68
- }
69
- export function findThemeTokenForPropertyValue(property, value, themeObj, path = []) {
70
- if (themeObj && typeof themeObj === 'object' && themeObj[property]) {
71
- const group = themeObj[property];
72
- if (typeof group === 'object' && group !== null) {
73
- const result = findThemeTokenForValue(value, group, [property]);
74
- if (result) {
75
- return result;
76
- }
77
- }
78
- }
79
- return findThemeTokenForValue(value, themeObj, path);
80
- }
@@ -1,2 +0,0 @@
1
- import preferThemeTokensRule from './rule-definition.js';
2
- export default preferThemeTokensRule;
@@ -1,2 +0,0 @@
1
- import preferThemeTokensRule from './rule-definition.js';
2
- export default preferThemeTokensRule;
@@ -1,3 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- declare const preferThemeTokensRule: Rule.RuleModule;
3
- export default preferThemeTokensRule;
@@ -1,29 +0,0 @@
1
- import { createThemeTokenVisitor } from './theme-token-visitor.js';
2
- const preferThemeTokensRule = {
3
- meta: {
4
- type: 'suggestion',
5
- docs: {
6
- description: 'enforce the use of theme tokens instead of direct values in vanilla-extract styles',
7
- category: 'Best Practices',
8
- recommended: true,
9
- },
10
- fixable: 'code',
11
- schema: [
12
- {
13
- type: 'object',
14
- properties: {
15
- themeImportPath: { type: 'string' },
16
- themeVarName: { type: 'string' },
17
- },
18
- additionalProperties: false,
19
- },
20
- ],
21
- messages: {
22
- preferThemeTokens: 'Use theme token "{{token}}" instead of direct value "{{value}}"',
23
- },
24
- },
25
- create(context) {
26
- return createThemeTokenVisitor(context);
27
- },
28
- };
29
- export default preferThemeTokensRule;
@@ -1,10 +0,0 @@
1
- type ThemeValue = string | number | null;
2
- type ThemeObject = {
3
- [key: string]: ThemeValue | ThemeObject;
4
- };
5
- export declare function loadThemeTokens(themeFilePath: string): ThemeObject | null;
6
- export declare function findThemeTokenForValue(value: ThemeValue, themeObj: ThemeObject, path?: string[]): {
7
- token: string;
8
- path: string[];
9
- } | null;
10
- export {};
@@ -1,71 +0,0 @@
1
- /* eslint-disable no-console */
2
- import fs from 'fs';
3
- import path from 'path';
4
- export function loadThemeTokens(themeFilePath) {
5
- try {
6
- console.log(`Attempting to load theme from: ${themeFilePath}`);
7
- const resolvedPath = path.resolve(process.cwd(), themeFilePath);
8
- console.log(`Resolved path: ${resolvedPath}`);
9
- if (!fs.existsSync(resolvedPath)) {
10
- console.error(`Theme file not found: ${resolvedPath}`);
11
- return null;
12
- }
13
- const content = fs.readFileSync(resolvedPath, 'utf8');
14
- console.log(`File content loaded. Length: ${content.length} characters`);
15
- const themeMatch = content.match(/createTheme\([^,]+,\s*(\{[\s\S]+?\})\s*\);/);
16
- if (!themeMatch || !themeMatch[1]) {
17
- console.error('No theme implementation found in the file');
18
- return null;
19
- }
20
- const themeStr = themeMatch[1];
21
- console.log(`Theme implementation extracted. Length: ${themeStr.length} characters`);
22
- // Use a safe evaluation method to parse the theme object
23
- const themeObj = Function(`return ${themeStr}`)();
24
- console.log('Parsed theme structure:', JSON.stringify(themeObj, null, 2));
25
- return themeObj;
26
- }
27
- catch (error) {
28
- console.error('Error loading theme tokens:', error);
29
- return null;
30
- }
31
- }
32
- // function parseThemeObject(str: string): ThemeObject {
33
- // const result: ThemeObject = {};
34
- // const lines = str.split('\n');
35
- // const stack: ThemeObject[] = [result];
36
- // for (const line of lines) {
37
- // const trimmed = line.trim();
38
- // if (!trimmed || trimmed.startsWith('//')) {
39
- // continue;
40
- // }
41
- // if (trimmed.endsWith('{')) {
42
- // const key = trimmed.slice(0, -1).trim();
43
- // const newObj: ThemeObject = {};
44
- // stack[stack.length - 1]![key] = newObj;
45
- // stack.push(newObj);
46
- // } else if (trimmed === '},') {
47
- // stack.pop();
48
- // } else {
49
- // const [key, value] = trimmed.split(':').map((s) => s.trim());
50
- // if (key && value) {
51
- // stack[stack.length - 1]![key] = value === 'null' ? null : value.replace(/,$/, '');
52
- // }
53
- // }
54
- // }
55
- // return result;
56
- // }
57
- export function findThemeTokenForValue(value, themeObj, path = []) {
58
- for (const [key, val] of Object.entries(themeObj)) {
59
- const currentPath = [...path, key];
60
- if (String(val) === String(value)) {
61
- return { token: currentPath.join('.'), path: currentPath };
62
- }
63
- if (typeof val === 'object' && val !== null) {
64
- const result = findThemeTokenForValue(value, val, currentPath);
65
- if (result) {
66
- return result;
67
- }
68
- }
69
- }
70
- return null;
71
- }
@@ -1,2 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- export declare function createThemeTokenVisitor(context: Rule.RuleContext): Rule.RuleListener;