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] no-unused-modules falls over when no src is provided #1334

Closed
himynameisdave opened this issue Apr 16, 2019 · 3 comments
Closed

[bug] no-unused-modules falls over when no src is provided #1334

himynameisdave opened this issue Apr 16, 2019 · 3 comments

Comments

@himynameisdave
Copy link
Contributor

If no src option is passed to import/no-unused-modules it falls over with the following error:

TypeError: Error while loading rule 'import/no-unused-modules': Cannot read property 'src' of undefined
Occurred while linting /root/static/js/apps/account/components/account-header/account-header-loadable.jsx
    at Object.create (/root/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:289:35)
    at createRuleListeners (/root/node_modules/eslint/lib/linter.js:578:21)
    at Object.keys.forEach.ruleId (/root/node_modules/eslint/lib/linter.js:732:31)
    at Array.forEach (<anonymous>)
    at runRules (/root/node_modules/eslint/lib/linter.js:690:34)
    at Linter._verifyWithoutProcessors (/root/node_modules/eslint/lib/linter.js:899:31)
    at preprocess.map.textBlock (/root/node_modules/eslint/lib/linter.js:955:35)
    at Array.map (<anonymous>)
    at Linter.verify (/root/node_modules/eslint/lib/linter.js:954:42)
    at Linter.verifyAndFix (/root/node_modules/eslint/lib/linter.js:1047:29)
error Command failed with exit code 2.

The documentation claims it defaults to process.cwd() which would be fine, but it still seems to provide that error, implying that it's maybe not being set correctly? Seems to originate from around here in the source.

Here are my versions:

eslint@5.16.0
eslint-plugin-import@2.17.1

$ node -v
> v10.15.3

I wish this rule would just use whatever dir/glob is being used from the command being run. So for us it's something like this:

eslint static/js/ --ext .jsx,.js

...where I would expect this rule to just pick up static/js/ instead of me manually having to set that in the rule config.


I am happy to help fix this and would just need to be pointed in the right direction! 👍

@himynameisdave
Copy link
Contributor Author

himynameisdave commented Apr 16, 2019

Fixed by 3512563.

I would still prefer that it looks at the directory provided by running the command before falling back to process.cwd(), but that can be addressed later. Thanks for fixing @Kiwka!

Hope we can cut a new version soon, but until then I don't mind supplying the src explicitly.

@ljharb
Copy link
Member

ljharb commented Apr 16, 2019

Released in v2.17.2.

@himynameisdave
Copy link
Contributor Author

Thanks @ljharb!

giphub

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

No branches or pull requests

2 participants