eslint-plugin-import: no-unused-modules does not work with shebangs
index.js
:
#!/usr/bin/env node
import { example } from './foo.js'
export { example }
foo.js
:
export const example = true
.eslintrc.yml
:
parserOptions:
ecmaVersion: 2019
sourceType: module
plugins: [import]
rules:
import/no-unused-modules: [2, {unusedExports: true}]
Then:
$ eslint
/home/user/example/foo.js
1:1 error exported declaration 'example' not used within other modules import/no-unused-modules
✖ 1 problem (1 error, 0 warnings)
However this works when removing #!/usr/bin/env node
.
eslint
: 5.16.0
eslint-plugin-import
: 2.17.3
node
: 12.3.1
OS: Ubuntu 19.04
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 19 (16 by maintainers)
https://github.com/import-js/eslint-plugin-import/pull/2431
Shebangs will soon become a regular part of the language, at which point eslint will parse then.
If the file doesn’t parse, these rules should probably bail out.
Yes I agree. I only added an
export
inindex.js
so it does not trigger an ESLint warning, to make the issue simpler.However even without that
export
, the bug is still present. I.e.foo.js
example
is reported as not imported, even thoughindex.js
imports it.