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

"import/extensions": ignorePackages value does not inforce the use of extensions. #1083

Closed
fthebaud opened this issue Apr 16, 2018 · 9 comments

Comments

@fthebaud
Copy link

fthebaud commented Apr 16, 2018

I'm using eslint 4.19.1 and eslint-plugin-import 2.11.0 with the following configuration:

settings: {
    react: {
      version: "16.3.0"
    },
    'import/extensions': ['.js', '.jsx'],
    'import/resolver': {
      webpack : {
        config: path.join(__dirname, '/config/webpack.config.dev.js')
      }
    },
  },
'import/extensions': ['warn', 'ignorePackages'],

The plugin does not raise any warning when I import files without extensions.

To reproduce the issue you can clone the project below and look for the file TestImportWithWarnings.jsx. https://github.com/fthebaud/react-boilerplate

@fthebaud
Copy link
Author

@ljharb I tested the following configurations:

'import/extensions': ['warn', 'always']:
I get warnings for missing extensions, but even on import React from 'react'; (This is the reason I want "ignorePackages")

'import/extensions': ['warn', 'always', 'ignorePackages']:
I don't get any warnings any more.

'import/extensions': ['warn', 'never']:
I get warnings when using .js and .jsx extensions, but not for .scss extensions.

'import/extensions': ['warn', 'never', 'ignorePackages']:
I don't get any warnings any more.

@ljharb
Copy link
Member

ljharb commented Apr 20, 2018

@fthebaud .scss extensions are entirely nonstandard so you'd always have to configure that yourself in the root plugin settings.

It sounds like you're saying that ignorePackages ignores all warnings on both always and never settings. If so, that's a big bug and something we need to fix ASAP, or else revert.

cc @collinsauve @millerized / #827

@collinsauve
Copy link
Contributor

collinsauve commented Apr 23, 2018

@fthebaud I downloaded that repo. I believe this is just a confusion in how the options for import/extensions work. The documentation here is either missing some instructions or might just be plain incorrect.

In your repo, these options will enforce that all imports are done with extensions except package imports. I believe this is what you are looking for?

"import/extensions": [
    "warn",
    "always",
    {
      "ignorePackages": true
    }
], 

@ljharb your comment on the PR is probably the best explanation out there as to how these options currently work.

@fthebaud
Copy link
Author

fthebaud commented Apr 23, 2018

@collinsauve

In your repo, these options will enforce that all imports are done with extensions except package imports. I believe this is what you are looking for?

Yes, this is what I'm looking for.

I tried the suggested configuration: 'import/extensions': ['warn', 'always', { 'ignorePackages': true }], but it's not working and I get an error:

[Error - 7:18:12 PM] /home/fabien/dev/code/perso/react-boilerplate/.eslintrc.js: Configuration for rule "import/extensions" is invalid: Value "always,[object Object]" should NOT have more than 1 items. Value "always,[object Object]" should NOT have more than 1 items. Value "true" should be equal to one of the allowed values. Value "always,[object Object]" should match some schema in anyOf

@millerized
Copy link
Contributor

millerized commented Apr 23, 2018

I tried the suggested configuration: 'import/extensions': ['warn', 'always', { 'ignorePackages': true }], but it's not working and I get an error:

@fthebaud: That error looks like an old version of eslint-plugin-import is being loaded. Perhaps trying blowing away node_modules and re-installing?

I use ['error', 'always', { 'ignorePackages': true }] daily and it is working great. I'll try out your repo once I get home later and see if I can reproduce on my end.

@ljharb
Copy link
Member

ljharb commented Apr 23, 2018

@millerized if the schema allows for an invalid set of options, then we should tighten the schema to error out on that.

@fthebaud
Copy link
Author

@millerized
Indeed, I had an old version (2.8.0) in my node_modules, I thought I had already replaced it with version 2.11.0. My bad...
Now it's working perfectly with @collinsauve configuration. I suggest making it clear in the documentation the minimum version required for certain rules/configuration.

Thank you all for your help!

@ljharb
Copy link
Member

ljharb commented Apr 23, 2018

@fthebaud in general you should be looking at the docs for the version you're on - for v2.8, it'd be https://github.com/benmosher/eslint-plugin-import/tree/v2.8.0/docs/rules

@fthebaud
Copy link
Author

@ljharb Thanks, I'll be more careful in the future!

@ljharb ljharb closed this as completed Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants