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-unused-vars false positive for exported function

See original GitHub issue

Tell us about your environment

  • ESLint Version: 6.3.0
  • Node Version: v8.11.2
  • npm Version: 5.6.0

What parser (default, Babel-ESLint, etc.) are you using? @typescript-eslint/parser

Please show your full configuration:

Configuration
module.exports = {
  env: {
    browser: true,
    es6: true,
  },
  extends: [
    'eslint:recommended',
    'plugin:prettier/recommended',
  ],
  "globals": {
    "$": false
  },
  "rules": {
  }
};

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

/* exported myFunc */
/* exported myVar */
{
  var myVar = 1;

  function myFunc() {
    return 1;
  }
}
./node_modules/.bin/eslint path/to/file

What did you expect to happen?

No error for myFunc (just like for myVar)

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

69:12 error ‘myFunc’ is defined but never used no-unused-vars

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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Nov 16, 2019

ESLint’s scope manager treats function declarations as block-scoped in ES2015+, even in non-strict mode. Therefore, the rule doesn’t see myFunc as being exported.

It doesn’t work like that in browsers because they are required to support legacy code. The example from the original post would indeed create global myFunc (in non-strict mode only).

But, it’s a legacy feature that should be avoided in new code, e.g. by using var myFunc = function () {} or window.myFunc = function () {}

0reactions
eslint-deprecated[bot]commented, Dec 17, 2019

Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript-eslint/no-unused-vars false positive in type ...
I am on version 4.22.1 and am still getting the warnings. Is there any additional configurations required to disable linting on function ......
Read more >
no-unused-vars - ESLint - Pluggable JavaScript Linter
This rule is aimed at eliminating unused variables, functions, and function parameters. A variable foo is considered to be used if any of...
Read more >
no-unused-vars - TypeScript ESLint
How to Use​ .eslintrc.cjs. module.exports = { "rules": { // Note: you must disable the base rule as it can report incorrect errors...
Read more >
typescript-eslint/no-unused-vars false positive in type ...
And we have @typescript-eslint/no-unused-vars error in string with type declaration, which says 'name' is defined but never used. example of type usage: export...
Read more >
node_modules/@typescript-eslint/eslint-plugin ...
eslint-plugin: [no-unnecessary-condition] false positive when array ... [no-unused-vars] properly handle ambient declaration exports (#2496) ...
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