import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.57k stars 1.57k forks source link

import/extensions false positive when node_modules are not present #1693

Open soullivaneuh opened 4 years ago

soullivaneuh commented 4 years ago

With the following import:

import 'moment/locale/fr';

I have the following error when node_modules is not present:

error  Missing file extension for "moment/locale/fr"             import/extensions

Not that I use eslint on a generic tools to be run accros project without repeting configuration.

The import/no-unresolved is automatically disable if node_modules is not present: https://gitlab.com/nexylan/pretty/blob/9488bf414bf6394d7d12ccfc4071d674622427d2/tools/eslint/.eslintrc.js#L46-49

But I don't import/extensions should be on error. BTW, I don't have any warning for other imports like this:

import VueMoment from 'vue-moment';
import VueRouter from 'vue-router';
import Vuelidate from 'vuelidate';
import axios from 'axios';
import moment from 'moment';

I'm using v2.20.0, but I don't think there is any fix about this extension according to the changelog.

soullivaneuh commented 4 years ago

BTW, still without node_module, for some imports like this:

import palette from 'google-palette/palette.js';

I do have this correct error:

error  Unexpected use of file extension "js" for "google-palette/palette.js"  import/extensions

EDIT: If I remove the extension, I go eslint is still yelling that I should add one.

ljharb commented 4 years ago

google-palette/palette.js or google-palette/palette are both valid paths depending on your extensions config.

Similarly, moment/locale/fr or moment/locale/fr.js are both valid.

All of those are asking for a specific file inside a package. Imports from a package directly - like vue-moment - are not asking for a file, they're asking for a package, so there'd never be an extension there.

Additionally, without node_modules present (as it should be present for any development or linting on the project anyways), there's no way for us to know if moment/locale/fr is a fr.js file, or an fr/index.js file, or an fr dir with a package.json and a "main" - so it's reasonable to have different behavior when you've failed to run npm install.