From d8c30cf6a84fa4bc7b642bbb789a9739a7594a0c Mon Sep 17 00:00:00 2001 From: Sergey Astapov Date: Fri, 29 Mar 2024 18:16:12 +0000 Subject: [PATCH 1/2] Add ESLint rule to require that relative imports use full extensions Use import ESLint plugin --- files/__addonLocation__/.eslintrc.cjs | 16 +++++++++++++++- files/__addonLocation__/package.json | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/files/__addonLocation__/.eslintrc.cjs b/files/__addonLocation__/.eslintrc.cjs index 53844836..639c4b9b 100644 --- a/files/__addonLocation__/.eslintrc.cjs +++ b/files/__addonLocation__/.eslintrc.cjs @@ -10,7 +10,7 @@ module.exports = { root: __dirname, },<% } %> }, - plugins: ['ember'], + plugins: ['ember', 'import'], extends: [ 'eslint:recommended', 'plugin:ember/recommended', @@ -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: [ diff --git a/files/__addonLocation__/package.json b/files/__addonLocation__/package.json index a81736c0..84f9c8e6 100644 --- a/files/__addonLocation__/package.json +++ b/files/__addonLocation__/package.json @@ -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", From b2dd7947b5dbeb2f60573aa6c38fab0ca9bd1839 Mon Sep 17 00:00:00 2001 From: Sergey Astapov Date: Fri, 29 Mar 2024 18:42:32 +0000 Subject: [PATCH 2/2] Update fixture and snapshots --- .../default/my-addon/src/components/template-import.gjs | 2 +- .../fixtures/default/my-addon/src/components/template-only.js | 3 +++ .../typescript/my-addon/src/components/template-import.gts | 2 +- tests/smoke-tests/--typescript.test.ts | 2 -- 4 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/default/my-addon/src/components/template-only.js diff --git a/tests/fixtures/default/my-addon/src/components/template-import.gjs b/tests/fixtures/default/my-addon/src/components/template-import.gjs index 063a3e6e..04f03636 100644 --- a/tests/fixtures/default/my-addon/src/components/template-import.gjs +++ b/tests/fixtures/default/my-addon/src/components/template-import.gjs @@ -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 { diff --git a/tests/fixtures/default/my-addon/src/components/template-only.js b/tests/fixtures/default/my-addon/src/components/template-only.js new file mode 100644 index 00000000..fa850535 --- /dev/null +++ b/tests/fixtures/default/my-addon/src/components/template-only.js @@ -0,0 +1,3 @@ +import templateOnly from '@ember/component/template-only'; + +export default templateOnly(); diff --git a/tests/fixtures/typescript/my-addon/src/components/template-import.gts b/tests/fixtures/typescript/my-addon/src/components/template-import.gts index 7906ac8e..443f08ec 100644 --- a/tests/fixtures/typescript/my-addon/src/components/template-import.gts +++ b/tests/fixtures/typescript/my-addon/src/components/template-import.gts @@ -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'; diff --git a/tests/smoke-tests/--typescript.test.ts b/tests/smoke-tests/--typescript.test.ts index b49009d2..a808189a 100644 --- a/tests/smoke-tests/--typescript.test.ts +++ b/tests/smoke-tests/--typescript.test.ts @@ -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", ]