@antebudimir/eslint-plugin-vanilla-extract 1.4.7 → 1.6.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.
Files changed (48) hide show
  1. package/README.md +52 -6
  2. package/dist/css-rules/alphabetical-order/property-order-enforcer.js +3 -3
  3. package/dist/css-rules/alphabetical-order/recipe-order-enforcer.js +3 -4
  4. package/dist/css-rules/alphabetical-order/style-object-processor.js +7 -8
  5. package/dist/css-rules/concentric-order/property-order-enforcer.js +10 -11
  6. package/dist/css-rules/concentric-order/recipe-order-enforcer.js +3 -4
  7. package/dist/css-rules/concentric-order/style-object-processor.js +15 -16
  8. package/dist/css-rules/concentric-order/types.d.ts +1 -0
  9. package/dist/css-rules/custom-order/property-order-enforcer.d.ts +2 -2
  10. package/dist/css-rules/custom-order/property-order-enforcer.js +50 -46
  11. package/dist/css-rules/custom-order/recipe-order-enforcer.d.ts +2 -1
  12. package/dist/css-rules/custom-order/recipe-order-enforcer.js +4 -5
  13. package/dist/css-rules/custom-order/rule-definition.js +3 -1
  14. package/dist/css-rules/custom-order/style-object-processor.d.ts +3 -2
  15. package/dist/css-rules/custom-order/style-object-processor.js +28 -29
  16. package/dist/css-rules/no-empty-blocks/conditional-processor.d.ts +6 -0
  17. package/dist/css-rules/no-empty-blocks/conditional-processor.js +26 -0
  18. package/dist/css-rules/no-empty-blocks/empty-nested-style-processor.d.ts +6 -0
  19. package/dist/css-rules/no-empty-blocks/empty-nested-style-processor.js +65 -0
  20. package/dist/css-rules/no-empty-blocks/empty-style-visitor-creator.d.ts +12 -0
  21. package/dist/css-rules/no-empty-blocks/empty-style-visitor-creator.js +183 -0
  22. package/dist/css-rules/no-empty-blocks/fix-utils.d.ts +22 -0
  23. package/dist/css-rules/no-empty-blocks/fix-utils.js +75 -0
  24. package/dist/css-rules/no-empty-blocks/index.d.ts +2 -0
  25. package/dist/css-rules/no-empty-blocks/index.js +2 -0
  26. package/dist/css-rules/no-empty-blocks/node-remover.d.ts +10 -0
  27. package/dist/css-rules/no-empty-blocks/node-remover.js +15 -0
  28. package/dist/css-rules/no-empty-blocks/property-utils.d.ts +9 -0
  29. package/dist/css-rules/no-empty-blocks/property-utils.js +28 -0
  30. package/dist/css-rules/no-empty-blocks/recipe-processor.d.ts +11 -0
  31. package/dist/css-rules/no-empty-blocks/recipe-processor.js +122 -0
  32. package/dist/css-rules/no-empty-blocks/rule-definition.d.ts +3 -0
  33. package/dist/css-rules/no-empty-blocks/rule-definition.js +30 -0
  34. package/dist/css-rules/no-empty-blocks/style-variants-processor.d.ts +10 -0
  35. package/dist/css-rules/no-empty-blocks/style-variants-processor.js +45 -0
  36. package/dist/css-rules/shared-utils/alphabetical-property-comparator.js +3 -3
  37. package/dist/css-rules/shared-utils/empty-object-processor.d.ts +11 -0
  38. package/dist/css-rules/shared-utils/empty-object-processor.js +15 -0
  39. package/dist/css-rules/shared-utils/font-face-property-order-enforcer.js +3 -3
  40. package/dist/css-rules/shared-utils/order-strategy-visitor-creator.d.ts +3 -1
  41. package/dist/css-rules/shared-utils/order-strategy-visitor-creator.js +1 -1
  42. package/dist/css-rules/shared-utils/property-separator.d.ts +1 -1
  43. package/dist/css-rules/shared-utils/property-separator.js +2 -2
  44. package/dist/css-rules/types.d.ts +1 -0
  45. package/dist/css-rules/types.js +1 -0
  46. package/dist/index.d.ts +3 -0
  47. package/dist/index.js +11 -3
  48. package/package.json +13 -13
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @antebudimir/eslint-plugin-vanilla-extract
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@antebudimir/eslint-plugin-vanilla-extract.svg)](https://www.npmjs.com/package/@antebudimir/eslint-plugin-vanilla-extract) [![CI](https://github.com/antebudimir/eslint-plugin-vanilla-extract/actions/workflows/ci.yml/badge.svg)](https://github.com/antebudimir/eslint-plugin-vanilla-extract/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/antebudimir/eslint-plugin-vanilla-extract/badge.svg?branch=main)](https://coveralls.io/github/antebudimir/eslint-plugin-vanilla-extract?branch=main)
3
+ [![CI](https://github.com/antebudimir/eslint-plugin-vanilla-extract/actions/workflows/ci.yml/badge.svg)](https://github.com/antebudimir/eslint-plugin-vanilla-extract/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/antebudimir/eslint-plugin-vanilla-extract/badge.svg?branch=main)](https://coveralls.io/github/antebudimir/eslint-plugin-vanilla-extract?branch=main) [![npm version](https://img.shields.io/npm/v/@antebudimir/eslint-plugin-vanilla-extract.svg)](https://www.npmjs.com/package/@antebudimir/eslint-plugin-vanilla-extract) ![NPM Downloads](https://img.shields.io/npm/d18m/%40antebudimir%2Feslint-plugin-vanilla-extract)
4
4
 
5
5
  An ESLint plugin for enforcing best practices in [vanilla-extract](https://github.com/vanilla-extract-css/vanilla-extract) CSS styles, including CSS property ordering and additional linting rules. Available presets are for alphabetical and [concentric](https://rhodesmill.org/brandon/2011/concentric-css/) CSS ordering. The plugin also supports a custom group ordering option based on groups available in [concentric CSS](src/css-rules/concentric-order/concentric-groups.ts).
6
6
 
@@ -139,11 +139,20 @@ export const myStyle = style({
139
139
 
140
140
  ### vanilla-extract/custom-order
141
141
 
142
- The `vanilla-extract/custom-order` rule allows you to enforce a custom ordering of CSS properties in your vanilla-extract styles. You can specify an array of property groups in the order you prefer, and the rule will ensure that properties within these groups are sorted according to their position in the concentric CSS model. All other groups that aren't included in the groups array will have their respective properties sorted after the last group in the array. You can choose to sort them either alphabetically or following the concentric CSS order (see list of concentric groups) by setting the `sortRemainingProperties` option to 'alphabetical' or 'concentric' respectively. If not set, `sortRemainingProperties` defaults to 'alphabetical'.
142
+ The `vanilla-extract/custom-order` rule enables you to enforce a custom ordering of CSS properties in your vanilla-extract styles. You can specify an array of property groups in your preferred order, and the rule will ensure that properties within these groups are sorted according to their position in the concentric CSS model.
143
143
 
144
- To configure the rule, add it to your ESLint configuration file with your desired options. You can customize the `groups` array to include any number of available CSS property groups you want to enforce, but minimum of 1 is required.
144
+ Key features of this rule include:
145
145
 
146
- Example usage:
146
+ 1. Custom group ordering: Define your preferred order of CSS property groups.
147
+ 2. Handling of unspecified groups: All groups not included in the custom array will have their properties sorted after the last specified group.
148
+ 3. Flexible sorting options: You can choose to sort remaining properties either alphabetically or following the concentric CSS order by setting the `sortRemainingProperties` option to 'alphabetical' or 'concentric' respectively.
149
+
150
+ Default behavior:
151
+
152
+ - If not set, `sortRemainingProperties` defaults to 'alphabetical'.
153
+ - If no `groupOrder` is specified or an empty array is provided, the rule will default to sorting all properties alphabetically, and `sortRemainingProperties` will be ignored even if set.
154
+
155
+ To configure the rule, add it to your ESLint configuration file with your desired options. You can customize the `groups` array to include any number of available CSS property groups you want to enforce, with a minimum of one group required.
147
156
 
148
157
  ```typescript
149
158
  // ❌ Incorrect (Unordered)
@@ -184,6 +193,42 @@ export const myStyle = style({
184
193
  });
185
194
  ```
186
195
 
196
+ ### vanilla-extract/no-empty-style-blocks
197
+
198
+ This rule detects and prevents empty style blocks in vanilla-extract stylesheets. It helps maintain cleaner codebases by eliminating empty style definitions that often result from incomplete refactoring or forgotten implementations.
199
+
200
+ ```typescript
201
+ // ❌ Incorrect
202
+ import { style } from '@vanilla-extract/css';
203
+
204
+ export const emptyStyle = style({});
205
+
206
+ export const nestedEmpty = style({
207
+ color: 'blue',
208
+
209
+ ':hover': {},
210
+ '@media': {
211
+ '(min-width: 768px)': {},
212
+ },
213
+ });
214
+
215
+ export const recipeWithEmptyVariants = recipe({
216
+ base: { color: 'black' },
217
+ variants: {},
218
+ });
219
+
220
+ // ✅ Correct
221
+ import { style } from '@vanilla-extract/css';
222
+
223
+ export const nestedEmpty = style({
224
+ color: 'blue',
225
+ });
226
+
227
+ export const recipeWithEmptyVariants = recipe({
228
+ base: { color: 'black' },
229
+ });
230
+ ```
231
+
187
232
  ## Font Face Declarations
188
233
 
189
234
  For `fontFace` and `globalFontFace` API calls, all three ordering rules (alphabetical, concentric, and custom) enforce the same special ordering:
@@ -257,11 +302,12 @@ The roadmap outlines the project's current status and future plans:
257
302
  - Initial release with support for alphabetical, concentric, and custom group CSS ordering.
258
303
  - Auto-fix capability integrated into ESLint.
259
304
  - Support for multiple vanilla-extract APIs (e.g., `style`, `styleVariants`, `recipe`, `globalStyle`, `fontFace`, etc.).
260
- - Rules tested.
305
+ - `no-empty-style-blocks` rule to disallow empty blocks.
306
+ - Comprehensive rule testing.
261
307
 
262
308
  ### Current Work
263
309
 
264
- - `no-empty-blocks` rule to disallow empty blocks.
310
+ - Setting up recommended ESLint configuration for the plugin.
265
311
 
266
312
  ### Upcoming Features
267
313
 
@@ -1,7 +1,7 @@
1
1
  import { TSESTree } from '@typescript-eslint/utils';
2
2
  import { comparePropertiesAlphabetically } from '../shared-utils/alphabetical-property-comparator.js';
3
3
  import { generateFixesForCSSOrder } from '../shared-utils/css-order-fixer.js';
4
- import { getPropertyName } from '../shared-utils/property-separator.js';
4
+ import { getPropertyNameForSorting } from '../shared-utils/property-separator.js';
5
5
  /**
6
6
  * Reports an ordering issue to ESLint and generates fixes.
7
7
  * @param ruleContext The ESLint rule context.
@@ -14,8 +14,8 @@ const reportOrderingIssue = (ruleContext, currentProperty, nextProperty, regular
14
14
  node: nextProperty,
15
15
  messageId: 'alphabeticalOrder',
16
16
  data: {
17
- nextProperty: getPropertyName(nextProperty),
18
- currentProperty: getPropertyName(currentProperty),
17
+ nextProperty: getPropertyNameForSorting(nextProperty),
18
+ currentProperty: getPropertyNameForSorting(currentProperty),
19
19
  },
20
20
  fix: (fixer) => generateFixesForCSSOrder(fixer, ruleContext, regularProperties, comparePropertiesAlphabetically, (property) => property),
21
21
  });
@@ -14,9 +14,8 @@ import { enforceAlphabeticalCSSOrderInStyleObject } from './style-object-process
14
14
  * 3. For each relevant property (e.g., 'base', 'variants'), it applies alphabetical ordering to the CSS properties.
15
15
  */
16
16
  export const enforceAlphabeticalCSSOrderInRecipe = (node, context) => {
17
- if (!node.arguments[0] || node.arguments[0].type !== 'ObjectExpression') {
18
- return;
17
+ if (node.arguments[0]?.type === 'ObjectExpression') {
18
+ const recipeObject = node.arguments[0];
19
+ processRecipeProperties(context, recipeObject, (context, object) => processStyleNode(context, object, enforceAlphabeticalCSSOrderInStyleObject));
19
20
  }
20
- const recipeObject = node.arguments[0];
21
- processRecipeProperties(context, recipeObject, (context, object) => processStyleNode(context, object, enforceAlphabeticalCSSOrderInStyleObject));
22
21
  };
@@ -15,14 +15,13 @@ import { enforceAlphabeticalCSSOrder } from './property-order-enforcer.js';
15
15
  * @param styleObject - The object expression representing the style object to be processed.
16
16
  */
17
17
  export const enforceAlphabeticalCSSOrderInStyleObject = (ruleContext, styleObject) => {
18
- if (!styleObject || styleObject.type !== AST_NODE_TYPES.ObjectExpression) {
19
- return;
20
- }
21
- if (isSelectorsObject(styleObject)) {
18
+ if (styleObject?.type === AST_NODE_TYPES.ObjectExpression) {
19
+ if (isSelectorsObject(styleObject)) {
20
+ processNestedSelectors(ruleContext, styleObject, enforceAlphabeticalCSSOrderInStyleObject);
21
+ return;
22
+ }
23
+ const { regularProperties } = separateProperties(styleObject.properties);
24
+ enforceAlphabeticalCSSOrder(ruleContext, regularProperties);
22
25
  processNestedSelectors(ruleContext, styleObject, enforceAlphabeticalCSSOrderInStyleObject);
23
- return;
24
26
  }
25
- const { regularProperties } = separateProperties(styleObject.properties);
26
- enforceAlphabeticalCSSOrder(ruleContext, regularProperties);
27
- processNestedSelectors(ruleContext, styleObject, enforceAlphabeticalCSSOrderInStyleObject);
28
27
  };
@@ -45,16 +45,15 @@ const compareProperties = (firstProperty, secondProperty) => {
45
45
  * @param cssPropertyInfoList - An array of CSS property information objects to be checked.
46
46
  */
47
47
  export const enforceConcentricCSSOrder = (ruleContext, cssPropertyInfoList) => {
48
- if (cssPropertyInfoList.length <= 1) {
49
- return;
50
- }
51
- // Create pairs of consecutive properties
52
- const propertyPairs = cssPropertyInfoList.slice(0, -1).map((currentProperty, index) => ({
53
- currentProperty,
54
- nextProperty: cssPropertyInfoList[index + 1],
55
- }));
56
- const violatingPair = propertyPairs.find(({ currentProperty, nextProperty }) => compareProperties(currentProperty, nextProperty) > 0);
57
- if (violatingPair) {
58
- reportOrderingIssue(ruleContext, violatingPair.currentProperty, violatingPair.nextProperty, cssPropertyInfoList);
48
+ if (cssPropertyInfoList.length > 1) {
49
+ // Create pairs of consecutive properties
50
+ const propertyPairs = cssPropertyInfoList.slice(0, -1).map((currentProperty, index) => ({
51
+ currentProperty,
52
+ nextProperty: cssPropertyInfoList[index + 1],
53
+ }));
54
+ const violatingPair = propertyPairs.find(({ currentProperty, nextProperty }) => compareProperties(currentProperty, nextProperty) > 0);
55
+ if (violatingPair) {
56
+ reportOrderingIssue(ruleContext, violatingPair.currentProperty, violatingPair.nextProperty, cssPropertyInfoList);
57
+ }
59
58
  }
60
59
  };
@@ -14,9 +14,8 @@ import { enforceConcentricCSSOrderInStyleObject } from './style-object-processor
14
14
  * 3. For each relevant property (e.g., 'base', 'variants'), it applies concentric ordering to the CSS properties.
15
15
  */
16
16
  export const enforceConcentricCSSOrderInRecipe = (ruleContext, callExpression) => {
17
- if (!callExpression.arguments[0] || callExpression.arguments[0].type !== 'ObjectExpression') {
18
- return;
17
+ if (callExpression.arguments[0]?.type === 'ObjectExpression') {
18
+ const recipeObjectExpression = callExpression.arguments[0];
19
+ processRecipeProperties(ruleContext, recipeObjectExpression, (currentContext, styleObject) => processStyleNode(currentContext, styleObject, enforceConcentricCSSOrderInStyleObject));
19
20
  }
20
- const recipeObjectExpression = callExpression.arguments[0];
21
- processRecipeProperties(ruleContext, recipeObjectExpression, (currentContext, styleObject) => processStyleNode(currentContext, styleObject, enforceConcentricCSSOrderInStyleObject));
22
21
  };
@@ -1,7 +1,7 @@
1
1
  import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
2
  import { createCSSPropertyPriorityMap } from '../shared-utils/css-property-priority-map.js';
3
3
  import { isSelectorsObject, processNestedSelectors } from '../shared-utils/nested-selectors-processor.js';
4
- import { getPropertyName, separateProperties } from '../shared-utils/property-separator.js';
4
+ import { getPropertyNameForSorting, separateProperties } from '../shared-utils/property-separator.js';
5
5
  import { enforceConcentricCSSOrder } from './property-order-enforcer.js';
6
6
  const cssPropertyPriorityMap = createCSSPropertyPriorityMap();
7
7
  /**
@@ -12,7 +12,7 @@ const cssPropertyPriorityMap = createCSSPropertyPriorityMap();
12
12
  */
13
13
  const buildCSSPropertyInfoList = (regularStyleProperties) => {
14
14
  return regularStyleProperties.map((styleProperty) => {
15
- const propertyName = getPropertyName(styleProperty);
15
+ const propertyName = getPropertyNameForSorting(styleProperty);
16
16
  const propertyInfo = cssPropertyPriorityMap.get(propertyName);
17
17
  return {
18
18
  name: propertyName,
@@ -41,19 +41,18 @@ const buildCSSPropertyInfoList = (regularStyleProperties) => {
41
41
  * @param styleObject - The object expression representing the style object to be processed.
42
42
  */
43
43
  export const enforceConcentricCSSOrderInStyleObject = (ruleContext, styleObject) => {
44
- if (!styleObject || styleObject.type !== AST_NODE_TYPES.ObjectExpression) {
45
- return;
44
+ if (styleObject?.type === AST_NODE_TYPES.ObjectExpression) {
45
+ if (isSelectorsObject(styleObject)) {
46
+ styleObject.properties.forEach((property) => {
47
+ if (property.type === AST_NODE_TYPES.Property && property.value.type === AST_NODE_TYPES.ObjectExpression) {
48
+ enforceConcentricCSSOrderInStyleObject(ruleContext, property.value);
49
+ }
50
+ });
51
+ return;
52
+ }
53
+ const { regularProperties } = separateProperties(styleObject.properties);
54
+ const cssPropertyInfoList = buildCSSPropertyInfoList(regularProperties);
55
+ enforceConcentricCSSOrder(ruleContext, cssPropertyInfoList);
56
+ processNestedSelectors(ruleContext, styleObject, enforceConcentricCSSOrderInStyleObject);
46
57
  }
47
- if (isSelectorsObject(styleObject)) {
48
- styleObject.properties.forEach((property) => {
49
- if (property.type === AST_NODE_TYPES.Property && property.value.type === AST_NODE_TYPES.ObjectExpression) {
50
- enforceConcentricCSSOrderInStyleObject(ruleContext, property.value);
51
- }
52
- });
53
- return;
54
- }
55
- const { regularProperties } = separateProperties(styleObject.properties);
56
- const cssPropertyInfoList = buildCSSPropertyInfoList(regularProperties);
57
- enforceConcentricCSSOrder(ruleContext, cssPropertyInfoList);
58
- processNestedSelectors(ruleContext, styleObject, enforceConcentricCSSOrderInStyleObject);
59
58
  };
@@ -6,3 +6,4 @@ export interface CSSPropertyInfo {
6
6
  positionInGroup: number;
7
7
  group?: string;
8
8
  }
9
+ export type SortRemainingProperties = 'alphabetical' | 'concentric';
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from 'eslint';
2
- import type { CSSPropertyInfo } from '../concentric-order/types.js';
2
+ import type { CSSPropertyInfo, SortRemainingProperties } from '../concentric-order/types.js';
3
3
  /**
4
4
  * Enforces a custom ordering of CSS properties based on user-defined groups.
5
5
  *
@@ -14,4 +14,4 @@ import type { CSSPropertyInfo } from '../concentric-order/types.js';
14
14
  * specified strategy. If an ordering violation is detected, an ESLint report is generated
15
15
  * with a suggested fix.
16
16
  */
17
- export declare const enforceCustomGroupOrder: (ruleContext: Rule.RuleContext, cssPropertyInfoList: CSSPropertyInfo[], userDefinedGroups?: string[], sortRemainingProperties?: "alphabetical" | "concentric") => void;
17
+ export declare const enforceCustomGroupOrder: (ruleContext: Rule.RuleContext, cssPropertyInfoList: CSSPropertyInfo[], userDefinedGroups?: string[], sortRemainingProperties?: SortRemainingProperties) => void;
@@ -15,53 +15,57 @@ import { createCSSPropertyPriorityMap } from '../shared-utils/css-property-prior
15
15
  * with a suggested fix.
16
16
  */
17
17
  export const enforceCustomGroupOrder = (ruleContext, cssPropertyInfoList, userDefinedGroups = [], sortRemainingProperties) => {
18
- if (cssPropertyInfoList.length <= 1) {
19
- return;
20
- }
21
- const cssPropertyPriorityMap = createCSSPropertyPriorityMap(userDefinedGroups);
22
- const compareProperties = (firstProperty, secondProperty) => {
23
- const firstPropertyInfo = cssPropertyPriorityMap.get(firstProperty.name) || {
24
- groupIndex: Infinity,
25
- positionInGroup: Infinity,
26
- inUserGroup: false,
27
- };
28
- const secondPropertyInfo = cssPropertyPriorityMap.get(secondProperty.name) || {
29
- groupIndex: Infinity,
30
- positionInGroup: Infinity,
31
- inUserGroup: false,
32
- };
33
- if (firstPropertyInfo.inUserGroup !== secondPropertyInfo.inUserGroup) {
34
- return firstPropertyInfo.inUserGroup ? -1 : 1;
35
- }
36
- if (firstPropertyInfo.inUserGroup) {
37
- if (firstPropertyInfo.groupIndex !== secondPropertyInfo.groupIndex) {
38
- return firstPropertyInfo.groupIndex - secondPropertyInfo.groupIndex;
18
+ if (cssPropertyInfoList.length > 1) {
19
+ const cssPropertyPriorityMap = createCSSPropertyPriorityMap(userDefinedGroups);
20
+ const compareProperties = (firstProperty, secondProperty) => {
21
+ const firstPropertyInfo = cssPropertyPriorityMap.get(firstProperty.name) || {
22
+ groupIndex: Infinity,
23
+ positionInGroup: Infinity,
24
+ inUserGroup: false,
25
+ };
26
+ const secondPropertyInfo = cssPropertyPriorityMap.get(secondProperty.name) || {
27
+ groupIndex: Infinity,
28
+ positionInGroup: Infinity,
29
+ inUserGroup: false,
30
+ };
31
+ if (firstPropertyInfo.inUserGroup !== secondPropertyInfo.inUserGroup) {
32
+ return firstPropertyInfo.inUserGroup ? -1 : 1;
39
33
  }
40
- return firstPropertyInfo.positionInGroup - secondPropertyInfo.positionInGroup;
41
- }
42
- // For properties not in user-defined groups
43
- if (sortRemainingProperties === 'alphabetical') {
44
- return firstProperty.name.localeCompare(secondProperty.name);
45
- }
46
- else {
47
- return (firstPropertyInfo.groupIndex - secondPropertyInfo.groupIndex ||
48
- firstPropertyInfo.positionInGroup - secondPropertyInfo.positionInGroup);
34
+ if (firstPropertyInfo.inUserGroup) {
35
+ if (firstPropertyInfo.groupIndex !== secondPropertyInfo.groupIndex) {
36
+ return firstPropertyInfo.groupIndex - secondPropertyInfo.groupIndex;
37
+ }
38
+ return firstPropertyInfo.positionInGroup - secondPropertyInfo.positionInGroup;
39
+ }
40
+ // For properties not in user-defined groups
41
+ if (sortRemainingProperties === 'alphabetical') {
42
+ return firstProperty.name.localeCompare(secondProperty.name);
43
+ }
44
+ else {
45
+ return (firstPropertyInfo.groupIndex - secondPropertyInfo.groupIndex ||
46
+ firstPropertyInfo.positionInGroup - secondPropertyInfo.positionInGroup);
47
+ }
48
+ };
49
+ const sortedPropertyList = [...cssPropertyInfoList].sort(compareProperties);
50
+ // Find the first pair that violates the new ordering
51
+ const violatingProperty = cssPropertyInfoList
52
+ .slice(0, -1)
53
+ .find((currentProperty, index) => currentProperty.name !== sortedPropertyList[index]?.name);
54
+ if (violatingProperty) {
55
+ const indexInSorted = cssPropertyInfoList.indexOf(violatingProperty);
56
+ const sortedProperty = sortedPropertyList[indexInSorted];
57
+ // Defensive programming - sortedProperty will always exist and have a name because sortedPropertyList is derived from cssPropertyInfoList and cssPropertyInfoList exists and is non-empty.
58
+ // This fallback is theoretically unreachable in practice but included for type safety.
59
+ const nextPropertyName = sortedProperty?.name ?? '';
60
+ ruleContext.report({
61
+ node: violatingProperty.node,
62
+ messageId: 'incorrectOrder',
63
+ data: {
64
+ currentProperty: violatingProperty.name,
65
+ nextProperty: nextPropertyName,
66
+ },
67
+ fix: (fixer) => generateFixesForCSSOrder(fixer, ruleContext, cssPropertyInfoList, compareProperties, (propertyInfo) => propertyInfo.node),
68
+ });
49
69
  }
50
- };
51
- const sortedPropertyList = [...cssPropertyInfoList].sort(compareProperties);
52
- // Find the first pair that violates the new ordering
53
- const violatingProperty = cssPropertyInfoList
54
- .slice(0, -1)
55
- .find((currentProperty, index) => currentProperty.name !== sortedPropertyList[index]?.name);
56
- if (violatingProperty) {
57
- ruleContext.report({
58
- node: violatingProperty.node,
59
- messageId: 'incorrectOrder',
60
- data: {
61
- currentProperty: violatingProperty.name,
62
- nextProperty: sortedPropertyList[cssPropertyInfoList.indexOf(violatingProperty)]?.name || '',
63
- },
64
- fix: (fixer) => generateFixesForCSSOrder(fixer, ruleContext, cssPropertyInfoList, compareProperties, (propertyInfo) => propertyInfo.node),
65
- });
66
70
  }
67
71
  };
@@ -1,5 +1,6 @@
1
1
  import type { Rule } from 'eslint';
2
2
  import { TSESTree } from '@typescript-eslint/utils';
3
+ import type { SortRemainingProperties } from '../concentric-order/types.js';
3
4
  /**
4
5
  * Enforces custom group ordering of CSS properties within a recipe function call.
5
6
  *
@@ -13,4 +14,4 @@ import { TSESTree } from '@typescript-eslint/utils';
13
14
  * 3. Applies custom group ordering to CSS properties in relevant properties (e.g., 'base', 'variants').
14
15
  * 4. Processes nested selectors and style objects recursively.
15
16
  */
16
- export declare const enforceUserDefinedGroupOrderInRecipe: (ruleContext: Rule.RuleContext, callExpression: TSESTree.CallExpression, userDefinedGroups: string[], sortRemainingPropertiesMethod?: "alphabetical" | "concentric") => void;
17
+ export declare const enforceUserDefinedGroupOrderInRecipe: (ruleContext: Rule.RuleContext, callExpression: TSESTree.CallExpression, userDefinedGroups: string[], sortRemainingProperties?: SortRemainingProperties) => void;
@@ -15,10 +15,9 @@ import { enforceUserDefinedGroupOrderInStyleObject } from './style-object-proces
15
15
  * 3. Applies custom group ordering to CSS properties in relevant properties (e.g., 'base', 'variants').
16
16
  * 4. Processes nested selectors and style objects recursively.
17
17
  */
18
- export const enforceUserDefinedGroupOrderInRecipe = (ruleContext, callExpression, userDefinedGroups, sortRemainingPropertiesMethod) => {
19
- if (!callExpression.arguments[0] || callExpression.arguments[0].type !== 'ObjectExpression') {
20
- return;
18
+ export const enforceUserDefinedGroupOrderInRecipe = (ruleContext, callExpression, userDefinedGroups, sortRemainingProperties) => {
19
+ if (callExpression.arguments[0]?.type === 'ObjectExpression') {
20
+ const recipeObjectExpression = callExpression.arguments[0];
21
+ processRecipeProperties(ruleContext, recipeObjectExpression, (currentContext, styleObject) => processStyleNode(currentContext, styleObject, (styleContext, styleObjectNode) => enforceUserDefinedGroupOrderInStyleObject(styleContext, styleObjectNode, userDefinedGroups, sortRemainingProperties)));
21
22
  }
22
- const recipeObjectExpression = callExpression.arguments[0];
23
- processRecipeProperties(ruleContext, recipeObjectExpression, (currentContext, styleObject) => processStyleNode(currentContext, styleObject, (styleContext, styleObjectNode) => enforceUserDefinedGroupOrderInStyleObject(styleContext, styleObjectNode, userDefinedGroups, sortRemainingPropertiesMethod)));
24
23
  };
@@ -27,8 +27,10 @@ const customGroupOrderRule = {
27
27
  },
28
28
  ],
29
29
  messages: {
30
- incorrectOrder: "Property '{{nextProperty}}' should come before '{{currentProperty}}' according to custom CSS group ordering.",
30
+ // default message for ordering in case no groupOrder is provided
31
+ alphabeticalOrder: "Property '{{nextProperty}}' should come before '{{currentProperty}}' according to alphabetical ordering.",
31
32
  fontFaceOrder: "Properties in fontFace should be ordered with 'src' first, followed by other properties in alphabetical order. Property '{{nextProperty}}' should come before '{{currentProperty}}'.",
33
+ incorrectOrder: "Property '{{nextProperty}}' should come before '{{currentProperty}}' according to custom CSS group ordering.",
32
34
  },
33
35
  },
34
36
  create(ruleContext) {
@@ -1,12 +1,13 @@
1
1
  import type { Rule } from 'eslint';
2
2
  import { TSESTree } from '@typescript-eslint/utils';
3
+ import type { SortRemainingProperties } from '../concentric-order/types.js';
3
4
  /**
4
5
  * Enforces a custom ordering of CSS properties based on user-defined groups in a given style object.
5
6
  *
6
7
  * @param context The ESLint rule context for reporting and fixing issues.
7
8
  * @param styleObject The ObjectExpression node representing the style object to be processed.
8
9
  * @param userDefinedGroups An array of property groups in the desired order.
9
- * @param sortRemainingPropertiesMethod Strategy for sorting properties not in user-defined groups ('alphabetical' or 'concentric'). Defaults to 'concentric'.
10
+ * @param sortRemainingProperties Strategy for sorting properties not in user-defined groups ('alphabetical' or 'concentric'). Defaults to 'concentric'.
10
11
  *
11
12
  * This function:
12
13
  * 1. Validates the input styleObject.
@@ -16,4 +17,4 @@ import { TSESTree } from '@typescript-eslint/utils';
16
17
  * 5. Enforces custom group ordering on the properties.
17
18
  * 6. Recursively processes nested selectors and style objects.
18
19
  */
19
- export declare const enforceUserDefinedGroupOrderInStyleObject: (ruleContext: Rule.RuleContext, styleObject: TSESTree.ObjectExpression, userDefinedGroups: string[], sortRemainingPropertiesMethod?: "alphabetical" | "concentric") => void;
20
+ export declare const enforceUserDefinedGroupOrderInStyleObject: (ruleContext: Rule.RuleContext, styleObject: TSESTree.ObjectExpression, userDefinedGroups: string[], sortRemainingProperties?: SortRemainingProperties) => void;
@@ -2,7 +2,7 @@ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
2
  import { concentricGroups } from '../concentric-order/concentric-groups.js';
3
3
  import { createCSSPropertyPriorityMap } from '../shared-utils/css-property-priority-map.js';
4
4
  import { isSelectorsObject, processNestedSelectors } from '../shared-utils/nested-selectors-processor.js';
5
- import { getPropertyName, separateProperties } from '../shared-utils/property-separator.js';
5
+ import { getPropertyNameForSorting, separateProperties } from '../shared-utils/property-separator.js';
6
6
  import { enforceCustomGroupOrder } from './property-order-enforcer.js';
7
7
  /**
8
8
  * Enforces a custom ordering of CSS properties based on user-defined groups in a given style object.
@@ -10,7 +10,7 @@ import { enforceCustomGroupOrder } from './property-order-enforcer.js';
10
10
  * @param context The ESLint rule context for reporting and fixing issues.
11
11
  * @param styleObject The ObjectExpression node representing the style object to be processed.
12
12
  * @param userDefinedGroups An array of property groups in the desired order.
13
- * @param sortRemainingPropertiesMethod Strategy for sorting properties not in user-defined groups ('alphabetical' or 'concentric'). Defaults to 'concentric'.
13
+ * @param sortRemainingProperties Strategy for sorting properties not in user-defined groups ('alphabetical' or 'concentric'). Defaults to 'concentric'.
14
14
  *
15
15
  * This function:
16
16
  * 1. Validates the input styleObject.
@@ -20,33 +20,32 @@ import { enforceCustomGroupOrder } from './property-order-enforcer.js';
20
20
  * 5. Enforces custom group ordering on the properties.
21
21
  * 6. Recursively processes nested selectors and style objects.
22
22
  */
23
- export const enforceUserDefinedGroupOrderInStyleObject = (ruleContext, styleObject, userDefinedGroups, sortRemainingPropertiesMethod = 'concentric') => {
24
- if (!styleObject || styleObject.type !== AST_NODE_TYPES.ObjectExpression) {
25
- return;
26
- }
27
- if (isSelectorsObject(styleObject)) {
28
- styleObject.properties.forEach((property) => {
29
- if (property.type === AST_NODE_TYPES.Property && property.value.type === AST_NODE_TYPES.ObjectExpression) {
30
- enforceUserDefinedGroupOrderInStyleObject(ruleContext, property.value, userDefinedGroups, sortRemainingPropertiesMethod);
31
- }
23
+ export const enforceUserDefinedGroupOrderInStyleObject = (ruleContext, styleObject, userDefinedGroups, sortRemainingProperties = 'concentric') => {
24
+ if (styleObject?.type === AST_NODE_TYPES.ObjectExpression) {
25
+ if (isSelectorsObject(styleObject)) {
26
+ styleObject.properties.forEach((property) => {
27
+ if (property.type === AST_NODE_TYPES.Property && property.value.type === AST_NODE_TYPES.ObjectExpression) {
28
+ enforceUserDefinedGroupOrderInStyleObject(ruleContext, property.value, userDefinedGroups, sortRemainingProperties);
29
+ }
30
+ });
31
+ return;
32
+ }
33
+ const cssPropertyPriorityMap = createCSSPropertyPriorityMap(userDefinedGroups);
34
+ const { regularProperties } = separateProperties(styleObject.properties);
35
+ const cssPropertyInfoList = regularProperties.map((property) => {
36
+ const propertyName = getPropertyNameForSorting(property);
37
+ const propertyInfo = cssPropertyPriorityMap.get(propertyName);
38
+ const group = userDefinedGroups.find((groupName) => concentricGroups[groupName]?.includes(propertyName)) || 'remaining';
39
+ return {
40
+ name: propertyName,
41
+ node: property,
42
+ priority: propertyInfo?.groupIndex ?? Number.MAX_SAFE_INTEGER,
43
+ positionInGroup: propertyInfo?.positionInGroup ?? Number.MAX_SAFE_INTEGER,
44
+ group,
45
+ inUserGroup: propertyInfo?.inUserGroup ?? false,
46
+ };
32
47
  });
33
- return;
48
+ enforceCustomGroupOrder(ruleContext, cssPropertyInfoList, userDefinedGroups, sortRemainingProperties);
49
+ processNestedSelectors(ruleContext, styleObject, (nestedContext, nestedNode) => enforceUserDefinedGroupOrderInStyleObject(nestedContext, nestedNode, userDefinedGroups, sortRemainingProperties));
34
50
  }
35
- const cssPropertyPriorityMap = createCSSPropertyPriorityMap(userDefinedGroups);
36
- const { regularProperties } = separateProperties(styleObject.properties);
37
- const cssPropertyInfoList = regularProperties.map((property) => {
38
- const propertyName = getPropertyName(property);
39
- const propertyInfo = cssPropertyPriorityMap.get(propertyName);
40
- const group = userDefinedGroups.find((groupName) => concentricGroups[groupName]?.includes(propertyName)) || 'remaining';
41
- return {
42
- name: propertyName,
43
- node: property,
44
- priority: propertyInfo?.groupIndex ?? Number.MAX_SAFE_INTEGER,
45
- positionInGroup: propertyInfo?.positionInGroup ?? Number.MAX_SAFE_INTEGER,
46
- group,
47
- inUserGroup: propertyInfo?.inUserGroup ?? false,
48
- };
49
- });
50
- enforceCustomGroupOrder(ruleContext, cssPropertyInfoList, userDefinedGroups, sortRemainingPropertiesMethod);
51
- processNestedSelectors(ruleContext, styleObject, (nestedContext, nestedNode) => enforceUserDefinedGroupOrderInStyleObject(nestedContext, nestedNode, userDefinedGroups, sortRemainingPropertiesMethod));
52
51
  };
@@ -0,0 +1,6 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ /**
4
+ * Handles conditional expressions with empty objects.
5
+ */
6
+ export declare function processConditionalExpression(context: Rule.RuleContext, node: TSESTree.ConditionalExpression, reportedNodes: Set<TSESTree.Node>, callNode: TSESTree.CallExpression): void;
@@ -0,0 +1,26 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ import { isEmptyObject } from '../shared-utils/empty-object-processor.js';
3
+ import { reportEmptyDeclaration } from './fix-utils.js';
4
+ /**
5
+ * Handles conditional expressions with empty objects.
6
+ */
7
+ export function processConditionalExpression(context, node, reportedNodes, callNode) {
8
+ const isConsequentEmpty = node.consequent.type === 'ObjectExpression' && isEmptyObject(node.consequent);
9
+ const isAlternateEmpty = node.alternate.type === 'ObjectExpression' && isEmptyObject(node.alternate);
10
+ // If both branches are empty, report the entire declaration for removal
11
+ if (isConsequentEmpty && isAlternateEmpty) {
12
+ reportedNodes.add(node);
13
+ reportEmptyDeclaration(context, node, callNode);
14
+ return;
15
+ }
16
+ // Otherwise, handle individual empty branches
17
+ if (isConsequentEmpty || isAlternateEmpty) {
18
+ const emptyNode = isConsequentEmpty ? node.consequent : node.alternate;
19
+ reportedNodes.add(emptyNode);
20
+ // No fix provided, just flagging the issue
21
+ context.report({
22
+ node: emptyNode,
23
+ messageId: 'emptyConditionalStyle',
24
+ });
25
+ }
26
+ }
@@ -0,0 +1,6 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ /**
4
+ * Processes nested style objects like selectors and media queries.
5
+ */
6
+ export declare function processEmptyNestedStyles(ruleContext: Rule.RuleContext, node: TSESTree.ObjectExpression, reportedNodes: Set<TSESTree.Node>): void;
@@ -0,0 +1,65 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ import { isEmptyObject } from '../shared-utils/empty-object-processor.js';
3
+ import { removeNodeWithComma } from './node-remover.js';
4
+ import { areAllChildrenEmpty, getStyleKeyName } from './property-utils.js';
5
+ /**
6
+ * Processes nested style objects like selectors and media queries.
7
+ */
8
+ export function processEmptyNestedStyles(ruleContext, node, reportedNodes) {
9
+ node.properties.forEach((property) => {
10
+ if (property.type !== 'Property') {
11
+ return;
12
+ }
13
+ const propertyName = getStyleKeyName(property.key);
14
+ if (!propertyName) {
15
+ return;
16
+ }
17
+ // Handle selectors, media queries, and supports
18
+ if ((propertyName === 'selectors' || propertyName.startsWith('@')) && property.value.type === 'ObjectExpression') {
19
+ // If the container is empty or all its children are empty, remove the entire property
20
+ if (isEmptyObject(property.value) || areAllChildrenEmpty(property.value)) {
21
+ if (!reportedNodes.has(property)) {
22
+ reportedNodes.add(property);
23
+ const messageId = propertyName === 'selectors'
24
+ ? 'emptySelectors'
25
+ : propertyName === '@media'
26
+ ? 'emptyMedia'
27
+ : propertyName === '@supports'
28
+ ? 'emptySupports'
29
+ : 'emptyConditionalStyle';
30
+ ruleContext.report({
31
+ node: property,
32
+ messageId,
33
+ fix(fixer) {
34
+ return removeNodeWithComma(ruleContext, property, fixer);
35
+ },
36
+ });
37
+ }
38
+ return;
39
+ }
40
+ // Process individual selectors or media queries if we're not removing the entire container
41
+ property.value.properties.forEach((nestedProperty) => {
42
+ if (nestedProperty.type === 'Property') {
43
+ if (nestedProperty.value.type === 'ObjectExpression') {
44
+ if (isEmptyObject(nestedProperty.value)) {
45
+ if (!reportedNodes.has(nestedProperty)) {
46
+ reportedNodes.add(nestedProperty);
47
+ ruleContext.report({
48
+ node: nestedProperty,
49
+ messageId: 'emptyNestedStyle',
50
+ fix(fixer) {
51
+ return removeNodeWithComma(ruleContext, nestedProperty, fixer);
52
+ },
53
+ });
54
+ }
55
+ }
56
+ else {
57
+ // Recursively process nested styles (for deeply nested selectors/media)
58
+ processEmptyNestedStyles(ruleContext, nestedProperty.value, reportedNodes);
59
+ }
60
+ }
61
+ }
62
+ });
63
+ }
64
+ });
65
+ }