nolintlint: allow to fix //nolint lines (#1583)

This commit is contained in:
Andrew Shannon Brown 2021-03-12 20:11:05 -08:00 committed by GitHub
parent d28c66672e
commit e1a734e559
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 345 additions and 132 deletions

17
test/testdata/fix/in/nolintlint.go vendored Normal file
View file

@ -0,0 +1,17 @@
//args: -Enolintlint -Elll
//expected_linter: nolintlint
//config: linters-settings.nolintlint.allow-leading-space=false
package p
import "fmt"
func nolintlint() {
fmt.Println() // nolint:bob // leading space should be dropped
fmt.Println() // nolint:bob // leading spaces should be dropped
// note that the next lines will retain trailing whitespace when fixed
fmt.Println() //nolint // nolint should be dropped
fmt.Println() //nolint:lll // nolint should be dropped
fmt.Println() //nolint:alice,lll // we don't drop individual linters from lists
}

17
test/testdata/fix/out/nolintlint.go vendored Normal file
View file

@ -0,0 +1,17 @@
//args: -Enolintlint -Elll
//expected_linter: nolintlint
//config: linters-settings.nolintlint.allow-leading-space=false
package p
import "fmt"
func nolintlint() {
fmt.Println() //nolint:bob // leading space should be dropped
fmt.Println() //nolint:bob // leading spaces should be dropped
// note that the next lines will retain trailing whitespace when fixed
fmt.Println()
fmt.Println()
fmt.Println() //nolint:alice,lll // we don't drop individual linters from lists
}

View file

@ -1,7 +1,8 @@
//args: -Enolintlint
//args: -Enolintlint -Emisspell
//expected_linter: nolintlint
//config: linters-settings.nolintlint.require-explanation=true
//config: linters-settings.nolintlint.require-specific=true
//config: linters-settings.nolintlint.allowing-leading-space=false
//config: linters-settings.nolintlint.allow-leading-space=false
package testdata
import "fmt"
@ -10,4 +11,11 @@ func Foo() {
fmt.Println("not specific") //nolint // ERROR "directive `.*` should mention specific linter such as `//nolint:my-linter`"
fmt.Println("not machine readable") // nolint // ERROR "directive `.*` should be written as `//nolint`"
fmt.Println("extra spaces") // nolint:deadcode // because // ERROR "directive `.*` should not have more than one leading space"
// test expanded range
//nolint:misspell // deliberate misspelling to trigger nolintlint
func() {
mispell := true
fmt.Println(mispell)
}()
}