no-unused-vars false positive for exported function
See original GitHub issueTell 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:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 () {}
orwindow.myFunc = function () {}
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.