@antebudimir/eslint-plugin-vanilla-extract 1.0.1 → 1.1.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 (53) hide show
  1. package/README.md +3 -2
  2. package/dist/cjs/css-rules/alphabetical-order/index.d.ts +2 -0
  3. package/dist/cjs/css-rules/alphabetical-order/index.js +7 -0
  4. package/dist/cjs/css-rules/alphabetical-order/property-order-enforcer.d.ts +14 -0
  5. package/dist/cjs/css-rules/alphabetical-order/property-order-enforcer.js +60 -0
  6. package/dist/cjs/css-rules/alphabetical-order/recipe-order-enforcer.d.ts +14 -0
  7. package/dist/cjs/css-rules/alphabetical-order/recipe-order-enforcer.js +25 -0
  8. package/dist/cjs/css-rules/alphabetical-order/rule-definition.d.ts +3 -0
  9. package/dist/cjs/css-rules/alphabetical-order/rule-definition.js +22 -0
  10. package/dist/cjs/css-rules/alphabetical-order/style-object-processor.d.ts +15 -0
  11. package/dist/cjs/css-rules/alphabetical-order/style-object-processor.js +32 -0
  12. package/dist/cjs/css-rules/concentric-order/concentric-groups.d.ts +7 -0
  13. package/dist/cjs/css-rules/concentric-order/concentric-groups.js +310 -0
  14. package/dist/cjs/css-rules/concentric-order/index.d.ts +2 -0
  15. package/dist/cjs/css-rules/concentric-order/index.js +7 -0
  16. package/dist/cjs/css-rules/concentric-order/property-order-enforcer.d.ts +16 -0
  17. package/dist/cjs/css-rules/concentric-order/property-order-enforcer.js +64 -0
  18. package/dist/cjs/css-rules/concentric-order/recipe-order-enforcer.d.ts +14 -0
  19. package/dist/cjs/css-rules/concentric-order/recipe-order-enforcer.js +25 -0
  20. package/dist/cjs/css-rules/concentric-order/rule-definition.d.ts +3 -0
  21. package/dist/cjs/css-rules/concentric-order/rule-definition.js +22 -0
  22. package/dist/cjs/css-rules/concentric-order/style-object-processor.d.ts +21 -0
  23. package/dist/cjs/css-rules/concentric-order/style-object-processor.js +63 -0
  24. package/dist/cjs/css-rules/concentric-order/types.d.ts +8 -0
  25. package/dist/cjs/css-rules/concentric-order/types.js +2 -0
  26. package/dist/cjs/css-rules/custom-order/property-order-enforcer.d.ts +17 -0
  27. package/dist/cjs/css-rules/custom-order/property-order-enforcer.js +71 -0
  28. package/dist/cjs/css-rules/custom-order/recipe-order-enforcer.d.ts +16 -0
  29. package/dist/cjs/css-rules/custom-order/recipe-order-enforcer.js +27 -0
  30. package/dist/cjs/css-rules/custom-order/rule-definition.d.ts +3 -0
  31. package/dist/cjs/css-rules/custom-order/rule-definition.js +42 -0
  32. package/dist/cjs/css-rules/custom-order/style-object-processor.d.ts +19 -0
  33. package/dist/cjs/css-rules/custom-order/style-object-processor.js +56 -0
  34. package/dist/cjs/css-rules/shared-utils/css-order-fixer.d.ts +17 -0
  35. package/dist/cjs/css-rules/shared-utils/css-order-fixer.js +43 -0
  36. package/dist/cjs/css-rules/shared-utils/css-property-priority-map.d.ts +25 -0
  37. package/dist/cjs/css-rules/shared-utils/css-property-priority-map.js +52 -0
  38. package/dist/cjs/css-rules/shared-utils/nested-selectors-processor.d.ts +25 -0
  39. package/dist/cjs/css-rules/shared-utils/nested-selectors-processor.js +40 -0
  40. package/dist/cjs/css-rules/shared-utils/order-strategy-visitor-creator.d.ts +17 -0
  41. package/dist/cjs/css-rules/shared-utils/order-strategy-visitor-creator.js +79 -0
  42. package/dist/cjs/css-rules/shared-utils/property-separator.d.ts +28 -0
  43. package/dist/cjs/css-rules/shared-utils/property-separator.js +53 -0
  44. package/dist/cjs/css-rules/shared-utils/recipe-property-processor.d.ts +16 -0
  45. package/dist/cjs/css-rules/shared-utils/recipe-property-processor.js +40 -0
  46. package/dist/cjs/css-rules/shared-utils/style-node-processor.d.ts +9 -0
  47. package/dist/cjs/css-rules/shared-utils/style-node-processor.js +25 -0
  48. package/dist/cjs/css-sample/sample.css.d.ts +161 -0
  49. package/dist/cjs/css-sample/sample.css.js +554 -0
  50. package/dist/cjs/index.d.ts +38 -0
  51. package/dist/cjs/index.js +43 -0
  52. package/dist/index.js +1 -1
  53. package/package.json +12 -15
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enforceConcentricCSSOrderInRecipe = void 0;
4
+ const recipe_property_processor_js_1 = require("../shared-utils/recipe-property-processor.js");
5
+ const style_node_processor_js_1 = require("../shared-utils/style-node-processor.js");
6
+ const style_object_processor_js_1 = require("./style-object-processor.js");
7
+ /**
8
+ * Enforces concentric ordering of CSS properties within a recipe function call.
9
+ *
10
+ * @param ruleContext The ESLint rule context for reporting and fixing issues.
11
+ * @param callExpression The CallExpression node representing the recipe function call.
12
+ *
13
+ * This function does the following:
14
+ * 1. Checks if the first argument of the recipe function is an ObjectExpression.
15
+ * 2. If valid, processes the recipe object's properties.
16
+ * 3. For each relevant property (e.g., 'base', 'variants'), it applies concentric ordering to the CSS properties.
17
+ */
18
+ const enforceConcentricCSSOrderInRecipe = (ruleContext, callExpression) => {
19
+ if (!callExpression.arguments[0] || callExpression.arguments[0].type !== 'ObjectExpression') {
20
+ return;
21
+ }
22
+ const recipeObjectExpression = callExpression.arguments[0];
23
+ (0, recipe_property_processor_js_1.processRecipeProperties)(ruleContext, recipeObjectExpression, (currentContext, styleObject) => (0, style_node_processor_js_1.processStyleNode)(currentContext, styleObject, style_object_processor_js_1.enforceConcentricCSSOrderInStyleObject));
24
+ };
25
+ exports.enforceConcentricCSSOrderInRecipe = enforceConcentricCSSOrderInRecipe;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const concentricOrderRule: Rule.RuleModule;
3
+ export default concentricOrderRule;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const order_strategy_visitor_creator_js_1 = require("../shared-utils/order-strategy-visitor-creator.js");
4
+ const concentricOrderRule = {
5
+ meta: {
6
+ type: 'suggestion',
7
+ docs: {
8
+ description: 'enforce concentric CSS property ordering in vanilla-extract styles',
9
+ category: 'Stylistic Issues',
10
+ recommended: true,
11
+ },
12
+ fixable: 'code',
13
+ schema: [],
14
+ messages: {
15
+ incorrectOrder: "Property '{{next}}' should come before '{{current}}' according to concentric CSS ordering.",
16
+ },
17
+ },
18
+ create(context) {
19
+ return (0, order_strategy_visitor_creator_js_1.createNodeVisitors)(context, 'concentric');
20
+ },
21
+ };
22
+ exports.default = concentricOrderRule;
@@ -0,0 +1,21 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ /**
4
+ * Enforces concentric ordering of CSS properties within a style object.
5
+ *
6
+ * This function processes the given style object to ensure that CSS properties
7
+ * follow a concentric order based on predefined priority groups. It handles
8
+ * different types of style objects by:
9
+ * 1. Validating that the input is an ObjectExpression.
10
+ * 2. Processing 'selectors' objects separately and recursively applying the
11
+ * concentric order enforcement.
12
+ * 3. Separating regular properties and building a list of CSSPropertyInfo
13
+ * objects with priority details.
14
+ * 4. Enforcing concentric order on the properties using their priority
15
+ * information.
16
+ * 5. Recursively processing nested selectors and style objects.
17
+ *
18
+ * @param ruleContext - The ESLint rule context for reporting and fixing issues.
19
+ * @param styleObject - The object expression representing the style object to be processed.
20
+ */
21
+ export declare const enforceConcentricCSSOrderInStyleObject: (ruleContext: Rule.RuleContext, styleObject: TSESTree.ObjectExpression) => void;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enforceConcentricCSSOrderInStyleObject = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const css_property_priority_map_js_1 = require("../shared-utils/css-property-priority-map.js");
6
+ const nested_selectors_processor_js_1 = require("../shared-utils/nested-selectors-processor.js");
7
+ const property_separator_js_1 = require("../shared-utils/property-separator.js");
8
+ const property_order_enforcer_js_1 = require("./property-order-enforcer.js");
9
+ const cssPropertyPriorityMap = (0, css_property_priority_map_js_1.createCSSPropertyPriorityMap)();
10
+ /**
11
+ * Builds a list of CSS properties with their priority information in the concentric order of their groups.
12
+ *
13
+ * @param regularStyleProperties An array of regular style properties.
14
+ * @returns An array of CSSPropertyInfo objects containing name, node, priority, and position information.
15
+ */
16
+ const buildCSSPropertyInfoList = (regularStyleProperties) => {
17
+ return regularStyleProperties.map((styleProperty) => {
18
+ const propertyName = (0, property_separator_js_1.getPropertyName)(styleProperty);
19
+ const propertyInfo = cssPropertyPriorityMap.get(propertyName);
20
+ return {
21
+ name: propertyName,
22
+ node: styleProperty,
23
+ priority: propertyInfo?.groupIndex ?? Number.MAX_SAFE_INTEGER,
24
+ positionInGroup: propertyInfo?.positionInGroup ?? Number.MAX_SAFE_INTEGER,
25
+ };
26
+ });
27
+ };
28
+ /**
29
+ * Enforces concentric ordering of CSS properties within a style object.
30
+ *
31
+ * This function processes the given style object to ensure that CSS properties
32
+ * follow a concentric order based on predefined priority groups. It handles
33
+ * different types of style objects by:
34
+ * 1. Validating that the input is an ObjectExpression.
35
+ * 2. Processing 'selectors' objects separately and recursively applying the
36
+ * concentric order enforcement.
37
+ * 3. Separating regular properties and building a list of CSSPropertyInfo
38
+ * objects with priority details.
39
+ * 4. Enforcing concentric order on the properties using their priority
40
+ * information.
41
+ * 5. Recursively processing nested selectors and style objects.
42
+ *
43
+ * @param ruleContext - The ESLint rule context for reporting and fixing issues.
44
+ * @param styleObject - The object expression representing the style object to be processed.
45
+ */
46
+ const enforceConcentricCSSOrderInStyleObject = (ruleContext, styleObject) => {
47
+ if (!styleObject || styleObject.type !== utils_1.AST_NODE_TYPES.ObjectExpression) {
48
+ return;
49
+ }
50
+ if ((0, nested_selectors_processor_js_1.isSelectorsObject)(styleObject)) {
51
+ styleObject.properties.forEach((property) => {
52
+ if (property.type === utils_1.AST_NODE_TYPES.Property && property.value.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
53
+ (0, exports.enforceConcentricCSSOrderInStyleObject)(ruleContext, property.value);
54
+ }
55
+ });
56
+ return;
57
+ }
58
+ const { regularProperties } = (0, property_separator_js_1.separateProperties)(styleObject.properties);
59
+ const cssPropertyInfoList = buildCSSPropertyInfoList(regularProperties);
60
+ (0, property_order_enforcer_js_1.enforceConcentricCSSOrder)(ruleContext, cssPropertyInfoList);
61
+ (0, nested_selectors_processor_js_1.processNestedSelectors)(ruleContext, styleObject, exports.enforceConcentricCSSOrderInStyleObject);
62
+ };
63
+ exports.enforceConcentricCSSOrderInStyleObject = enforceConcentricCSSOrderInStyleObject;
@@ -0,0 +1,8 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ export interface CSSPropertyInfo {
3
+ name: string;
4
+ node: TSESTree.Property;
5
+ priority: number;
6
+ positionInGroup: number;
7
+ group?: string;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enforceCustomGroupOrder = void 0;
4
+ const css_order_fixer_js_1 = require("../shared-utils/css-order-fixer.js");
5
+ const css_property_priority_map_js_1 = require("../shared-utils/css-property-priority-map.js");
6
+ /**
7
+ * Enforces a custom ordering of CSS properties based on user-defined groups.
8
+ *
9
+ * @param ruleContext The ESLint rule context used for reporting and fixing.
10
+ * @param cssPropertyInfoList An array of CSS property information objects to be ordered.
11
+ * @param userDefinedGroups Array of user-defined property groups for custom ordering.
12
+ * @param sortRemainingProperties Strategy for sorting properties not in user-defined groups
13
+ * ('alphabetical' or 'concentric'). Defaults to 'concentric'.
14
+ *
15
+ * This function compares CSS properties based on their group priority and position within
16
+ * those groups. Properties not part of user-defined groups are sorted according to the
17
+ * specified strategy. If an ordering violation is detected, an ESLint report is generated
18
+ * with a suggested fix.
19
+ */
20
+ const enforceCustomGroupOrder = (ruleContext, cssPropertyInfoList, userDefinedGroups = [], sortRemainingProperties) => {
21
+ if (cssPropertyInfoList.length <= 1) {
22
+ return;
23
+ }
24
+ const cssPropertyPriorityMap = (0, css_property_priority_map_js_1.createCSSPropertyPriorityMap)(userDefinedGroups);
25
+ const compareProperties = (firstProperty, secondProperty) => {
26
+ const firstPropertyInfo = cssPropertyPriorityMap.get(firstProperty.name) || {
27
+ groupIndex: Infinity,
28
+ positionInGroup: Infinity,
29
+ inUserGroup: false,
30
+ };
31
+ const secondPropertyInfo = cssPropertyPriorityMap.get(secondProperty.name) || {
32
+ groupIndex: Infinity,
33
+ positionInGroup: Infinity,
34
+ inUserGroup: false,
35
+ };
36
+ if (firstPropertyInfo.inUserGroup !== secondPropertyInfo.inUserGroup) {
37
+ return firstPropertyInfo.inUserGroup ? -1 : 1;
38
+ }
39
+ if (firstPropertyInfo.inUserGroup) {
40
+ if (firstPropertyInfo.groupIndex !== secondPropertyInfo.groupIndex) {
41
+ return firstPropertyInfo.groupIndex - secondPropertyInfo.groupIndex;
42
+ }
43
+ return firstPropertyInfo.positionInGroup - secondPropertyInfo.positionInGroup;
44
+ }
45
+ // For properties not in user-defined groups
46
+ if (sortRemainingProperties === 'alphabetical') {
47
+ return firstProperty.name.localeCompare(secondProperty.name);
48
+ }
49
+ else {
50
+ return (firstPropertyInfo.groupIndex - secondPropertyInfo.groupIndex ||
51
+ firstPropertyInfo.positionInGroup - secondPropertyInfo.positionInGroup);
52
+ }
53
+ };
54
+ const sortedPropertyList = [...cssPropertyInfoList].sort(compareProperties);
55
+ // Find the first pair that violates the new ordering
56
+ const violatingProperty = cssPropertyInfoList
57
+ .slice(0, -1)
58
+ .find((currentProperty, index) => currentProperty.name !== sortedPropertyList[index]?.name);
59
+ if (violatingProperty) {
60
+ ruleContext.report({
61
+ node: violatingProperty.node,
62
+ messageId: 'incorrectOrder',
63
+ data: {
64
+ currentProperty: violatingProperty.name,
65
+ nextProperty: sortedPropertyList[cssPropertyInfoList.indexOf(violatingProperty)]?.name || '',
66
+ },
67
+ fix: (fixer) => (0, css_order_fixer_js_1.generateFixesForCSSOrder)(fixer, ruleContext, cssPropertyInfoList, compareProperties, (propertyInfo) => propertyInfo.node),
68
+ });
69
+ }
70
+ };
71
+ exports.enforceCustomGroupOrder = enforceCustomGroupOrder;
@@ -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,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enforceUserDefinedGroupOrderInRecipe = void 0;
4
+ const recipe_property_processor_js_1 = require("../shared-utils/recipe-property-processor.js");
5
+ const style_node_processor_js_1 = require("../shared-utils/style-node-processor.js");
6
+ const style_object_processor_js_1 = require("./style-object-processor.js");
7
+ /**
8
+ * Enforces custom group ordering of CSS properties within a recipe function call.
9
+ *
10
+ * @param ruleContext The ESLint rule context for reporting and fixing issues.
11
+ * @param callExpression The CallExpression node representing the recipe function call.
12
+ * @param userDefinedGroups An array of property groups in the desired order.
13
+ *
14
+ * This function does the following:
15
+ * 1. Validates that the first argument of the recipe function is an ObjectExpression.
16
+ * 2. Processes the recipe object's properties if valid.
17
+ * 3. Applies custom group ordering to CSS properties in relevant properties (e.g., 'base', 'variants').
18
+ * 4. Processes nested selectors and style objects recursively.
19
+ */
20
+ const enforceUserDefinedGroupOrderInRecipe = (ruleContext, callExpression, userDefinedGroups, sortRemainingPropertiesMethod) => {
21
+ if (!callExpression.arguments[0] || callExpression.arguments[0].type !== 'ObjectExpression') {
22
+ return;
23
+ }
24
+ const recipeObjectExpression = callExpression.arguments[0];
25
+ (0, recipe_property_processor_js_1.processRecipeProperties)(ruleContext, recipeObjectExpression, (currentContext, styleObject) => (0, style_node_processor_js_1.processStyleNode)(currentContext, styleObject, (styleContext, styleObjectNode) => (0, style_object_processor_js_1.enforceUserDefinedGroupOrderInStyleObject)(styleContext, styleObjectNode, userDefinedGroups, sortRemainingPropertiesMethod)));
26
+ };
27
+ exports.enforceUserDefinedGroupOrderInRecipe = enforceUserDefinedGroupOrderInRecipe;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const customGroupOrderRule: Rule.RuleModule;
3
+ export default customGroupOrderRule;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const concentric_groups_js_1 = require("../concentric-order/concentric-groups.js");
4
+ const order_strategy_visitor_creator_js_1 = require("../shared-utils/order-strategy-visitor-creator.js");
5
+ const customGroupOrderRule = {
6
+ meta: {
7
+ type: 'suggestion',
8
+ docs: {
9
+ description: 'enforce custom group CSS property ordering in vanilla-extract styles',
10
+ category: 'Stylistic Issues',
11
+ recommended: true,
12
+ },
13
+ fixable: 'code',
14
+ schema: [
15
+ {
16
+ type: 'object',
17
+ properties: {
18
+ groupOrder: {
19
+ type: 'array',
20
+ items: {
21
+ enum: concentric_groups_js_1.availableGroups,
22
+ },
23
+ },
24
+ sortRemainingProperties: {
25
+ enum: ['alphabetical', 'concentric'],
26
+ },
27
+ },
28
+ additionalProperties: false,
29
+ },
30
+ ],
31
+ messages: {
32
+ incorrectOrder: "Property '{{nextProperty}}' should come before '{{currentProperty}}' according to custom CSS group ordering.",
33
+ },
34
+ },
35
+ create(ruleContext) {
36
+ const ruleConfiguration = ruleContext.options[0];
37
+ const userDefinedGroupOrder = ruleConfiguration?.groupOrder ?? [];
38
+ const sortRemainingPropertiesMethod = ruleConfiguration?.sortRemainingProperties ?? 'alphabetical';
39
+ return (0, order_strategy_visitor_creator_js_1.createNodeVisitors)(ruleContext, 'userDefinedGroupOrder', userDefinedGroupOrder, sortRemainingPropertiesMethod);
40
+ },
41
+ };
42
+ exports.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,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enforceUserDefinedGroupOrderInStyleObject = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const concentric_groups_js_1 = require("../concentric-order/concentric-groups.js");
6
+ const css_property_priority_map_js_1 = require("../shared-utils/css-property-priority-map.js");
7
+ const nested_selectors_processor_js_1 = require("../shared-utils/nested-selectors-processor.js");
8
+ const property_separator_js_1 = require("../shared-utils/property-separator.js");
9
+ const property_order_enforcer_js_1 = require("./property-order-enforcer.js");
10
+ /**
11
+ * Enforces a custom ordering of CSS properties based on user-defined groups in a given style object.
12
+ *
13
+ * @param context The ESLint rule context for reporting and fixing issues.
14
+ * @param styleObject The ObjectExpression node representing the style object to be processed.
15
+ * @param userDefinedGroups An array of property groups in the desired order.
16
+ * @param sortRemainingPropertiesMethod Strategy for sorting properties not in user-defined groups ('alphabetical' or 'concentric'). Defaults to 'concentric'.
17
+ *
18
+ * This function:
19
+ * 1. Validates the input styleObject.
20
+ * 2. Handles 'selectors' objects separately, processing their nested style objects.
21
+ * 3. Creates a priority map based on user-defined groups.
22
+ * 4. Processes regular properties, creating a list of CSSPropertyInfo objects.
23
+ * 5. Enforces custom group ordering on the properties.
24
+ * 6. Recursively processes nested selectors and style objects.
25
+ */
26
+ const enforceUserDefinedGroupOrderInStyleObject = (ruleContext, styleObject, userDefinedGroups, sortRemainingPropertiesMethod = 'concentric') => {
27
+ if (!styleObject || styleObject.type !== utils_1.AST_NODE_TYPES.ObjectExpression) {
28
+ return;
29
+ }
30
+ if ((0, nested_selectors_processor_js_1.isSelectorsObject)(styleObject)) {
31
+ styleObject.properties.forEach((property) => {
32
+ if (property.type === utils_1.AST_NODE_TYPES.Property && property.value.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
33
+ (0, exports.enforceUserDefinedGroupOrderInStyleObject)(ruleContext, property.value, userDefinedGroups, sortRemainingPropertiesMethod);
34
+ }
35
+ });
36
+ return;
37
+ }
38
+ const cssPropertyPriorityMap = (0, css_property_priority_map_js_1.createCSSPropertyPriorityMap)(userDefinedGroups);
39
+ const { regularProperties } = (0, property_separator_js_1.separateProperties)(styleObject.properties);
40
+ const cssPropertyInfoList = regularProperties.map((property) => {
41
+ const propertyName = (0, property_separator_js_1.getPropertyName)(property);
42
+ const propertyInfo = cssPropertyPriorityMap.get(propertyName);
43
+ const group = userDefinedGroups.find((groupName) => concentric_groups_js_1.concentricGroups[groupName]?.includes(propertyName)) || 'remaining';
44
+ return {
45
+ name: propertyName,
46
+ node: property,
47
+ priority: propertyInfo?.groupIndex ?? Number.MAX_SAFE_INTEGER,
48
+ positionInGroup: propertyInfo?.positionInGroup ?? Number.MAX_SAFE_INTEGER,
49
+ group,
50
+ inUserGroup: propertyInfo?.inUserGroup ?? false,
51
+ };
52
+ });
53
+ (0, property_order_enforcer_js_1.enforceCustomGroupOrder)(ruleContext, cssPropertyInfoList, userDefinedGroups, sortRemainingPropertiesMethod);
54
+ (0, nested_selectors_processor_js_1.processNestedSelectors)(ruleContext, styleObject, (nestedContext, nestedNode) => (0, exports.enforceUserDefinedGroupOrderInStyleObject)(nestedContext, nestedNode, userDefinedGroups, sortRemainingPropertiesMethod));
55
+ };
56
+ exports.enforceUserDefinedGroupOrderInStyleObject = enforceUserDefinedGroupOrderInStyleObject;
@@ -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,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateFixesForCSSOrder = void 0;
4
+ /**
5
+ * Generates ESLint fixes for CSS property ordering violations.
6
+ * @param eslintFixer The ESLint fixer instance used to create fix objects.
7
+ * @param ruleContext The ESLint rule context, providing access to the source code.
8
+ * @param cssProperties The list of CSS properties to sort (can be TSESTree.Property[] or CSSPropertyInfo[]).
9
+ * @param compareProperties A comparison function that defines the sorting logic for the properties.
10
+ * @param extractNode A function that extracts the AST node from each property (used for text replacement).
11
+ * @returns An array of ESLint Fix objects to correct the property order.
12
+ *
13
+ * This function performs the following steps:
14
+ * 1. Sorts the input properties using the provided comparison function.
15
+ * 2. Maps the original and sorted properties to their text ranges.
16
+ * 3. Creates fix objects for properties whose positions have changed after sorting.
17
+ * 4. Returns an array of fixes that, when applied, will reorder the properties correctly.
18
+ */
19
+ const generateFixesForCSSOrder = (eslintFixer, ruleContext, cssProperties, compareProperties, extractNode) => {
20
+ const sourceCode = ruleContext.sourceCode;
21
+ // Sort properties using the provided comparison function
22
+ const sortedProperties = [...cssProperties].sort(compareProperties);
23
+ // Map each original property to its text range
24
+ const originalPropertyRanges = cssProperties.map((property) => ({
25
+ property,
26
+ range: extractNode(property).range,
27
+ }));
28
+ // Map sorted properties back to their original range information
29
+ const sortedPropertyRanges = sortedProperties.map((property) => originalPropertyRanges.find((rangeInfo) => rangeInfo.property === property));
30
+ // Generate fixes for properties that have changed position
31
+ return originalPropertyRanges
32
+ .map((originalRangeInfo, index) => {
33
+ const sortedRangeInfo = sortedPropertyRanges[index];
34
+ // Create a fix only if the property's position has changed
35
+ if (originalRangeInfo && sortedRangeInfo && originalRangeInfo !== sortedRangeInfo) {
36
+ const sortedPropertyText = sourceCode.getText(extractNode(sortedRangeInfo.property));
37
+ return eslintFixer.replaceText(extractNode(originalRangeInfo.property), sortedPropertyText);
38
+ }
39
+ return null;
40
+ })
41
+ .filter((fix) => fix !== null);
42
+ };
43
+ exports.generateFixesForCSSOrder = generateFixesForCSSOrder;
@@ -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,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCSSPropertyPriorityMap = void 0;
4
+ const concentric_groups_js_1 = require("../concentric-order/concentric-groups.js");
5
+ /**
6
+ * Creates a map of CSS properties to their priority information.
7
+ *
8
+ * This function generates a Map where each key is a CSS property (in camelCase),
9
+ * and each value is an object containing:
10
+ * - groupIndex: The index of the property's group
11
+ * - positionInGroup: The position of the property within its group
12
+ * - inUserGroup: Whether the property is in a user-specified group
13
+ *
14
+ * The function prioritizes user-specified groups over default concentric groups.
15
+ * If user groups are provided, they are processed first. Any remaining concentric
16
+ * groups are then processed to ensure complete coverage of CSS properties.
17
+ *
18
+ * @param userGroups - An optional array of user-specified group names to prioritize
19
+ * @returns A Map of CSS properties to their priority information
20
+ *
21
+ * @example
22
+ * const priorityMap = createCSSPropertyPriorityMap(['layout', 'typography']);
23
+ * console.log(priorityMap.get('display')); // { groupIndex: 0, positionInGroup: 0, inUserGroup: true }
24
+ */
25
+ const createCSSPropertyPriorityMap = (userGroups = []) => {
26
+ const cssPropertyPriorityMap = new Map();
27
+ const processGroup = (groupName, groupIndex, inUserGroup) => {
28
+ const properties = concentric_groups_js_1.concentricGroups[groupName] || [];
29
+ properties.forEach((property, positionInGroup) => {
30
+ const camelCaseProperty = property.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
31
+ if (!cssPropertyPriorityMap.has(camelCaseProperty)) {
32
+ cssPropertyPriorityMap.set(camelCaseProperty, {
33
+ groupIndex,
34
+ positionInGroup,
35
+ inUserGroup,
36
+ });
37
+ }
38
+ });
39
+ };
40
+ // Process user-specified groups first
41
+ userGroups.forEach((groupName, index) => processGroup(groupName, index, true));
42
+ // Process remaining groups if needed (for concentric order or as fallback)
43
+ if (userGroups.length === 0 || userGroups.length < Object.keys(concentric_groups_js_1.concentricGroups).length) {
44
+ Object.keys(concentric_groups_js_1.concentricGroups).forEach((groupName, index) => {
45
+ if (!userGroups.includes(groupName)) {
46
+ processGroup(groupName, userGroups.length + index, false);
47
+ }
48
+ });
49
+ }
50
+ return cssPropertyPriorityMap;
51
+ };
52
+ exports.createCSSPropertyPriorityMap = createCSSPropertyPriorityMap;
@@ -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,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processNestedSelectors = exports.isSelectorsObject = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ /**
6
+ * Determines if the given object node is a 'selectors' object within a style definition.
7
+ * @param objectNode The object expression node to check.
8
+ * @returns True if the node is a 'selectors' object, false otherwise.
9
+ *
10
+ * This function checks if:
11
+ * 1. The node has a parent
12
+ * 2. The parent is a Property node
13
+ * 3. The parent's key is an Identifier
14
+ * 4. The parent's key name is 'selectors'
15
+ */
16
+ const isSelectorsObject = (objectNode) => {
17
+ return (objectNode.parent &&
18
+ objectNode.parent.type === utils_1.AST_NODE_TYPES.Property &&
19
+ objectNode.parent.key.type === 'Identifier' &&
20
+ objectNode.parent.key.name === 'selectors');
21
+ };
22
+ exports.isSelectorsObject = isSelectorsObject;
23
+ /**
24
+ * Processes nested selectors within a 'selectors' object by recursively validating their value objects.
25
+ * @param context The ESLint rule context.
26
+ * @param objectNode The object expression node representing the 'selectors' object.
27
+ * @param validateFn A function to validate each nested selector's value object.
28
+ *
29
+ * This function iterates through each property of the 'selectors' object:
30
+ * - If a property's value is an ObjectExpression, it applies the validateFn to that object.
31
+ * - This allows for validation of nested style objects within selectors.
32
+ */
33
+ const processNestedSelectors = (context, objectNode, validateFn) => {
34
+ objectNode.properties.forEach((property) => {
35
+ if (property.type === utils_1.AST_NODE_TYPES.Property && property.value.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
36
+ validateFn(context, property.value);
37
+ }
38
+ });
39
+ };
40
+ exports.processNestedSelectors = processNestedSelectors;