package e2e import ( "os" "path/filepath" "strings" "testing" ) // Every comment in this tree is one line, which is a standing instruction, so a test holds it. func TestEveryCommentIsOneLine(t *testing.T) { root, err := filepath.Abs("..") if err != nil { t.Fatal(err) } skip := map[string]bool{".git": true, "plans": true, "misc": true, ".playwright-mcp": true} err = filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error { if err != nil { return nil } if d.IsDir() { if skip[d.Name()] { return filepath.SkipDir } return nil } switch filepath.Ext(path) { case ".go", ".js", ".css": default: return nil } body, err := os.ReadFile(path) if err != nil { return nil } where := strings.TrimPrefix(path, root+string(filepath.Separator)) run, start := 0, 0 for i, line := range strings.Split(string(body), "\n") { if strings.HasPrefix(strings.TrimSpace(line), "//") { if run == 0 { start = i + 1 } run++ continue } if run > 1 { t.Errorf("%s:%d has a %d line comment block, and every comment here is one line", where, start, run) } run = 0 } if run > 1 { t.Errorf("%s:%d has a %d line comment block, and every comment here is one line", where, start, run) } if strings.Contains(string(body), "/*") && filepath.Ext(path) == ".css" { for i, line := range strings.Split(string(body), "\n") { open := strings.Contains(line, "/*") if open && !strings.Contains(line[strings.Index(line, "/*"):], "*/") { t.Errorf("%s:%d opens a css comment it does not close on the same line", where, i+1) } } } return nil }) if err != nil { t.Fatal(err) } }