For AI agents: the complete documentation index is available at https://gabrielcsapo.github.io/lintrs/llms.txt, the full documentation bundle is available at https://gabrielcsapo.github.io/lintrs/llms-full.txt, and this page is available as Markdown at https://gabrielcsapo.github.io/lintrs/guide/testing-rules.md.

Testing rules

NativeRuleTester (from @lintrs/cli/native) runs RuleTester-style cases through the real lintrs binary, in a temporary project with a tsconfig and an eslint.config.mjs that imports your plugin. Use it with node:test:

import { NativeRuleTester } from "@lintrs/cli/native";
import { test } from "node:test";

const tester = new NativeRuleTester({
  // module specifier of a file default-exporting the nativePlugin() result
  plugin: new URL("./index.mjs", import.meta.url).href,
});

test("value-is-string", () => {
  tester.run("demo/value-is-string", {
    valid: [{ code: "const value = 1;" }],
    invalid: [
      {
        code: 'const value = "s";',
        filename: "case.ts",
        errors: [
          {
            message: "identifier 'value' has type string",
            line: 1,
            column: 7,
            endLine: 1,
            endColumn: 12,
          },
        ],
      },
    ],
  });
});
OptionMeaning
pluginRequired. Module exporting the plugin.
binarylintrs binary. Default: under target/lintrs-native
envExtra environment for the run.
nodeModulesnode_modules directory symlinked into the temp project. Default: lintrs's

Case fields: code, filename, options; invalid cases add errors: { message, line, column, endLine, endColumn } and output (source after fixes).