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

no-lone-blocks does not check statements in switch cases #8047

Closed
not-an-aardvark opened this issue Feb 8, 2017 · 1 comment · Fixed by renovatebot/renovate#111 · May be fixed by iamhunter/teammates#4
Closed

no-lone-blocks does not check statements in switch cases #8047

not-an-aardvark opened this issue Feb 8, 2017 · 1 comment · Fixed by renovatebot/renovate#111 · May be fixed by iamhunter/teammates#4
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules

Comments

@not-an-aardvark
Copy link
Member

Tell us about your environment

  • ESLint Version: master
  • Node Version: 7.5.0
  • npm Version: 4.1.2

What parser (default, Babel-ESLint, etc.) are you using?

default

Please show your full configuration:

rules:
  no-lone-blocks: error

What did you do? Please include the actual source code causing the issue.

switch (foo) {
  case 1:
    bar();
    {
      baz();
    }
}

What did you expect to happen?

I expected an error to be reported.

What actually happened? Please include the actual, raw output from ESLint.

No error was reported.

I know that it's fairly common to enclose an entire switch case in a block, e.g.

switch (foo) {
  case 1: {
    bar();
    baz();
  }
}

So I think the best solution is to report a block in a switch case only if there are other statements in the case.

@not-an-aardvark not-an-aardvark added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules labels Feb 8, 2017
not-an-aardvark added a commit that referenced this issue Feb 8, 2017
There are currently three types of nodes that can contain a list of statements:

* `Program`
* `BlockStatement`
* `SwitchCase`

Several rules have to check for these node types, and sometimes they do it incorrectly (see #8047). This commit puts the node types in a constant in `ast-utils`.
not-an-aardvark added a commit that referenced this issue Feb 8, 2017
There are currently three types of nodes that can contain a list of statements:

* `Program`
* `BlockStatement`
* `SwitchCase`

Several rules have to check for these node types, and sometimes they do it incorrectly (see #8047). This commit puts the node types in a constant in `ast-utils`.
@0xallie
Copy link

0xallie commented Jul 11, 2017

Please make this configurable. I want to consistently use blocks in all cases of switch statements that use let or const, but want to be warned about potential unnecessary blocks elsewhere.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules
Projects
None yet
1 participant