cli-lint-admission.mjs 956 B

123456789101112131415161718192021222324
  1. import { posix } from "node:path";
  2. /** 当前各包都是直接 oxlint;未知脚本必须显式接入,不能被枚举器悄悄漏过。 */
  3. export function parseLintCommand(command) {
  4. if (!/^oxlint(?: [\w./*-]+)*$/u.test(command) || /(?:--format| -f)(?: |$)/u.test(command))
  5. throw new Error(`不支持的 CLI lint 命令:${command}`);
  6. return command.split(" ").slice(1);
  7. }
  8. export function classifyLintDiagnostics(diagnostics, { relativeDirectory, pristine }) {
  9. const accepted = [],
  10. errors = [],
  11. warnings = [];
  12. for (const diagnostic of diagnostics) {
  13. const path = posix.normalize(
  14. posix.join(relativeDirectory, diagnostic.filename.replaceAll("\\", "/")),
  15. );
  16. if (diagnostic.severity !== "error") warnings.push(diagnostic);
  17. else if (diagnostic.code === "eslint(max-lines)" && pristine.has(path))
  18. accepted.push(diagnostic);
  19. else errors.push(diagnostic);
  20. }
  21. return { accepted, errors, warnings };
  22. }