Validate helpers

This commit is contained in:
Adria Navarro 2025-02-14 11:12:57 +01:00
parent ec2d78829e
commit 901df11e8c
3 changed files with 13 additions and 5 deletions

View File

@ -284,17 +284,19 @@
return
}
const config = validations[helperName]
const { arguments: expectedArguments = [] } =
validations[helperName]
const providedParams = node.params
if (providedParams.length !== config.arguments.length) {
if (providedParams.length !== expectedArguments.length) {
diagnostics.push({
from,
to,
severity: "error",
message: `Helper "${helperName}" expects ${
config.arguments.length
} parameters (${config.arguments.join(", ")}), but got ${
expectedArguments.length
} parameters (${expectedArguments.join(", ")}), but got ${
providedParams.length
}.`,
})

View File

@ -110,6 +110,12 @@
}
return validations
}, {}),
...helperOptions.reduce<CodeValidator>((validations, option) => {
validations[option.label] = {
arguments: option.args,
}
return validations
}, {}),
}
$: {

View File

@ -12,6 +12,6 @@ export interface BindingCompletionOption extends Completion {
export type CodeValidator = Record<
string,
{
arguments: any[]
arguments?: any[]
}
>