143 lines · 5.4 KB
import { z } from "zod";

const MAX_RESULTS = 5000;
const MAX_MESSAGE = 2000;
/** Distinct tool runs per upload; more than this is a flood, not a scan (INT-A11). */
export const MAX_RUNS = 20;
const MAX_RULE_NAME = 200;
const MAX_TOOL_NAME = 100;
const MAX_LINE = 10_000_000;
const MAX_PATH = 1024;
const CRITICAL_SCORE = 9;
const HIGH_SCORE = 7;
const MEDIUM_SCORE = 4;

const message = z.object({ text: z.string().optional(), markdown: z.string().optional() }).loose();
const region = z.object({ startLine: z.number().int().optional(), endLine: z.number().int().optional() }).loose();
const location = z
  .object({
    physicalLocation: z
      .object({
        artifactLocation: z.object({ uri: z.string().optional() }).loose().optional(),
        region: region.optional(),
      })
      .loose()
      .optional(),
  })
  .loose();
const level = z.enum(["error", "warning", "note", "none"]);
const rule = z
  .object({
    id: z.string(),
    name: z.string().optional(),
    shortDescription: message.optional(),
    defaultConfiguration: z.object({ level: level.optional() }).loose().optional(),
    properties: z.record(z.string(), z.unknown()).optional(),
  })
  .loose();
const result = z
  .object({
    ruleId: z.string().optional(),