Project rules instead of check scripts

Coding agents write a new scripts/check-*.mjs each time a project needs a check that no linter provides. vibator gives those checks one home: a rule is one file in.vibator/, and npx vibator runs them all.

npm install --save-dev vibator
npx vibator init
npx vibator

Requires Node 24 or later, or Bun 1.4.2 or later. init writes a starter rule in .vibator/. With Bun, --bun runs vibator on Bun instead of Node.

.vibator/colors-from-tokens.ts
import { defineRule, vibator } from "vibator";

export default defineRule({
  id: "colors-from-tokens",
  title: "CSS colors come from tokens.css",
  check: () =>
    vibator.text
      .search(
        vibator.project.files.match(["src/**/*.css", "!src/styles/tokens.css"]),
        /#[0-9a-f]{3,8}\b/i,
      )
      .map((hit) => ({
        ...hit,
        message: `Hardcoded color ${hit.text}`,
        fix: "Use a variable from tokens.css",
      })),
});
npx vibator

Running npx vibator reports one finding: src/components/card.css, line 11, column 23, error from the rule colors-from-tokens: Hardcoded color #f97316. 1 error, 0 warnings.

From custom scripts to a rule set

Every check script becomes a rule. Each step below builds on the one before it.

Replace check scripts with rules

A check script writes its own file walk, parsing, output, and exit code. A rule is the check alone, one file in .vibator/. vibator does the rest.

From script to rule
A check scriptA rule
Find filesglobSync and its own excludesproject.files
Read themreadFileSync, regex loopstext.search, ts.parse
Reportconsole.errorOne report format
Failprocess.exit(1)A severity per rule
FixBy hand--write

Read the whole project through one API

A rule reads files, JSON, TypeScript syntax trees, package.json, git, and the shell through vibator. It never imports fs.

It sees every file at once, so it can compare files with each other.

Namespace reference
  • vibator.projectFiles and folders
  • vibator.textLines and search
  • vibator.jsonValues and key paths
  • vibator.tsSyntax trees and types
  • vibator.packagepackage.json manifests
  • vibator.moduleImport resolution
  • vibator.gitStaged and changed files
  • vibator.shellRun a command
  • vibator.globMatch paths
  • vibator.ignoreIgnore markers

Findings that say what to do

Each finding keeps three fields apart: message says what is wrong,expected states the standard, and fix gives the next action.

A person or an agent acts on a finding without reading the rule.

Rule definition
npx vibator --reporter json
{
  "ruleId": "env-example",
  "severity": "error",
  "file": "src/config.ts",
  "line": 2,
  "column": 20,
  "message": "API_KEY is read but not in .env.example",
  "expected": "Every variable the code reads has an entry in .env.example",
  "fix": "Add API_KEY= to .env.example"
}

One report for every rule

Every rule reports in the same format, with the file, line, column, and the code around it.

--reporter json feeds your own tools. --reporter sarif feeds code scanning.

Reporters
npx vibator
src/config.ts:2:20 error env-example  API_KEY is read but not in .env.example
  1 | export const url = process.env.API_URL;
> 2 | export const key = process.env.API_KEY;

1 error(s), 0 warning(s)

Fix what a rule can fix

A rule can implement fix. With --write, vibator runs the check, the fix, and the check again.

The report shows only what the fix left.

Rule definition
  1. checkFinds the problems
  2. fixChanges the files
  3. checkReports what is left

Run it where the work happens

--staged, --changed, and --since scope a run to the files git reports, for a pre-commit hook or a pull request job.

.vibator.json sets a severity per rule. An error fails the run, a warning reports and passes.

Configuration
Scoped runs
npx vibator --staged         # files staged for commit
npx vibator --changed        # uncommitted changes
npx vibator --since main     # changes since a ref
.vibator.json
{
  "rules": {
    "env-example": "error",
    "colors-from-tokens": "warn",
    "no-conflict-markers": "off"
  }
}

Test rules like code

runRule from vibator/testing runs one rule against content you write in the test. It works in any test runner.

Test a rule
colors-from-tokens.test.ts
import { expect, it } from "vitest";
import { runRule } from "vibator/testing";
import rule from "../.vibator/colors-from-tokens.ts";

it("flags a hardcoded color", async () => {
  const findings = await runRule(rule, {
    files: { "src/card.css": "a { color: #fff; }" },
  });
  expect(findings.map((finding) => finding.message)).toEqual([
    "Hardcoded color #fff",
  ]);
});

Let agents write and fix rules

vibator ships three skills for Claude Code and compatible agents.npx vibator skills --install copies them into the project.

An agent then writes a rule instead of a script and fixes what the rules report.

Agent skills
  • writing-vibator-rulesWrites a rule in .vibator/ instead of a check script.
  • fixing-vibator-findingsActs on each finding's message, expected, and fix.
  • configuring-vibatorSets severities, options, and plugins in .vibator.json.

Extend the namespace with plugins

A plugin is a package that adds its own namespace to vibator withdefineNamespace, such as vibator.i18n. Every rule in a project that loads it reads the namespace like the built-in ones, with its types.

A plugin can also ship rules that use its namespace.

Plugins and shared configuration
@acme/vibator-i18n/src/namespace.ts
import { defineNamespace, vibator } from "vibator";

export const i18n = defineNamespace("i18n", {
  file(locale: string) {
    return vibator.project.files.get(
      `${vibator.project.root}/locales/${locale}.json`,
    );
  },
  keys(locale: string): string[] {
    return vibator.json.keys(vibator.json.parse(i18n.file(locale)));
  },
});
.vibator.json
{
  "plugins": ["@acme/vibator-i18n"]
}

Share one config across repositories

A base config sets the plugins and the severities once. Each repository extends it and overrides only what differs.

Plugins add up, and rules merge by id, so the project's severity wins.

extends
@acme/vibator-config/vibator.json
{
  "plugins": ["@acme/vibator-i18n"],
  "rules": { "locales-match": "error" }
}
.vibator.json
{
  "extends": ["@acme/vibator-config/vibator.json"],
  "rules": { "locales-match": "warn" }
}

Read the docs

The guides go from install to your first rule. The reference covers every API and flag.

Get started