@antebudimir/eslint-plugin-vanilla-extract 1.2.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.
- package/README.md +46 -8
- package/dist/css-rules/alphabetical-order/__tests__/animation.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/animation.test.js +108 -0
- package/dist/css-rules/alphabetical-order/__tests__/font-face.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/font-face.test.js +138 -0
- package/dist/css-rules/alphabetical-order/__tests__/global.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/global.test.js +51 -0
- package/dist/css-rules/alphabetical-order/__tests__/recipe.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/recipe.test.js +91 -0
- package/dist/css-rules/alphabetical-order/__tests__/style.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/style.test.js +108 -0
- package/dist/css-rules/alphabetical-order/__tests__/variants.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/variants.test.js +63 -0
- package/dist/css-rules/alphabetical-order/property-order-enforcer.js +1 -11
- package/dist/css-rules/alphabetical-order/rule-definition.js +2 -1
- package/dist/css-rules/concentric-order/__tests__/animation.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/animation.test.js +69 -0
- package/dist/css-rules/concentric-order/__tests__/font-face.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/font-face.test.js +94 -0
- package/dist/css-rules/concentric-order/__tests__/global.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/global.test.js +57 -0
- package/dist/css-rules/concentric-order/__tests__/recipe.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/recipe.test.js +100 -0
- package/dist/css-rules/concentric-order/__tests__/style.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/style.test.js +126 -0
- package/dist/css-rules/concentric-order/__tests__/variants.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/variants.test.js +133 -0
- package/dist/css-rules/concentric-order/property-order-enforcer.js +2 -2
- package/dist/css-rules/concentric-order/rule-definition.js +3 -1
- package/dist/css-rules/custom-order/__tests__/animation.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/animation.test.js +148 -0
- package/dist/css-rules/custom-order/__tests__/font-face.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/font-face.test.js +124 -0
- package/dist/css-rules/custom-order/__tests__/global.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/global.test.js +124 -0
- package/dist/css-rules/custom-order/__tests__/recipe.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/recipe.test.js +208 -0
- package/dist/css-rules/custom-order/__tests__/style.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/style.test.js +249 -0
- package/dist/css-rules/custom-order/__tests__/variants.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/variants.test.js +184 -0
- package/dist/css-rules/custom-order/rule-definition.js +1 -0
- package/dist/css-rules/shared-utils/__tests__/css-property-priority-map.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/css-property-priority-map.test.js +37 -0
- package/dist/css-rules/shared-utils/__tests__/font-face-property-order-enforcer.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/font-face-property-order-enforcer.test.js +58 -0
- package/dist/css-rules/shared-utils/__tests__/order-strategy-visitor-creator.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/order-strategy-visitor-creator.test.js +125 -0
- package/dist/css-rules/shared-utils/__tests__/property-name-extractor.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/property-name-extractor.test.js +53 -0
- package/dist/css-rules/shared-utils/__tests__/recipe-property-processor.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/recipe-property-processor.test.js +116 -0
- package/dist/css-rules/shared-utils/__tests__/style-node-processor.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/style-node-processor.test.js +55 -0
- package/dist/css-rules/shared-utils/__tests__/test-property-name-rule.d.ts +3 -0
- package/dist/css-rules/shared-utils/__tests__/test-property-name-rule.js +30 -0
- package/dist/css-rules/shared-utils/alphabetical-property-comparator.d.ts +8 -0
- package/dist/css-rules/shared-utils/alphabetical-property-comparator.js +19 -0
- package/dist/css-rules/shared-utils/font-face-property-order-enforcer.d.ts +10 -0
- package/dist/css-rules/shared-utils/font-face-property-order-enforcer.js +39 -0
- package/dist/css-rules/shared-utils/order-strategy-visitor-creator.d.ts +4 -3
- package/dist/css-rules/shared-utils/order-strategy-visitor-creator.js +23 -8
- package/dist/css-rules/shared-utils/style-node-processor.js +2 -5
- package/dist/index.js +1 -1
- package/package.json +11 -6
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,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;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Compares two CSS properties alphabetically.
|
|
4
|
+
* @param firstProperty The first property to compare.
|
|
5
|
+
* @param secondProperty The second property to compare.
|
|
6
|
+
* @returns A number indicating the relative order of the properties (-1, 0, or 1).
|
|
7
|
+
*/
|
|
8
|
+
export declare const comparePropertiesAlphabetically: (firstProperty: TSESTree.Property, secondProperty: TSESTree.Property) => number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getPropertyName } from './property-separator.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compares two CSS properties alphabetically.
|
|
4
|
+
* @param firstProperty The first property to compare.
|
|
5
|
+
* @param secondProperty The second property to compare.
|
|
6
|
+
* @returns A number indicating the relative order of the properties (-1, 0, or 1).
|
|
7
|
+
*/
|
|
8
|
+
export const comparePropertiesAlphabetically = (firstProperty, secondProperty) => {
|
|
9
|
+
const firstName = getPropertyName(firstProperty);
|
|
10
|
+
const secondName = getPropertyName(secondProperty);
|
|
11
|
+
// Special handling for 'src' property - it should always come first (relates to font face APIs only)
|
|
12
|
+
if (firstName === 'src') {
|
|
13
|
+
return -1;
|
|
14
|
+
}
|
|
15
|
+
if (secondName === 'src') {
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
return firstName.localeCompare(secondName);
|
|
19
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
3
|
+
/**
|
|
4
|
+
* Processes a font face declaration to enforce property ordering:
|
|
5
|
+
* 'src' first, then other properties alphabetically.
|
|
6
|
+
*
|
|
7
|
+
* @param ruleContext The ESLint rule context for reporting and fixing issues.
|
|
8
|
+
* @param fontFaceObject The object expression representing the font face declaration.
|
|
9
|
+
*/
|
|
10
|
+
export declare const enforceFontFaceOrder: (ruleContext: Rule.RuleContext, fontFaceObject: TSESTree.ObjectExpression) => void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { generateFixesForCSSOrder } from '../shared-utils/css-order-fixer.js';
|
|
3
|
+
import { getPropertyName, separateProperties } from '../shared-utils/property-separator.js';
|
|
4
|
+
import { comparePropertiesAlphabetically } from './alphabetical-property-comparator.js';
|
|
5
|
+
/**
|
|
6
|
+
* Processes a font face declaration to enforce property ordering:
|
|
7
|
+
* 'src' first, then other properties alphabetically.
|
|
8
|
+
*
|
|
9
|
+
* @param ruleContext The ESLint rule context for reporting and fixing issues.
|
|
10
|
+
* @param fontFaceObject The object expression representing the font face declaration.
|
|
11
|
+
*/
|
|
12
|
+
export const enforceFontFaceOrder = (ruleContext, fontFaceObject) => {
|
|
13
|
+
if (!fontFaceObject || fontFaceObject.type !== AST_NODE_TYPES.ObjectExpression) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const { regularProperties } = separateProperties(fontFaceObject.properties);
|
|
17
|
+
if (regularProperties.length <= 1) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// Create pairs of consecutive properties
|
|
21
|
+
const propertyPairs = regularProperties.slice(0, -1).map((currentProperty, index) => ({
|
|
22
|
+
currentProperty,
|
|
23
|
+
nextProperty: regularProperties[index + 1],
|
|
24
|
+
}));
|
|
25
|
+
const violatingPair = propertyPairs.find(({ currentProperty, nextProperty }) => comparePropertiesAlphabetically(currentProperty, nextProperty) > 0);
|
|
26
|
+
if (violatingPair) {
|
|
27
|
+
const nextPropertyName = getPropertyName(violatingPair.nextProperty);
|
|
28
|
+
const currentPropertyName = getPropertyName(violatingPair.currentProperty);
|
|
29
|
+
ruleContext.report({
|
|
30
|
+
node: violatingPair.nextProperty,
|
|
31
|
+
messageId: 'fontFaceOrder',
|
|
32
|
+
data: {
|
|
33
|
+
nextProperty: nextPropertyName,
|
|
34
|
+
currentProperty: currentPropertyName,
|
|
35
|
+
},
|
|
36
|
+
fix: (fixer) => generateFixesForCSSOrder(fixer, ruleContext, regularProperties, comparePropertiesAlphabetically, (property) => property),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -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.
|
|
12
|
-
* 2.
|
|
13
|
-
* 3. The '
|
|
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
|
*/
|
|
@@ -5,6 +5,7 @@ import { enforceConcentricCSSOrderInRecipe } from '../concentric-order/recipe-or
|
|
|
5
5
|
import { enforceConcentricCSSOrderInStyleObject } from '../concentric-order/style-object-processor.js';
|
|
6
6
|
import { enforceUserDefinedGroupOrderInRecipe } from '../custom-order/recipe-order-enforcer.js';
|
|
7
7
|
import { enforceUserDefinedGroupOrderInStyleObject } from '../custom-order/style-object-processor.js';
|
|
8
|
+
import { enforceFontFaceOrder } from './font-face-property-order-enforcer.js';
|
|
8
9
|
import { processStyleNode } from './style-node-processor.js';
|
|
9
10
|
/**
|
|
10
11
|
* Creates an ESLint rule listener with visitors for style-related function calls.
|
|
@@ -15,9 +16,10 @@ import { processStyleNode } from './style-node-processor.js';
|
|
|
15
16
|
* @returns An object with visitor functions for the ESLint rule.
|
|
16
17
|
*
|
|
17
18
|
* This function sets up visitors for the following cases:
|
|
18
|
-
* 1.
|
|
19
|
-
* 2.
|
|
20
|
-
* 3. The '
|
|
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
|
|
21
23
|
*
|
|
22
24
|
* Each visitor applies the appropriate ordering strategy to the style objects in these function calls.
|
|
23
25
|
*/
|
|
@@ -43,18 +45,31 @@ export const createNodeVisitors = (ruleContext, orderingStrategy, userDefinedGro
|
|
|
43
45
|
if (node.callee.type !== 'Identifier') {
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
48
|
+
const fontFaceFunctionArgumentIndexMap = {
|
|
49
|
+
fontFace: 0, // First argument (index 0)
|
|
50
|
+
globalFontFace: 1, // Second argument (index 1)
|
|
51
|
+
};
|
|
52
|
+
// Handle font face functions with special ordering
|
|
53
|
+
if (node.callee.name in fontFaceFunctionArgumentIndexMap &&
|
|
54
|
+
node.arguments.length >
|
|
55
|
+
fontFaceFunctionArgumentIndexMap[node.callee.name]) {
|
|
56
|
+
const argumentIndex = fontFaceFunctionArgumentIndexMap[node.callee.name];
|
|
57
|
+
const styleArguments = node.arguments[argumentIndex];
|
|
58
|
+
enforceFontFaceOrder(ruleContext, styleArguments);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
46
61
|
// Handle style-related functions
|
|
47
|
-
if (['
|
|
62
|
+
if (['keyframes', 'style', 'styleVariants'].includes(node.callee.name)) {
|
|
48
63
|
if (node.arguments.length > 0) {
|
|
49
|
-
const
|
|
50
|
-
processStyleNode(ruleContext,
|
|
64
|
+
const styleArguments = node.arguments[0];
|
|
65
|
+
processStyleNode(ruleContext, styleArguments, processProperty);
|
|
51
66
|
}
|
|
52
67
|
}
|
|
53
68
|
// Handle global functions
|
|
54
69
|
if ((node.callee.name === 'globalKeyframes' || node.callee.name === 'globalStyle') &&
|
|
55
70
|
node.arguments.length >= 2) {
|
|
56
|
-
const
|
|
57
|
-
processStyleNode(ruleContext,
|
|
71
|
+
const styleArguments = node.arguments[1];
|
|
72
|
+
processStyleNode(ruleContext, styleArguments, processProperty);
|
|
58
73
|
}
|
|
59
74
|
// Handle recipe function
|
|
60
75
|
if (node.callee.name === 'recipe') {
|
|
@@ -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 (
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (node.type === 'ObjectExpression') {
|
|
9
|
+
if (node?.type === 'ObjectExpression') {
|
|
13
10
|
processProperty(ruleContext, node);
|
|
14
11
|
}
|
|
15
|
-
if (node
|
|
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.
|
|
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
|
-
"description": "ESLint plugin for enforcing
|
|
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,25 +51,30 @@
|
|
|
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
|
-
"version:
|
|
72
|
-
"version:minor": "pnpm version minor --no-git-tag-version",
|
|
73
|
-
"version:patch": "pnpm version patch --no-git-tag-version"
|
|
78
|
+
"version:update": "node scripts/update-version.mjs"
|
|
74
79
|
}
|
|
75
80
|
}
|