UNPKG

@antebudimir/eslint-plugin-vanilla-extract

Version:

ESLint plugin for enforcing best practices in vanilla-extract CSS styles, including CSS property ordering and additional linting rules.

46 lines (45 loc) 1.77 kB
import { TSESTree } from '@typescript-eslint/utils'; import { isEmptyObject } from '../shared-utils/empty-object-processor.js'; import { removeNodeWithComma } from './node-remover.js'; /** * Processes styleVariants function calls to detect and remove empty style variants. * * @param ruleContext The ESLint rule context. * @param node The styleVariants call argument (object expression). * @param reportedNodes A set of nodes that have already been reported. */ export function processStyleVariants(ruleContext, node, reportedNodes) { node.properties.forEach((property) => { if (property.type !== 'Property') { return; } // Check for empty arrays if (property.value.type === 'ArrayExpression' && property.value.elements.length === 0) { if (!reportedNodes.has(property)) { reportedNodes.add(property); ruleContext.report({ node: property, messageId: 'emptyVariantValue', fix(fixer) { return removeNodeWithComma(ruleContext, property, fixer); }, }); } return; } // Check for empty objects if (property.value.type === 'ObjectExpression' && isEmptyObject(property.value)) { if (!reportedNodes.has(property)) { reportedNodes.add(property); ruleContext.report({ node: property, messageId: 'emptyVariantValue', fix(fixer) { return removeNodeWithComma(ruleContext, property, fixer); }, }); } return; } }); }