Skip to content

Commit

Permalink
ci: Add lint rule no-dynamic-import-template (no-changelog) (#8089)
Browse files Browse the repository at this point in the history
Follow-up to: #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.

<img width="940" alt="Capture 2023-12-19 at 12 39 55@2x"
src="https://github.com/n8n-io/n8n/assets/44588767/78d4a277-ccff-455c-8610-d1bba39d93f2">
  • Loading branch information
ivov authored Dec 21, 2023
1 parent 01e9a79 commit d1b2aff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/@n8n_io/eslint-config/local-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit d1b2aff

Please sign in to comment.