import-js / eslint-plugin-import

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

Autofix for "extensions" rule #1003

Open silvenon opened 6 years ago

silvenon commented 6 years ago

I would like to work on autofixing the extensions rule, would you be open for that? Removing the extension is not a problem, but adding one is tricky, because we can't know whether a should be a.js or a/index.js, right? Should the autofix only work one way?

ljharb commented 6 years ago

You'd have to check the filesystem, for one. However, for the index case, a probably should remain as a because it doesn't point to a file, it points to a directory (the index.js is implicit).

silvenon commented 6 years ago

Thanks! If the import path is unresolved, should I always treat it as valid as far as extensions rule is concerned? Or should I autofix ./foo.js to ./foo, but not the other way around?

I'm asking because I can't know whether ./foo refers to ./foo.js or ./foo/index.js as it's unresolved, that's why I can only autofix ./foo.js to ./foo (in case the option is never).

Or is it best to ignore the extensions rule if it's unresolved?

ljharb commented 6 years ago

I think if a path is unresolved, the extensions rule should ignore it, because there's nothing safe for it to do there.

pkerschbaum commented 1 month ago

duplicate of #1749?

silvenon commented 1 month ago

Actually, the reverse is true, but let's close this one because I'm no longer up for working on this, I forgot about offering to do it, sorry!