Repository: mgechev/revive (go)

Issue:
comment-spacings false positives for nolint directives
**Describe the bug**
I'm using revive with golangci-lint and since the latest update I'm getting errors like this:
```
api/common/validate/validate.go:15:1: comment-spacings: no space between comment delimiter and comment text (revive)
//nolint:gochecknoglobals
```
I've updated the config to contain `nolint` in the `comment-spacings` arguments to make it go away but it's odd as this was not happening before.

**To Reproduce**
Steps to reproduce the behavior:
1. I updated golangci-lint:
```sh
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
```

2. I run it with the following flags & configuration file:
```shell
golangci-lint run
```

```yaml
linters:
  disable-all: true
  enable:
    - revive
linters-settings:
  revive:
    rules:
      - name: comment-spacings
        disabled: false
```


**Desktop (please complete the following information):**
 - OS: Ubuntu 22.04.2 LTS
 - go version go1.20.2 linux/amd64



Pull request:
Fix #808
Closes #808 by ignoring comments matching the official pattern for directives


Patch:
diff --git a/rule/comment-spacings.go b/rule/comment-spacings.go
index 0a29b96..bfb7eaf 100644
--- a/rule/comment-spacings.go
+++ b/rule/comment-spacings.go
@@ -20,12 +20,7 @@ func (r *CommentSpacingsRule) configure(arguments lint.Arguments) {
 	defer r.Unlock()
 
 	if r.allowList == nil {
-		r.allowList = []string{
-			"//go:",
-			"//revive:",
-			"//nolint:",
-		}
-
+		r.allowList = []string{}
 		for _, arg := range arguments {
 			allow, ok := arg.(string) // Alt. non panicking version
 			if !ok {
@@ -87,5 +82,5 @@ func (r *CommentSpacingsRule) isAllowed(line string) bool {
 		}
 	}
 
-	return false
+	return isDirectiveComment(line)
 }
diff --git a/rule/utils.go b/rule/utils.go
index 5778e76..8ffded4 100644
--- a/rule/utils.go
+++ b/rule/utils.go
@@ -165,3 +165,9 @@ func checkNumberOfArguments(expected int, args lint.Arguments, ruleName string)
 		panic(fmt.Sprintf("not enough arguments for %s rule, expected %d, got %d. Please check the rule's documentation", ruleName, expected, len(args)))
 	}
 }
+
+var directiveCommentRE = regexp.MustCompile("//(line |extern |export |[a-z0-9]+:[a-z0-9])") // see https://go-review.googlesource.com/c/website/+/442516/1..2/_content/doc/comment.md#494
+
+func isDirectiveComment(line string) bool {
+	return directiveCommentRE.MatchString(line)
+}


Test patch:
diff --git a/testdata/comment-spacings.go b/testdata/comment-spacings.go
index 92c832c..da8459b 100644
--- a/testdata/comment-spacings.go
+++ b/testdata/comment-spacings.go
@@ -47,3 +47,8 @@ type c struct {
 	//+optional
 	d *int `json:"d,omitempty"`
 }
+
+//extern open
+//export MyFunction
+
+//nolint:gochecknoglobals