Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💅 noUselessLoneBlockStatements collides with useSingleCaseStatement when using switch #834

Closed
1 task done
hougesen opened this issue Nov 22, 2023 · 2 comments · Fixed by #844
Closed
1 task done
Assignees
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@hougesen
Copy link

Environment information

CLI:
  Version:                      1.3.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "rio"
  JS_RUNTIME_VERSION:           "v18.18.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/9.8.1"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           true
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Workspace:
  Open Documents:               0

Rule name

noUselessLoneBlockStatements

Playground link

https://biomejs.dev/playground/?indentStyle=space&quoteStyle=single&trailingComma=none&lintRules=all&code=cwB3AGkAdABjAGgAIAAoADEAKQAgAHsACgAgACAALwAvACAAdQBzAGUAUwBpAG4AZwBsAGUAQwBhAHMAZQBTAHQAYQB0AGUAbQBlAG4AdAAgAGkAcwAgAHQAcgBpAGcAZwBlAHIAZQBkAAoAIAAgAGQAZQBmAGEAdQBsAHQAOgAKACAAIAAgACAAYwBvAG4AcwBvAGwAZQAuAGkAbgBmAG8AKAAnADEAJwApADsACgAgACAAIAAgAGMAbwBuAHMAbwBsAGUALgBpAG4AZgBvACgAJwAyACcAKQA7AAoAIAAgACAAIABiAHIAZQBhAGsAOwAKAH0ACgAKAHMAdwBpAHQAYwBoACAAKAAxACkAIAB7AAoAIAAgAC8ALwAgAG4AbwBVAHMAZQBsAGUAcwBzAEwAbwBuAGUAQgBsAG8AYwBrAFMAdABhAHQAZQBtAGUAbgB0AHMAIABpAHMAIAB0AHIAaQBnAGcAZQByAGUAZAAKACAAIABkAGUAZgBhAHUAbAB0ADoAIAB7AAoAIAAgACAAIABjAG8AbgBzAG8AbABlAC4AaQBuAGYAbwAoACcAMQAnACkAOwAKACAAIAAgACAAYwBvAG4AcwBvAGwAZQAuAGkAbgBmAG8AKAAnADIAJwApADsACgAgACAAIAAgAGIAcgBlAGEAawA7AAoAIAAgAH0ACgB9AAoACgBzAHcAaQB0AGMAaAAgACgAMQApACAAewAKACAAIAAvAC8AIABuAG8AIAByAHUAbABlAHMAIABhAHIAZQAgAHQAcgBpAGcAZwBlAHIAZQBkAAoAIAAgAGQAZQBmAGEAdQBsAHQAOgAgAHsACgAgACAAIAAgAGMAbwBuAHMAdAAgAF8AIAA9ACAAJwAnADsACgAgACAAIAAgAGMAbwBuAHMAbwBsAGUALgBpAG4AZgBvACgAJwAxACcAKQA7AAoAIAAgACAAIABjAG8AbgBzAG8AbABlAC4AaQBuAGYAbwAoACcAMgAnACkAOwAKACAAIAAgACAAYgByAGUAYQBrADsACgAgACAAfQAKAH0ACgA%3D

Expected result

When both noUselessLoneBlockStatements and useSingleCaseStatement are turned on there will be an endless loop of "fixes" since they try to change the fix for each other.

The following code triggers the useSingleCaseStatement ("A switch clause should only have a single statement"):

switch (1) {
  // useSingleCaseStatement is triggered
  default:
    console.info("1");
    console.info("2");
    break;
}

When using the auto-fix the code is turned into the following:

switch (1) {
  // noUselessLoneBlockStatements is triggered
  default: {
    console.info("1");
    console.info("2");
    break;
  }
}

Which then triggers noUselessLoneBlockStatements. Using the auto-fix for noUselessLoneBlockStatementswill turn the code into the first code snippet (again).

The noUselessLoneBlockStatements rule works as expected when there is a variable declaration:

switch (1) {
  // no rules are triggered
  default: {
    const _ = "";
    console.info("1");
    console.info("2");
    break;
  }
}

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@ematipico ematipico added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project labels Nov 22, 2023
@vasucp1207
Copy link
Member

Can I take this issue.
Also which rule is better to address this problem, check condition in useSingleCaseStatement when there is no declaration in it or to check noUselessLoneBlockStatements.

@Conaclos
Copy link
Member

Also which rule is better to address this problem, check condition in useSingleCaseStatement when there is no declaration in it or to check noUselessLoneBlockStatements.

Assigned :)
noUselessLoneBlockStatements should ignore a block statement on a case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants