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.

44 lines (43 loc) 2.03 kB
import { availableGroups } from '../concentric-order/concentric-groups.js'; import { createNodeVisitors } from '../shared-utils/order-strategy-visitor-creator.js'; const customGroupOrderRule = { meta: { type: 'suggestion', docs: { description: 'enforce custom group CSS property ordering in vanilla-extract styles', category: 'Stylistic Issues', recommended: true, }, fixable: 'code', schema: [ { type: 'object', properties: { groupOrder: { type: 'array', items: { enum: availableGroups, }, }, sortRemainingProperties: { enum: ['alphabetical', 'concentric'], }, }, additionalProperties: false, }, ], messages: { // default message for ordering in case no groupOrder is provided alphabeticalOrder: "Property '{{nextProperty}}' should come before '{{currentProperty}}' according to alphabetical ordering.", fontFaceOrder: "Properties in fontFace should be ordered with 'src' first, followed by other properties in alphabetical order. Property '{{nextProperty}}' should come before '{{currentProperty}}'.", incorrectOrder: "Property '{{nextProperty}}' should come before '{{currentProperty}}' according to custom CSS group ordering.", }, }, create(ruleContext) { const ruleConfiguration = ruleContext.options[0]; const userDefinedGroupOrder = ruleConfiguration?.groupOrder ?? []; const sortRemainingPropertiesMethod = ruleConfiguration?.sortRemainingProperties ?? 'alphabetical'; return createNodeVisitors(ruleContext, 'userDefinedGroupOrder', userDefinedGroupOrder, sortRemainingPropertiesMethod); }, }; export default customGroupOrderRule;