mirror of
https://github.com/antebudimir/eslint-plugin-vanilla-extract.git
synced 2026-01-01 09:23:31 +00:00
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.
This commit is contained in:
parent
f346002fb0
commit
175ce9aef8
45 changed files with 2674 additions and 566 deletions
36
src/css-rules/no-empty-blocks/conditional-processor.ts
Normal file
36
src/css-rules/no-empty-blocks/conditional-processor.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import type { Rule } from 'eslint';
|
||||
import { TSESTree } from '@typescript-eslint/utils';
|
||||
import { isEmptyObject } from '../shared-utils/empty-object-processor.js';
|
||||
import { reportEmptyDeclaration } from './fix-utils.js';
|
||||
|
||||
/**
|
||||
* Handles conditional expressions with empty objects.
|
||||
*/
|
||||
export function processConditionalExpression(
|
||||
context: Rule.RuleContext,
|
||||
node: TSESTree.ConditionalExpression,
|
||||
reportedNodes: Set<TSESTree.Node>,
|
||||
callNode: TSESTree.CallExpression,
|
||||
): void {
|
||||
const isConsequentEmpty = node.consequent.type === 'ObjectExpression' && isEmptyObject(node.consequent);
|
||||
const isAlternateEmpty = node.alternate.type === 'ObjectExpression' && isEmptyObject(node.alternate);
|
||||
|
||||
// If both branches are empty, report the entire declaration for removal
|
||||
if (isConsequentEmpty && isAlternateEmpty) {
|
||||
reportedNodes.add(node);
|
||||
reportEmptyDeclaration(context, node, callNode);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, handle individual empty branches
|
||||
if (isConsequentEmpty || isAlternateEmpty) {
|
||||
const emptyNode = isConsequentEmpty ? node.consequent : node.alternate;
|
||||
reportedNodes.add(emptyNode);
|
||||
|
||||
// No fix provided, just flagging the issue
|
||||
context.report({
|
||||
node: emptyNode as Rule.Node,
|
||||
messageId: 'emptyConditionalStyle',
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue