Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linter rule to require that relative imports use full extensions #220

Closed
lukemelia opened this issue Oct 23, 2023 · 3 comments · Fixed by #279
Closed

Add linter rule to require that relative imports use full extensions #220

lukemelia opened this issue Oct 23, 2023 · 3 comments · Fixed by #279

Comments

@lukemelia
Copy link
Contributor

The addon build expects relative imports to use full extensions (.ts, .gts, .js, .hbs). This can be easy for an Ember developer to forget since it is not a requirement in ember-cli-built apps. It would be helpful to have a lint rule enabled by default that errors when a relative import is used without an extension.

@lukemelia lukemelia changed the title Add lint step to require that relative imports use full extensions Add linter rule to require that relative imports use full extensions Oct 23, 2023
@simonihmig
Copy link
Collaborator

I have such a rule already in place in a private repo. Also one for enforcing relative imports (instead of self-referencing your package name, which worked in v1 addons). And both are auto-fixable. I should be able to extract and open-source them hopefully soon...

@NullVoxPopuli
Copy link
Collaborator

NullVoxPopuli commented Feb 21, 2024

found it:

{
	files: ['src/**/*.{js,ts,gjs,gts}'],
	rules: {
		'import/extensions': ['error', 'always', { ignorePackages: true }],

	},
},

https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md

anyone want to PR a good eslint-plugin-import setup to the addon-blueprint here?

@SergeAstapov
Copy link
Contributor

SergeAstapov commented Mar 29, 2024

import/extensions from eslint-plugin-import works great with one caveat - it does not support type-only imports.

Here is an issue to track progress import-js/eslint-plugin-import#2530

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants