eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

Autofix for "extensions" rule

Open silvenon opened this issue 7 years ago • 5 comments

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?

silvenon avatar Jan 19 '18 21:01 silvenon

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

ljharb avatar Jan 19 '18 23:01 ljharb

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?

silvenon avatar Jan 24 '18 17:01 silvenon

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

ljharb avatar Jan 24 '18 21:01 ljharb

duplicate of #1749?

patricktree avatar May 18 '24 14:05 patricktree

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!

silvenon avatar May 18 '24 14:05 silvenon

I'm closing this one per OPs request, plus overlap with 1749

soryy708 avatar Jan 23 '25 21:01 soryy708