UNPKG

@antebudimir/eslint-plugin-vanilla-extract

Version:

Comprehensive ESLint plugin for vanilla-extract with CSS property ordering, style validation, and best practices enforcement. Supports alphabetical, concentric and custom CSS ordering, auto-fixing, and zero-runtime safety.

28 lines (27 loc) 1.57 kB
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'; import { isSelectorsObject, processNestedSelectors } from '../shared-utils/nested-selectors-processor.js'; import { separateProperties } from '../shared-utils/property-separator.js'; import { enforceAlphabeticalCSSOrder } from './property-order-enforcer.js'; /** * Processes a style object to enforce alphabetical ordering of CSS properties. * * This function handles different types of style objects: * 1. If the object is invalid or not an ObjectExpression, it returns immediately. * 2. For 'selectors' objects, it processes nested selectors recursively. * 3. For regular style objects, it separates and enforces alphabetical order on properties. * 4. It always processes nested objects recursively, regardless of type. * * @param ruleContext - The ESLint rule context for reporting and fixing issues. * @param styleObject - The object expression representing the style object to be processed. */ export const enforceAlphabeticalCSSOrderInStyleObject = (ruleContext, styleObject) => { if (styleObject?.type === AST_NODE_TYPES.ObjectExpression) { if (isSelectorsObject(styleObject)) { processNestedSelectors(ruleContext, styleObject, enforceAlphabeticalCSSOrderInStyleObject); return; } const { regularProperties } = separateProperties(styleObject.properties); enforceAlphabeticalCSSOrder(ruleContext, regularProperties); processNestedSelectors(ruleContext, styleObject, enforceAlphabeticalCSSOrderInStyleObject); } };