mirror of
https://github.com/mgechev/revive.git
synced 2025-04-23 11:58:51 +02:00
refactor: Reduce package-comments output scope (#791)
This reduces the amount of lines reported by package-comments by only reporting the `package XXXXXXX' line, instead of the whole file.
This commit is contained in:
parent
8c2cd33315
commit
b2bc00bd75
@ -58,12 +58,14 @@ func (l *lintPackageComments) checkPackageComment() []lint.Failure {
|
|||||||
var packageFile *ast.File // which name is $package.go
|
var packageFile *ast.File // which name is $package.go
|
||||||
var firstFile *ast.File
|
var firstFile *ast.File
|
||||||
var firstFileName string
|
var firstFileName string
|
||||||
|
var fileSource string
|
||||||
for name, file := range l.file.Pkg.Files() {
|
for name, file := range l.file.Pkg.Files() {
|
||||||
if file.AST.Doc != nil {
|
if file.AST.Doc != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if name == "doc.go" {
|
if name == "doc.go" {
|
||||||
docFile = file.AST
|
docFile = file.AST
|
||||||
|
fileSource = "doc.go"
|
||||||
}
|
}
|
||||||
if name == file.AST.Name.String()+".go" {
|
if name == file.AST.Name.String()+".go" {
|
||||||
packageFile = file.AST
|
packageFile = file.AST
|
||||||
@ -76,14 +78,21 @@ func (l *lintPackageComments) checkPackageComment() []lint.Failure {
|
|||||||
// prefer warning on doc.go, $package.go over first file
|
// prefer warning on doc.go, $package.go over first file
|
||||||
if docFile == nil {
|
if docFile == nil {
|
||||||
docFile = packageFile
|
docFile = packageFile
|
||||||
|
fileSource = l.fileAst.Name.String() + ".go"
|
||||||
}
|
}
|
||||||
if docFile == nil {
|
if docFile == nil {
|
||||||
docFile = firstFile
|
docFile = firstFile
|
||||||
|
fileSource = firstFileName
|
||||||
}
|
}
|
||||||
|
|
||||||
if docFile != nil {
|
if docFile != nil {
|
||||||
|
pkgFile := l.file.Pkg.Files()[fileSource]
|
||||||
return []lint.Failure{{
|
return []lint.Failure{{
|
||||||
Category: "comments",
|
Category: "comments",
|
||||||
Node: docFile,
|
Position: lint.FailurePosition{
|
||||||
|
Start: pkgFile.ToPosition(docFile.Pos()),
|
||||||
|
End: pkgFile.ToPosition(docFile.Name.End()),
|
||||||
|
},
|
||||||
Confidence: 1,
|
Confidence: 1,
|
||||||
Failure: "should have a package comment",
|
Failure: "should have a package comment",
|
||||||
}}
|
}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user