MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / validateHeader

Function validateHeader

src/tools/propose-commit.ts:21–49  ·  view source on GitHub ↗
(lines: string[], ext: string)

Source from the content-addressed store, hash-verified

19}
20
21function validateHeader(lines: string[], ext: string): ValidationError[] {
22 const errors: ValidationError[] = [];
23 const commentPrefixes: Record<string, string> = {
24 ".ts": "//", ".tsx": "//", ".js": "//", ".jsx": "//",
25 ".rs": "//", ".go": "//", ".c": "//", ".cpp": "//",
26 ".java": "//", ".cs": "//", ".swift": "//", ".kt": "//",
27 ".py": "#", ".rb": "#", ".lua": "--", ".zig": "//",
28 };
29
30 const prefix = commentPrefixes[ext];
31 if (!prefix) return errors;
32
33 const headerLines = lines.slice(0, 5).filter((l) => l.startsWith(prefix));
34 if (headerLines.length < 2) {
35 errors.push({
36 rule: "header",
37 message: `Missing 2-line file header. First 2 lines must be ${prefix} comments explaining the file.`,
38 });
39 }
40
41 if (headerLines.length >= 2 && !headerLines[1].toUpperCase().includes("FEATURE:")) {
42 errors.push({
43 rule: "feature-tag",
44 message: `Line 2 should include a FEATURE: tag (e.g., "${prefix} FEATURE: Feature Name"). Links files to feature hubs.`,
45 });
46 }
47
48 return errors;
49}
50
51function validateNoInlineComments(lines: string[], ext: string): ValidationError[] {
52 const errors: ValidationError[] = [];

Callers 1

proposeCommitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected