feat(hooks): add comment-checker hook for detecting unnecessary comments
- Port Go comment-checker to TypeScript using web-tree-sitter - Support 38 programming languages via tree-sitter-wasms - Filter out valid comments: BDD patterns, lint directives, docstrings, shebangs - Integrate with OpenCode's tool.execute.before/after hooks - Attach feedback to Write/Edit/MultiEdit tool output
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { FileComments } from "../types"
|
||||
|
||||
function escapeXml(text: string): string {
|
||||
return text
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'")
|
||||
}
|
||||
|
||||
export function buildCommentsXml(fileCommentsList: FileComments[]): string {
|
||||
const lines: string[] = []
|
||||
|
||||
for (const fc of fileCommentsList) {
|
||||
lines.push(`<comments file="${escapeXml(fc.filePath)}">`)
|
||||
for (const comment of fc.comments) {
|
||||
lines.push(`\t<comment line-number="${comment.lineNumber}">${escapeXml(comment.text)}</comment>`)
|
||||
}
|
||||
lines.push(`</comments>`)
|
||||
}
|
||||
|
||||
return lines.join("\n")
|
||||
}
|
||||
Reference in New Issue
Block a user