@antebudimir/eslint-plugin-vanilla-extract 1.12.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -14
- package/dist/css-rules/no-px-unit/_tests_/no-px-unit.test.d.ts +1 -0
- package/dist/css-rules/no-px-unit/_tests_/no-px-unit.test.js +163 -0
- package/dist/css-rules/no-px-unit/index.d.ts +2 -0
- package/dist/css-rules/no-px-unit/index.js +2 -0
- package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.d.ts +2 -0
- package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.js +55 -0
- package/dist/css-rules/no-px-unit/processor.d.ts +3 -0
- package/dist/css-rules/no-px-unit/processor.js +93 -0
- package/dist/css-rules/no-px-unit/px-unit-processor.d.ts +14 -0
- package/dist/css-rules/no-px-unit/px-unit-processor.js +104 -0
- package/dist/css-rules/no-px-unit/px-unit-visitor-creator.d.ts +11 -0
- package/dist/css-rules/no-px-unit/px-unit-visitor-creator.js +64 -0
- package/dist/css-rules/no-px-unit/rule-definition.d.ts +3 -0
- package/dist/css-rules/no-px-unit/rule-definition.js +37 -0
- package/dist/css-rules/no-px-unit/visitor-creator.d.ts +2 -0
- package/dist/css-rules/no-px-unit/visitor-creator.js +55 -0
- package/dist/css-rules/prefer-logical-properties/_tests_/prefer-logical-properties.test.d.ts +1 -0
- package/dist/css-rules/prefer-logical-properties/_tests_/prefer-logical-properties.test.js +572 -0
- package/dist/css-rules/prefer-logical-properties/index.d.ts +2 -0
- package/dist/css-rules/prefer-logical-properties/index.js +2 -0
- package/dist/css-rules/prefer-logical-properties/logical-properties-processor.d.ts +19 -0
- package/dist/css-rules/prefer-logical-properties/logical-properties-processor.js +202 -0
- package/dist/css-rules/prefer-logical-properties/logical-properties-visitor-creator.d.ts +14 -0
- package/dist/css-rules/prefer-logical-properties/logical-properties-visitor-creator.js +67 -0
- package/dist/css-rules/prefer-logical-properties/property-mappings.d.ts +44 -0
- package/dist/css-rules/prefer-logical-properties/property-mappings.js +179 -0
- package/dist/css-rules/prefer-logical-properties/rule-definition.d.ts +3 -0
- package/dist/css-rules/prefer-logical-properties/rule-definition.js +35 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/sample.css.d.ts +75 -0
- package/dist/sample.css.js +540 -0
- package/package.json +2 -2
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { isPhysicalProperty, getLogicalProperty, toKebabCase, toCamelCase, TEXT_ALIGN_PHYSICAL_VALUES, FLOAT_PHYSICAL_VALUES, CLEAR_PHYSICAL_VALUES, VALUE_BASED_PHYSICAL_PROPERTIES, } from './property-mappings.js';
|
|
3
|
+
/**
|
|
4
|
+
* Get the text value from a node (string literal or simple template literal)
|
|
5
|
+
*/
|
|
6
|
+
const getValueText = (node) => {
|
|
7
|
+
if (node.type === AST_NODE_TYPES.Literal && typeof node.value === 'string') {
|
|
8
|
+
return node.value;
|
|
9
|
+
}
|
|
10
|
+
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
11
|
+
return node.quasis.map((quasi) => quasi.value.raw ?? '').join('');
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Check if a node can be auto-fixed (literal or simple template literal)
|
|
17
|
+
*/
|
|
18
|
+
const canAutoFix = (node) => {
|
|
19
|
+
if (node.type === AST_NODE_TYPES.Literal && typeof node.value === 'string') {
|
|
20
|
+
return 'literal';
|
|
21
|
+
}
|
|
22
|
+
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
23
|
+
return 'simple-template';
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Check if a property value contains physical directional values
|
|
29
|
+
*/
|
|
30
|
+
const hasPhysicalValue = (propertyName, value) => {
|
|
31
|
+
const trimmedValue = value.trim().toLowerCase();
|
|
32
|
+
if (propertyName === 'text-align' || propertyName === 'textAlign') {
|
|
33
|
+
if (trimmedValue in TEXT_ALIGN_PHYSICAL_VALUES) {
|
|
34
|
+
return {
|
|
35
|
+
hasPhysical: true,
|
|
36
|
+
fixedValue: TEXT_ALIGN_PHYSICAL_VALUES[trimmedValue],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (propertyName === 'float') {
|
|
41
|
+
if (trimmedValue in FLOAT_PHYSICAL_VALUES) {
|
|
42
|
+
return {
|
|
43
|
+
hasPhysical: true,
|
|
44
|
+
fixedValue: FLOAT_PHYSICAL_VALUES[trimmedValue],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (propertyName === 'clear') {
|
|
49
|
+
if (trimmedValue in CLEAR_PHYSICAL_VALUES) {
|
|
50
|
+
return {
|
|
51
|
+
hasPhysical: true,
|
|
52
|
+
fixedValue: CLEAR_PHYSICAL_VALUES[trimmedValue],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (propertyName === 'resize') {
|
|
57
|
+
if (trimmedValue === 'horizontal' || trimmedValue === 'vertical') {
|
|
58
|
+
const fixedValue = trimmedValue === 'horizontal' ? 'inline' : 'block';
|
|
59
|
+
return { hasPhysical: true, fixedValue };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return { hasPhysical: false };
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Normalize property name to both camelCase and kebab-case for checking
|
|
66
|
+
*/
|
|
67
|
+
const normalizePropertyName = (name) => {
|
|
68
|
+
const kebab = toKebabCase(name);
|
|
69
|
+
const camel = toCamelCase(name);
|
|
70
|
+
return { camel, kebab };
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Check if a property is in the allow list
|
|
74
|
+
*/
|
|
75
|
+
const isAllowed = (propertyName, allowSet) => {
|
|
76
|
+
const { camel, kebab } = normalizePropertyName(propertyName);
|
|
77
|
+
return allowSet.has(propertyName) || allowSet.has(camel) || allowSet.has(kebab);
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Get the appropriate logical property name based on the original format
|
|
81
|
+
*/
|
|
82
|
+
const getLogicalPropertyInFormat = (originalName, logicalName) => {
|
|
83
|
+
// If original is kebab-case (contains hyphen), return kebab-case
|
|
84
|
+
if (originalName.includes('-')) {
|
|
85
|
+
return toKebabCase(logicalName);
|
|
86
|
+
}
|
|
87
|
+
// Otherwise return camelCase
|
|
88
|
+
return toCamelCase(logicalName);
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Create a fix for replacing a property key
|
|
92
|
+
*/
|
|
93
|
+
const createPropertyKeyFix = (fixer, property, newPropertyName, context) => {
|
|
94
|
+
const key = property.key;
|
|
95
|
+
if (key.type === AST_NODE_TYPES.Identifier) {
|
|
96
|
+
return fixer.replaceText(key, newPropertyName);
|
|
97
|
+
}
|
|
98
|
+
if (key.type === AST_NODE_TYPES.Literal && typeof key.value === 'string') {
|
|
99
|
+
// Preserve quote style
|
|
100
|
+
const sourceCode = context.getSourceCode();
|
|
101
|
+
const originalText = sourceCode.getText(key);
|
|
102
|
+
const quote = originalText[0];
|
|
103
|
+
return fixer.replaceText(key, `${quote}${newPropertyName}${quote}`);
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Create a fix for replacing a property value
|
|
109
|
+
*/
|
|
110
|
+
const createPropertyValueFix = (fixer, valueNode, newValue, fixType) => {
|
|
111
|
+
if (fixType === 'literal') {
|
|
112
|
+
return fixer.replaceText(valueNode, `'${newValue}'`);
|
|
113
|
+
}
|
|
114
|
+
// simple-template
|
|
115
|
+
return fixer.replaceText(valueNode, `\`${newValue}\``);
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Recursively processes a vanilla-extract style object and reports physical CSS properties.
|
|
119
|
+
*
|
|
120
|
+
* - Detects physical property names and suggests logical equivalents
|
|
121
|
+
* - Detects physical directional values (e.g., text-align: left)
|
|
122
|
+
* - Skips properties in the allow list
|
|
123
|
+
* - Provides auto-fixes where unambiguous
|
|
124
|
+
* - Traverses nested objects, @media, and selectors
|
|
125
|
+
*
|
|
126
|
+
* @param context ESLint rule context
|
|
127
|
+
* @param node The ObjectExpression node representing the style object
|
|
128
|
+
* @param allowSet Set of property names to skip
|
|
129
|
+
*/
|
|
130
|
+
export const processLogicalPropertiesInStyleObject = (context, node, allowSet) => {
|
|
131
|
+
for (const property of node.properties) {
|
|
132
|
+
if (property.type !== AST_NODE_TYPES.Property)
|
|
133
|
+
continue;
|
|
134
|
+
// Determine property name
|
|
135
|
+
let propertyName = null;
|
|
136
|
+
if (property.key.type === AST_NODE_TYPES.Identifier) {
|
|
137
|
+
propertyName = property.key.name;
|
|
138
|
+
}
|
|
139
|
+
else if (property.key.type === AST_NODE_TYPES.Literal && typeof property.key.value === 'string') {
|
|
140
|
+
propertyName = property.key.value;
|
|
141
|
+
}
|
|
142
|
+
if (!propertyName)
|
|
143
|
+
continue;
|
|
144
|
+
// Handle nested containers (@media, selectors, etc.)
|
|
145
|
+
if (propertyName === '@media' || propertyName === 'selectors') {
|
|
146
|
+
if (property.value.type === AST_NODE_TYPES.ObjectExpression) {
|
|
147
|
+
for (const nested of property.value.properties) {
|
|
148
|
+
if (nested.type === AST_NODE_TYPES.Property && nested.value.type === AST_NODE_TYPES.ObjectExpression) {
|
|
149
|
+
processLogicalPropertiesInStyleObject(context, nested.value, allowSet);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
// Recurse into nested objects
|
|
156
|
+
if (property.value.type === AST_NODE_TYPES.ObjectExpression) {
|
|
157
|
+
processLogicalPropertiesInStyleObject(context, property.value, allowSet);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
// Skip if property is in allow list
|
|
161
|
+
if (isAllowed(propertyName, allowSet)) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
// Check for physical property names
|
|
165
|
+
if (isPhysicalProperty(propertyName)) {
|
|
166
|
+
const logicalProp = getLogicalProperty(propertyName);
|
|
167
|
+
if (logicalProp) {
|
|
168
|
+
const logicalInFormat = getLogicalPropertyInFormat(propertyName, logicalProp);
|
|
169
|
+
context.report({
|
|
170
|
+
node: property.key,
|
|
171
|
+
messageId: 'preferLogicalProperty',
|
|
172
|
+
data: {
|
|
173
|
+
physical: propertyName,
|
|
174
|
+
logical: logicalInFormat,
|
|
175
|
+
},
|
|
176
|
+
fix: (fixer) => createPropertyKeyFix(fixer, property, logicalInFormat, context),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
// Check for value-based physical properties
|
|
182
|
+
if (VALUE_BASED_PHYSICAL_PROPERTIES.has(propertyName)) {
|
|
183
|
+
const valueText = getValueText(property.value);
|
|
184
|
+
if (valueText) {
|
|
185
|
+
const { hasPhysical, fixedValue } = hasPhysicalValue(propertyName, valueText);
|
|
186
|
+
if (hasPhysical && fixedValue) {
|
|
187
|
+
const fixType = canAutoFix(property.value);
|
|
188
|
+
context.report({
|
|
189
|
+
node: property.value,
|
|
190
|
+
messageId: 'preferLogicalValue',
|
|
191
|
+
data: {
|
|
192
|
+
property: propertyName,
|
|
193
|
+
physical: valueText.trim(),
|
|
194
|
+
logical: fixedValue,
|
|
195
|
+
},
|
|
196
|
+
fix: fixType ? (fixer) => createPropertyValueFix(fixer, property.value, fixedValue, fixType) : undefined,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
/**
|
|
3
|
+
* Creates ESLint rule visitors for detecting and reporting physical CSS properties
|
|
4
|
+
* in vanilla-extract style objects.
|
|
5
|
+
*
|
|
6
|
+
* - Tracks calls to vanilla-extract APIs (style, recipe, keyframes, globalStyle, fontFace, etc.)
|
|
7
|
+
* - Detects physical property names and directional values
|
|
8
|
+
* - Respects the `allow` option for allowlisting properties
|
|
9
|
+
* - Provides auto-fixes for unambiguous conversions
|
|
10
|
+
*
|
|
11
|
+
* @param context ESLint rule context used to read options and report diagnostics
|
|
12
|
+
* @returns Rule listener that inspects vanilla-extract call expressions and processes style objects
|
|
13
|
+
*/
|
|
14
|
+
export declare const createLogicalPropertiesVisitors: (context: Rule.RuleContext) => Rule.RuleListener;
|
|
@@ -0,0 +1,67 @@
|
|
|
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 { processLogicalPropertiesInStyleObject } from './logical-properties-processor.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates ESLint rule visitors for detecting and reporting physical CSS properties
|
|
8
|
+
* in vanilla-extract style objects.
|
|
9
|
+
*
|
|
10
|
+
* - Tracks calls to vanilla-extract APIs (style, recipe, keyframes, globalStyle, fontFace, etc.)
|
|
11
|
+
* - Detects physical property names and directional values
|
|
12
|
+
* - Respects the `allow` option for allowlisting properties
|
|
13
|
+
* - Provides auto-fixes for unambiguous conversions
|
|
14
|
+
*
|
|
15
|
+
* @param context ESLint rule context used to read options and report diagnostics
|
|
16
|
+
* @returns Rule listener that inspects vanilla-extract call expressions and processes style objects
|
|
17
|
+
*/
|
|
18
|
+
export const createLogicalPropertiesVisitors = (context) => {
|
|
19
|
+
const tracker = new ReferenceTracker();
|
|
20
|
+
const trackingVisitor = createReferenceTrackingVisitor(tracker);
|
|
21
|
+
const options = context.options?.[0] || {};
|
|
22
|
+
const allowSet = new Set((options.allow ?? []).map((prop) => prop));
|
|
23
|
+
const process = (context, object) => processLogicalPropertiesInStyleObject(context, object, allowSet);
|
|
24
|
+
return {
|
|
25
|
+
...trackingVisitor,
|
|
26
|
+
CallExpression(node) {
|
|
27
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier)
|
|
28
|
+
return;
|
|
29
|
+
const functionName = node.callee.name;
|
|
30
|
+
if (!tracker.isTrackedFunction(functionName))
|
|
31
|
+
return;
|
|
32
|
+
const originalName = tracker.getOriginalName(functionName);
|
|
33
|
+
if (!originalName)
|
|
34
|
+
return;
|
|
35
|
+
switch (originalName) {
|
|
36
|
+
case 'fontFace':
|
|
37
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
38
|
+
process(context, node.arguments[0]);
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case 'globalFontFace':
|
|
42
|
+
if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
43
|
+
process(context, node.arguments[1]);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case 'style':
|
|
47
|
+
case 'styleVariants':
|
|
48
|
+
case 'keyframes':
|
|
49
|
+
if (node.arguments.length > 0) {
|
|
50
|
+
processStyleNode(context, node.arguments[0], (context, object) => process(context, object));
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case 'globalStyle':
|
|
54
|
+
case 'globalKeyframes':
|
|
55
|
+
if (node.arguments.length >= 2) {
|
|
56
|
+
processStyleNode(context, node.arguments[1], (context, object) => process(context, object));
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
case 'recipe':
|
|
60
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
61
|
+
processRecipeProperties(context, node.arguments[0], (context, object) => process(context, object));
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping of physical CSS properties to their logical equivalents.
|
|
3
|
+
* Includes margin, padding, border, inset, and positioning properties.
|
|
4
|
+
*/
|
|
5
|
+
export interface PropertyMapping {
|
|
6
|
+
logical: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Direct physical → logical property mappings
|
|
11
|
+
*/
|
|
12
|
+
export declare const PHYSICAL_TO_LOGICAL: Record<string, PropertyMapping>;
|
|
13
|
+
/**
|
|
14
|
+
* Text-align directional values that should be replaced
|
|
15
|
+
*/
|
|
16
|
+
export declare const TEXT_ALIGN_PHYSICAL_VALUES: Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Float directional values that should be replaced
|
|
19
|
+
*/
|
|
20
|
+
export declare const FLOAT_PHYSICAL_VALUES: Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* Clear directional values that should be replaced
|
|
23
|
+
*/
|
|
24
|
+
export declare const CLEAR_PHYSICAL_VALUES: Record<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* Properties where the value (not the property name) needs to be checked for physical directions
|
|
27
|
+
*/
|
|
28
|
+
export declare const VALUE_BASED_PHYSICAL_PROPERTIES: Set<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a property name is a physical property that should be converted
|
|
31
|
+
*/
|
|
32
|
+
export declare function isPhysicalProperty(propertyName: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Get the logical equivalent of a physical property
|
|
35
|
+
*/
|
|
36
|
+
export declare function getLogicalProperty(propertyName: string): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Convert camelCase to kebab-case
|
|
39
|
+
*/
|
|
40
|
+
export declare function toKebabCase(name: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Convert kebab-case to camelCase
|
|
43
|
+
*/
|
|
44
|
+
export declare function toCamelCase(name: string): string;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping of physical CSS properties to their logical equivalents.
|
|
3
|
+
* Includes margin, padding, border, inset, and positioning properties.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Direct physical → logical property mappings
|
|
7
|
+
*/
|
|
8
|
+
export const PHYSICAL_TO_LOGICAL = {
|
|
9
|
+
// Margin properties
|
|
10
|
+
'margin-left': { logical: 'margin-inline-start' },
|
|
11
|
+
'margin-right': { logical: 'margin-inline-end' },
|
|
12
|
+
'margin-top': { logical: 'margin-block-start' },
|
|
13
|
+
'margin-bottom': { logical: 'margin-block-end' },
|
|
14
|
+
marginLeft: { logical: 'marginInlineStart' },
|
|
15
|
+
marginRight: { logical: 'marginInlineEnd' },
|
|
16
|
+
marginTop: { logical: 'marginBlockStart' },
|
|
17
|
+
marginBottom: { logical: 'marginBlockEnd' },
|
|
18
|
+
// Padding properties
|
|
19
|
+
'padding-left': { logical: 'padding-inline-start' },
|
|
20
|
+
'padding-right': { logical: 'padding-inline-end' },
|
|
21
|
+
'padding-top': { logical: 'padding-block-start' },
|
|
22
|
+
'padding-bottom': { logical: 'padding-block-end' },
|
|
23
|
+
paddingLeft: { logical: 'paddingInlineStart' },
|
|
24
|
+
paddingRight: { logical: 'paddingInlineEnd' },
|
|
25
|
+
paddingTop: { logical: 'paddingBlockStart' },
|
|
26
|
+
paddingBottom: { logical: 'paddingBlockEnd' },
|
|
27
|
+
// Border width properties
|
|
28
|
+
'border-left-width': { logical: 'border-inline-start-width' },
|
|
29
|
+
'border-right-width': { logical: 'border-inline-end-width' },
|
|
30
|
+
'border-top-width': { logical: 'border-block-start-width' },
|
|
31
|
+
'border-bottom-width': { logical: 'border-block-end-width' },
|
|
32
|
+
borderLeftWidth: { logical: 'borderInlineStartWidth' },
|
|
33
|
+
borderRightWidth: { logical: 'borderInlineEndWidth' },
|
|
34
|
+
borderTopWidth: { logical: 'borderBlockStartWidth' },
|
|
35
|
+
borderBottomWidth: { logical: 'borderBlockEndWidth' },
|
|
36
|
+
// Border style properties
|
|
37
|
+
'border-left-style': { logical: 'border-inline-start-style' },
|
|
38
|
+
'border-right-style': { logical: 'border-inline-end-style' },
|
|
39
|
+
'border-top-style': { logical: 'border-block-start-style' },
|
|
40
|
+
'border-bottom-style': { logical: 'border-block-end-style' },
|
|
41
|
+
borderLeftStyle: { logical: 'borderInlineStartStyle' },
|
|
42
|
+
borderRightStyle: { logical: 'borderInlineEndStyle' },
|
|
43
|
+
borderTopStyle: { logical: 'borderBlockStartStyle' },
|
|
44
|
+
borderBottomStyle: { logical: 'borderBlockEndStyle' },
|
|
45
|
+
// Border color properties
|
|
46
|
+
'border-left-color': { logical: 'border-inline-start-color' },
|
|
47
|
+
'border-right-color': { logical: 'border-inline-end-color' },
|
|
48
|
+
'border-top-color': { logical: 'border-block-start-color' },
|
|
49
|
+
'border-bottom-color': { logical: 'border-block-end-color' },
|
|
50
|
+
borderLeftColor: { logical: 'borderInlineStartColor' },
|
|
51
|
+
borderRightColor: { logical: 'borderInlineEndColor' },
|
|
52
|
+
borderTopColor: { logical: 'borderBlockStartColor' },
|
|
53
|
+
borderBottomColor: { logical: 'borderBlockEndColor' },
|
|
54
|
+
// Border shorthand properties
|
|
55
|
+
'border-left': { logical: 'border-inline-start' },
|
|
56
|
+
'border-right': { logical: 'border-inline-end' },
|
|
57
|
+
'border-top': { logical: 'border-block-start' },
|
|
58
|
+
'border-bottom': { logical: 'border-block-end' },
|
|
59
|
+
borderLeft: { logical: 'borderInlineStart' },
|
|
60
|
+
borderRight: { logical: 'borderInlineEnd' },
|
|
61
|
+
borderTop: { logical: 'borderBlockStart' },
|
|
62
|
+
borderBottom: { logical: 'borderBlockEnd' },
|
|
63
|
+
// Border radius properties
|
|
64
|
+
'border-top-left-radius': { logical: 'border-start-start-radius' },
|
|
65
|
+
'border-top-right-radius': { logical: 'border-start-end-radius' },
|
|
66
|
+
'border-bottom-left-radius': { logical: 'border-end-start-radius' },
|
|
67
|
+
'border-bottom-right-radius': { logical: 'border-end-end-radius' },
|
|
68
|
+
borderTopLeftRadius: { logical: 'borderStartStartRadius' },
|
|
69
|
+
borderTopRightRadius: { logical: 'borderStartEndRadius' },
|
|
70
|
+
borderBottomLeftRadius: { logical: 'borderEndStartRadius' },
|
|
71
|
+
borderBottomRightRadius: { logical: 'borderEndEndRadius' },
|
|
72
|
+
// Inset properties
|
|
73
|
+
left: { logical: 'inset-inline-start' },
|
|
74
|
+
right: { logical: 'inset-inline-end' },
|
|
75
|
+
top: { logical: 'inset-block-start' },
|
|
76
|
+
bottom: { logical: 'inset-block-end' },
|
|
77
|
+
'inset-left': { logical: 'inset-inline-start' },
|
|
78
|
+
'inset-right': { logical: 'inset-inline-end' },
|
|
79
|
+
'inset-top': { logical: 'inset-block-start' },
|
|
80
|
+
'inset-bottom': { logical: 'inset-block-end' },
|
|
81
|
+
insetLeft: { logical: 'insetInlineStart' },
|
|
82
|
+
insetRight: { logical: 'insetInlineEnd' },
|
|
83
|
+
insetTop: { logical: 'insetBlockStart' },
|
|
84
|
+
insetBottom: { logical: 'insetBlockEnd' },
|
|
85
|
+
// Overflow properties
|
|
86
|
+
'overflow-x': { logical: 'overflow-inline' },
|
|
87
|
+
'overflow-y': { logical: 'overflow-block' },
|
|
88
|
+
overflowX: { logical: 'overflowInline' },
|
|
89
|
+
overflowY: { logical: 'overflowBlock' },
|
|
90
|
+
// Overscroll properties
|
|
91
|
+
'overscroll-behavior-x': { logical: 'overscroll-behavior-inline' },
|
|
92
|
+
'overscroll-behavior-y': { logical: 'overscroll-behavior-block' },
|
|
93
|
+
overscrollBehaviorX: { logical: 'overscrollBehaviorInline' },
|
|
94
|
+
overscrollBehaviorY: { logical: 'overscrollBehaviorBlock' },
|
|
95
|
+
// Scroll margin properties
|
|
96
|
+
'scroll-margin-left': { logical: 'scroll-margin-inline-start' },
|
|
97
|
+
'scroll-margin-right': { logical: 'scroll-margin-inline-end' },
|
|
98
|
+
'scroll-margin-top': { logical: 'scroll-margin-block-start' },
|
|
99
|
+
'scroll-margin-bottom': { logical: 'scroll-margin-block-end' },
|
|
100
|
+
scrollMarginLeft: { logical: 'scrollMarginInlineStart' },
|
|
101
|
+
scrollMarginRight: { logical: 'scrollMarginInlineEnd' },
|
|
102
|
+
scrollMarginTop: { logical: 'scrollMarginBlockStart' },
|
|
103
|
+
scrollMarginBottom: { logical: 'scrollMarginBlockEnd' },
|
|
104
|
+
// Scroll padding properties
|
|
105
|
+
'scroll-padding-left': { logical: 'scroll-padding-inline-start' },
|
|
106
|
+
'scroll-padding-right': { logical: 'scroll-padding-inline-end' },
|
|
107
|
+
'scroll-padding-top': { logical: 'scroll-padding-block-start' },
|
|
108
|
+
'scroll-padding-bottom': { logical: 'scroll-padding-block-end' },
|
|
109
|
+
scrollPaddingLeft: { logical: 'scrollPaddingInlineStart' },
|
|
110
|
+
scrollPaddingRight: { logical: 'scrollPaddingInlineEnd' },
|
|
111
|
+
scrollPaddingTop: { logical: 'scrollPaddingBlockStart' },
|
|
112
|
+
scrollPaddingBottom: { logical: 'scrollPaddingBlockEnd' },
|
|
113
|
+
// Size properties
|
|
114
|
+
width: { logical: 'inline-size' },
|
|
115
|
+
height: { logical: 'block-size' },
|
|
116
|
+
'min-width': { logical: 'min-inline-size' },
|
|
117
|
+
'min-height': { logical: 'min-block-size' },
|
|
118
|
+
'max-width': { logical: 'max-inline-size' },
|
|
119
|
+
'max-height': { logical: 'max-block-size' },
|
|
120
|
+
minWidth: { logical: 'minInlineSize' },
|
|
121
|
+
minHeight: { logical: 'minBlockSize' },
|
|
122
|
+
maxWidth: { logical: 'maxInlineSize' },
|
|
123
|
+
maxHeight: { logical: 'maxBlockSize' },
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Text-align directional values that should be replaced
|
|
127
|
+
*/
|
|
128
|
+
export const TEXT_ALIGN_PHYSICAL_VALUES = {
|
|
129
|
+
left: 'start',
|
|
130
|
+
right: 'end',
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Float directional values that should be replaced
|
|
134
|
+
*/
|
|
135
|
+
export const FLOAT_PHYSICAL_VALUES = {
|
|
136
|
+
left: 'inline-start',
|
|
137
|
+
right: 'inline-end',
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Clear directional values that should be replaced
|
|
141
|
+
*/
|
|
142
|
+
export const CLEAR_PHYSICAL_VALUES = {
|
|
143
|
+
left: 'inline-start',
|
|
144
|
+
right: 'inline-end',
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Properties where the value (not the property name) needs to be checked for physical directions
|
|
148
|
+
*/
|
|
149
|
+
export const VALUE_BASED_PHYSICAL_PROPERTIES = new Set([
|
|
150
|
+
'text-align',
|
|
151
|
+
'textAlign',
|
|
152
|
+
'float',
|
|
153
|
+
'clear',
|
|
154
|
+
'resize',
|
|
155
|
+
]);
|
|
156
|
+
/**
|
|
157
|
+
* Check if a property name is a physical property that should be converted
|
|
158
|
+
*/
|
|
159
|
+
export function isPhysicalProperty(propertyName) {
|
|
160
|
+
return propertyName in PHYSICAL_TO_LOGICAL;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get the logical equivalent of a physical property
|
|
164
|
+
*/
|
|
165
|
+
export function getLogicalProperty(propertyName) {
|
|
166
|
+
return PHYSICAL_TO_LOGICAL[propertyName]?.logical ?? null;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Convert camelCase to kebab-case
|
|
170
|
+
*/
|
|
171
|
+
export function toKebabCase(name) {
|
|
172
|
+
return name.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Convert kebab-case to camelCase
|
|
176
|
+
*/
|
|
177
|
+
export function toCamelCase(name) {
|
|
178
|
+
return name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
179
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createLogicalPropertiesVisitors } from './logical-properties-visitor-creator.js';
|
|
2
|
+
const preferLogicalPropertiesRule = {
|
|
3
|
+
meta: {
|
|
4
|
+
type: 'suggestion',
|
|
5
|
+
docs: {
|
|
6
|
+
description: 'enforce logical CSS properties over physical directional properties in vanilla-extract',
|
|
7
|
+
category: 'Best Practices',
|
|
8
|
+
recommended: false,
|
|
9
|
+
},
|
|
10
|
+
fixable: 'code',
|
|
11
|
+
schema: [
|
|
12
|
+
{
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
allow: {
|
|
16
|
+
type: 'array',
|
|
17
|
+
items: { type: 'string' },
|
|
18
|
+
uniqueItems: true,
|
|
19
|
+
default: [],
|
|
20
|
+
description: 'List of physical properties to allow (supports both camelCase and kebab-case)',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
messages: {
|
|
27
|
+
preferLogicalProperty: 'Prefer logical CSS property "{{ logical }}" over physical property "{{ physical }}". Logical properties adapt to writing direction.',
|
|
28
|
+
preferLogicalValue: 'Prefer logical value "{{ logical }}" over physical value "{{ physical }}" for property "{{ property }}". Logical values adapt to writing direction.',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
create(context) {
|
|
32
|
+
return createLogicalPropertiesVisitors(context);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
export default preferLogicalPropertiesRule;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,9 +8,11 @@ declare const vanillaExtract: {
|
|
|
8
8
|
'concentric-order': import("eslint").Rule.RuleModule;
|
|
9
9
|
'custom-order': import("eslint").Rule.RuleModule;
|
|
10
10
|
'no-empty-style-blocks': import("eslint").Rule.RuleModule;
|
|
11
|
+
'no-px-unit': import("eslint").Rule.RuleModule;
|
|
11
12
|
'no-trailing-zero': import("eslint").Rule.RuleModule;
|
|
12
13
|
'no-unknown-unit': import("eslint").Rule.RuleModule;
|
|
13
14
|
'no-zero-unit': import("eslint").Rule.RuleModule;
|
|
15
|
+
'prefer-logical-properties': import("eslint").Rule.RuleModule;
|
|
14
16
|
};
|
|
15
17
|
configs: {};
|
|
16
18
|
};
|
package/dist/index.js
CHANGED
|
@@ -2,22 +2,26 @@ import alphabeticalOrderRule from './css-rules/alphabetical-order/index.js';
|
|
|
2
2
|
import concentricOrderRule from './css-rules/concentric-order/index.js';
|
|
3
3
|
import customOrderRule from './css-rules/custom-order/rule-definition.js';
|
|
4
4
|
import noEmptyStyleBlocksRule from './css-rules/no-empty-blocks/rule-definition.js';
|
|
5
|
+
import noPxUnitRule from './css-rules/no-px-unit/index.js';
|
|
5
6
|
import noTrailingZeroRule from './css-rules/no-trailing-zero/rule-definition.js';
|
|
6
7
|
import noUnknownUnitRule from './css-rules/no-unknown-unit/rule-definition.js';
|
|
7
8
|
import noZeroUnitRule from './css-rules/no-zero-unit/rule-definition.js';
|
|
9
|
+
import preferLogicalPropertiesRule from './css-rules/prefer-logical-properties/index.js';
|
|
8
10
|
const vanillaExtract = {
|
|
9
11
|
meta: {
|
|
10
12
|
name: '@antebudimir/eslint-plugin-vanilla-extract',
|
|
11
|
-
version: '1.
|
|
13
|
+
version: '1.14.0',
|
|
12
14
|
},
|
|
13
15
|
rules: {
|
|
14
16
|
'alphabetical-order': alphabeticalOrderRule,
|
|
15
17
|
'concentric-order': concentricOrderRule,
|
|
16
18
|
'custom-order': customOrderRule,
|
|
17
19
|
'no-empty-style-blocks': noEmptyStyleBlocksRule,
|
|
20
|
+
'no-px-unit': noPxUnitRule,
|
|
18
21
|
'no-trailing-zero': noTrailingZeroRule,
|
|
19
22
|
'no-unknown-unit': noUnknownUnitRule,
|
|
20
23
|
'no-zero-unit': noZeroUnitRule,
|
|
24
|
+
'prefer-logical-properties': preferLogicalPropertiesRule,
|
|
21
25
|
},
|
|
22
26
|
configs: {},
|
|
23
27
|
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export declare const theFont: string;
|
|
2
|
+
export declare const spinster: void;
|
|
3
|
+
export declare const starter: string;
|
|
4
|
+
export declare const accordionContent: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
5
|
+
isOpen: {
|
|
6
|
+
false: {
|
|
7
|
+
boxSizing: "inherit";
|
|
8
|
+
position: "relative";
|
|
9
|
+
insetInlineEnd: "inherit";
|
|
10
|
+
display: "flex";
|
|
11
|
+
gap: "revert";
|
|
12
|
+
transform: "none";
|
|
13
|
+
margin: "11rem";
|
|
14
|
+
outline: "none";
|
|
15
|
+
border: "Background";
|
|
16
|
+
borderRadius: "initial";
|
|
17
|
+
borderEndStartRadius: "initial";
|
|
18
|
+
borderEndEndRadius: "initial";
|
|
19
|
+
borderInlineStart: "ActiveBorder";
|
|
20
|
+
borderInlineEnd: "ActiveBorder";
|
|
21
|
+
boxShadow: "none";
|
|
22
|
+
backgroundColor: "initial";
|
|
23
|
+
cursor: "pointer";
|
|
24
|
+
inlineSize: "100%";
|
|
25
|
+
color: "red";
|
|
26
|
+
fontSize: "large";
|
|
27
|
+
};
|
|
28
|
+
true: {
|
|
29
|
+
boxSizing: "inherit";
|
|
30
|
+
position: "relative";
|
|
31
|
+
insetInlineEnd: "inherit";
|
|
32
|
+
display: "flex";
|
|
33
|
+
gap: "revert";
|
|
34
|
+
transform: "none";
|
|
35
|
+
margin: "11rem";
|
|
36
|
+
outline: "none";
|
|
37
|
+
border: "Background";
|
|
38
|
+
borderRadius: "initial";
|
|
39
|
+
borderEndStartRadius: "initial";
|
|
40
|
+
borderEndEndRadius: "initial";
|
|
41
|
+
borderInlineStart: "ActiveBorder";
|
|
42
|
+
borderInlineEnd: "ActiveBorder";
|
|
43
|
+
boxShadow: "none";
|
|
44
|
+
backgroundColor: "initial";
|
|
45
|
+
cursor: "pointer";
|
|
46
|
+
inlineSize: "100%";
|
|
47
|
+
color: "red";
|
|
48
|
+
fontSize: "large";
|
|
49
|
+
':hover': {
|
|
50
|
+
boxSizing: "inherit";
|
|
51
|
+
position: "relative";
|
|
52
|
+
insetInlineEnd: "inherit";
|
|
53
|
+
display: "flex";
|
|
54
|
+
gap: "revert";
|
|
55
|
+
transform: "none";
|
|
56
|
+
margin: "11rem";
|
|
57
|
+
outline: "none";
|
|
58
|
+
border: "Background";
|
|
59
|
+
borderRadius: "initial";
|
|
60
|
+
borderEndStartRadius: "initial";
|
|
61
|
+
borderEndEndRadius: "initial";
|
|
62
|
+
borderInlineStart: "ActiveBorder";
|
|
63
|
+
borderInlineEnd: "ActiveBorder";
|
|
64
|
+
boxShadow: "none";
|
|
65
|
+
backgroundColor: "initial";
|
|
66
|
+
cursor: "pointer";
|
|
67
|
+
inlineSize: "100%";
|
|
68
|
+
color: "red";
|
|
69
|
+
fontSize: "large";
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
}>;
|
|
74
|
+
export declare const item: string;
|
|
75
|
+
export declare const selectButtonVariants: Record<"bordered" | "borderless", string>;
|