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 ESLint rule to require that relative imports use full extensions #279

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion files/__addonLocation__/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
root: __dirname,
},<% } %>
},
plugins: ['ember'],
plugins: ['ember', 'import'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
Expand All @@ -32,6 +32,20 @@ module.exports = {
// Add any custom rules here
},
},
// require relative imports use full extensions
{
files: ['src/**/*.{js,ts,gjs,gts}'],
rules: {
'import/extensions': ['error', 'always', { ignorePackages: true }],
},
},
<% } else { %> // require relative imports use full extensions
{
files: ['src/**/*.{js,gjs}'],
rules: {
'import/extensions': ['error', 'always', { ignorePackages: true }],
},
},
<% } %> // node files
{
files: [
Expand Down
1 change: 1 addition & 0 deletions files/__addonLocation__/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-ember": "^11.12.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.4.0",
"eslint-plugin-prettier": "^5.0.1",
"prettier": "^3.1.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Component from '@glimmer/component';
import TemplateOnly from './template-only';
import TemplateOnly from './template-only.js';
import { on } from '@ember/modifier';

export default class TemplateImport extends Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import templateOnly from '@ember/component/template-only';

export default templateOnly();
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Component from '@glimmer/component';
import TemplateOnly from './template-only';
import TemplateOnly from './template-only.ts';
import AnotherGts from './another-gts.gts'; // N.B. relative imports inside a v2 addon should have explicit file extensions (this is consistent with how node treats ES modules)
import { on } from '@ember/modifier';
import { action } from '@ember/object';
Expand Down
2 changes: 0 additions & 2 deletions tests/smoke-tests/--typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
"index.js",
"index.js.map",
"services",
"template-only-B8yJqW69.js",
"template-only-B8yJqW69.js.map",
"template-registry.js",
"template-registry.js.map",
]
Expand Down