@aurelienbbn/agentlint
Version:
Stateless, deterministic CLI that bridges traditional linters and AI-assisted code review
98 lines (97 loc) • 2.5 kB
JavaScript
import { r as FlagRecord, t as Position } from "./node-yh9mLvnE.mjs";
import { Schema } from "effect";
//#region src/domain/rule.ts
/**
* Rule definition types and the `defineRule` helper.
*
* A rule is a reusable lint check defined by {@link RuleMeta} (what to check)
* and a `createOnce` factory (how to check it). The factory returns a
* {@link Visitors} object whose keys are tree-sitter node types.
*
* @module
* @since 0.1.0
*/
/**
* Static metadata for a rule.
*
* Defined as a `Schema.Struct` so that rule metadata is validated at
* runtime when `defineRule` is called — catches typos, missing fields,
* and wrong types with clear error messages.
*
* @since 0.1.0
* @category models
*/
const RuleMeta = Schema.Struct({
name: Schema.String,
description: Schema.String,
languages: Schema.Array(Schema.String),
instruction: Schema.String,
include: Schema.optional(Schema.Array(Schema.String)),
ignore: Schema.optional(Schema.Array(Schema.String))
});
/**
* Identity function that provides type inference and IDE support for rule definitions.
*
* @example
* ```ts
* import { defineRule } from "agentlint"
*
* export const myRule = defineRule({
* meta: {
* name: "my-rule",
* description: "Checks for something",
* languages: ["ts", "tsx"],
* instruction: "Evaluate whether ..."
* },
* createOnce(context) {
* return {
* comment(node) {
* context.flag({ node, message: "Found comment" })
* }
* }
* }
* })
* ```
*
* @since 0.1.0
* @category constructors
*/
function defineRule(rule) {
Schema.decodeUnknownSync(RuleMeta)(rule.meta);
return rule;
}
//#endregion
//#region src/domain/config.ts
/**
* Configuration types and the `defineConfig` helper.
*
* A config file (`agentlint.config.ts`) default-exports an {@link AgentReviewConfig}
* object that maps rule names to rule definitions and optionally scopes which
* files are scanned.
*
* @module
* @since 0.1.0
*/
/**
* Identity function that provides type inference and IDE support for config files.
*
* @example
* ```ts
* import { defineConfig } from "agentlint"
*
* export default defineConfig({
* include: ["src/**\/*.ts"],
* rules: { "my-rule": myRule }
* })
* ```
*
* @since 0.1.0
* @category constructors
*/
function defineConfig(config) {
for (const rule of Object.values(config.rules)) Schema.decodeUnknownSync(RuleMeta)(rule.meta);
return config;
}
//#endregion
export { FlagRecord, Position, RuleMeta, defineConfig, defineRule };
//# sourceMappingURL=index.mjs.map