Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ 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
# Allow trailing comments in ending of blocks
allow-trailing-comment: false
# Force newlines in end of case at this limit (0 = never).
force-case-trailing-whitespace: 0

linters:
enable:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,12 @@ 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
# Allow trailing comments in ending of blocks
allow-trailing-comment: false
# Force newlines in end of case at this limit (0 = never).
force-case-trailing-whitespace: 0

linters:
enable:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.12

require (
github.com/OpenPeeDeeP/depguard v1.0.1
github.com/bombsimon/wsl v1.2.5
github.com/bombsimon/wsl v1.2.7
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
Original file line number Diff line number Diff line change
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.5 h1:9gTOkIwVtoDZywvX802SDHokeX4kW1cKnV8ZTVAPkRs=
github.com/bombsimon/wsl v1.2.5/go.mod h1:43lEF/i0kpXbLCeDXL9LMT8c92HyBywXb0AsgMHYngM=
github.com/bombsimon/wsl v1.2.7 h1:hckBZYt27e6Ff6yqV/SurMUe48BmXzJk/KVjxDyWtUE=
github.com/bombsimon/wsl v1.2.7/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
22 changes: 12 additions & 10 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,12 @@ type GocognitSettings struct {
}

type WSLSettings struct {
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"`
StrictAppend bool `mapstructure:"strict-append"`
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
AllowMultiLineAssignCuddle bool `mapstructure:"allow-multiline-assign"`
AllowCuddleDeclaration bool `mapstructure:"allow-cuddle-declarations"`
AllowTrailingComment bool `mapstructure:"allow-trailing-comment"`
CaseForceTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace:"`
}

var defaultLintersSettings = LintersSettings{
Expand Down Expand Up @@ -291,11 +292,12 @@ var defaultLintersSettings = LintersSettings{
MinComplexity: 30,
},
WSL: WSLSettings{
StrictAppend: true,
AllowAssignAndCallCuddle: true,
AllowMultiLineAssignCuddle: true,
AllowCaseTrailingWhitespace: true,
AllowCuddleDeclaration: false,
StrictAppend: true,
AllowAssignAndCallCuddle: true,
AllowMultiLineAssignCuddle: true,
AllowCuddleDeclaration: false,
AllowTrailingComment: false,
CaseForceTrailingWhitespaceLimit: 0,
},
}

Expand Down
15 changes: 8 additions & 7 deletions pkg/golinters/wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ func NewWSL() *goanalysis.Linter {
files = []string{}
linterCfg = lintCtx.Cfg.LintersSettings.WSL
processorCfg = wsl.Configuration{
StrictAppend: linterCfg.StrictAppend,
AllowAssignAndCallCuddle: linterCfg.AllowAssignAndCallCuddle,
AllowMultiLineAssignCuddle: linterCfg.AllowMultiLineAssignCuddle,
AllowCaseTrailingWhitespace: linterCfg.AllowCaseTrailingWhitespace,
AllowCuddleDeclaration: linterCfg.AllowCuddleDeclaration,
AllowCuddleWithCalls: []string{"Lock", "RLock"},
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
StrictAppend: linterCfg.StrictAppend,
AllowAssignAndCallCuddle: linterCfg.AllowAssignAndCallCuddle,
AllowMultiLineAssignCuddle: linterCfg.AllowMultiLineAssignCuddle,
AllowCuddleDeclaration: linterCfg.AllowCuddleDeclaration,
AllowTrailingComment: linterCfg.AllowTrailingComment,
CaseForceTrailingWhitespaceLimit: linterCfg.CaseForceTrailingWhitespaceLimit,
AllowCuddleWithCalls: []string{"Lock", "RLock"},
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
}
)

Expand Down
40 changes: 39 additions & 1 deletion test/testdata/wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func allowTrailing(i int) {

case 2:
fmt.Println("two")

// Comments OK too!
case 3:
fmt.Println("three")
}
Expand All @@ -172,3 +172,41 @@ func ExampleSomeOutput() {
// Output:
// Hello, world
}

func IncDecStmt() {
counter := 0
for range make([]int, 5) {
counter++
}

type t struct {
counter int
}

x := t{5}

x.counter--
if x.counter > 0 {
fmt.Println("not yet 0")
}
}

func AnonymousBlock() {
func(a, b int) { // ERROR "block should not start with a whitespace"

fmt.Println(a + b)
}(1, 1)
}

func MultilineComment() {
if true {
/*
Ok to start block with
a
long
multiline
cmoment
*/
fmt.Println("true")
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading