Skip to content

Commit 56c5594

Browse files
authored
analysis: create header missing diagnostics on package pos (#9)
1 parent 1a711aa commit 56c5594

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

analysis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (a *analyzer) checkFile(pass *analysis.Pass, file *ast.File) error {
179179
return fmt.Errorf("create %s header: %w", filename, err)
180180
}
181181
pass.Report(analysis.Diagnostic{
182-
Pos: file.FileStart,
182+
Pos: file.Package,
183183
Category: analyzerName,
184184
Message: "missing license header",
185185
SuggestedFixes: []analysis.SuggestedFix{{

analysis_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ func TestAnalyzer(t *testing.T) {
5252
t.Fatalf("NewAnalyzer() err = %v", err)
5353
}
5454

55+
// Test with sources containing build directives.
56+
t.Run("builddirective", func(t *testing.T) {
57+
t.Parallel()
58+
packageDir := filepath.Join(analysistest.TestData(), "src/builddirective/")
59+
_ = analysistest.Run(t, packageDir, a)
60+
})
61+
5562
// Different header contains a file with a different license header.
5663
// This license header should stay as-is and should not be modified.
5764
t.Run("differentheader", func(t *testing.T) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//go:build !foo
2+
3+
package main // want "missing license header"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) 2025 Test
2+
3+
//go:build !foo
4+
5+
package main // want "missing license header"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// Package packagecomment has a package-level doc comment. This comment should // want "missing license header"
1+
// Package packagecomment has a package-level doc comment. This comment should
22
// not affect the generation of a license header above it.
3-
package packagecomment
3+
package packagecomment // want "missing license header"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) 2025 Test
22

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

0 commit comments

Comments
 (0)