fix: harden CLI parsing, MCP startup and release integrity
This commit is contained in:
1 parent
f0902f5f20
commit
103ead0fe5
53 files changed
+3713
-1945
No files matched your search
@@ -1,6 +1,62 @@
|
||||
import type { WorkflowTask } from "../../types.js";
|
||||
import type { ScriptIssue } from "./types.js";
|
||||
import { hasReturnStatement } from "./lint-js.js";
|
||||
|
||||
/** Mask literals/comments without moving offsets used by diagnostics. */
|
||||
function scanMvelCode(code: string, issues: ScriptIssue[]): string {
|
||||
const masked = code.split("");
|
||||
let mode: "code" | "line" | "block" | "'" | '"' = "code";
|
||||
let start = { line: 1, column: 1 };
|
||||
let line = 1;
|
||||
let column = 1;
|
||||
let escaped = false;
|
||||
|
||||
for (let i = 0; i < code.length; i++) {
|
||||
const ch = code[i];
|
||||
const next = code[i + 1];
|
||||
if (mode === "code") {
|
||||
if (ch === "'" || ch === '"') {
|
||||
mode = ch;
|
||||
start = { line, column };
|
||||
masked[i] = " ";
|
||||
} else if (ch === "/" && (next === "/" || next === "*")) {
|
||||
mode = next === "/" ? "line" : "block";
|
||||
start = { line, column };
|
||||
masked[i] = masked[i + 1] = " ";
|
||||
i++;
|
||||
column++;
|
||||
}
|
||||
} else {
|
||||
if (ch !== "\n" && ch !== "\r") masked[i] = " ";
|
||||
if (mode === "line") {
|
||||
if (ch === "\n" || ch === "\r") mode = "code";
|
||||
} else if (mode === "block") {
|
||||
if (ch === "*" && next === "/") {
|
||||
masked[++i] = " ";
|
||||
column++;
|
||||
mode = "code";
|
||||
}
|
||||
} else if (escaped) {
|
||||
escaped = false;
|
||||
} else if (ch === "\\") {
|
||||
escaped = true;
|
||||
} else if (ch === mode) {
|
||||
mode = "code";
|
||||
}
|
||||
}
|
||||
if (ch === "\n") { line++; column = 1; }
|
||||
else column++;
|
||||
}
|
||||
|
||||
if (mode === "block" || mode === "'" || mode === '"') {
|
||||
issues.push({
|
||||
level: "error",
|
||||
...start,
|
||||
rule: mode === "block" ? "unterminated-comment" : "unterminated-string",
|
||||
message: mode === "block" ? "未闭合的块注释" : `未闭合的字符串: ${mode}`,
|
||||
});
|
||||
}
|
||||
return masked.join("");
|
||||
}
|
||||
|
||||
/**
|
||||
* 静态检查 MVEL (code) 括号闭合与上游节点引用有效性
|
||||
@@ -26,7 +82,8 @@ export function lintMvelCode(
|
||||
return { issues, referencedNodes, hasReturn: false };
|
||||
}
|
||||
|
||||
const hasRet = hasReturnStatement(code);
|
||||
const executableCode = scanMvelCode(code, issues);
|
||||
const hasRet = /\breturn\b/.test(executableCode);
|
||||
if (!hasRet) {
|
||||
issues.push({
|
||||
level: "warning",
|
||||
@@ -37,12 +94,12 @@ export function lintMvelCode(
|
||||
|
||||
// 1. 括号与引号对称性平衡检查
|
||||
const stack: Array<{ char: string; line: number }> = [];
|
||||
const lines = code.split(/\r?\n/);
|
||||
const lines = executableCode.split(/\r?\n/);
|
||||
|
||||
for (let l = 0; l < lines.length; l++) {
|
||||
const lineText = lines[l];
|
||||
// 忽略单行注释
|
||||
const cleanLine = lineText.replace(/\/\/.*$/, "");
|
||||
// 忽略单行注释,以及扫描器已屏蔽的字符串与块注释。
|
||||
const cleanLine = lineText;
|
||||
|
||||
for (let c = 0; c < cleanLine.length; c++) {
|
||||
const ch = cleanLine[c];
|
||||
@@ -80,7 +137,7 @@ export function lintMvelCode(
|
||||
const foundRefs = new Set<string>();
|
||||
let match: RegExpExecArray | null;
|
||||
|
||||
while ((match = nodeRefRegex.exec(code)) !== null) {
|
||||
while ((match = nodeRefRegex.exec(executableCode)) !== null) {
|
||||
foundRefs.add(match[1]);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user