runLint

tcmts.cli.run.runLint · #o4wnnva3 · term · runs on the server

uses tcmts.cli.main.execute, which uses tcmts.cli.help.usageError, which uses tcmts.cli.help.usageOf, which uses tcmts.cli.style.bold, which uses node:util

Runs tcm lint.

import { routeLint } from "#codebase/tcmts/cli/commands";
import { lintDefinitions } from "#codebase/tcmts/cli/lint";
import { execute, printIssue } from "#codebase/tcmts/cli/main";
import type { Context } from "#codebase/tcmts/cli/run";
import { bold, dim, green, red } from "#codebase/tcmts/cli/style";
import { shortHash } from "#codebase/tcmts/core/hash";
import { parse } from "@bomb.sh/router";

export function runLint({ cb, cmd, rest }: Context): number {
  const { model } = execute(cmd, parse(routeLint(), { argv: rest }));
  const ns = model.namespace ?? "";
  const targets = cb.store
    .names()
    .filter((n) => n.kind !== "type" && (!ns || n.path === ns || n.path.startsWith(ns + ".")));
  const results = lintDefinitions(cb, targets, model.fresh);
  let warnings = 0;
  let errors = 0;
  for (const r of results) {
    if (!r.issues.length) continue;
    console.log(`${bold(r.path)} ${dim(shortHash(r.hash))}`);
    for (const i of r.issues) {
      printIssue(r.text, i);
      if (i.severity === "error") errors++;
      else warnings++;
    }
  }
  const cached = results.filter((r) => r.cached).length;
  console.log(
    `${errors ? red(`${errors} error(s)`) : green("no errors")}, ${warnings} warning(s) in ${results.length} definition(s)${cached ? dim(` (${cached} cached)`) : ""}`,
  );
  return errors ? 1 : 0;
}

uses

used by