eslint-plugin-import
eslint-plugin-import copied to clipboard
import/extensions should allow for disambiguation between directory and file
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
├── ...
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.
Agreed. I was surprised by the structure myself.
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