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
2 changes: 1 addition & 1 deletion analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (a *analyzer) checkFile(pass *analysis.Pass, file *ast.File) error {
return fmt.Errorf("create %s header: %w", filename, err)
}
pass.Report(analysis.Diagnostic{
Pos: file.FileStart,
Pos: file.Package,
Category: analyzerName,
Message: "missing license header",
SuggestedFixes: []analysis.SuggestedFix{{
Expand Down
7 changes: 7 additions & 0 deletions analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ func TestAnalyzer(t *testing.T) {
t.Fatalf("NewAnalyzer() err = %v", err)
}

// Test with sources containing build directives.
t.Run("builddirective", func(t *testing.T) {
t.Parallel()
packageDir := filepath.Join(analysistest.TestData(), "src/builddirective/")
_ = analysistest.Run(t, packageDir, a)
})

// Different header contains a file with a different license header.
// This license header should stay as-is and should not be modified.
t.Run("differentheader", func(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions testdata/src/builddirective/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//go:build !foo

package main // want "missing license header"
5 changes: 5 additions & 0 deletions testdata/src/builddirective/main.go.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2025 Test

//go:build !foo

package main // want "missing license header"
4 changes: 2 additions & 2 deletions testdata/src/packagecomment/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Package packagecomment has a package-level doc comment. This comment should // want "missing license header"
// Package packagecomment has a package-level doc comment. This comment should
// not affect the generation of a license header above it.
package packagecomment
package packagecomment // want "missing license header"
4 changes: 2 additions & 2 deletions testdata/src/packagecomment/main.go.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2025 Test

// Package packagecomment has a package-level doc comment. This comment should // want "missing license header"
// Package packagecomment has a package-level doc comment. This comment should
// not affect the generation of a license header above it.
package packagecomment
package packagecomment // want "missing license header"