mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 11:49:59 +00:00
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. <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">
This commit is contained in:
@@ -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) =>
|
const isJsonParseCall = (node) =>
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
|
'n8n-local-rules/no-dynamic-import-template': 'error',
|
||||||
|
|
||||||
// TODO: Remove this
|
// TODO: Remove this
|
||||||
'import/no-cycle': 'warn',
|
'import/no-cycle': 'warn',
|
||||||
'import/order': 'off',
|
'import/order': 'off',
|
||||||
|
|||||||
Reference in New Issue
Block a user