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 ignores extension overrides if ignorePackages is set in object options #1248

Closed
le0nik opened this issue Dec 19, 2018 · 4 comments

Comments

@le0nik
Copy link
Contributor

le0nik commented Dec 19, 2018

node: v10.14.1
eslint: v5.10.0
eslint-plugin-import: v2.14.0

.eslintrc.js

module.exports = {
  plugins: ['import'],
  rules: {
    'import/extensions': ['error', 'always', {
      ignorePackages: true,
      js: 'never',
    }]
  }
}

./src/index.js

import app from './app';

Running eslint results in an error:

/Volumes/Projects/project/src/index.js
1:22  error  Missing file extension "js" for "./app"  import/extensions

The problem seems to be here https://github.com/benmosher/eslint-plugin-import/blob/1cd82eb27df85768fbd076e4ff6b7f36d6f652ce/src/rules/extensions.js#L36-L45

Plugin expects extensions overrides to be specified inside pattern property inside the options object if ignorePackages property is also specified. It's not documented here though.

So this configuration works correctly:

{
  rules: {
    'import/extensions': ['error', 'always', {
      ignorePackages: true,
      pattern: { // wrap extensions in the `pattern` object
        js: 'never',
      }
    }]
  }
}

Either documentation is lacking or pattern property should not be expected in options.

@ljharb
Copy link
Member

ljharb commented Jan 12, 2019

Ths doesn’t seem resolved yet?

@ljharb ljharb reopened this Jan 12, 2019
@ivo-stefchev
Copy link
Contributor

ivo-stefchev commented Aug 5, 2019

Oh, how I love explicit configs.
So the reason why this doesn't work:

module.exports = {
  plugins: ['import'],
  rules: {
    'import/extensions': ['error', 'always', {
      ignorePackages: true,
      js: 'never',
    }]
  }
}

is because in order to apply the js part - you need to have ingnorePackages to be undefined. So basically if ignorePackages is present in the object - it disables all extension specific options. For me at least this makes very little sense

@ivo-stefchev
Copy link
Contributor

Also this defaultConfig is enum of three possible values.

"import/extensions": [<severity>, "never" | "always" | "ignorePackages"]

ignorePackages doesn't do anything when you set it, hence I propose to be removed from the enumValues and left only as boolean property part of the object.

@ljharb
Copy link
Member

ljharb commented Aug 6, 2019

Seems like a good PR.

@ljharb ljharb closed this as completed in b511da2 Jan 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants