fix
Some checks failed
Deploy / deploy (build, debian, 22, /root/OJDeploy/data/clientnext) (push) Has been cancelled
Deploy / deploy (build:staging, school, 8822, /root/OJ/data/dist) (push) Has been cancelled

This commit is contained in:
2026-05-25 23:10:07 -06:00
parent f970bb955d
commit e8bc91bd59

View File

@@ -103,28 +103,45 @@ const NODE_TARGET_LABELS: Record<string, string> = {
class_definition: "类定义", class_definition: "类定义",
} }
type AstRule = { engine: string; target?: string; min?: number; max?: number; message: string } type AstRule = {
engine: string
target?: string
label?: string
exact?: number
min?: number
max?: number
message: string
}
function ruleDescription(rule: AstRule): string { function ruleDescription(rule: AstRule): string {
if (rule.message) return rule.message
const target = rule.target || "" const target = rule.target || ""
const targetLabel = NODE_TARGET_LABELS[target] || target const targetLabel = rule.label || NODE_TARGET_LABELS[target] || target
const range = (min?: number, max?: number) => { const countDesc = () => {
if (min !== undefined && max !== undefined) return `${min}${max}` if (rule.exact !== undefined) return `出现 ${rule.exact}`
if (min !== undefined) return `至少 ${min}` if (rule.min !== undefined && rule.max !== undefined) return `出现 ${rule.min}${rule.max}`
if (max !== undefined) return ` ${max}` if (rule.min !== undefined) return `少出现 ${rule.min}`
if (rule.max !== undefined) return `至多出现 ${rule.max}`
return ""
}
const callDesc = () => {
if (rule.exact !== undefined) return `调用 ${rule.exact}`
if (rule.min !== undefined && rule.max !== undefined) return `调用 ${rule.min}${rule.max}`
if (rule.min !== undefined) return `至少调用 ${rule.min}`
if (rule.max !== undefined) return `至多调用 ${rule.max}`
return "" return ""
} }
switch (rule.engine) { switch (rule.engine) {
case "must_exist_node": return `必须使用 ${targetLabel}` case "must_exist_node": return `必须使用 ${targetLabel}`
case "must_not_exist_node": return `不能使用 ${targetLabel}` case "must_not_exist_node": return `不能使用 ${targetLabel}`
case "count_node": return `${targetLabel} 出现次数 ${range(rule.min, rule.max)}` case "count_node": return `${targetLabel} ${countDesc()}`
case "must_call_function": return `必须调用函数 ${target}` case "must_call_function": return `必须调用 ${target}()`
case "must_not_call_function": return `不能调用函数 ${target}` case "must_not_call_function": return `不能调用 ${target}()`
case "count_function_call": return `函数 ${target} 调用次数 ${range(rule.min, rule.max)}` case "count_function_call": return `${target}() ${callDesc()}`
case "must_call_method": return `必须调用方法 ${target}` case "must_call_method": return `必须调用 .${target}()`
case "must_not_call_method": return `不能调用方法 ${target}` case "must_not_call_method": return `不能调用 .${target}()`
case "must_use_operator": return `必须使用运算符 ${target}` case "must_use_operator": return `必须使用 ${target} 运算符`
default: return rule.message || rule.engine default: return rule.engine
} }
} }