question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

curly 'multi' autofix produces syntax errors with lexical declarations

See original GitHub issue

Tell us about your environment

  • ESLint Version: 6.0.1 (same with 5.16.0)
  • Node Version: 10.16.0
  • npm Version: 6.9.0

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

default

Please show your full configuration:

Configuration
module.exports = {
  parserOptions: {
    ecmaVersion: 6,
  },
  rules: {
    "curly": ["error", "multi"]
  }
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

if (foo) {
  let bar;
}
eslint index.js --fix

What did you expect to happen?

No errors, similar to how multi-or-nest works.

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

if (foo) 
  let bar; // SyntaxError: Lexical declaration cannot appear in a single-statement context

Are you willing to submit a pull request to fix this bug?

Yes.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
mdjermanoviccommented, Jun 26, 2019

It’s most likely a bad practice to have a function declaration anywhere other than directly in the body.

Perhaps ESLint should never modify such code, i.e. never move function declarations to {} or out from its existing {}, because it can produce some unpredictable differences even if it isn’t a syntax error.

1reaction
mdjermanoviccommented, Jun 26, 2019

Ok, I’m working on this.

It might take some time, all options have to be checked and the consistent modifier adds some complexity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
eslint/CHANGELOG.md
... curly `multi` reports single lexical declarations (fixes #11908) (#12513) ... prefer-template autofix produces syntax error with octal escapes (#12085) ...
Read more >
node_modules/eslint/CHANGELOG.md · master · tbrousso ...
... Fix: curly multi reports single lexical declarations (fixes #11908) (#12513) (Milos Djermanovic); ac60621 Fix: unexpected autofix in ...
Read more >
Syntax Errors in Coding and What You Can Do to Fix Them
A syntax error commonly occurs in coding when the coder has typed in something incorrectly. Syntax errors are easy to find and fix....
Read more >
PHP parse/syntax errors; and how to solve them
Which often occurs in multi-line and nested array declarations. $array = [1,[2,3],4,[5 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found