Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cmd/commentcheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ func check(root string) error {
if err != nil {
return err
}
var nonBuild []token.Position
for _, cg := range file.Comments {
for _, c := range cg.List {
if fset.Position(c.Slash).Line > 1 {
bad = append(bad, path)
return nil
if strings.HasPrefix(c.Text, "//go:build") {
continue
}
nonBuild = append(nonBuild, fset.Position(c.Slash))
}
}
if len(nonBuild) != 1 || nonBuild[0].Line != 1 {
bad = append(bad, path)
}
return nil
}
if err := filepath.WalkDir(root, walk); err != nil {
Expand Down
13 changes: 10 additions & 3 deletions cmd/commentcheck/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ import (
func TestCheck(t *testing.T) {
t.Run("compliant", func(t *testing.T) {
dir := t.TempDir()
write(t, dir, "ok.go", "// ok.go\npackage main\n")
write(t, dir, "ok.go", "// ok.go\n//go:build test\n\npackage main\n")
if err := check(dir); err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("noncompliant", func(t *testing.T) {
t.Run("noncompliant extra comment", func(t *testing.T) {
dir := t.TempDir()
write(t, dir, "bad.go", "// bad.go\npackage main\n// bad\n")
write(t, dir, "bad.go", "// bad.go\n//go:build test\n\npackage main\n// bad\n")
if err := check(dir); err == nil {
t.Fatalf("expected error")
}
})
t.Run("noncompliant missing comment", func(t *testing.T) {
dir := t.TempDir()
write(t, dir, "bad.go", "//go:build test\n\npackage main\n")
if err := check(dir); err == nil {
t.Fatalf("expected error")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/fs/ewindows_other.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// internal/fs/ewindows_other.go
//go:build !windows

// internal/fs/ewindows_other.go
package fs

func isErrWindows(err error) bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/fs/ewindows_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// internal/fs/ewindows_windows.go
//go:build windows

// internal/fs/ewindows_windows.go
package fs

import (
Expand Down
1 change: 1 addition & 0 deletions internal/fs/stdio.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// internal/fs/stdio.go
package fs

import "io"
Expand Down
Loading