Skip to content

Commit

Permalink
Fix #808 (#986)
Browse files Browse the repository at this point in the history
fix #808 by using the official regexp for directives
---------

Co-authored-by: chavacava <[email protected]>
  • Loading branch information
chavacava and chavacava authored May 10, 2024
1 parent 582822e commit 85333f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 2 additions & 7 deletions rule/comment-spacings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -87,5 +82,5 @@ func (r *CommentSpacingsRule) isAllowed(line string) bool {
}
}

return false
return isDirectiveComment(line)
}
6 changes: 6 additions & 0 deletions rule/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions testdata/comment-spacings.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ type c struct {
//+optional
d *int `json:"d,omitempty"`
}

//extern open
//export MyFunction

//nolint:gochecknoglobals

0 comments on commit 85333f8

Please sign in to comment.