@aurelienbbn/agentlint
Version:
Stateless, deterministic CLI that bridges traditional linters and AI-assisted code review
137 lines (136 loc) • 3.55 kB
JavaScript
import { Schema } from "effect";
//#region src/domain/flag.ts
/**
* Flag types — what rules produce when they detect patterns.
*
* {@link FlagOptions} is the rule-author API (passed to `context.flag()`).
* {@link FlagRecord} is the enriched internal record used by the reporter.
*
* @module
* @since 0.1.0
*/
/**
* Enriched flag record after processing — ready for the reporter.
*
* Uses `Schema.Class` for structural equality AND runtime validation
* on construction — invalid fields throw a clear `ParseError`.
*
* @since 0.1.0
* @category models
*/
var FlagRecord = class extends Schema.Class("FlagRecord")({
ruleName: Schema.String,
filename: Schema.String,
line: Schema.Number,
col: Schema.Number,
message: Schema.String,
sourceSnippet: Schema.String,
hash: Schema.String,
instruction: Schema.UndefinedOr(Schema.String),
suggest: Schema.UndefinedOr(Schema.String)
}) {};
//#endregion
//#region src/domain/node.ts
/**
* Lazy wrapper around tree-sitter's `Node`.
*
* Provides a stable public API that keeps the tree-sitter dependency
* out of the consumer-facing surface. Children and parent are wrapped
* on first access — nodes that are never inspected cost nothing.
*
* @module
* @since 0.1.0
*/
/**
* 0-indexed position in source text.
*
* Defined as a `Schema.Struct` so positions can be decoded and
* validated from external sources if needed.
*
* @since 0.1.0
* @category models
*/
const Position = Schema.Struct({
row: Schema.Number,
column: Schema.Number
});
/**
* Private implementation of {@link AgentReviewNode}.
*
* Wraps a tree-sitter `Node` and lazily creates child/parent wrappers
* on first access. Nodes that are never traversed incur zero allocation.
*
* @since 0.1.0
* @category internals
*/
var AgentReviewNodeImpl = class AgentReviewNodeImpl {
#inner;
#children;
#parent;
constructor(inner) {
this.#inner = inner;
}
get type() {
return this.#inner.type;
}
get text() {
return this.#inner.text;
}
get startPosition() {
return this.#inner.startPosition;
}
get endPosition() {
return this.#inner.endPosition;
}
get isNamed() {
return this.#inner.isNamed;
}
get childCount() {
return this.#inner.childCount;
}
get children() {
if (this.#children === void 0) {
const result = [];
for (const c of this.#inner.children) if (c !== null) result.push(new AgentReviewNodeImpl(c));
this.#children = result;
}
return this.#children;
}
get parent() {
if (this.#parent === void 0) {
const p = this.#inner.parent;
this.#parent = p ? new AgentReviewNodeImpl(p) : null;
}
return this.#parent;
}
childByFieldName(name) {
const child = this.#inner.childForFieldName(name);
return child ? new AgentReviewNodeImpl(child) : null;
}
childrenByType(type) {
const result = [];
for (const c of this.#inner.children) if (c !== null && c.type === type) result.push(new AgentReviewNodeImpl(c));
return result;
}
descendantsOfType(type) {
const result = [];
for (const c of this.#inner.descendantsOfType(type)) if (c !== null) result.push(new AgentReviewNodeImpl(c));
return result;
}
};
/**
* Wrap a raw tree-sitter node in the public {@link AgentReviewNode} interface.
*
* This is the only bridge between the internal tree-sitter dependency
* and the consumer-facing API. All child/parent nodes are lazily wrapped
* on access.
*
* @since 0.1.0
* @category constructors
*/
function wrapNode(inner) {
return new AgentReviewNodeImpl(inner);
}
//#endregion
export { wrapNode as n, FlagRecord as r, Position as t };
//# sourceMappingURL=node-yh9mLvnE.mjs.map