Repository: mgechev/revive (go)

Issue:
package-comments position includes the whole file
**Describe the bug**
When using JSON as the formatter, the package-comments rule reports that the issue starts at the very beginning of the file and spans to the last line, which I think is unexpected. 

**To Reproduce**
Steps to reproduce the behavior:
1. Get latest revive release
2. Run it against its own codebase, using `--formatter json`
3. It should report an issue on `main.go`, that spans the entire file.

```console
> pwd
/work/revive

> revive --formatter json
[{"Severity":"warning","Failure":"should have a package comment","RuleName":"package-comments","Category":"comments","Position":{"Start":{"Filename":"main.go","Offset":0,"Line":1,"Column":1},"End":{"Filename":"main.go","Offset":86,"Line":7,"Column":2}},"Confidence":1,"ReplacementLine":""}]
```

**Expected behavior**
Instead, revive should report only the line containing `package xyz`, which is the target of the missing comment:

```console
> pwd
/work/revive

> revive --formatter json
[{"Severity":"warning","Failure":"should have a package comment","RuleName":"package-comments","Category":"comments","Position":{"Start":{"Filename":"main.go","Offset":0,"Line":1,"Column":1},"End":{"Filename":"main.go","Offset":12,"Line":1,"Column":13}},"Confidence":1,"ReplacementLine":""}]
```

**Logs**
N/A


Pull request description:
refactor: Reduce package-comments output scope
This reduces the amount of lines reported by package-comments by only reporting the `package xyz` line, instead of the whole file.

Closes #790 

Patch:
diff --git a/rule/comment-spacings.go b/rule/comment-spacings.go
index abe2ad7..e0898c3 100644
--- a/rule/comment-spacings.go
+++ b/rule/comment-spacings.go
@@ -47,7 +47,13 @@ func (r *CommentSpacingsRule) Apply(file *lint.File, args lint.Arguments) []lint
 				continue // nothing to do
 			}
 
-			isOK := commentLine[2] == ' '
+			isMultiLineComment := commentLine[1] == '*'
+			isOK := commentLine[2] == '\n'
+			if isMultiLineComment && isOK {
+				continue
+			}
+
+			isOK = (commentLine[2] == ' ') || (commentLine[2] == '\t')
 			if isOK {
 				continue
 			}
diff --git a/rule/package-comments.go b/rule/package-comments.go
index 33963ab..02f246b 100644
--- a/rule/package-comments.go
+++ b/rule/package-comments.go
@@ -58,12 +58,14 @@ func (l *lintPackageComments) checkPackageComment() []lint.Failure {
 	var packageFile *ast.File // which name is $package.go
 	var firstFile *ast.File
 	var firstFileName string
+	var fileSource string
 	for name, file := range l.file.Pkg.Files() {
 		if file.AST.Doc != nil {
 			return nil
 		}
 		if name == "doc.go" {
 			docFile = file.AST
+			fileSource = "doc.go"
 		}
 		if name == file.AST.Name.String()+".go" {
 			packageFile = file.AST
@@ -76,14 +78,21 @@ func (l *lintPackageComments) checkPackageComment() []lint.Failure {
 	// prefer warning on doc.go, $package.go over first file
 	if docFile == nil {
 		docFile = packageFile
+		fileSource = l.fileAst.Name.String() + ".go"
 	}
 	if docFile == nil {
 		docFile = firstFile
+		fileSource = firstFileName
 	}
+
 	if docFile != nil {
+		pkgFile := l.file.Pkg.Files()[fileSource]
 		return []lint.Failure{{
-			Category:   "comments",
-			Node:       docFile,
+			Category: "comments",
+			Position: lint.FailurePosition{
+				Start: pkgFile.ToPosition(docFile.Pos()),
+				End:   pkgFile.ToPosition(docFile.Name.End()),
+			},
 			Confidence: 1,
 			Failure:    "should have a package comment",
 		}}


Test patch:
diff --git a/testdata/comment-spacings.go b/testdata/comment-spacings.go
index a5465fa..5b1d281 100644
--- a/testdata/comment-spacings.go
+++ b/testdata/comment-spacings.go
@@ -22,3 +22,20 @@ type hello struct {
 var a string
 
 //myOwnDirective: do something
+
+/*
+Should be valid
+*/
+
+//	Tabs between comment delimeter and comment text should be fine
+
+// MATCH:34 /no space between comment delimiter and comment text/
+
+/*Not valid
+ */
+
+/*	valid
+ */
+
+/* valid
+ */