eslint-plugin-vanilla-extract/src/css-rules/no-empty-blocks/rule-definition.ts
Ante Budimir 175ce9aef8 feat 🥁: add no-empty-style-blocks rule
Add comprehensive rule to detect and prevent empty CSS style blocks:

- Identify style objects with no properties
- Flag empty style blocks as potential code quality issues
- Provide auto-fix capability to remove empty blocks
- Handle edge cases like comments-only blocks

This rule helps maintain cleaner codebases by eliminating empty style definitions that often result from incomplete refactoring or forgotten implementations, reducing confusion and unnecessary code.
2025-04-06 16:34:35 +03:00

33 lines
1.3 KiB
TypeScript

import type { Rule } from 'eslint';
import { createEmptyStyleVisitors } from './empty-style-visitor-creator.js';
const noEmptyStyleBlocksRule: Rule.RuleModule = {
meta: {
type: 'suggestion',
docs: {
description: 'disallow empty style blocks in vanilla-extract stylesheets',
category: 'Best Practices',
recommended: true,
},
fixable: 'code',
schema: [],
messages: {
emptyConditionalStyle: 'Empty conditional style object should be removed.',
emptyMedia: 'Empty @media object should be removed.',
emptyNestedStyle: 'Empty nested style object should be removed.',
emptyRecipeProperty: 'Empty {{propertyName}} object in recipe should be removed.',
emptySelectors: 'Empty selectors object should be removed.',
emptySpreadObject: 'Empty spread object should be removed.',
emptyStyleDeclaration: 'Declarations with only empty style blocks should be removed.',
emptySupports: 'Empty @supports object should be removed.',
emptyVariantCategory: 'Empty variant category should be removed.',
emptyVariantValue: 'Empty variant value should be removed.',
invalidPropertyType: 'Variant values must be objects, found {{type}} instead.',
},
},
create(ruleContext) {
return createEmptyStyleVisitors(ruleContext);
},
};
export default noEmptyStyleBlocksRule;