Skip to content

Commit

Permalink
Reduce argument count severity & improve message
Browse files Browse the repository at this point in the history
  • Loading branch information
valtzu committed Jan 12, 2025
1 parent 866030f commit 61835a7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* **BC BREAK:** Separate files are no longer included in the release (due to using `cm-buildhelper`)
* Tests are now in TypeScript too
* Autocomplete is now less aggressive
* Severity of "too many arguments" linter error was lowered from error -> warning

0.8
---
Expand Down
5 changes: 3 additions & 2 deletions src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const expressionLanguageLinterSource = (state: EditorState) => {

return;
case Arguments:
const args = resolveFunctionDefinition(node.node.prevSibling, state, config)?.args;
const fn = resolveFunctionDefinition(node.node.prevSibling, state, config);
const args = fn?.args;
if (!args) {
return;
}
Expand All @@ -44,7 +45,7 @@ export const expressionLanguageLinterSource = (state: EditorState) => {
}

if (i > args.length - 1) {
diagnostics.push({ from: n.from, to: n.to, severity: 'error', message: `Unexpected argument` });
diagnostics.push({ from: n.from, to: n.to, severity: 'warning', message: `Unexpected argument – <code>${fn.name}</code> takes ${args.length} argument${args.length == 1 ? '' : 's'}` });
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion test/test-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("Expression language linting", () => {
ist(diagnostics.length, 1);
ist(diagnostics[0].from, 18);
ist(diagnostics[0].to, 19);
ist(diagnostics[0].message, "Unexpected argument");
ist(diagnostics[0].message, "Unexpected argument – <code>smash_my_head</code> takes 1 argument");
});

it("complains about wrong argument type using constant", () => {
Expand Down

0 comments on commit 61835a7

Please sign in to comment.