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 1 commit into from Sep 14, 2019


Copy link

krawaller commented Aug 31, 2019

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?


Please show your full 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?


Is this a breaking change?


@eslint eslint bot added the triage label Aug 31, 2019
@krawaller krawaller force-pushed the krawaller:david/nestedblocks branch from 767c418 to edd8602 Aug 31, 2019
@ilyavolodin ilyavolodin added accepted bug rule and removed triage labels Sep 14, 2019
Copy link

mysticatea left a comment

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
16 checks passed
16 checks passed
Verify Files
Test (ubuntu-latest, 8.x)
Test (ubuntu-latest, 10.x)
Test (ubuntu-latest, 12.x)
Test (windows-latest, 12.x)
Test (macOS-latest, 12.x)
Browser Test
commit-message Commit message follows guidelines
continuous-integration Build #20190831.5 succeeded
continuous-integration (Test on Node.js 10 (Linux)) Test on Node.js 10 (Linux) succeeded
continuous-integration (Test on Node.js 12 (Linux)) Test on Node.js 12 (Linux) succeeded
continuous-integration (Test on Node.js 12 (Windows)) Test on Node.js 12 (Windows) succeeded
continuous-integration (Test on Node.js 12 (macOS)) Test on Node.js 12 (macOS) succeeded
continuous-integration (Test on Node.js 8 (Linux)) Test on Node.js 8 (Linux) succeeded
licence/cla Contributor License Agreement is signed.
release-monitor No patch release is pending
@eslint eslint bot locked and limited conversation to collaborators Mar 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.