mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
nolintlint: allow to fix //nolint lines (#1583)
This commit is contained in:
parent
d28c66672e
commit
e1a734e559
10 changed files with 345 additions and 132 deletions
17
test/testdata/fix/in/nolintlint.go
vendored
Normal file
17
test/testdata/fix/in/nolintlint.go
vendored
Normal 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
17
test/testdata/fix/out/nolintlint.go
vendored
Normal 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
|
||||
}
|
12
test/testdata/nolintlint.go
vendored
12
test/testdata/nolintlint.go
vendored
|
@ -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)
|
||||
}()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue