Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ESLint crashes with import/no-unused-modules and ignoreExports option #1323

Closed
ehmicky opened this issue Apr 14, 2019 · 8 comments · Fixed by #1331
Closed

[BUG] ESLint crashes with import/no-unused-modules and ignoreExports option #1323

ehmicky opened this issue Apr 14, 2019 · 8 comments · Fixed by #1331

Comments

@ehmicky
Copy link

ehmicky commented Apr 14, 2019

ESLint crashes with the following error:

$ eslint .
TypeError: Cannot read property 'get' of undefined
Occurred while linting /home/ehmicky/dir/a.js:1
    at checkExportPresence (/home/ehmicky/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:308:37)
    at Program:exit (/home/ehmicky/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:712:9)
    at listeners.(anonymous function).forEach.listener (/home/ehmicky/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/home/ehmicky/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/ehmicky/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/home/ehmicky/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.leaveNode (/home/ehmicky/node_modules/eslint/lib/util/node-event-generator.js:303:14)
    at CodePathAnalyzer.leaveNode (/home/ehmicky/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:654:23)
    at nodeQueue.forEach.traversalInfo (/home/ehmicky/node_modules/eslint/lib/linter.js:770:32)

The current directory contains the following files:

dir/a.js:

import { test } from './b.js'

dir/b.js:

export const test = true

.eslintrc.json:

{
  "parserOptions": {
    "ecmaVersion": 2019,
    "sourceType": "module"
  },
  "plugins": ["import"],
  "rules": {
    "import/no-unused-modules": [
      2,
      {
        "ignoreExports": ["dir/"],
        "unusedExports": true,
        "missingExports": true
      }
    ]
  }
}

package.json (and node_modules):

{
  "name": "unused-modules-bug",
  "version": "1.0.0",
  "dependencies": {},
  "devDependencies": {
    "eslint": "^6.0.0-alpha.0",
    "eslint-plugin-import": "^2.17.1"
  }
}

Thanks for your help!

@ehmicky ehmicky changed the title ESLint crashes with import/no-unused-modules and ignoreExports option [BUG] ESLint crashes with import/no-unused-modules and ignoreExports option Apr 14, 2019
@ljharb
Copy link
Member

ljharb commented Apr 15, 2019

hm, is export test = true even valid JS without a const/let/var keyword?

@ehmicky
Copy link
Author

ehmicky commented Apr 15, 2019

Oops :) no it's not. I fixed the example. I tried it again and the bug is still reproducible.

(Bug originally happened in a big repository, I tried to reduce it to a minimally reproducible example)

@ljharb
Copy link
Member

ljharb commented Apr 15, 2019

Does this happen in eslint 5, or only in eslint 6 alpha?

@ehmicky
Copy link
Author

ehmicky commented Apr 15, 2019

It still happens with eslint 5.16.0.

Would you like me to create a demo repository?

@ljharb
Copy link
Member

ljharb commented Apr 15, 2019

Yes, that'd be great, thanks. We already have some test cases for this that seem to be passing, so a repro would be great.

@ehmicky
Copy link
Author

ehmicky commented Apr 15, 2019

Yes, absolutely. I will do it tomorrow (I am off my laptop for the evening).

@rfermann
Copy link
Contributor

rfermann commented Apr 15, 2019

No need to create a repository. Your provided source is sufficient to reproduce the issue.

The crash happens when dir/b.js gets linted. As this file is being ignored, no export list has been built up for the file. The problem is, that the rule still tries to read the export list for this file instead of ignoring the file.

#1331 should fix this issue.

@ehmicky
Copy link
Author

ehmicky commented Apr 16, 2019

I tried it and it works. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants