IF Commons GitHub

test-rule

A rule of a lint plugin run against code, in a test (commons lint 0001-lint FR-009): the files are written to a new folder and the real linter, bun lint of the pinned Bun, is run over them with the plugin loaded by --plugin and only the rule turned on by --rule, so that a test proves the rule and the way bun lint loads it. Its problems come back from its JSON report, decoded.

The linter is the Bun named by IFC_LINT_BUN (a path to a Bun whose lint runs plugins), else the pinned canary through bun x --no-install bun@<LINT_BUN_VERSION>, which is never fetched here: where it is not installed, linter() says so and the tests that need it are skipped with that reason (bun x bun@<LINT_BUN_VERSION> --version installs it).

import { lintFiles } from "./test-rule.ts";
const problems = await lintFiles({ rule: "no-registry-import", files: { "a.ts": 'import x from "npm:x";\nexport { x };\n' } });
// { kind: "ok", value: [{ file: "a.ts", rule: "no-registry-import", line: 1, column: 1, message: "..." }] }

Spec: 0001-lint FR-009

Source: commons/lint/src/test-rule.ts

4 of 7 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

LINT_BUN_VERSIONconstno test imports it
const LINT_BUN_VERSION: "1.4.4-canary.20261115.1"

The Bun whose lint runs ESLint plugins, until a release has it (FR-028).

PLUGIN_PATHconstno test imports it
const PLUGIN_PATH: string

The plugin of this folder.

Problemtype
type Problem = {
  readonly file: string;
  readonly rule: string;
  readonly line: number;
  readonly column: number;
  readonly message: string;
};

A problem the linter reported: the file (as given), the rule without its prefix, the line and column from 1, and the message.

Imported by 9 tests of the run (1 passed, 0 failed): the library's results

LintRuntype
type LintRun = {
  readonly rule: string;
  readonly options?: unknown;
  readonly files: Readonly<Record<string, string>>;
  readonly plugin?: string;
  /** The plugin's name, the prefix of its rules (`ifc` by default). */
  readonly prefix?: string;
};

A rule to run: its name, its options object, the files (relative paths and their text), and the plugin (this folder's by default).

Imported by 9 tests of the run (1 passed, 0 failed): the library's results

lintCommandfunctionno test imports it
function lintCommand(): readonly string[]

The command that runs bun lint, without lint: IFC_LINT_BUN, or the pinned canary through bun x --no-install.

linterfunction
function linter(): Promise<Result<readonly string[], string>>

The linter's command where it runs and can load a plugin, or why not.

Imported by 9 tests of the run (1 passed, 0 failed): the library's results

lintFilesfunction
function lintFiles(r: LintRun): Promise<Result<readonly Problem[], string>>

The problems one rule of a plugin finds in the files given (0001-lint FR-009), by running bun lint over them in a new folder (its working folder, with a bunfig.toml of an empty [lint]), the rule set to error with its options. Problems of other rules (Bun's own defaults) are left out. An error where the linter fails (exit 2: a rule threw, or the plugin did not load).

Imported by 9 tests of the run (1 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.