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 src option #1338

Closed
ehmicky opened this issue Apr 21, 2019 · 12 comments · Fixed by #1347
Closed

[BUG] ESLint crashes with import/no-unused-modules and src option #1338

ehmicky opened this issue Apr 21, 2019 · 12 comments · Fixed by #1347

Comments

@ehmicky
Copy link

ehmicky commented Apr 21, 2019

This issue is probably related to #1323. It is slightly different though. It's also using the latest version of eslint-plugin-import, including the fix of #1323.

ESLint crashes with the following error:

$ eslint .
TypeError: Cannot read property 'get' of undefined
Occurred while linting /home/ehmicky/no-unused-modules-bug/file.js:1
    at checkUsage (/home/ehmicky/no-unused-modules-bug/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:339:33)
    at ExportNamedDeclaration.node.declaration.declarations.forEach.declaration (/home/ehmicky/no-unused-modules-bug/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:732:15)
    at Array.forEach (<anonymous>)
    at ExportNamedDeclaration (/home/ehmicky/no-unused-modules-bug/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:731:43)
    at listeners.(anonymous function).forEach.listener (/home/ehmicky/no-unused-modules-bug/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/home/ehmicky/no-unused-modules-bug/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/ehmicky/no-unused-modules-bug/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/home/ehmicky/no-unused-modules-bug/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (/home/ehmicky/no-unused-modules-bug/node_modules/eslint/lib/util/node-event-generator.js:294:14)

The current directory contains the following files:

src/main.js:

export const main = true

file.js:

export const test = true

.eslintrc.json:

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

package.json:

{
  "name": "no-unused-modules-bug",
  "version": "1.0.0",
  "dependencies": {},
  "devDependencies": {
    "eslint": "^5.16.0",
    "eslint-plugin-import": "^2.17.2"
  }
}
@ljharb
Copy link
Member

ljharb commented Apr 21, 2019

cc @rfermann

@rfermann
Copy link
Contributor

@ljharb: thanks for adding. I will tackle this issue after #1339 is solved.

@ehmicky
Copy link
Author

ehmicky commented Apr 21, 2019

Thanks @rfermann!

@ehmicky
Copy link
Author

ehmicky commented Apr 22, 2019

I created a demo repo: https://github.com/ehmicky/no-unused-modules-bug-two

@dfleury
Copy link

dfleury commented Apr 25, 2019

I also got this problem. However I didn't need to specify a src option to crash my process, so the default value is enough to reproduce.
My config is:

import/no-unused-modules:
  - error
  - missingExports: true
    unusedExports: true

@ehmicky
Copy link
Author

ehmicky commented Apr 25, 2019

@dfleury could you share a minimally reproducible example? Including:

  • eslint config
  • files to lint
  • how eslint is spawned (e.g. eslint command)
  • error message produced
  • versions (node, eslint, eslint-plugin-import)

Like this the maintainers can make sure your issue is fixed together with mine (if they have the same cause).

@rfermann
Copy link
Contributor

The problem was, that there was a file to be linted which was outside the specified src folder. These files should be excluded from being linted by this rule.

@dfleury can you verify that you are linting files outside the src folder (process.cwd() by default)?

@ehmicky
Copy link
Author

ehmicky commented Apr 27, 2019

This is fixing my problem, thanks!

@dfleury I think this issue should be closed after this PR is merged. If the PR does not solve your issue, then it means it was a separate problem, i.e. should be a separate issue. What do you think?

@ehmicky
Copy link
Author

ehmicky commented Apr 27, 2019

@ljharb Would it be possible to release a new version? Thanks!

@ljharb
Copy link
Member

ljharb commented Apr 27, 2019

As soon as i have the time :-) it is a weekend, after all.

@ehmicky
Copy link
Author

ehmicky commented Apr 27, 2019

Absolutely, there is no rush! :)
Thanks for the bug fix.

@dfleury
Copy link

dfleury commented Apr 29, 2019

Yes, I can confirm that's working with this fix.
Sorry by not giving a demo in time. I was having some difficulties to reproduce it without knowing the right conditions to do it since my working project is kinda big to track all possibilities in mind.
Once @rfermann told us the problem, I could reproduce it in my WIP demo.
Thanks @rfermann!

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

Successfully merging a pull request may close this issue.

4 participants