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

Lodash modularized libs cause false positive for import/extensions #378

Closed
sindresorhus opened this issue Jun 15, 2016 · 9 comments
Closed

Comments

@sindresorhus
Copy link

sindresorhus commented Jun 15, 2016

Config

'import/extensions': [2, 'never'],

Code

import template from 'lodash.template';

Result

✖   14:22  Unexpected use of file extension "template" for "lodash.template"  import/extensions

Not sure how this should be handled, but I definitely don't want to specify all the Lodash modules as extensions. Ideally, Lodash would have used proper slugged names like lodash-template...

// @jdalton

@jdalton
Copy link

jdalton commented Jun 15, 2016

If you have a rule against extensions you could have a list of what those extensions are (deny list).

@benmosher
Copy link
Member

I think ideally we should resolve the imported file and ensure that its extension is not being used. Directories with dots should be fine.

It won't help in cases where the import can't be resolved, obviously. I think that's a substantial improvement.

@sindresorhus
Copy link
Author

@benmosher 👍

@sindresorhus
Copy link
Author

@jdalton The problem is that my rule is to deny all extensions, so listing them wouldn't work, but @benmosher's proposal sounds like a good solution.

@benmosher
Copy link
Member

Fun fact: the rule already does what I suggested, probably as of 1.8.0. Looks like this PR is pinned to 1.7.0.

Upgrading your import plugin version should fix it?

@sindresorhus
Copy link
Author

@benmosher I used 1.9.0.

@benmosher
Copy link
Member

Weird. Are you using a custom resolver? There was a critical issue with custom resolver loading in 1.9.0, just published the fix via 1.9.1 this morning.

I suspect you aren't, though. Will look deeper into this, there must be a bug with the resolution.

@sindresorhus
Copy link
Author

No custom resolver, but turns out I didn't have the dependency in node_modules...

sindresorhus added a commit to xojs/xo that referenced this issue Jun 16, 2016
I'm explicitly specifying extensions so it won't report when using for example `require('lodash.template')` and the dependency is not resolvable (read not installed). Also people might use Webpack and require files like `.css` and `.png` and those extensions should definitely be included. Read more: import-js/eslint-plugin-import#378
@jdalton
Copy link

jdalton commented Jun 16, 2016

🤘

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

3 participants