From d8c30cf6a84fa4bc7b642bbb789a9739a7594a0c Mon Sep 17 00:00:00 2001 From: Sergey Astapov Date: Fri, 29 Mar 2024 18:16:12 +0000 Subject: [PATCH] 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",