Validate body

This commit is contained in:
Adria Navarro 2025-02-14 12:22:49 +01:00
parent bc015eba1a
commit f2e8888c94
5 changed files with 16 additions and 1 deletions

View File

@ -296,9 +296,19 @@
return
}
const { arguments: expectedArguments = [] } =
const { arguments: expectedArguments = [], requiresBlock } =
validations[helperName]
if (requiresBlock && !isBlockStatement(node)) {
diagnostics.push({
from,
to,
severity: "error",
message: `Helper "${helperName}" requires a body.`,
})
return
}
const providedParams = node.params
if (providedParams.length !== expectedArguments.length) {

View File

@ -84,6 +84,7 @@ const helpersToCompletion = (
return {
label: helperName,
args: helper.args,
requiresBlock: helper.requiresBlock,
info: () => buildHelperInfoNode(helper),
type: "helper",
section: helperSection,

View File

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

View File

@ -7,11 +7,13 @@ export type BindingCompletion = (context: CompletionContext) => {
export interface BindingCompletionOption extends Completion {
args?: any[]
requiresBlock?: boolean
}
export type CodeValidator = Record<
string,
{
arguments?: any[]
requiresBlock?: boolean
}
>

View File

@ -2,4 +2,5 @@ export interface Helper {
example: string
description: string
args: any[]
requiresBlock?: boolean
}