pi-lens
Version:
Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo
41 lines (40 loc) • 1.53 kB
JavaScript
import { isTestFile } from "../../file-utils.js";
const PLACEHOLDER_PATTERNS = [
/add\s+more\s+validation/i,
/handle\s+(additional|more)\s+cases?/i,
/can\s+be\s+extended\s+in\s+the\s+future/i,
/extend\s+this\s+(logic|function|method|handler|module)/i,
/customize\s+this\s+(logic|behavior|function|method|handler)/i,
/future\s+enhancement/i,
/implement\s+.+\s+here/i,
];
export const placeholderCommentsRule = {
id: "placeholder-comments",
requires: ["file.comments"],
appliesTo(ctx) {
return /\.tsx?$/.test(ctx.filePath) && !isTestFile(ctx.filePath);
},
evaluate(ctx, store) {
const comments = store.getFileFact(ctx.filePath, "file.comments");
if (!comments)
return [];
const diagnostics = [];
for (const comment of comments) {
const matched = PLACEHOLDER_PATTERNS.some((pattern) => pattern.test(comment.text));
if (!matched)
continue;
diagnostics.push({
id: `placeholder-comments:${ctx.filePath}:${comment.line}:1`,
tool: "fact-rules",
filePath: ctx.filePath,
line: comment.line,
column: 1,
severity: "warning",
semantic: "warning",
rule: "placeholder-comments",
message: "Placeholder comment detected. Prefer comments that describe current behavior over future intent.",
});
}
return diagnostics;
},
};