@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.
46 lines (45 loc) • 1.77 kB
JavaScript
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 const 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;
}
});
};