fix(editor): Curb direct item access linting (#4591)

🐛 Curb direct item access linting
This commit is contained in:
Iván Ovejero 2022-11-14 11:22:55 +01:00 committed by GitHub
parent ccacd42b37
commit 271cd06a6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -412,14 +412,19 @@ export const linterExtension = (Vue as CodeNodeEditorMixin).extend({
left: { declarations: Array<{ id: { type: string; name: string } }> };
};
const isForOfStatement = (node: Node) =>
const isForOfStatementOverN8nVar = (node: Node) =>
node.type === 'ForOfStatement' &&
node.left.type === 'VariableDeclaration' &&
node.left.declarations.length === 1 &&
node.left.declarations[0].type === 'VariableDeclarator' &&
node.left.declarations[0].id.type === 'Identifier';
node.left.declarations[0].id.type === 'Identifier' &&
node.right.type === 'CallExpression' &&
node.right.callee.type === 'MemberExpression' &&
node.right.callee.computed === false &&
node.right.callee.object.type === 'Identifier' &&
node.right.callee.object.name.startsWith('$'); // n8n var, e.g $input
const found = walk<TargetNode>(ast, isForOfStatement);
const found = walk<TargetNode>(ast, isForOfStatementOverN8nVar);
if (found.length === 1) {
const itemAlias = found[0].left.declarations[0].id.name;