mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-12 16:10:30 +02:00
|
Some checks are pending
Build: Benchmark Image / build (push) Waiting to run
CI: Master (Build, Test, Lint) / Build for Github Cache (push) Waiting to run
CI: Master (Build, Test, Lint) / Unit tests (22.x) (push) Waiting to run
CI: Master (Build, Test, Lint) / Unit tests (24.13.1) (push) Waiting to run
CI: Master (Build, Test, Lint) / Unit tests (25.x) (push) Waiting to run
CI: Master (Build, Test, Lint) / Lint (push) Waiting to run
CI: Master (Build, Test, Lint) / Performance (push) Waiting to run
CI: Master (Build, Test, Lint) / Notify Slack on failure (push) Blocked by required conditions
Util: Sync API Docs / sync-public-api (push) Waiting to run
|
||
|---|---|---|
| .. | ||
| src | ||
| eslint.config.mjs | ||
| package.json | ||
| README.md | ||
| tsconfig.build.json | ||
| tsconfig.json | ||
| vitest.config.ts | ||
@n8n/rules-engine
Generic, typed rules engine for static analysis tools.
Usage
import { BaseRule, RuleRunner, toJSON } from '@n8n/rules-engine';
import type { Violation } from '@n8n/rules-engine';
// 1. Define a context type
interface MyContext {
rootDir: string;
files: string[];
}
// 2. Create a rule
class NoTodoRule extends BaseRule<MyContext> {
readonly id = 'no-todo';
readonly name = 'No TODO comments';
readonly description = 'Flag TODO comments in source files';
readonly severity = 'warning' as const;
analyze(context: MyContext): Violation[] {
// Your analysis logic here
return [];
}
}
// 3. Run it
const runner = new RuleRunner<MyContext>();
runner.registerRule(new NoTodoRule());
const report = await runner.run({ rootDir: '/project', files: [] }, '/project');
console.log(toJSON(report, '/project'));
API
BaseRule<TContext>
Abstract base class. Extend it to create rules.
id,name,description,severity— rule metadatafixable— whether the rule supports auto-fixing (default:false)analyze(context)— returnsViolation[]orPromise<Violation[]>fix(context, violations)— returnsFixResult[](override for fixable rules)configure(settings)— apply runtime settings (severity, options)createViolation(file, line, column, message, suggestion?, fixable?, fixData?)— helper
RuleRunner<TContext>
Registry and executor for rules.
registerRule(rule)— add a ruleapplySettings(settingsMap)— configure rules by idenableOnly(ruleIds)— run only specific rulesrun(context, projectRoot, options?)— run all enabled rules, returnsReportrunRule(ruleId, context, projectRoot, options?)— run a single ruleisRuleFixable(ruleId)— check if a rule supports fixinggetRuleDetails()— list all rules with metadata
toJSON(report, rootDir?)
Serialize a report to JSON, optionally converting absolute paths to relative.
Baseline
Incremental adoption — only flag new violations, not pre-existing ones.
generateBaseline(report, rootDir)— snapshot current violationssaveBaseline(baseline, filePath)— write to diskloadBaseline(filePath)— read from diskfilterReportByBaseline(report, baseline, rootDir)— remove known violations
Consumers
@n8n/code-health— monorepo dependency and code quality checks@n8n/playwright-janitor— Playwright test architecture enforcement (planned)