Skip to content

Commit

Permalink
Update WSL to v1.2.5 (#811)
Browse files Browse the repository at this point in the history
* Update WSL to v1.2.4

* Fix false positive multiline case
* Fix false positive slice expression
* Fix false positive index expression
* Support to configure/allow cuddle declarations
* Support to configurre/allow case blocks to end with whitespace
* Support cuddle defer http body close

* Re-generate README.md

* Update WSL to v1.2.5

* Support output comments for example functions

* Fix bad field tag for config
  • Loading branch information
bombsimon authored and jirfag committed Oct 14, 2019
1 parent d47b6f5 commit 22df2d7
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 40 deletions.
4 changes: 4 additions & 0 deletions .golangci.example.yml
Expand Up @@ -220,6 +220,10 @@ linters-settings:
allow-assign-and-call: true
# Allow multiline assignments to be cuddled. Default is true.
allow-multiline-assign: true
# Allow case blocks to end with a whitespace.
allow-case-traling-whitespace: true
# Allow declarations (var) to be cuddled.
allow-cuddle-declarations: false

linters:
enable:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -819,6 +819,10 @@ linters-settings:
allow-assign-and-call: true
# Allow multiline assignments to be cuddled. Default is true.
allow-multiline-assign: true
# Allow case blocks to end with a whitespace.
allow-case-traling-whitespace: true
# Allow declarations (var) to be cuddled.
allow-cuddle-declarations: false
linters:
enable:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -4,7 +4,7 @@ go 1.12

require (
github.com/OpenPeeDeeP/depguard v1.0.1
github.com/bombsimon/wsl v1.2.1
github.com/bombsimon/wsl v1.2.5
github.com/fatih/color v1.7.0
github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db
github.com/go-lintpack/lintpack v0.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -11,8 +11,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bombsimon/wsl v1.2.1 h1:DcLf3V66dJi4a+KHt+F1FdOeBZ05adHqTMYFvjgv06k=
github.com/bombsimon/wsl v1.2.1/go.mod h1:43lEF/i0kpXbLCeDXL9LMT8c92HyBywXb0AsgMHYngM=
github.com/bombsimon/wsl v1.2.5 h1:9gTOkIwVtoDZywvX802SDHokeX4kW1cKnV8ZTVAPkRs=
github.com/bombsimon/wsl v1.2.5/go.mod h1:43lEF/i0kpXbLCeDXL9LMT8c92HyBywXb0AsgMHYngM=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Expand Down
16 changes: 10 additions & 6 deletions pkg/config/config.go
Expand Up @@ -255,9 +255,11 @@ type GocognitSettings struct {
}

type WSLSettings struct {
StrictAppend bool `mapstructure:"strict-append"`
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
AllowMultiLineAssignCuddle bool `mapstructure:"allow-multiline-assign"`
StrictAppend bool `mapstructure:"strict-append"`
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
AllowMultiLineAssignCuddle bool `mapstructure:"allow-multiline-assign"`
AllowCaseTrailingWhitespace bool `mapstructure:"allow-case-trailing-whitespace"`
AllowCuddleDeclaration bool `mapstructure:"allow-cuddle-declarations"`
}

var defaultLintersSettings = LintersSettings{
Expand Down Expand Up @@ -289,9 +291,11 @@ var defaultLintersSettings = LintersSettings{
MinComplexity: 30,
},
WSL: WSLSettings{
StrictAppend: true,
AllowAssignAndCallCuddle: true,
AllowMultiLineAssignCuddle: true,
StrictAppend: true,
AllowAssignAndCallCuddle: true,
AllowMultiLineAssignCuddle: true,
AllowCaseTrailingWhitespace: true,
AllowCuddleDeclaration: false,
},
}

Expand Down
12 changes: 7 additions & 5 deletions pkg/golinters/wsl.go
Expand Up @@ -37,11 +37,13 @@ func NewWSL() *goanalysis.Linter {
files = []string{}
linterCfg = lintCtx.Cfg.LintersSettings.WSL
processorCfg = wsl.Configuration{
StrictAppend: linterCfg.StrictAppend,
AllowAssignAndCallCuddle: linterCfg.AllowAssignAndCallCuddle,
AllowMultiLineAssignCuddle: linterCfg.AllowMultiLineAssignCuddle,
AllowCuddleWithCalls: []string{"Lock", "RLock"},
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
StrictAppend: linterCfg.StrictAppend,
AllowAssignAndCallCuddle: linterCfg.AllowAssignAndCallCuddle,
AllowMultiLineAssignCuddle: linterCfg.AllowMultiLineAssignCuddle,
AllowCaseTrailingWhitespace: linterCfg.AllowCaseTrailingWhitespace,
AllowCuddleDeclaration: linterCfg.AllowCuddleDeclaration,
AllowCuddleWithCalls: []string{"Lock", "RLock"},
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
}
)

Expand Down
1 change: 1 addition & 0 deletions test/linters_test.go
Expand Up @@ -105,6 +105,7 @@ func testOneSource(t *testing.T, sourcePath string) {
"--print-issued-lines=false",
"--print-linter-name=false",
"--out-format=line-number",
"--max-same-issues=10",
}

rc := extractRunContextFromComments(t, sourcePath)
Expand Down
72 changes: 72 additions & 0 deletions test/testdata/wsl.go
Expand Up @@ -100,3 +100,75 @@ func f3() int {
}

func onelineShouldNotError() error { return nil }

func multilineCase() {
// Multiline cases
switch {
case true,
false:
fmt.Println("ok")
case false ||
true:
fmt.Println("ok")
case true,
false:
fmt.Println("ok")
}
}

func sliceExpr() {
// Index- and slice expressions.
var aSlice = []int{1, 2, 3}

start := 2
if v := aSlice[start]; v == 1 {
fmt.Println("ok")
}

notOk := 1
if v := aSlice[start]; v == 1 { // ERROR "if statements should only be cuddled with assignments used in the if statement itself"
fmt.Println("notOk")
fmt.Println(notOk)
}

end := 2
if len(aSlice[start:end]) > 2 {
fmt.Println("ok")
}
}

func indexExpr() {
var aMap = map[string]struct{}{"key": {}}

key := "key"
if k, ok := aMap[key]; ok {
fmt.Println(k)
}

xxx := "xxx"
if _, ok := aMap[key]; ok { // ERROR "if statements should only be cuddled with assignments used in the if statement itself"
fmt.Println("not ok")
fmt.Println(xxx)
}
}

func allowTrailing(i int) {
switch i {
case 1:
fmt.Println("one")

case 2:
fmt.Println("two")

case 3:
fmt.Println("three")
}
}

// ExampleSomeOutput simulates an example function.
func ExampleSomeOutput() {
fmt.Println("Hello, world")

// Output:
// Hello, world
}

0 comments on commit 22df2d7

Please sign in to comment.