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.

no-undef not reported in switch case block

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.19.1
  • Node Version: 10.7.0
  • npm Version: 6.4.0

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

Please show your full configuration:

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

switch (1) {
case 0:
    const x = 1;
    break;
case 1:
    console.log(x);
    break;
}
eslint test.js

What did you expect to happen?

error ‘x’ is not defined no-undef

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
not-an-aardvarkcommented, Aug 31, 2018

This is intended to be caught by no-case-declarations. The ReferenceErrors are resulting from a temporal dead zone reference to y, because y is declared in scope but is read before the declaration is executed.

0reactions
nzakascommented, Sep 19, 2018

The team has determined that this behavior is working as intended, so closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

enable rule no-case-declarations to prevent usage of ... - GitHub
During refactoring, var x was removed which triggers two no-undef errors. First error is solved with let x = 1 but that makes...
Read more >
ESLint/Nodejs: Error linting due to default switch case
js file using ESLint I received a an unexpected lexical declaration (no-case declarations) error. c:\>eslint C:\modules\myFile.js 503:17 error ...
Read more >
The switch Statement (The Java™ Tutorials > Learning the ...
The body of a switch statement is known as a switch block. A statement in the switch block can be labeled with one...
Read more >
DCL41-C. Do not declare variables inside a switch statement ...
Using test conditions or initializing variables before the first case statement in a switch block can result in unexpected behavior and undefined behavior....
Read more >
Disallow Use of undefined Variable (no-undefined) - ESLint
The undefined variable in JavaScript is actually a property of the global object. As such, in ECMAScript 3 it was possible to overwrite...
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