From d1b2affd2c140fefb318af5b411c65c40aae8afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 21 Dec 2023 14:15:37 +0100 Subject: [PATCH] ci: Add lint rule `no-dynamic-import-template` (no-changelog) (#8089) Follow-up to: https://github.com/n8n-io/n8n/pull/8086 `tsc-alias` as of 1.8.7 is unable to resolve template strings in dynamic imports. Since the module name mapper in Jest is able to, this issue is hard to detect, hence the new lint rule `no-dynamic-import-template`. This is for now specific to `@/` in the `cli` package - we can generalize later if needed. Ideally we should contribute a fix upstream when we have more time. Capture 2023-12-19 at 12 39 55@2x --- packages/@n8n_io/eslint-config/local-rules.js | 26 +++++++++++++++++++ packages/cli/.eslintrc.js | 2 ++ 2 files changed, 28 insertions(+) diff --git a/packages/@n8n_io/eslint-config/local-rules.js b/packages/@n8n_io/eslint-config/local-rules.js index 16e405a602d06..0d3ff867b3cff 100644 --- a/packages/@n8n_io/eslint-config/local-rules.js +++ b/packages/@n8n_io/eslint-config/local-rules.js @@ -396,6 +396,32 @@ module.exports = { }; }, }, + + 'no-dynamic-import-template': { + meta: { + type: 'error', + docs: { + description: + 'Disallow non-relative imports in template string argument to `await import()`, because `tsc-alias` as of 1.8.7 is unable to resolve aliased paths in this scenario.', + recommended: true, + }, + }, + create: function (context) { + return { + 'AwaitExpression > ImportExpression TemplateLiteral'(node) { + const templateValue = node.quasis[0].value.cooked; + + if (!templateValue?.startsWith('@/')) return; + + context.report({ + node, + message: + 'Use relative imports in template string argument to `await import()`, because `tsc-alias` as of 1.8.7 is unable to resolve aliased paths in this scenario.', + }); + }, + }; + }, + }, }; const isJsonParseCall = (node) => diff --git a/packages/cli/.eslintrc.js b/packages/cli/.eslintrc.js index 75676e3a4bc95..1840061479716 100644 --- a/packages/cli/.eslintrc.js +++ b/packages/cli/.eslintrc.js @@ -19,6 +19,8 @@ module.exports = { ], rules: { + 'n8n-local-rules/no-dynamic-import-template': 'error', + // TODO: Remove this 'import/no-cycle': 'warn', 'import/order': 'off',