@antebudimir/eslint-plugin-vanilla-extract 1.5.0 → 1.7.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 (42) hide show
  1. package/README.md +78 -4
  2. package/dist/css-rules/alphabetical-order/property-order-enforcer.js +3 -3
  3. package/dist/css-rules/concentric-order/style-object-processor.js +2 -2
  4. package/dist/css-rules/concentric-order/types.d.ts +1 -0
  5. package/dist/css-rules/custom-order/property-order-enforcer.d.ts +2 -2
  6. package/dist/css-rules/custom-order/property-order-enforcer.js +2 -3
  7. package/dist/css-rules/custom-order/recipe-order-enforcer.d.ts +2 -1
  8. package/dist/css-rules/custom-order/recipe-order-enforcer.js +2 -2
  9. package/dist/css-rules/custom-order/style-object-processor.d.ts +3 -2
  10. package/dist/css-rules/custom-order/style-object-processor.js +7 -7
  11. package/dist/css-rules/no-empty-blocks/conditional-processor.d.ts +6 -0
  12. package/dist/css-rules/no-empty-blocks/conditional-processor.js +26 -0
  13. package/dist/css-rules/no-empty-blocks/empty-nested-style-processor.d.ts +6 -0
  14. package/dist/css-rules/no-empty-blocks/empty-nested-style-processor.js +65 -0
  15. package/dist/css-rules/no-empty-blocks/empty-style-visitor-creator.d.ts +12 -0
  16. package/dist/css-rules/no-empty-blocks/empty-style-visitor-creator.js +183 -0
  17. package/dist/css-rules/no-empty-blocks/fix-utils.d.ts +22 -0
  18. package/dist/css-rules/no-empty-blocks/fix-utils.js +75 -0
  19. package/dist/css-rules/no-empty-blocks/index.d.ts +2 -0
  20. package/dist/css-rules/no-empty-blocks/index.js +2 -0
  21. package/dist/css-rules/no-empty-blocks/node-remover.d.ts +10 -0
  22. package/dist/css-rules/no-empty-blocks/node-remover.js +15 -0
  23. package/dist/css-rules/no-empty-blocks/property-utils.d.ts +9 -0
  24. package/dist/css-rules/no-empty-blocks/property-utils.js +28 -0
  25. package/dist/css-rules/no-empty-blocks/recipe-processor.d.ts +11 -0
  26. package/dist/css-rules/no-empty-blocks/recipe-processor.js +122 -0
  27. package/dist/css-rules/no-empty-blocks/rule-definition.d.ts +3 -0
  28. package/dist/css-rules/no-empty-blocks/rule-definition.js +30 -0
  29. package/dist/css-rules/no-empty-blocks/style-variants-processor.d.ts +10 -0
  30. package/dist/css-rules/no-empty-blocks/style-variants-processor.js +45 -0
  31. package/dist/css-rules/shared-utils/alphabetical-property-comparator.js +3 -3
  32. package/dist/css-rules/shared-utils/empty-object-processor.d.ts +11 -0
  33. package/dist/css-rules/shared-utils/empty-object-processor.js +15 -0
  34. package/dist/css-rules/shared-utils/font-face-property-order-enforcer.js +3 -3
  35. package/dist/css-rules/shared-utils/order-strategy-visitor-creator.d.ts +3 -1
  36. package/dist/css-rules/shared-utils/property-separator.d.ts +1 -1
  37. package/dist/css-rules/shared-utils/property-separator.js +2 -2
  38. package/dist/css-rules/types.d.ts +1 -0
  39. package/dist/css-rules/types.js +1 -0
  40. package/dist/index.d.ts +4 -20
  41. package/dist/index.js +9 -20
  42. package/package.json +13 -13
@@ -0,0 +1,75 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * Finds the target declaration node for a given call expression.
4
+ *
5
+ * Traverses the AST upwards from the `callNode` to find the appropriate
6
+ * declaration node. For global APIs, it targets the expression statement.
7
+ * For non-global APIs, it looks for variable declarations or export
8
+ * named declarations.
9
+ *
10
+ * @param callNode - The call expression node to start from.
11
+ * @param isGlobalApi - A flag indicating whether the API is global.
12
+ * @returns The target declaration node or null if not found.
13
+ */
14
+ export const findTargetDeclarationNode = (callNode, isGlobalApi) => {
15
+ let current = callNode;
16
+ while (current.parent) {
17
+ current = current.parent;
18
+ // For global APIs, we only need to check for ExpressionStatement
19
+ if (isGlobalApi && current.type === 'ExpressionStatement') {
20
+ return current;
21
+ }
22
+ // For non-global APIs, check for variable declarations and exports
23
+ if (!isGlobalApi) {
24
+ if (current.type === 'VariableDeclarator' && current.parent && current.parent.type === 'VariableDeclaration') {
25
+ // If this is part of an export, get the export declaration
26
+ if (current.parent.parent && current.parent.parent.type === 'ExportNamedDeclaration') {
27
+ return current.parent.parent;
28
+ }
29
+ return current.parent;
30
+ }
31
+ }
32
+ }
33
+ return null;
34
+ };
35
+ /**
36
+ * Reports an issue for an empty style declaration, and provides a fix to remove the declaration.
37
+ * @param ruleContext The ESLint rule context.
38
+ * @param node The node to report the issue on.
39
+ * @param callNode The CallExpression node of the style() function.
40
+ */
41
+ export const reportEmptyDeclaration = (ruleContext, node, callNode) => {
42
+ // Check if this is a global API function
43
+ const isGlobalApi = callNode.callee.type === 'Identifier' &&
44
+ ['globalStyle', 'globalFontFace', 'globalKeyframes'].includes(callNode.callee.name);
45
+ // Find the parent declaration node
46
+ const targetDeclarationNode = findTargetDeclarationNode(callNode, isGlobalApi);
47
+ if (targetDeclarationNode) {
48
+ ruleContext.report({
49
+ node: node,
50
+ messageId: 'emptyStyleDeclaration',
51
+ fix(fixer) {
52
+ const sourceCode = ruleContext.sourceCode;
53
+ const startLine = sourceCode.getLocFromIndex(targetDeclarationNode.range[0]).line;
54
+ const lineStart = sourceCode.getIndexFromLoc({
55
+ line: startLine,
56
+ column: 0,
57
+ });
58
+ // Find next line after the declaration
59
+ const endLine = sourceCode.getLocFromIndex(targetDeclarationNode.range[1]).line;
60
+ const nextLineStart = sourceCode.getIndexFromLoc({
61
+ line: endLine + 1,
62
+ column: 0,
63
+ });
64
+ return fixer.removeRange([lineStart, nextLineStart]);
65
+ },
66
+ });
67
+ }
68
+ else {
69
+ // Report the issue without providing a fix
70
+ ruleContext.report({
71
+ node: node,
72
+ messageId: 'emptyStyleDeclaration',
73
+ });
74
+ }
75
+ };
@@ -0,0 +1,2 @@
1
+ import noEmptyStyleBlocksRule from './rule-definition.js';
2
+ export default noEmptyStyleBlocksRule;
@@ -0,0 +1,2 @@
1
+ import noEmptyStyleBlocksRule from './rule-definition.js';
2
+ export default noEmptyStyleBlocksRule;
@@ -0,0 +1,10 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { TSESTree } from '@typescript-eslint/utils';
3
+ /**
4
+ * Removes the given node and also removes a trailing comma if it exists.
5
+ * @param ruleContext The ESLint rule context.
6
+ * @param node The node to remove.
7
+ * @param fixer The ESLint fixer.
8
+ * @returns The fix object.
9
+ */
10
+ export declare function removeNodeWithComma(ruleContext: Rule.RuleContext, node: TSESTree.Node, fixer: Rule.RuleFixer): Rule.Fix;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Removes the given node and also removes a trailing comma if it exists.
3
+ * @param ruleContext The ESLint rule context.
4
+ * @param node The node to remove.
5
+ * @param fixer The ESLint fixer.
6
+ * @returns The fix object.
7
+ */
8
+ export function removeNodeWithComma(ruleContext, node, fixer) {
9
+ const sourceCode = ruleContext.sourceCode;
10
+ const tokenAfter = sourceCode.getTokenAfter(node);
11
+ if (tokenAfter && tokenAfter.value === ',' && node.range && tokenAfter.range) {
12
+ return fixer.removeRange([node.range[0], tokenAfter.range[1]]);
13
+ }
14
+ return fixer.remove(node);
15
+ }
@@ -0,0 +1,9 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * Gets the property name regardless of whether it's an identifier or a literal.
4
+ */
5
+ export declare function getStyleKeyName(key: TSESTree.Expression | TSESTree.PrivateIdentifier): string | null;
6
+ /**
7
+ * Checks if all properties in a style object are empty objects.
8
+ */
9
+ export declare const areAllChildrenEmpty: (stylesObject: TSESTree.ObjectExpression) => boolean;
@@ -0,0 +1,28 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ import { isEmptyObject } from '../shared-utils/empty-object-processor.js';
3
+ /**
4
+ * Gets the property name regardless of whether it's an identifier or a literal.
5
+ */
6
+ export function getStyleKeyName(key) {
7
+ if (key.type === 'Identifier') {
8
+ return key.name;
9
+ }
10
+ if (key.type === 'Literal' && typeof key.value === 'string') {
11
+ return key.value;
12
+ }
13
+ return null;
14
+ }
15
+ /**
16
+ * Checks if all properties in a style object are empty objects.
17
+ */
18
+ export const areAllChildrenEmpty = (stylesObject) => {
19
+ if (stylesObject.properties.length === 0) {
20
+ return true;
21
+ }
22
+ return stylesObject.properties.every((property) => {
23
+ if (property.type !== 'Property' || property.value.type !== 'ObjectExpression') {
24
+ return false;
25
+ }
26
+ return isEmptyObject(property.value);
27
+ });
28
+ };
@@ -0,0 +1,11 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ /**
4
+ * Processes a recipe object, removing empty `base` and `variants` properties, as well as empty
5
+ * variant categories and values.
6
+ *
7
+ * @param ruleContext The ESLint rule context.
8
+ * @param recipeNode The recipe object node to process.
9
+ * @param reportedNodes A set of nodes that have already been reported by other processors.
10
+ */
11
+ export declare function processRecipeProperties(ruleContext: Rule.RuleContext, recipeNode: TSESTree.ObjectExpression, reportedNodes: Set<TSESTree.Node>): void;
@@ -0,0 +1,122 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ import { isEmptyObject } from '../shared-utils/empty-object-processor.js';
3
+ import { processEmptyNestedStyles } from './empty-nested-style-processor.js';
4
+ import { removeNodeWithComma } from './node-remover.js';
5
+ import { areAllChildrenEmpty, getStyleKeyName } from './property-utils.js';
6
+ /**
7
+ * Processes a recipe object, removing empty `base` and `variants` properties, as well as empty
8
+ * variant categories and values.
9
+ *
10
+ * @param ruleContext The ESLint rule context.
11
+ * @param recipeNode The recipe object node to process.
12
+ * @param reportedNodes A set of nodes that have already been reported by other processors.
13
+ */
14
+ export function processRecipeProperties(ruleContext, recipeNode, reportedNodes) {
15
+ recipeNode.properties.forEach((property) => {
16
+ if (property.type !== 'Property') {
17
+ return;
18
+ }
19
+ const propertyName = getStyleKeyName(property.key);
20
+ if (!propertyName) {
21
+ return;
22
+ }
23
+ // Handle empty base or variants properties
24
+ if ((propertyName === 'base' || propertyName === 'variants') &&
25
+ property.value.type === 'ObjectExpression' &&
26
+ isEmptyObject(property.value)) {
27
+ if (!reportedNodes.has(property)) {
28
+ reportedNodes.add(property);
29
+ ruleContext.report({
30
+ node: property,
31
+ messageId: 'emptyRecipeProperty',
32
+ data: {
33
+ propertyName,
34
+ },
35
+ fix(fixer) {
36
+ return removeNodeWithComma(ruleContext, property, fixer);
37
+ },
38
+ });
39
+ }
40
+ }
41
+ // Process base property nested objects
42
+ if (propertyName === 'base' && property.value.type === 'ObjectExpression') {
43
+ processEmptyNestedStyles(ruleContext, property.value, reportedNodes);
44
+ }
45
+ // Process variant values
46
+ if (propertyName === 'variants' && property.value.type === 'ObjectExpression') {
47
+ // If variants is empty, it will be handled by the check above
48
+ if (!isEmptyObject(property.value)) {
49
+ // Process variant categories
50
+ property.value.properties.forEach((variantCategoryProperty) => {
51
+ if (variantCategoryProperty.type !== 'Property' ||
52
+ variantCategoryProperty.value.type !== 'ObjectExpression') {
53
+ return;
54
+ }
55
+ // Check if all values in this category are empty
56
+ if (isEmptyObject(variantCategoryProperty.value) || areAllChildrenEmpty(variantCategoryProperty.value)) {
57
+ if (!reportedNodes.has(variantCategoryProperty)) {
58
+ reportedNodes.add(variantCategoryProperty);
59
+ ruleContext.report({
60
+ node: variantCategoryProperty,
61
+ messageId: 'emptyVariantCategory',
62
+ fix(fixer) {
63
+ return removeNodeWithComma(ruleContext, variantCategoryProperty, fixer);
64
+ },
65
+ });
66
+ }
67
+ return;
68
+ }
69
+ // Process individual variant values
70
+ variantCategoryProperty.value.properties.forEach((variantValueProperty) => {
71
+ if (variantValueProperty.type !== 'Property') {
72
+ return;
73
+ }
74
+ // Check for non-object variant values
75
+ if (variantValueProperty.value.type !== 'ObjectExpression') {
76
+ if (!reportedNodes.has(variantValueProperty)) {
77
+ reportedNodes.add(variantValueProperty);
78
+ // Get a user-friendly type description as a string
79
+ const friendlyType = (() => {
80
+ const nodeType = variantValueProperty.value.type;
81
+ if (nodeType === 'Literal') {
82
+ const literalValue = variantValueProperty.value;
83
+ return literalValue.value === null ? 'null' : typeof literalValue.value;
84
+ }
85
+ else if (nodeType === 'Identifier') {
86
+ return 'variable';
87
+ }
88
+ return nodeType;
89
+ })();
90
+ ruleContext.report({
91
+ node: variantValueProperty,
92
+ messageId: 'invalidPropertyType',
93
+ data: {
94
+ type: friendlyType,
95
+ },
96
+ });
97
+ }
98
+ return;
99
+ }
100
+ // Check for empty objects in variant properties
101
+ if (isEmptyObject(variantValueProperty.value)) {
102
+ if (!reportedNodes.has(variantValueProperty)) {
103
+ reportedNodes.add(variantValueProperty);
104
+ ruleContext.report({
105
+ node: variantValueProperty,
106
+ messageId: 'emptyVariantValue',
107
+ fix(fixer) {
108
+ return removeNodeWithComma(ruleContext, variantValueProperty, fixer);
109
+ },
110
+ });
111
+ }
112
+ }
113
+ else {
114
+ // Process nested styles within variant values
115
+ processEmptyNestedStyles(ruleContext, variantValueProperty.value, reportedNodes);
116
+ }
117
+ });
118
+ });
119
+ }
120
+ }
121
+ });
122
+ }
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noEmptyStyleBlocksRule: Rule.RuleModule;
3
+ export default noEmptyStyleBlocksRule;
@@ -0,0 +1,30 @@
1
+ import { createEmptyStyleVisitors } from './empty-style-visitor-creator.js';
2
+ const noEmptyStyleBlocksRule = {
3
+ meta: {
4
+ type: 'suggestion',
5
+ docs: {
6
+ description: 'disallow empty style blocks in vanilla-extract stylesheets',
7
+ category: 'Best Practices',
8
+ recommended: true,
9
+ },
10
+ fixable: 'code',
11
+ schema: [],
12
+ messages: {
13
+ emptyConditionalStyle: 'Empty conditional style object should be removed.',
14
+ emptyMedia: 'Empty @media object should be removed.',
15
+ emptyNestedStyle: 'Empty nested style object should be removed.',
16
+ emptyRecipeProperty: 'Empty {{propertyName}} object in recipe should be removed.',
17
+ emptySelectors: 'Empty selectors object should be removed.',
18
+ emptySpreadObject: 'Empty spread object should be removed.',
19
+ emptyStyleDeclaration: 'Declarations with only empty style blocks should be removed.',
20
+ emptySupports: 'Empty @supports object should be removed.',
21
+ emptyVariantCategory: 'Empty variant category should be removed.',
22
+ emptyVariantValue: 'Empty variant value should be removed.',
23
+ invalidPropertyType: 'Variant values must be objects, found {{type}} instead.',
24
+ },
25
+ },
26
+ create(ruleContext) {
27
+ return createEmptyStyleVisitors(ruleContext);
28
+ },
29
+ };
30
+ export default noEmptyStyleBlocksRule;
@@ -0,0 +1,10 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ /**
4
+ * Processes styleVariants function calls to detect and remove empty style variants.
5
+ *
6
+ * @param ruleContext The ESLint rule context.
7
+ * @param node The styleVariants call argument (object expression).
8
+ * @param reportedNodes A set of nodes that have already been reported.
9
+ */
10
+ export declare function processStyleVariants(ruleContext: Rule.RuleContext, node: TSESTree.ObjectExpression, reportedNodes: Set<TSESTree.Node>): void;
@@ -0,0 +1,45 @@
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
+ /**
5
+ * Processes styleVariants function calls to detect and remove empty style variants.
6
+ *
7
+ * @param ruleContext The ESLint rule context.
8
+ * @param node The styleVariants call argument (object expression).
9
+ * @param reportedNodes A set of nodes that have already been reported.
10
+ */
11
+ export function processStyleVariants(ruleContext, node, reportedNodes) {
12
+ node.properties.forEach((property) => {
13
+ if (property.type !== 'Property') {
14
+ return;
15
+ }
16
+ // Check for empty arrays
17
+ if (property.value.type === 'ArrayExpression' && property.value.elements.length === 0) {
18
+ if (!reportedNodes.has(property)) {
19
+ reportedNodes.add(property);
20
+ ruleContext.report({
21
+ node: property,
22
+ messageId: 'emptyVariantValue',
23
+ fix(fixer) {
24
+ return removeNodeWithComma(ruleContext, property, fixer);
25
+ },
26
+ });
27
+ }
28
+ return;
29
+ }
30
+ // Check for empty objects
31
+ if (property.value.type === 'ObjectExpression' && isEmptyObject(property.value)) {
32
+ if (!reportedNodes.has(property)) {
33
+ reportedNodes.add(property);
34
+ ruleContext.report({
35
+ node: property,
36
+ messageId: 'emptyVariantValue',
37
+ fix(fixer) {
38
+ return removeNodeWithComma(ruleContext, property, fixer);
39
+ },
40
+ });
41
+ }
42
+ return;
43
+ }
44
+ });
45
+ }
@@ -1,4 +1,4 @@
1
- import { getPropertyName } from './property-separator.js';
1
+ import { getPropertyNameForSorting } from './property-separator.js';
2
2
  /**
3
3
  * Compares two CSS properties alphabetically.
4
4
  * @param firstProperty The first property to compare.
@@ -6,8 +6,8 @@ import { getPropertyName } from './property-separator.js';
6
6
  * @returns A number indicating the relative order of the properties (-1, 0, or 1).
7
7
  */
8
8
  export const comparePropertiesAlphabetically = (firstProperty, secondProperty) => {
9
- const firstName = getPropertyName(firstProperty);
10
- const secondName = getPropertyName(secondProperty);
9
+ const firstName = getPropertyNameForSorting(firstProperty);
10
+ const secondName = getPropertyNameForSorting(secondProperty);
11
11
  // Special handling for 'src' property - it should always come first (relates to font face APIs only)
12
12
  if (firstName === 'src') {
13
13
  return -1;
@@ -0,0 +1,11 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * Type guard to check if a node is an ObjectExpression.
4
+ */
5
+ export declare const isObjectExpression: (node: TSESTree.Node) => node is TSESTree.ObjectExpression;
6
+ /**
7
+ * Checks if an object expression is empty (has no properties).
8
+ * @param node The node to check.
9
+ * @returns True if the node is an ObjectExpression with no properties.
10
+ */
11
+ export declare const isEmptyObject: (node: TSESTree.Node) => boolean;
@@ -0,0 +1,15 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * Type guard to check if a node is an ObjectExpression.
4
+ */
5
+ export const isObjectExpression = (node) => {
6
+ return node.type === 'ObjectExpression';
7
+ };
8
+ /**
9
+ * Checks if an object expression is empty (has no properties).
10
+ * @param node The node to check.
11
+ * @returns True if the node is an ObjectExpression with no properties.
12
+ */
13
+ export const isEmptyObject = (node) => {
14
+ return isObjectExpression(node) && node.properties.length === 0;
15
+ };
@@ -1,6 +1,6 @@
1
1
  import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
2
  import { generateFixesForCSSOrder } from '../shared-utils/css-order-fixer.js';
3
- import { getPropertyName, separateProperties } from '../shared-utils/property-separator.js';
3
+ import { getPropertyNameForSorting, separateProperties } from '../shared-utils/property-separator.js';
4
4
  import { comparePropertiesAlphabetically } from './alphabetical-property-comparator.js';
5
5
  /**
6
6
  * Processes a font face declaration to enforce property ordering:
@@ -24,8 +24,8 @@ export const enforceFontFaceOrder = (ruleContext, fontFaceObject) => {
24
24
  }));
25
25
  const violatingPair = propertyPairs.find(({ currentProperty, nextProperty }) => comparePropertiesAlphabetically(currentProperty, nextProperty) > 0);
26
26
  if (violatingPair) {
27
- const nextPropertyName = getPropertyName(violatingPair.nextProperty);
28
- const currentPropertyName = getPropertyName(violatingPair.currentProperty);
27
+ const nextPropertyName = getPropertyNameForSorting(violatingPair.nextProperty);
28
+ const currentPropertyName = getPropertyNameForSorting(violatingPair.currentProperty);
29
29
  ruleContext.report({
30
30
  node: violatingPair.nextProperty,
31
31
  messageId: 'fontFaceOrder',
@@ -1,4 +1,6 @@
1
1
  import type { Rule } from 'eslint';
2
+ import type { SortRemainingProperties } from '../concentric-order/types.js';
3
+ import type { OrderingStrategy } from '../types.js';
2
4
  /**
3
5
  * Creates an ESLint rule listener with visitors for style-related function calls.
4
6
  * @param ruleContext The ESLint rule context.
@@ -15,4 +17,4 @@ import type { Rule } from 'eslint';
15
17
  *
16
18
  * Each visitor applies the appropriate ordering strategy to the style objects in these function calls.
17
19
  */
18
- export declare const createNodeVisitors: (ruleContext: Rule.RuleContext, orderingStrategy: "alphabetical" | "concentric" | "userDefinedGroupOrder", userDefinedGroupOrder?: string[], sortRemainingProperties?: "alphabetical" | "concentric") => Rule.RuleListener;
20
+ export declare const createNodeVisitors: (ruleContext: Rule.RuleContext, orderingStrategy: OrderingStrategy, userDefinedGroupOrder?: string[], sortRemainingProperties?: SortRemainingProperties) => Rule.RuleListener;
@@ -9,7 +9,7 @@ import { TSESTree } from '@typescript-eslint/utils';
9
9
  * - Literal (string): Returns the string value.
10
10
  * For any other type of key, it returns an empty string.
11
11
  */
12
- export declare const getPropertyName: (property: TSESTree.Property) => string;
12
+ export declare const getPropertyNameForSorting: (property: TSESTree.Property) => string;
13
13
  /**
14
14
  * Separates object properties into regular and special categories.
15
15
  * @param properties An array of object literal elements to be categorized.
@@ -9,7 +9,7 @@ import { TSESTree } from '@typescript-eslint/utils';
9
9
  * - Literal (string): Returns the string value.
10
10
  * For any other type of key, it returns an empty string.
11
11
  */
12
- export const getPropertyName = (property) => {
12
+ export const getPropertyNameForSorting = (property) => {
13
13
  if (property.key.type === 'Identifier') {
14
14
  return property.key.name;
15
15
  }
@@ -36,7 +36,7 @@ export const separateProperties = (properties) => {
36
36
  // Separate regular CSS properties from special ones (pseudo selectors, etc.)
37
37
  properties.forEach((property) => {
38
38
  if (property.type === 'Property') {
39
- const propName = getPropertyName(property);
39
+ const propName = getPropertyNameForSorting(property);
40
40
  if (propName.startsWith(':') || propName.startsWith('@') || propName === 'selectors') {
41
41
  specialProperties.push(property);
42
42
  }
@@ -0,0 +1 @@
1
+ export type OrderingStrategy = 'alphabetical' | 'concentric' | 'userDefinedGroupOrder';
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -7,32 +7,16 @@ export declare const vanillaExtract: {
7
7
  'alphabetical-order': import("eslint").Rule.RuleModule;
8
8
  'concentric-order': import("eslint").Rule.RuleModule;
9
9
  'custom-order': import("eslint").Rule.RuleModule;
10
+ 'no-empty-style-blocks': import("eslint").Rule.RuleModule;
10
11
  };
11
12
  configs: {
12
13
  recommended: {
13
- plugins: {
14
- 'vanilla-extract': {
15
- rules: {
16
- 'concentric-order': import("eslint").Rule.RuleModule;
17
- };
18
- };
19
- };
14
+ plugins: string[];
20
15
  rules: {
21
16
  'vanilla-extract/concentric-order': string;
17
+ 'vanilla-extract/no-empty-style-blocks': string;
22
18
  };
23
- }[];
24
- alphabetical: {
25
- plugins: {
26
- 'vanilla-extract': {
27
- rules: {
28
- 'alphabetical-order': import("eslint").Rule.RuleModule;
29
- };
30
- };
31
- };
32
- rules: {
33
- 'vanilla-extract/alphabetical-order': string;
34
- };
35
- }[];
19
+ };
36
20
  };
37
21
  };
38
22
  export default vanillaExtract;
package/dist/index.js CHANGED
@@ -1,37 +1,26 @@
1
1
  import alphabeticalOrderRule from './css-rules/alphabetical-order/index.js';
2
2
  import concentricOrderRule from './css-rules/concentric-order/index.js';
3
3
  import customOrderRule from './css-rules/custom-order/rule-definition.js';
4
+ import noEmptyStyleBlocksRule from './css-rules/no-empty-blocks/rule-definition.js';
4
5
  export const vanillaExtract = {
5
6
  meta: {
6
7
  name: '@antebudimir/eslint-plugin-vanilla-extract',
7
- version: '1.5.0',
8
+ version: '1.7.0',
8
9
  },
9
10
  rules: {
10
11
  'alphabetical-order': alphabeticalOrderRule,
11
12
  'concentric-order': concentricOrderRule,
12
13
  'custom-order': customOrderRule,
14
+ 'no-empty-style-blocks': noEmptyStyleBlocksRule,
13
15
  },
14
16
  configs: {
15
- recommended: [
16
- {
17
- plugins: {
18
- 'vanilla-extract': {
19
- rules: { 'concentric-order': concentricOrderRule },
20
- },
21
- },
22
- rules: { 'vanilla-extract/concentric-order': 'warn' },
17
+ recommended: {
18
+ plugins: ['vanilla-extract'],
19
+ rules: {
20
+ 'vanilla-extract/concentric-order': 'error',
21
+ 'vanilla-extract/no-empty-style-blocks': 'error',
23
22
  },
24
- ],
25
- alphabetical: [
26
- {
27
- plugins: {
28
- 'vanilla-extract': {
29
- rules: { 'alphabetical-order': alphabeticalOrderRule },
30
- },
31
- },
32
- rules: { 'vanilla-extract/alphabetical-order': 'warn' },
33
- },
34
- ],
23
+ },
35
24
  },
36
25
  };
37
26
  export default vanillaExtract;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antebudimir/eslint-plugin-vanilla-extract",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "ESLint plugin for enforcing best practices in vanilla-extract CSS styles, including CSS property ordering and additional linting rules.",
5
5
  "author": "Ante Budimir",
6
6
  "license": "MIT",
@@ -49,24 +49,24 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@eslint/eslintrc": "^3.3.0",
52
- "@types/node": "^20.17.19",
53
- "@typescript-eslint/eslint-plugin": "^8.25.0",
54
- "@typescript-eslint/parser": "^8.25.0",
55
- "@typescript-eslint/rule-tester": "^8.26.0",
56
- "@typescript-eslint/utils": "^8.25.0",
52
+ "@types/node": "^20.17.24",
53
+ "@typescript-eslint/eslint-plugin": "^8.26.1",
54
+ "@typescript-eslint/parser": "^8.26.1",
55
+ "@typescript-eslint/rule-tester": "^8.26.1",
56
+ "@typescript-eslint/utils": "^8.26.1",
57
57
  "@vanilla-extract/css": "^1.17.1",
58
58
  "@vanilla-extract/recipes": "^0.5.5",
59
59
  "@vitest/coverage-v8": "3.0.8",
60
- "eslint": "^9.21.0",
61
- "eslint-config-prettier": "^10.0.2",
62
- "eslint-import-resolver-typescript": "^3.8.3",
60
+ "eslint": "^9.22.0",
61
+ "eslint-config-prettier": "^10.1.1",
62
+ "eslint-import-resolver-typescript": "^3.8.5",
63
63
  "eslint-plugin-eslint-plugin": "^6.4.0",
64
64
  "eslint-plugin-import": "^2.31.0",
65
65
  "eslint-vitest-rule-tester": "^1.1.0",
66
- "prettier": "^3.5.2",
67
- "typescript": "^5.7.3",
68
- "typescript-eslint": "^8.25.0",
69
- "vitest": "^3.0.8"
66
+ "prettier": "^3.5.3",
67
+ "typescript": "^5.8.2",
68
+ "typescript-eslint": "^8.26.1",
69
+ "vitest": "3.0.8"
70
70
  },
71
71
  "scripts": {
72
72
  "build": "tsc",