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

import/extensions should allow for disambiguation between directory and file

Open cuberoot opened this issue 4 years ago • 3 comments

I have a project that uses "import/extensions": "never" however I have hit a case with the new version of the npm module lit. It is common to import like this:

import { customElement, property } from 'lit/decorators.js'

I can't remove the .js because there is also a directory called decorators and that gets imported instead, which causes an error. It would be great if the import/extensions did not complain when you use an extension to disambiguate with another entity that has the same name without the extension.

The tree structure looks like this:

lit
├── CHANGELOG.md
├── LICENSE
├── README.md
├── decorators
│   ├── custom-element.d.ts
│   ├── custom-element.d.ts.map
│   ├── custom-element.js
│   ├── custom-element.js.map
│   ├── event-options.d.ts
│   ├── event-options.d.ts.map
│   ├── event-options.js
│   ├── event-options.js.map
│   ├── ...
├── decorators.d.ts
├── decorators.d.ts.map
├── decorators.js
├── decorators.js.map
├── ...

cuberoot avatar Jun 24 '21 03:06 cuberoot

That does seem reasonable (altho it's super frustrating that a package author would design such an unfortunate file structure). Ideally, they'd move decorators.js to decorators/index.js.

ljharb avatar Jun 24 '21 05:06 ljharb

Agreed. I was surprised by the structure myself.

cuberoot avatar Jun 24 '21 05:06 cuberoot

If you're using https://github.com/import-js/eslint-import-resolver-typescript, there should be no problem with this case

See also some related test cases

https://github.com/import-js/eslint-import-resolver-typescript/tree/master/tests/withJsExtension

Source https://github.com/import-js/eslint-import-resolver-typescript/blob/master/src/index.ts#L276-L304

JounQin avatar Jul 19 '22 21:07 JounQin