Eslint-plugin-import: "import/extensions": ignorePackages value does not inforce the use of extensions.

Created on 16 Apr 2018  路  9Comments  路  Source: benmosher/eslint-plugin-import

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

bug help wanted

All 9 comments

@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.

@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

@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.

@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

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.

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

@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!

@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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nkt picture nkt  路  51Comments

steve-taylor picture steve-taylor  路  24Comments

yenbekbay picture yenbekbay  路  44Comments

ljharb picture ljharb  路  29Comments

nevir picture nevir  路  40Comments