mgechev / revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
https://revive.run
MIT License
4.69k stars 269 forks source link

comment-spacings exceptions do not work if there's no colon after the exception #980

Closed gfariasalves-ionos closed 2 months ago

gfariasalves-ionos commented 2 months ago

Describe the bug Some projects like Kubebuilder have markers that do not follow the pattern //name:, example: //+optional. Due to https://github.com/mgechev/revive/blob/f88f60da20b2cdc9db2ad6ce5978da32531b0cda/rule/comment-spacings.go#L34 having a colon added at the end they don't work.

To Reproduce Steps to reproduce the behavior:

  1. Write this config file:

    [rule.comment-spacings]
    arguments = ["+optional"]
  2. Write this test file:

    
    package main

import "fmt"

// example is an example struct //+optional type example struct { a int }

func main() { a := example{a: 1} fmt.Println(a.a) }


**Expected behavior**
I don't get an error

**Logs**
I get an error (logs from golangci-lint but the idea is the same):

comment-spacings: no space between comment delimiter and comment text (revive) //+optional ^



**Desktop (please complete the following information):**
 - OS: OpenSUSE Tumbleweed
 - Version of Go: 1.22
chavacava commented 2 months ago

Hi @gfariasalves-ionos, thanks for reporting the issue. As you already pointed out, removing the : from line 34 of the rule will fix the problem. (PR are welcome)

gfariasalves-ionos commented 2 months ago

I'll create one :)