mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(editor): Curb arg linting for $input.first()
and $input.last()
(#4526)
🐛 Curb arg linting
This commit is contained in:
parent
39d4bb2639
commit
0edd4bcc87
|
@ -267,34 +267,38 @@ export const linterExtension = (Vue as CodeNodeEditorMixin).extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lint for `.first()` or `.last()` called with argument in `runOnceForAllItems` mode
|
* Lint for `$input.first()` or `$input.last()` called with argument in `runOnceForAllItems` mode
|
||||||
*
|
*
|
||||||
* $input.itemMatching()
|
* $input.first(arg) -> $input.first()
|
||||||
|
* $input.last(arg) -> $input.last()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (this.mode === 'runOnceForAllItems') {
|
if (this.mode === 'runOnceForAllItems') {
|
||||||
type TargetNode = RangeNode & {
|
type TargetNode = RangeNode & {
|
||||||
callee: RangeNode & { property: { name: string } & RangeNode };
|
callee: { property: { name: string } & RangeNode };
|
||||||
};
|
};
|
||||||
|
|
||||||
const isItemMatchingCallWithoutArg = (node: Node) =>
|
const inputFirstOrLastCalledWithArg = (node: Node) =>
|
||||||
node.type === 'CallExpression' &&
|
node.type === 'CallExpression' &&
|
||||||
node.callee.type === 'MemberExpression' &&
|
node.callee.type === 'MemberExpression' &&
|
||||||
|
node.callee.computed === false &&
|
||||||
|
node.callee.object.type === 'Identifier' &&
|
||||||
|
node.callee.object.name === '$input' &&
|
||||||
node.callee.property.type === 'Identifier' &&
|
node.callee.property.type === 'Identifier' &&
|
||||||
['first', 'last'].includes(node.callee.property.name) &&
|
['first', 'last'].includes(node.callee.property.name)
|
||||||
node.arguments.length !== 0;
|
&& node.arguments.length !== 0;
|
||||||
|
|
||||||
walk<TargetNode>(ast, isItemMatchingCallWithoutArg).forEach((node) => {
|
walk<TargetNode>(ast, inputFirstOrLastCalledWithArg).forEach((node) => {
|
||||||
const [start, end] = this.getRange(node.callee.property);
|
const [start, end] = this.getRange(node.callee.property);
|
||||||
|
|
||||||
const message = [
|
const message = [
|
||||||
`\`.${node.callee.property.name}()\``,
|
`\`$input.${node.callee.property.name}()\``,
|
||||||
this.$locale.baseText('codeNodeEditor.linter.allItems.firstOrLastCalledWithArg'),
|
this.$locale.baseText('codeNodeEditor.linter.allItems.firstOrLastCalledWithArg'),
|
||||||
].join(' ');
|
].join(' ');
|
||||||
|
|
||||||
lintings.push({
|
lintings.push({
|
||||||
from: start,
|
from: start,
|
||||||
to: end + '()'.length,
|
to: end,
|
||||||
severity: DEFAULT_LINTER_SEVERITY,
|
severity: DEFAULT_LINTER_SEVERITY,
|
||||||
message,
|
message,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue