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-inner-declarations inconsistency

See original GitHub issue

Tell us about your environment

  • ESLint Version: 6.3.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: 2015,
  }
};

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

Demo link

/*eslint no-inner-declarations: ["error", "both"]*/

if (foo)
  var a;

if (foo)
  function f(){}

function bar() {
  if (foo)
    var a;

  if (foo)
    function f(){}
}
eslint index.js

What did you expect to happen?

To be consistent, either 4 errors or no errors?

This rule requires that function declarations and, optionally, variable declarations be in the root of a program or the body of a function.

Are these declarations in the root/body? Also, the documentation is later more specific:

“functions” (default) disallows function declarations in nested blocks

“both” disallows function and var declarations in nested blocks

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

2 errors:

11:5  error  Move variable declaration to function body root  no-inner-declarations
14:5  error  Move function declaration to function body root  no-inner-declarations
/*eslint no-inner-declarations: ["error", "both"]*/

if (foo)
  var a; // no error

if (foo)
  function f(){} // no error

function bar() {
  if (foo)
    var a; // error

  if (foo)
    function f(){} // error
}

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

Yes, if this is confirmed to be a bug.

Perhaps the rule should allow only these places for function and var declaration nodes:

  • Program > node
  • ExportNamedDeclaration > node
  • ExportDefaultDeclaration > node (function only)
  • Function > BlockStatement > node

meaning that there should be 4 errors in the above example, but I’m not sure is this the intention of this rule.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Sep 7, 2019

I would be 👍 for having 4 errors in your example.

1reaction
mdjermanoviccommented, Mar 19, 2020

@anikethsaha Sure, thanks!

It isn’t entirely clear what should be done, but it looks like a good idea to continue the discussion on a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rule Change: Remove no-inner-declaration from eslint ...
Remove no-inner-declarations from the recommended rule set. ... Browsers: allowed, but inconsistent behavior between different browsers.
Read more >
New Zealand Bill of Rights (Declarations of ... - Beehive.govt.nz
A 'declaration of inconsistency' is a formal statement by a court or tribunal that an Act is inconsistent with fundamental human rights ...
Read more >
Declarations of Inconsistency (edited) - OUR Archive
The NZBORA, s 4 is clear; where another enactment is inconsistent with its rights guarantees, that other enactment remains valid law. No (additional)...
Read more >
New Zealand Bill of Rights (Declarations of Inconsistency ...
This bill helps provide a mechanism for the Executive and the House of Representatives to consider, and, if they think fit, respond to,...
Read more >
Dialogue and the Declaration of Inconsistency: How a bill ...
The New Zealand Bills of Rights (Declarations of Inconsistency) Amendment Bill 2020 is ... inconsistency is a formal, non-binding judicial declaration of ...
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