Skip to content

feat: add suggestions to no-empty-blocks#479

Open
k-yle wants to merge 1 commit into
eslint:mainfrom
k-yle:kh/autofix-empty-blocks
Open

feat: add suggestions to no-empty-blocks#479
k-yle wants to merge 1 commit into
eslint:mainfrom
k-yle:kh/autofix-empty-blocks

Conversation

@k-yle

@k-yle k-yle commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

Add sugggestions to no-empty-blocks. There are two different cases:

  • @layer name {} becomes @layer name
  • all other empty blocks like a {} become

What changes did you make? (Give an overview)

Related Issues

Closes #476

Is there anything you'd like reviewers to focus on?

Comment thread src/rules/no-empty-blocks.js Outdated
Comment thread src/rules/no-empty-blocks.js Outdated
@DMartens DMartens moved this from Needs Triage to Second Review Needed in Triage Jun 28, 2026
@DMartens

Copy link
Copy Markdown

Thank you for the PR. Just found two small refactorings using more appropriate methods.
Also checked and tried ways to create a parse error / changing AST after removal but could not find one.
Would like the second reviewer to focus on this.

@k-yle k-yle force-pushed the kh/autofix-empty-blocks branch from 7790a62 to a91126c Compare June 29, 2026 12:38

messages: {
emptyBlock: "Unexpected empty block found.",
deleteEmptyBlock: "Delete the empty block.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly misleading since fixer.remove(parent) removes the entire rule, not just the block.

parent.name === "layer";

return fixer.remove(
isAtLayer ? node : parent,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the block of a named layer can cause a parsing error (explorer). Instead, it needs to be replaced with a semicolon to become a valid layer statement. For unnamed layers, I think it is fine to remove the entire rule.

Because of this distinction, we should probably split this into two separate suggestions:

removeRule: "Remove the empty rule.",
convertToStatement: "Convert to layer statement.",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Second Review Needed

Development

Successfully merging this pull request may close these issues.

Rule Change: autofix for no-empty-blocks

3 participants