-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
GoLangCI-lint documentation https://golangci-lint.run/usage/false-positives/
Use
//nolint
instead of// nolint
because machine-readable comments should have no space by Go convention.
I think some improvements may have been made between rc1 and rc2, but I still noticed some diffs
What version of Go are you using (go version
)?
$ go version go version go1.19rc2 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env # not relevant
What did you do?
Formatted code with gofmt
What did you expect to see?
Machine-readable comments, such as //nolint: <some linter>
or //#nosec XXX
preserving their formatting
What did you see instead?
gofmt
reformatting those comments to add a leading whitespace (// nolint: <some linter>
, // #nosec
The following go file should not produce a diff after running gofmt
;
package main
import "fmt"
// Some variables that are defined here
//
//nolint:govet
var (
var1 int //#nosec G501
var2 int
)
// foo is something
//nolint: gosimple
var var3 = "foo"
// bar is something
//
//nolint: gosimple
var var4 = "bar"
func main() {
//#nosec G305 -- Some comment here
var5 := "hello"
fmt.Println(var1, var2, var3, var4, var5)
}
// function1 does something.
//nolint
func function1() {}
// function2 does something.
//
//nolint:gocyclo
func function2() {}
// function3 does something.
//
//nolint:gocyclo // Some comment here
func function3() {}
//nolint
func function4() {}
//nolint:gocyclo // Some comment here
func function5() {}
func function6() { //nolint
}
func function7() { //nolint:gocyclo // Some comment here
}
// function1 does something.
//#nosec G305 -- Some comment here
func function8() {}
// function2 does something.
//
//#nosec G305 -- Some comment here
func function9() {}
//#nosec G305 -- Some comment here
func function10() {}
//#nosec G305
func function11() {}
func function12() { //#nosec G305
}
func function13() { //#nosec G305 -- Some comment here
}
type Foo struct{}
// Method1 does something
//
//nolint: gocyclo
func (p *Foo) Method1() {}
// Method2 does something
//
//nolint:gocyclo
func (p *Foo) Method2() {}
// Method3 does something
//nolint:gocyclo
func (p *Foo) Method3() {}
// Method4 does something
//nolint
func (p *Foo) Method4() {}