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

Fix: patch hole in the no-lone-blocks rule #12193

Merged
merged 1 commit into from Sep 14, 2019

Conversation

krawaller
Copy link
Contributor

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

[X] Bug fix

Tell us about your environment

  • ESLint Version: 6.3.0
  • Node Version: 11.12.0
  • npm Version: 6.7.0

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

default

Please show your full configuration:

Configuration
module.exports = {
  parserOptions: {
    ecmaVersion: 2015,
  },
};

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

There is a hole in the ES6 logic for the no-lone-blocks rule. It is set to accept blocks with declarations, but if such a block appears as a lonely child of another block, it should be an error.

// Not caught by the rule prior to this PR
function foo() {
  {
    const x = 4; 
  }
}

I've seen this more than once in the wild - I suspect it can (somewhat) easily happen when you extract a piece of logic into a function.

What did you expect to happen?

Such blocks should be flagged as errors by the rule.

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

No error.

What changes did you make? (Give an overview)

Added extra condition and tests to cover this case.

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

No.

Is this a breaking change?

No.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Aug 31, 2019
@ilyavolodin ilyavolodin added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Sep 14, 2019
Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.

LGTM. But the tag of the commit message should be Update: because this patch increase errors.

@mysticatea mysticatea merged commit d3c2334 into eslint:master Sep 14, 2019
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 13, 2020
@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 Mar 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants