Skip to content

Conversation

jaymarvelz
Copy link
Contributor

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

This PR enhances the no-empty rule to no longer report an error for switch statements that are empty but contain a comment. This aligns the behavior for switch statements with how the rule already handles other empty block statements.

  • Added a check to detect comments between the braces of an empty switch statement. If comments are present, the rule now exits without reporting an error.
  • Previously, the rule highlighted the entire switch statement for being empty. Now, it precisely highlights only the empty block braces ({}), which is consistent with the reporting for other block types.
  • Added a suggestion that provides a fix to insert a /* empty */ comment into empty switch statement that triggers the rule.
  • Updated the test suite to verify the new behavior and ensure the suggestion works correctly. Also added an example to the rule's documentation to reflect this change.

Fixes #20000

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

@jaymarvelz jaymarvelz requested a review from a team as a code owner August 26, 2025 08:40
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Aug 26, 2025
Copy link

netlify bot commented Aug 26, 2025

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 8b1ccba
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/68ada575777fd500081b3a7f

@eslint-github-bot eslint-github-bot bot added the bug ESLint is working incorrectly label Aug 26, 2025
Copy link

linux-foundation-easycla bot commented Aug 26, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions github-actions bot added the rule Relates to ESLint's core rules label Aug 26, 2025
@lumirlumir lumirlumir added the accepted There is consensus among the team that this change meets the criteria for inclusion label Aug 26, 2025
@mdjermanovic mdjermanovic moved this from Needs Triage to Implementing in Triage Aug 26, 2025
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Leaving open for two more days, per our policies, to give other chance to review.

@mdjermanovic mdjermanovic moved this from Implementing to Merge Candidates in Triage Aug 26, 2025
@mdjermanovic mdjermanovic merged commit bfa4601 into eslint:main Aug 28, 2025
38 of 51 checks passed
@github-project-automation github-project-automation bot moved this from Merge Candidates to Complete in Triage Aug 28, 2025
nzakas pushed a commit that referenced this pull request Sep 23, 2025
…20045)

* fix: ignore empty switch statements with comments in no-empty rule

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

Labels

accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly contributor pool rule Relates to ESLint's core rules

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Rule Change: no-empty rule does not ignore empty switch statements with comments

3 participants