@antebudimir/eslint-plugin-vanilla-extract 1.0.1

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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +242 -0
  3. package/dist/css/test.css.d.ts +159 -0
  4. package/dist/css/test.css.js +468 -0
  5. package/dist/css/testFileForOtherMethods.css.d.ts +3 -0
  6. package/dist/css/testFileForOtherMethods.css.js +101 -0
  7. package/dist/css-rules/alphabetical-order/index.d.ts +2 -0
  8. package/dist/css-rules/alphabetical-order/index.js +2 -0
  9. package/dist/css-rules/alphabetical-order/property-order-enforcer.d.ts +14 -0
  10. package/dist/css-rules/alphabetical-order/property-order-enforcer.js +57 -0
  11. package/dist/css-rules/alphabetical-order/recipe-order-enforcer.d.ts +14 -0
  12. package/dist/css-rules/alphabetical-order/recipe-order-enforcer.js +22 -0
  13. package/dist/css-rules/alphabetical-order/rule-definition.d.ts +3 -0
  14. package/dist/css-rules/alphabetical-order/rule-definition.js +20 -0
  15. package/dist/css-rules/alphabetical-order/style-object-processor.d.ts +15 -0
  16. package/dist/css-rules/alphabetical-order/style-object-processor.js +28 -0
  17. package/dist/css-rules/concentric-order/concentric-groups.d.ts +7 -0
  18. package/dist/css-rules/concentric-order/concentric-groups.js +307 -0
  19. package/dist/css-rules/concentric-order/index.d.ts +2 -0
  20. package/dist/css-rules/concentric-order/index.js +2 -0
  21. package/dist/css-rules/concentric-order/property-order-enforcer.d.ts +16 -0
  22. package/dist/css-rules/concentric-order/property-order-enforcer.js +60 -0
  23. package/dist/css-rules/concentric-order/recipe-order-enforcer.d.ts +14 -0
  24. package/dist/css-rules/concentric-order/recipe-order-enforcer.js +22 -0
  25. package/dist/css-rules/concentric-order/rule-definition.d.ts +3 -0
  26. package/dist/css-rules/concentric-order/rule-definition.js +20 -0
  27. package/dist/css-rules/concentric-order/style-object-processor.d.ts +21 -0
  28. package/dist/css-rules/concentric-order/style-object-processor.js +59 -0
  29. package/dist/css-rules/concentric-order/types.d.ts +8 -0
  30. package/dist/css-rules/concentric-order/types.js +1 -0
  31. package/dist/css-rules/custom-order/property-order-enforcer.d.ts +17 -0
  32. package/dist/css-rules/custom-order/property-order-enforcer.js +67 -0
  33. package/dist/css-rules/custom-order/recipe-order-enforcer.d.ts +16 -0
  34. package/dist/css-rules/custom-order/recipe-order-enforcer.js +24 -0
  35. package/dist/css-rules/custom-order/rule-definition.d.ts +3 -0
  36. package/dist/css-rules/custom-order/rule-definition.js +40 -0
  37. package/dist/css-rules/custom-order/style-object-processor.d.ts +19 -0
  38. package/dist/css-rules/custom-order/style-object-processor.js +52 -0
  39. package/dist/css-rules/shared-utils/css-order-fixer.d.ts +17 -0
  40. package/dist/css-rules/shared-utils/css-order-fixer.js +39 -0
  41. package/dist/css-rules/shared-utils/css-property-priority-map.d.ts +25 -0
  42. package/dist/css-rules/shared-utils/css-property-priority-map.js +48 -0
  43. package/dist/css-rules/shared-utils/nested-selectors-processor.d.ts +25 -0
  44. package/dist/css-rules/shared-utils/nested-selectors-processor.js +35 -0
  45. package/dist/css-rules/shared-utils/order-strategy-visitor-creator.d.ts +17 -0
  46. package/dist/css-rules/shared-utils/order-strategy-visitor-creator.js +76 -0
  47. package/dist/css-rules/shared-utils/property-separator.d.ts +28 -0
  48. package/dist/css-rules/shared-utils/property-separator.js +49 -0
  49. package/dist/css-rules/shared-utils/recipe-property-processor.d.ts +16 -0
  50. package/dist/css-rules/shared-utils/recipe-property-processor.js +37 -0
  51. package/dist/css-rules/shared-utils/style-node-processor.d.ts +9 -0
  52. package/dist/css-rules/shared-utils/style-node-processor.js +22 -0
  53. package/dist/css-sample/sample.css.d.ts +161 -0
  54. package/dist/css-sample/sample.css.js +551 -0
  55. package/dist/index.d.ts +38 -0
  56. package/dist/index.js +37 -0
  57. package/package.json +75 -0
@@ -0,0 +1,17 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { CSSPropertyInfo } from '../concentric-order/types.js';
3
+ /**
4
+ * Enforces a custom ordering of CSS properties based on user-defined groups.
5
+ *
6
+ * @param ruleContext The ESLint rule context used for reporting and fixing.
7
+ * @param cssPropertyInfoList An array of CSS property information objects to be ordered.
8
+ * @param userDefinedGroups Array of user-defined property groups for custom ordering.
9
+ * @param sortRemainingProperties Strategy for sorting properties not in user-defined groups
10
+ * ('alphabetical' or 'concentric'). Defaults to 'concentric'.
11
+ *
12
+ * This function compares CSS properties based on their group priority and position within
13
+ * those groups. Properties not part of user-defined groups are sorted according to the
14
+ * specified strategy. If an ordering violation is detected, an ESLint report is generated
15
+ * with a suggested fix.
16
+ */
17
+ export declare const enforceCustomGroupOrder: (ruleContext: Rule.RuleContext, cssPropertyInfoList: CSSPropertyInfo[], userDefinedGroups?: string[], sortRemainingProperties?: "alphabetical" | "concentric") => void;
@@ -0,0 +1,67 @@
1
+ import { generateFixesForCSSOrder } from '../shared-utils/css-order-fixer.js';
2
+ import { createCSSPropertyPriorityMap } from '../shared-utils/css-property-priority-map.js';
3
+ /**
4
+ * Enforces a custom ordering of CSS properties based on user-defined groups.
5
+ *
6
+ * @param ruleContext The ESLint rule context used for reporting and fixing.
7
+ * @param cssPropertyInfoList An array of CSS property information objects to be ordered.
8
+ * @param userDefinedGroups Array of user-defined property groups for custom ordering.
9
+ * @param sortRemainingProperties Strategy for sorting properties not in user-defined groups
10
+ * ('alphabetical' or 'concentric'). Defaults to 'concentric'.
11
+ *
12
+ * This function compares CSS properties based on their group priority and position within
13
+ * those groups. Properties not part of user-defined groups are sorted according to the
14
+ * specified strategy. If an ordering violation is detected, an ESLint report is generated
15
+ * with a suggested fix.
16
+ */
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;
39
+ }
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);
49
+ }
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
+ }
67
+ };
@@ -0,0 +1,16 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ /**
4
+ * Enforces custom group ordering of CSS properties within a recipe function call.
5
+ *
6
+ * @param ruleContext The ESLint rule context for reporting and fixing issues.
7
+ * @param callExpression The CallExpression node representing the recipe function call.
8
+ * @param userDefinedGroups An array of property groups in the desired order.
9
+ *
10
+ * This function does the following:
11
+ * 1. Validates that the first argument of the recipe function is an ObjectExpression.
12
+ * 2. Processes the recipe object's properties if valid.
13
+ * 3. Applies custom group ordering to CSS properties in relevant properties (e.g., 'base', 'variants').
14
+ * 4. Processes nested selectors and style objects recursively.
15
+ */
16
+ export declare const enforceUserDefinedGroupOrderInRecipe: (ruleContext: Rule.RuleContext, callExpression: TSESTree.CallExpression, userDefinedGroups: string[], sortRemainingPropertiesMethod?: "alphabetical" | "concentric") => void;
@@ -0,0 +1,24 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
3
+ import { processStyleNode } from '../shared-utils/style-node-processor.js';
4
+ import { enforceUserDefinedGroupOrderInStyleObject } from './style-object-processor.js';
5
+ /**
6
+ * Enforces custom group ordering of CSS properties within a recipe function call.
7
+ *
8
+ * @param ruleContext The ESLint rule context for reporting and fixing issues.
9
+ * @param callExpression The CallExpression node representing the recipe function call.
10
+ * @param userDefinedGroups An array of property groups in the desired order.
11
+ *
12
+ * This function does the following:
13
+ * 1. Validates that the first argument of the recipe function is an ObjectExpression.
14
+ * 2. Processes the recipe object's properties if valid.
15
+ * 3. Applies custom group ordering to CSS properties in relevant properties (e.g., 'base', 'variants').
16
+ * 4. Processes nested selectors and style objects recursively.
17
+ */
18
+ export const enforceUserDefinedGroupOrderInRecipe = (ruleContext, callExpression, userDefinedGroups, sortRemainingPropertiesMethod) => {
19
+ if (!callExpression.arguments[0] || callExpression.arguments[0].type !== 'ObjectExpression') {
20
+ return;
21
+ }
22
+ const recipeObjectExpression = callExpression.arguments[0];
23
+ processRecipeProperties(ruleContext, recipeObjectExpression, (currentContext, styleObject) => processStyleNode(currentContext, styleObject, (styleContext, styleObjectNode) => enforceUserDefinedGroupOrderInStyleObject(styleContext, styleObjectNode, userDefinedGroups, sortRemainingPropertiesMethod)));
24
+ };
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const customGroupOrderRule: Rule.RuleModule;
3
+ export default customGroupOrderRule;
@@ -0,0 +1,40 @@
1
+ import { availableGroups } from '../concentric-order/concentric-groups.js';
2
+ import { createNodeVisitors } from '../shared-utils/order-strategy-visitor-creator.js';
3
+ const customGroupOrderRule = {
4
+ meta: {
5
+ type: 'suggestion',
6
+ docs: {
7
+ description: 'enforce custom group CSS property ordering in vanilla-extract styles',
8
+ category: 'Stylistic Issues',
9
+ recommended: true,
10
+ },
11
+ fixable: 'code',
12
+ schema: [
13
+ {
14
+ type: 'object',
15
+ properties: {
16
+ groupOrder: {
17
+ type: 'array',
18
+ items: {
19
+ enum: availableGroups,
20
+ },
21
+ },
22
+ sortRemainingProperties: {
23
+ enum: ['alphabetical', 'concentric'],
24
+ },
25
+ },
26
+ additionalProperties: false,
27
+ },
28
+ ],
29
+ messages: {
30
+ incorrectOrder: "Property '{{nextProperty}}' should come before '{{currentProperty}}' according to custom CSS group ordering.",
31
+ },
32
+ },
33
+ create(ruleContext) {
34
+ const ruleConfiguration = ruleContext.options[0];
35
+ const userDefinedGroupOrder = ruleConfiguration?.groupOrder ?? [];
36
+ const sortRemainingPropertiesMethod = ruleConfiguration?.sortRemainingProperties ?? 'alphabetical';
37
+ return createNodeVisitors(ruleContext, 'userDefinedGroupOrder', userDefinedGroupOrder, sortRemainingPropertiesMethod);
38
+ },
39
+ };
40
+ export default customGroupOrderRule;
@@ -0,0 +1,19 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ /**
4
+ * Enforces a custom ordering of CSS properties based on user-defined groups in a given style object.
5
+ *
6
+ * @param context The ESLint rule context for reporting and fixing issues.
7
+ * @param styleObject The ObjectExpression node representing the style object to be processed.
8
+ * @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
+ *
11
+ * This function:
12
+ * 1. Validates the input styleObject.
13
+ * 2. Handles 'selectors' objects separately, processing their nested style objects.
14
+ * 3. Creates a priority map based on user-defined groups.
15
+ * 4. Processes regular properties, creating a list of CSSPropertyInfo objects.
16
+ * 5. Enforces custom group ordering on the properties.
17
+ * 6. Recursively processes nested selectors and style objects.
18
+ */
19
+ export declare const enforceUserDefinedGroupOrderInStyleObject: (ruleContext: Rule.RuleContext, styleObject: TSESTree.ObjectExpression, userDefinedGroups: string[], sortRemainingPropertiesMethod?: "alphabetical" | "concentric") => void;
@@ -0,0 +1,52 @@
1
+ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
+ import { concentricGroups } from '../concentric-order/concentric-groups.js';
3
+ import { createCSSPropertyPriorityMap } from '../shared-utils/css-property-priority-map.js';
4
+ import { isSelectorsObject, processNestedSelectors } from '../shared-utils/nested-selectors-processor.js';
5
+ import { getPropertyName, separateProperties } from '../shared-utils/property-separator.js';
6
+ import { enforceCustomGroupOrder } from './property-order-enforcer.js';
7
+ /**
8
+ * Enforces a custom ordering of CSS properties based on user-defined groups in a given style object.
9
+ *
10
+ * @param context The ESLint rule context for reporting and fixing issues.
11
+ * @param styleObject The ObjectExpression node representing the style object to be processed.
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'.
14
+ *
15
+ * This function:
16
+ * 1. Validates the input styleObject.
17
+ * 2. Handles 'selectors' objects separately, processing their nested style objects.
18
+ * 3. Creates a priority map based on user-defined groups.
19
+ * 4. Processes regular properties, creating a list of CSSPropertyInfo objects.
20
+ * 5. Enforces custom group ordering on the properties.
21
+ * 6. Recursively processes nested selectors and style objects.
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
+ }
32
+ });
33
+ return;
34
+ }
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
+ };
@@ -0,0 +1,17 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Generates ESLint fixes for CSS property ordering violations.
4
+ * @param eslintFixer The ESLint fixer instance used to create fix objects.
5
+ * @param ruleContext The ESLint rule context, providing access to the source code.
6
+ * @param cssProperties The list of CSS properties to sort (can be TSESTree.Property[] or CSSPropertyInfo[]).
7
+ * @param compareProperties A comparison function that defines the sorting logic for the properties.
8
+ * @param extractNode A function that extracts the AST node from each property (used for text replacement).
9
+ * @returns An array of ESLint Fix objects to correct the property order.
10
+ *
11
+ * This function performs the following steps:
12
+ * 1. Sorts the input properties using the provided comparison function.
13
+ * 2. Maps the original and sorted properties to their text ranges.
14
+ * 3. Creates fix objects for properties whose positions have changed after sorting.
15
+ * 4. Returns an array of fixes that, when applied, will reorder the properties correctly.
16
+ */
17
+ export declare const generateFixesForCSSOrder: <T>(eslintFixer: Rule.RuleFixer, ruleContext: Rule.RuleContext, cssProperties: T[], compareProperties: (firstProperty: T, secondProperty: T) => number, extractNode: (property: T) => Rule.Node) => Rule.Fix[];
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Generates ESLint fixes for CSS property ordering violations.
3
+ * @param eslintFixer The ESLint fixer instance used to create fix objects.
4
+ * @param ruleContext The ESLint rule context, providing access to the source code.
5
+ * @param cssProperties The list of CSS properties to sort (can be TSESTree.Property[] or CSSPropertyInfo[]).
6
+ * @param compareProperties A comparison function that defines the sorting logic for the properties.
7
+ * @param extractNode A function that extracts the AST node from each property (used for text replacement).
8
+ * @returns An array of ESLint Fix objects to correct the property order.
9
+ *
10
+ * This function performs the following steps:
11
+ * 1. Sorts the input properties using the provided comparison function.
12
+ * 2. Maps the original and sorted properties to their text ranges.
13
+ * 3. Creates fix objects for properties whose positions have changed after sorting.
14
+ * 4. Returns an array of fixes that, when applied, will reorder the properties correctly.
15
+ */
16
+ export const generateFixesForCSSOrder = (eslintFixer, ruleContext, cssProperties, compareProperties, extractNode) => {
17
+ const sourceCode = ruleContext.sourceCode;
18
+ // Sort properties using the provided comparison function
19
+ const sortedProperties = [...cssProperties].sort(compareProperties);
20
+ // Map each original property to its text range
21
+ const originalPropertyRanges = cssProperties.map((property) => ({
22
+ property,
23
+ range: extractNode(property).range,
24
+ }));
25
+ // Map sorted properties back to their original range information
26
+ const sortedPropertyRanges = sortedProperties.map((property) => originalPropertyRanges.find((rangeInfo) => rangeInfo.property === property));
27
+ // Generate fixes for properties that have changed position
28
+ return originalPropertyRanges
29
+ .map((originalRangeInfo, index) => {
30
+ const sortedRangeInfo = sortedPropertyRanges[index];
31
+ // Create a fix only if the property's position has changed
32
+ if (originalRangeInfo && sortedRangeInfo && originalRangeInfo !== sortedRangeInfo) {
33
+ const sortedPropertyText = sourceCode.getText(extractNode(sortedRangeInfo.property));
34
+ return eslintFixer.replaceText(extractNode(originalRangeInfo.property), sortedPropertyText);
35
+ }
36
+ return null;
37
+ })
38
+ .filter((fix) => fix !== null);
39
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Creates a map of CSS properties to their priority information.
3
+ *
4
+ * This function generates a Map where each key is a CSS property (in camelCase),
5
+ * and each value is an object containing:
6
+ * - groupIndex: The index of the property's group
7
+ * - positionInGroup: The position of the property within its group
8
+ * - inUserGroup: Whether the property is in a user-specified group
9
+ *
10
+ * The function prioritizes user-specified groups over default concentric groups.
11
+ * If user groups are provided, they are processed first. Any remaining concentric
12
+ * groups are then processed to ensure complete coverage of CSS properties.
13
+ *
14
+ * @param userGroups - An optional array of user-specified group names to prioritize
15
+ * @returns A Map of CSS properties to their priority information
16
+ *
17
+ * @example
18
+ * const priorityMap = createCSSPropertyPriorityMap(['layout', 'typography']);
19
+ * console.log(priorityMap.get('display')); // { groupIndex: 0, positionInGroup: 0, inUserGroup: true }
20
+ */
21
+ export declare const createCSSPropertyPriorityMap: (userGroups?: string[]) => Map<string, {
22
+ groupIndex: number;
23
+ positionInGroup: number;
24
+ inUserGroup: boolean;
25
+ }>;
@@ -0,0 +1,48 @@
1
+ import { concentricGroups } from '../concentric-order/concentric-groups.js';
2
+ /**
3
+ * Creates a map of CSS properties to their priority information.
4
+ *
5
+ * This function generates a Map where each key is a CSS property (in camelCase),
6
+ * and each value is an object containing:
7
+ * - groupIndex: The index of the property's group
8
+ * - positionInGroup: The position of the property within its group
9
+ * - inUserGroup: Whether the property is in a user-specified group
10
+ *
11
+ * The function prioritizes user-specified groups over default concentric groups.
12
+ * If user groups are provided, they are processed first. Any remaining concentric
13
+ * groups are then processed to ensure complete coverage of CSS properties.
14
+ *
15
+ * @param userGroups - An optional array of user-specified group names to prioritize
16
+ * @returns A Map of CSS properties to their priority information
17
+ *
18
+ * @example
19
+ * const priorityMap = createCSSPropertyPriorityMap(['layout', 'typography']);
20
+ * console.log(priorityMap.get('display')); // { groupIndex: 0, positionInGroup: 0, inUserGroup: true }
21
+ */
22
+ export const createCSSPropertyPriorityMap = (userGroups = []) => {
23
+ const cssPropertyPriorityMap = new Map();
24
+ const processGroup = (groupName, groupIndex, inUserGroup) => {
25
+ const properties = concentricGroups[groupName] || [];
26
+ properties.forEach((property, positionInGroup) => {
27
+ const camelCaseProperty = property.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
28
+ if (!cssPropertyPriorityMap.has(camelCaseProperty)) {
29
+ cssPropertyPriorityMap.set(camelCaseProperty, {
30
+ groupIndex,
31
+ positionInGroup,
32
+ inUserGroup,
33
+ });
34
+ }
35
+ });
36
+ };
37
+ // Process user-specified groups first
38
+ userGroups.forEach((groupName, index) => processGroup(groupName, index, true));
39
+ // Process remaining groups if needed (for concentric order or as fallback)
40
+ if (userGroups.length === 0 || userGroups.length < Object.keys(concentricGroups).length) {
41
+ Object.keys(concentricGroups).forEach((groupName, index) => {
42
+ if (!userGroups.includes(groupName)) {
43
+ processGroup(groupName, userGroups.length + index, false);
44
+ }
45
+ });
46
+ }
47
+ return cssPropertyPriorityMap;
48
+ };
@@ -0,0 +1,25 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ /**
4
+ * Determines if the given object node is a 'selectors' object within a style definition.
5
+ * @param objectNode The object expression node to check.
6
+ * @returns True if the node is a 'selectors' object, false otherwise.
7
+ *
8
+ * This function checks if:
9
+ * 1. The node has a parent
10
+ * 2. The parent is a Property node
11
+ * 3. The parent's key is an Identifier
12
+ * 4. The parent's key name is 'selectors'
13
+ */
14
+ export declare const isSelectorsObject: (objectNode: TSESTree.ObjectExpression) => boolean;
15
+ /**
16
+ * Processes nested selectors within a 'selectors' object by recursively validating their value objects.
17
+ * @param context The ESLint rule context.
18
+ * @param objectNode The object expression node representing the 'selectors' object.
19
+ * @param validateFn A function to validate each nested selector's value object.
20
+ *
21
+ * This function iterates through each property of the 'selectors' object:
22
+ * - If a property's value is an ObjectExpression, it applies the validateFn to that object.
23
+ * - This allows for validation of nested style objects within selectors.
24
+ */
25
+ export declare const processNestedSelectors: (context: Rule.RuleContext, objectNode: TSESTree.ObjectExpression, validateFn: (context: Rule.RuleContext, objectNode: TSESTree.ObjectExpression) => void) => void;
@@ -0,0 +1,35 @@
1
+ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * Determines if the given object node is a 'selectors' object within a style definition.
4
+ * @param objectNode The object expression node to check.
5
+ * @returns True if the node is a 'selectors' object, false otherwise.
6
+ *
7
+ * This function checks if:
8
+ * 1. The node has a parent
9
+ * 2. The parent is a Property node
10
+ * 3. The parent's key is an Identifier
11
+ * 4. The parent's key name is 'selectors'
12
+ */
13
+ export const isSelectorsObject = (objectNode) => {
14
+ return (objectNode.parent &&
15
+ objectNode.parent.type === AST_NODE_TYPES.Property &&
16
+ objectNode.parent.key.type === 'Identifier' &&
17
+ objectNode.parent.key.name === 'selectors');
18
+ };
19
+ /**
20
+ * Processes nested selectors within a 'selectors' object by recursively validating their value objects.
21
+ * @param context The ESLint rule context.
22
+ * @param objectNode The object expression node representing the 'selectors' object.
23
+ * @param validateFn A function to validate each nested selector's value object.
24
+ *
25
+ * This function iterates through each property of the 'selectors' object:
26
+ * - If a property's value is an ObjectExpression, it applies the validateFn to that object.
27
+ * - This allows for validation of nested style objects within selectors.
28
+ */
29
+ export const processNestedSelectors = (context, objectNode, validateFn) => {
30
+ objectNode.properties.forEach((property) => {
31
+ if (property.type === AST_NODE_TYPES.Property && property.value.type === AST_NODE_TYPES.ObjectExpression) {
32
+ validateFn(context, property.value);
33
+ }
34
+ });
35
+ };
@@ -0,0 +1,17 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Creates an ESLint rule listener with visitors for style-related function calls.
4
+ * @param ruleContext The ESLint rule context.
5
+ * @param orderingStrategy The strategy to use for ordering CSS properties ('alphabetical', 'concentric', or 'userDefinedGroupOrder').
6
+ * @param userDefinedGroupOrder An optional array of property groups for the 'userDefinedGroupOrder' strategy.
7
+ * @param sortRemainingProperties An optional strategy for sorting properties not in user-defined groups.
8
+ * @returns An object with visitor functions for the ESLint rule.
9
+ *
10
+ * This function sets up visitors for the following cases:
11
+ * 1. Style-related functions: 'style', 'styleVariants', 'createVar', 'createTheme', 'createThemeContract'
12
+ * 2. The 'globalStyle' function
13
+ * 3. The 'recipe' function
14
+ *
15
+ * Each visitor applies the appropriate ordering strategy to the style objects in these function calls.
16
+ */
17
+ export declare const createNodeVisitors: (ruleContext: Rule.RuleContext, orderingStrategy: "alphabetical" | "concentric" | "userDefinedGroupOrder", userDefinedGroupOrder?: string[], sortRemainingProperties?: "alphabetical" | "concentric") => Rule.RuleListener;
@@ -0,0 +1,76 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ import { enforceAlphabeticalCSSOrderInRecipe } from '../alphabetical-order/recipe-order-enforcer.js';
3
+ import { enforceAlphabeticalCSSOrderInStyleObject } from '../alphabetical-order/style-object-processor.js';
4
+ import { enforceConcentricCSSOrderInRecipe } from '../concentric-order/recipe-order-enforcer.js';
5
+ import { enforceConcentricCSSOrderInStyleObject } from '../concentric-order/style-object-processor.js';
6
+ import { enforceUserDefinedGroupOrderInRecipe } from '../custom-order/recipe-order-enforcer.js';
7
+ import { enforceUserDefinedGroupOrderInStyleObject } from '../custom-order/style-object-processor.js';
8
+ import { processStyleNode } from './style-node-processor.js';
9
+ /**
10
+ * Creates an ESLint rule listener with visitors for style-related function calls.
11
+ * @param ruleContext The ESLint rule context.
12
+ * @param orderingStrategy The strategy to use for ordering CSS properties ('alphabetical', 'concentric', or 'userDefinedGroupOrder').
13
+ * @param userDefinedGroupOrder An optional array of property groups for the 'userDefinedGroupOrder' strategy.
14
+ * @param sortRemainingProperties An optional strategy for sorting properties not in user-defined groups.
15
+ * @returns An object with visitor functions for the ESLint rule.
16
+ *
17
+ * This function sets up visitors for the following cases:
18
+ * 1. Style-related functions: 'style', 'styleVariants', 'createVar', 'createTheme', 'createThemeContract'
19
+ * 2. The 'globalStyle' function
20
+ * 3. The 'recipe' function
21
+ *
22
+ * Each visitor applies the appropriate ordering strategy to the style objects in these function calls.
23
+ */
24
+ export const createNodeVisitors = (ruleContext, orderingStrategy, userDefinedGroupOrder, sortRemainingProperties) => {
25
+ // Select the appropriate property processing function based on the ordering strategy
26
+ const processProperty = (() => {
27
+ switch (orderingStrategy) {
28
+ case 'alphabetical':
29
+ return enforceAlphabeticalCSSOrderInStyleObject;
30
+ case 'concentric':
31
+ return enforceConcentricCSSOrderInStyleObject;
32
+ case 'userDefinedGroupOrder':
33
+ if (!userDefinedGroupOrder || userDefinedGroupOrder.length === 0) {
34
+ throw new Error('💥 👿 User-defined group order must be provided for userDefinedGroupOrder strategy');
35
+ }
36
+ return (ruleContext, node) => enforceUserDefinedGroupOrderInStyleObject(ruleContext, node, userDefinedGroupOrder, sortRemainingProperties);
37
+ default:
38
+ return enforceAlphabeticalCSSOrderInStyleObject;
39
+ }
40
+ })();
41
+ return {
42
+ CallExpression(node) {
43
+ if (node.callee.type !== 'Identifier') {
44
+ return;
45
+ }
46
+ // Handle style-related functions
47
+ if (['style', 'styleVariants', 'createVar', 'createTheme', 'createThemeContract'].includes(node.callee.name)) {
48
+ if (node.arguments.length > 0) {
49
+ const styleArg = node.arguments[0];
50
+ processStyleNode(ruleContext, styleArg, processProperty);
51
+ }
52
+ }
53
+ // Handle globalStyle function
54
+ if (node.callee.name === 'globalStyle' && node.arguments.length >= 2) {
55
+ const styleArg = node.arguments[1];
56
+ processStyleNode(ruleContext, styleArg, processProperty);
57
+ }
58
+ // Handle recipe function
59
+ if (node.callee.name === 'recipe') {
60
+ switch (orderingStrategy) {
61
+ case 'alphabetical':
62
+ enforceAlphabeticalCSSOrderInRecipe(node, ruleContext);
63
+ break;
64
+ case 'concentric':
65
+ enforceConcentricCSSOrderInRecipe(ruleContext, node);
66
+ break;
67
+ case 'userDefinedGroupOrder':
68
+ if (userDefinedGroupOrder) {
69
+ enforceUserDefinedGroupOrderInRecipe(ruleContext, node, userDefinedGroupOrder, sortRemainingProperties);
70
+ }
71
+ break;
72
+ }
73
+ }
74
+ },
75
+ };
76
+ };
@@ -0,0 +1,28 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * Extracts the name of a property from a TSESTree.Property node.
4
+ * @param property The property node to extract the name from.
5
+ * @returns The name of the property as a string, or an empty string if the name cannot be determined.
6
+ *
7
+ * This function handles two types of property keys:
8
+ * - Identifier: Returns the name directly.
9
+ * - Literal (string): Returns the string value.
10
+ * For any other type of key, it returns an empty string.
11
+ */
12
+ export declare const getPropertyName: (property: TSESTree.Property) => string;
13
+ /**
14
+ * Separates object properties into regular and special categories.
15
+ * @param properties An array of object literal elements to be categorized.
16
+ * @returns An object containing two arrays: regularProperties and specialProperties.
17
+ *
18
+ * This function categorizes properties as follows:
19
+ * - Regular properties: Standard CSS properties.
20
+ * - Special properties: Properties that start with ':' (pseudo-selectors),
21
+ * '@' (at-rules), or are named 'selectors'.
22
+ *
23
+ * Non-Property type elements in the input array are ignored.
24
+ */
25
+ export declare const separateProperties: (properties: TSESTree.ObjectLiteralElement[]) => {
26
+ regularProperties: TSESTree.Property[];
27
+ specialProperties: TSESTree.Property[];
28
+ };
@@ -0,0 +1,49 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * Extracts the name of a property from a TSESTree.Property node.
4
+ * @param property The property node to extract the name from.
5
+ * @returns The name of the property as a string, or an empty string if the name cannot be determined.
6
+ *
7
+ * This function handles two types of property keys:
8
+ * - Identifier: Returns the name directly.
9
+ * - Literal (string): Returns the string value.
10
+ * For any other type of key, it returns an empty string.
11
+ */
12
+ export const getPropertyName = (property) => {
13
+ if (property.key.type === 'Identifier') {
14
+ return property.key.name;
15
+ }
16
+ else if (property.key.type === 'Literal' && typeof property.key.value === 'string') {
17
+ return property.key.value;
18
+ }
19
+ return '';
20
+ };
21
+ /**
22
+ * Separates object properties into regular and special categories.
23
+ * @param properties An array of object literal elements to be categorized.
24
+ * @returns An object containing two arrays: regularProperties and specialProperties.
25
+ *
26
+ * This function categorizes properties as follows:
27
+ * - Regular properties: Standard CSS properties.
28
+ * - Special properties: Properties that start with ':' (pseudo-selectors),
29
+ * '@' (at-rules), or are named 'selectors'.
30
+ *
31
+ * Non-Property type elements in the input array are ignored.
32
+ */
33
+ export const separateProperties = (properties) => {
34
+ const regularProperties = [];
35
+ const specialProperties = [];
36
+ // Separate regular CSS properties from special ones (pseudo selectors, etc.)
37
+ properties.forEach((property) => {
38
+ if (property.type === 'Property') {
39
+ const propName = getPropertyName(property);
40
+ if (propName.startsWith(':') || propName.startsWith('@') || propName === 'selectors') {
41
+ specialProperties.push(property);
42
+ }
43
+ else {
44
+ regularProperties.push(property);
45
+ }
46
+ }
47
+ });
48
+ return { regularProperties, specialProperties };
49
+ };
@@ -0,0 +1,16 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ /**
4
+ * Processes the `base` and `variants` properties of a recipe object.
5
+ * @param ruleContext The ESLint rule context.
6
+ * @param recipeNode The recipe object node to process.
7
+ * @param processProperty A callback function to process each property object (e.g., for alphabetical or concentric ordering).
8
+ *
9
+ * This function iterates through the properties of the recipe object:
10
+ * - For the `base` property, it directly processes the object.
11
+ * - For the `variants` property, it processes each variant's options individually.
12
+ *
13
+ * The function skips any non-Property nodes or nodes without an Identifier key.
14
+ * It only processes ObjectExpression values to ensure type safety.
15
+ */
16
+ export declare const processRecipeProperties: (ruleContext: Rule.RuleContext, recipeNode: TSESTree.ObjectExpression, processProperty: (ruleContext: Rule.RuleContext, value: TSESTree.ObjectExpression) => void) => void;