| 19 | } |
| 20 | |
| 21 | function 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 | |
| 51 | function validateNoInlineComments(lines: string[], ext: string): ValidationError[] { |
| 52 | const errors: ValidationError[] = []; |