eslint-plugin-import
eslint-plugin-import copied to clipboard
import/extensions: ignore imports starting with #
Feature Request
It would be nice if it was easy to exclude '#' based imports from the "import/extensions" rule, similar to how it is easy to exclude imports from other packages for this rule.
Background
When an import starts with '#' it is resolved by looking for a matching entry in "imports". These import rules are very similar to the rules applied when you are importing from another package, especially one that specifies "exports" to translate import paths.
As such, it is normal that these kinds of imports may not require a file extension even if relative imports do.
Workaround
You can define an override for imports starting with #, e.g.
'import/extensions': [
'error',
'ignorePackages',
{
pathGroupOverrides: [
{
pattern: '#**',
action: 'ignore',
},
],
},
],
Why it should be ignored? Node doesn't support ignore its extension. And we've already have pattern support to ignore such case.
https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md#rule-details
The proper way to support imports is to require that they exactly match what the “exports” field has in it, but we don’t support “exports” yet, and thus not yet “imports” either.
This could likely be fixed as part of fixing https://github.com/import-js/eslint-plugin-import/issues/3189
If the "imports" subpath mapping is set up to add extensions, then we don't want to put the extension when we import it. However, we can of course just not do things that way and have the extension when we import and modify the extension in the imports mapping.