tools icon indicating copy to clipboard operation
tools copied to clipboard

🐛 Rule: useSingleCaseStatement considers break keyword as 2nd statement

Open ysageev opened this issue 2 years ago • 6 comments

Environment information

CLI:
  Version:              10.0.1-nightly.00266da
  Color support:        true

Platform:
  CPU Architecture:     x86_64
  OS:                   windows

Environment:
  ROME_LOG_DIR:         unset
  NO_COLOR:             unset
  TERM:                 "xterm-256color"

Rome Configuration:
  Status:               loaded
  Formatter disabled:   false
  Linter disabled:      false

Workspace:
  Open Documents:       0

Discovering running Rome servers...

Incompatible Rome Server: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

i Rage discovered this running server using an incompatible version of Rome.

Server:
  Version:              <=10.0.0

What happened?

The linter wants to insert blocks around any case that has a statement and a break statement:

image

Expected result

It should not flag <statement> break as needing blocks.

Code of Conduct

  • [X] I agree to follow Rome's Code of Conduct

ysageev avatar Nov 17 '22 20:11 ysageev

I ran into this issue as well.

sebmellen avatar Nov 17 '22 21:11 sebmellen

I am wondering why Rome did not choose to implement no-case-declarations?

Conaclos avatar Nov 17 '22 21:11 Conaclos

👋 @rome/staff please triage this issue by adding one of the following labels: S-Bug: confirmed, S-Planned , S-Wishlist or umbrella

github-actions[bot] avatar Dec 02 '22 12:12 github-actions[bot]

I think we could replace this rule with useSwitchClauseBlock which enforces block for every non-empty switch clauses (including single statement). The new rule could be a stylistic rule and be not recommended. Or we could add an option to useBlock for covering this.

Conaclos avatar Dec 02 '22 14:12 Conaclos

I think we could replace this rule with useSwitchClauseBlock which enforces block for every non-empty switch clauses (including single statement). The new rule could be a stylistic rule and be not recommended. Or we could add an option to useBlock for covering this.

Since it is a very common use case to have one statement per case, and every non-fall-through case needs a break, the rule should not flag <statement>; break; as needing a block. The name of the rule and use case is otherwise fine.

ysageev avatar Dec 02 '22 14:12 ysageev

The issue is that I don't see the purpose of this rule. I think it is only for stylistic consistency...

Conaclos avatar Dec 02 '22 14:12 Conaclos

From version 11.0.0, this rule has been moved to the style group and is not recommended anymore.

ematipico avatar Dec 07 '22 16:12 ematipico