From 301d3716b21f5532ff88e621e4439d1d375e923f Mon Sep 17 00:00:00 2001 From: Olivier Zalmanski Date: Mon, 4 Sep 2023 15:41:29 +0200 Subject: [PATCH] Update import/extensions rules in typescript config --- config/typescript.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/config/typescript.js b/config/typescript.js index ff7d0795c..197b070e1 100644 --- a/config/typescript.js +++ b/config/typescript.js @@ -7,10 +7,16 @@ // Omit `.d.ts` because 1) TypeScript compilation already confirms that // types are resolved, and 2) it would mask an unresolved // `.ts`/`.tsx`/`.js`/`.jsx` implementation. -const typeScriptExtensions = ['.ts', '.cts', '.mts', '.tsx']; +const typeScriptKeys = ['ts', 'cts', 'mts', 'tsx']; +const typeScriptExtensions = typeScriptKeys.map((key) => `.${key}`); +const typeScriptFiles = typeScriptExtensions.map((ext) => `**/*${ext}`); const allExtensions = [...typeScriptExtensions, '.js', '.jsx']; +const typeScriptRules = Object.fromEntries( + typeScriptKeys.map((key) => [key, 'never']), +); + module.exports = { settings: { 'import/extensions': allExtensions, @@ -31,4 +37,16 @@ module.exports = { // TypeScript compilation already ensures that named imports exist in the referenced module 'import/named': 'off', }, + overrides: [ + { + files: typeScriptFiles, + rules: { + 'import/extensions': [ + 'error', + 'ignorePackages', + typeScriptRules, + ], + }, + }, + ], };