testLintWithNothingToSetUp

tcmts.cli.test.e2e.lint.testLintWithNothingToSetUp · #oznrnljc · term

Lint: oxlint with nothing to set up, plugins from what the code uses, findings cached by hash.

import { setUp } from "#codebase/tcmts/cli/test/e2e/lint";
import assert from "node:assert/strict";

export const testLintWithNothingToSetUp = () => {
  const { tcm, write } = setUp();
  // warnings show while saving, and don't stop it
  const added = tcm("add", "ui.tsx");
  assert.match(
    added,
    /3:10 {2}warning {2}Missing `alt` attribute\. jsx-a11y\(alt-text\)/,
    "JSX brings the accessibility rules",
  );
  assert.match(
    added,
    /7:3 {2}warning {2}`debugger` statement is not allowed eslint\(no-debugger\)/,
  );
  assert.match(added, /\+ new {7}ui\.half/);

  const lint = tcm("lint");
  assert.match(
    lint,
    /ui\.Pic #\w+\n {2}2:10 {2}warning {2}Missing `alt` attribute/,
    "positions in the definition as tcm view shows it",
  );
  assert.match(lint, /no errors, 2 warning\(s\) in 2 definition\(s\)$/m);
  assert.match(tcm("lint"), /\(2 cached\)/, "unchanged definitions aren't linted again");
  // a comment that turns a rule off changes the text, not the hash: what's found follows the text
  write(
    "ui.tsx",
    `// tcm: namespace ui\nexport const half = (n: number): number => {\n  // eslint-disable-next-line no-debugger\n  debugger;\n  return n / 2;\n};\n`,
  );
  assert.match(tcm("update", "ui.tsx"), /~ text {6}ui\.half/);
  assert.match(
    tcm("lint"),
    /no errors, 1 warning\(s\) in 2 definition\(s\) \(1 cached\)$/m,
    "linted again, its warning gone",
  );
}

uses