fix(editor): curb item method linting in single-item mode in CodeNodeEditor linter (#4455)

🐛 Curb item method linting
This commit is contained in:
Iván Ovejero
2022-10-27 12:18:02 +02:00
committed by GitHub
parent f29f812b28
commit b226aed9bb
2 changed files with 9 additions and 6 deletions

View File

@@ -215,22 +215,25 @@ export const linterExtension = (Vue as CodeNodeEditorMixin).extend({
const isUnavailableMethodinEachItem = (node: Node) =>
node.type === 'MemberExpression' &&
node.computed === false &&
node.object.type === 'Identifier' &&
node.object.name === '$input' &&
node.property.type === 'Identifier' &&
['first', 'last', 'all', 'itemMatching'].includes(node.property.name);
walk<TargetNode>(ast, isUnavailableMethodinEachItem).forEach((node) => {
const [start, end] = this.getRange(node.property);
const message = [
`\`.${node.property.name}()\``,
this.$locale.baseText('codeNodeEditor.linter.eachItem.unavailableMethod'),
].join(' ');
const method = this.getText(node.property);
if (!method) return;
lintings.push({
from: start,
to: end,
severity: DEFAULT_LINTER_SEVERITY,
message,
message: this.$locale.baseText('codeNodeEditor.linter.eachItem.unavailableMethod', {
interpolate: { method },
}),
});
});
}

View File

@@ -237,7 +237,7 @@
"codeNodeEditor.linter.eachItem.emptyReturn": "Code doesn't return an object. Please return an object representing the output item",
"codeNodeEditor.linter.eachItem.legacyItemAccess": "`item` is not defined. Did you mean `$input.item.json`?",
"codeNodeEditor.linter.eachItem.returnArray": "Code doesn't return an object. Array found instead. Please return an object representing the output item",
"codeNodeEditor.linter.eachItem.unavailableMethod": "is only available in the 'Run Once for All Items' mode.",
"codeNodeEditor.linter.eachItem.unavailableMethod": "Method `$input.{method}()` is only available in the 'Run Once for All Items' mode.",
"codeNodeEditor.linter.bothModes.syntaxError": "Syntax error",
"collectionParameter.choose": "Choose...",
"collectionParameter.noProperties": "No properties",