Skip to content

Commit b1cec47

Browse files
authored
wsl: support all configs and update docs (#3202)
1 parent 8f00a10 commit b1cec47

File tree

3 files changed

+88
-85
lines changed

3 files changed

+88
-85
lines changed

.golangci.reference.yml

+64-63
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,11 @@ linters-settings:
701701
# List of allowed modules.
702702
# Default: []
703703
modules:
704-
- gopkg.in/yaml.v2
704+
- gopkg.in/yaml.v2
705705
# List of allowed module domains.
706706
# Default: []
707707
domains:
708-
- golang.org
708+
- golang.org
709709
blocked:
710710
# List of blocked modules.
711711
# Default: []
@@ -1261,21 +1261,21 @@ linters-settings:
12611261
# Please refer to https://github.com/yeya24/promlinter#usage for detailed usage.
12621262
# Default: []
12631263
disabled-linters:
1264-
- Help
1265-
- MetricUnits
1266-
- Counter
1267-
- HistogramSummaryReserved
1268-
- MetricTypeInName
1269-
- ReservedChars
1270-
- CamelCase
1271-
- UnitAbbreviations
1264+
- Help
1265+
- MetricUnits
1266+
- Counter
1267+
- HistogramSummaryReserved
1268+
- MetricTypeInName
1269+
- ReservedChars
1270+
- CamelCase
1271+
- UnitAbbreviations
12721272

12731273
reassign:
12741274
# Patterns for global variable names that are checked for reassignment.
12751275
# See https://github.com/curioswitch/go-reassign#usage
12761276
# Default: ["EOF", "Err.*"]
12771277
patterns:
1278-
- ".*"
1278+
- ".*"
12791279

12801280
revive:
12811281
# Maximum number of open files at the same time.
@@ -1316,7 +1316,7 @@ linters-settings:
13161316
- name: argument-limit
13171317
severity: warning
13181318
disabled: false
1319-
arguments: [4]
1319+
arguments: [ 4 ]
13201320
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#atomic
13211321
- name: atomic
13221322
severity: warning
@@ -1325,7 +1325,7 @@ linters-settings:
13251325
- name: banned-characters
13261326
severity: warning
13271327
disabled: false
1328-
arguments: ["Ω","Σ","σ", "7"]
1328+
arguments: [ "Ω","Σ","σ", "7" ]
13291329
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bare-return
13301330
- name: bare-return
13311331
severity: warning
@@ -1427,8 +1427,8 @@ linters-settings:
14271427
severity: warning
14281428
disabled: false
14291429
arguments:
1430-
- "checkPrivateReceivers"
1431-
- "sayRepetitiveInsteadOfStutters"
1430+
- "checkPrivateReceivers"
1431+
- "sayRepetitiveInsteadOfStutters"
14321432
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#file-header
14331433
- name: file-header
14341434
severity: warning
@@ -1569,8 +1569,8 @@ linters-settings:
15691569
severity: warning
15701570
disabled: false
15711571
arguments:
1572-
- [ "ID" ] # AllowList
1573-
- [ "VM" ] # DenyList
1572+
- [ "ID" ] # AllowList
1573+
- [ "VM" ] # DenyList
15741574
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-declaration
15751575
- name: var-declaration
15761576
severity: warning
@@ -1868,56 +1868,57 @@ linters-settings:
18681868
# See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for documentation of available settings.
18691869
# These are the defaults for `golangci-lint`.
18701870

1871-
# Controls if you may cuddle assignments and anything without needing an empty line between them.
1872-
# Default: false
1873-
allow-assign-and-anything: false
1874-
1875-
# Controls if you may cuddle assignments and calls without needing an empty line between them.
1876-
# Default: true
1871+
# Do strict checking when assigning from append (x = append(x, y)). If
1872+
# this is set to true - the append call must append either a variable
1873+
# assigned, called or used on the line above.
1874+
strict-append: true
1875+
1876+
# Allows assignments to be cuddled with variables used in calls on
1877+
# line above and calls to be cuddled with assignments of variables
1878+
# used in call on line above.
18771879
allow-assign-and-call: true
1878-
1879-
# Controls if you're allowed to cuddle multiple declarations.
1880-
# This is false by default to encourage you to group them in one var block.
1881-
# One major benefit with this is that if the variables are assigned the assignments will be tabulated.
1882-
# Default: false
1883-
allow-cuddle-declarations: false
1884-
1885-
# Controls if you may cuddle assignments even if they span over multiple lines.
1886-
# Default: true
1880+
1881+
# Allows assignments to be cuddled with anything.
1882+
allow-assign-and-anything: false
1883+
1884+
# Allows cuddling to assignments even if they span over multiple lines.
18871885
allow-multiline-assign: true
1888-
1889-
# This option allows whitespace after each comment group that begins a block.
1890-
# Default: false
1891-
allow-separated-leading-comment: false
1892-
1893-
# Controls if blocks can end with comments.
1894-
# This is not encouraged sine it's usually code smell but might be useful do improve understanding or learning purposes.
1895-
# To be allowed there must be no whitespace between the comment and the last statement or the comment and the closing brace.
1896-
# Default: false
1897-
allow-trailing-comment: false
1898-
1899-
# Can be set to force trailing newlines at the end of case blocks to improve readability.
1900-
# If the number of lines (including comments) in a case block exceeds this number
1901-
# a linter error will be yielded if the case does not end with a newline.
1902-
# Default: 0
1886+
1887+
# If the number of lines in a case block is equal to or lager than this
1888+
# number, the case *must* end white a newline.
19031889
force-case-trailing-whitespace: 0
1904-
1905-
# Enforces that an `if` statement checking an error variable is cuddled
1906-
# with the line that assigned that error variable.
1907-
# Default: false
1908-
force-err-cuddling: false
1909-
1910-
# Enforces that an assignment which is actually a short declaration (using `:=`)
1911-
# is only allowed to cuddle with other short declarations, and not plain assignments, blocks, etc.
1912-
# This rule helps make declarations stand out by themselves, much the same as grouping var statement.
1913-
# Default: false
1890+
1891+
# Allow blocks to end with comments.
1892+
allow-trailing-comment: false
1893+
1894+
# Allow multiple comments in the beginning of a block separated with newline.
1895+
allow-separated-leading-comment: false
1896+
1897+
# Allow multiple var/declaration statements to be cuddled.
1898+
allow-cuddle-declarations: false
1899+
1900+
# Aa list of call idents that everything can be cuddled with.
1901+
# Defaults to calls looking like locks.
1902+
allow-cuddle-with-calls: [ "Lock", "RLock" ]
1903+
1904+
# AllowCuddleWithRHS is a list of right hand side variables that is allowed
1905+
# to be cuddled with anything. Defaults to assignments or calls looking
1906+
# like unlocks.
1907+
allow-cuddle-with-rhs: [ "Unlock", "RUnlock" ]
1908+
1909+
# Causes an error when an If statement that checks an error variable doesn't
1910+
# cuddle with the assignment of that variable.
1911+
enforce-err-cuddling: false
1912+
1913+
# When enforce-err-cuddling is enabled this is a list of names
1914+
# used for error variables to check for in the conditional.
1915+
error-variable-names: [ "err" ]
1916+
1917+
# Causes an error if a short declaration (:=) cuddles with anything other than
1918+
# another short declaration.
1919+
# This logic overrides enforce-err-cuddling among others.
19141920
force-short-decl-cuddling: false
19151921

1916-
# Controls if the checks for slice append should be "strict"
1917-
# in the sense that it will only allow these assignments to be cuddled with variables being appended.
1918-
# Default: true
1919-
strict-append: true
1920-
19211922
# The custom section can be used to define linter plugins to be loaded at runtime.
19221923
# See README documentation for more info.
19231924
custom:
@@ -2292,5 +2293,5 @@ severity:
22922293
# Default: []
22932294
rules:
22942295
- linters:
2295-
- dupl
2296+
- dupl
22962297
severity: info

pkg/config/linters_settings.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,15 @@ var defaultLintersSettings = LintersSettings{
120120
AllowAssignAndCallCuddle: true,
121121
AllowAssignAndAnythingCuddle: false,
122122
AllowMultiLineAssignCuddle: true,
123-
AllowCuddleDeclaration: false,
123+
ForceCaseTrailingWhitespaceLimit: 0,
124124
AllowTrailingComment: false,
125125
AllowSeparatedLeadingComment: false,
126+
AllowCuddleDeclaration: false,
127+
AllowCuddleWithCalls: []string{"Lock", "RLock"},
128+
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
126129
ForceCuddleErrCheckAndAssign: false,
130+
ErrorVariableNames: []string{"err"},
127131
ForceExclusiveShortDeclarations: false,
128-
ForceCaseTrailingWhitespaceLimit: 0,
129132
},
130133
}
131134

@@ -693,16 +696,19 @@ type WrapcheckSettings struct {
693696
}
694697

695698
type WSLSettings struct {
696-
StrictAppend bool `mapstructure:"strict-append"`
697-
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
698-
AllowAssignAndAnythingCuddle bool `mapstructure:"allow-assign-and-anything"`
699-
AllowMultiLineAssignCuddle bool `mapstructure:"allow-multiline-assign"`
700-
AllowCuddleDeclaration bool `mapstructure:"allow-cuddle-declarations"`
701-
AllowTrailingComment bool `mapstructure:"allow-trailing-comment"`
702-
AllowSeparatedLeadingComment bool `mapstructure:"allow-separated-leading-comment"`
703-
ForceCuddleErrCheckAndAssign bool `mapstructure:"force-err-cuddling"`
704-
ForceExclusiveShortDeclarations bool `mapstructure:"force-short-decl-cuddling"`
705-
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
699+
StrictAppend bool `mapstructure:"strict-append"`
700+
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
701+
AllowAssignAndAnythingCuddle bool `mapstructure:"allow-assign-and-anything"`
702+
AllowMultiLineAssignCuddle bool `mapstructure:"allow-multiline-assign"`
703+
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
704+
AllowTrailingComment bool `mapstructure:"allow-trailing-comment"`
705+
AllowSeparatedLeadingComment bool `mapstructure:"allow-separated-leading-comment"`
706+
AllowCuddleDeclaration bool `mapstructure:"allow-cuddle-declarations"`
707+
AllowCuddleWithCalls []string `mapstructure:"allow-cuddle-with-calls"`
708+
AllowCuddleWithRHS []string `mapstructure:"allow-cuddle-with-rhs"`
709+
ForceCuddleErrCheckAndAssign bool `mapstructure:"enforce-err-cuddling"`
710+
ErrorVariableNames []string `mapstructure:"error-variable-names"`
711+
ForceExclusiveShortDeclarations bool `mapstructure:"force-short-decl-cuddling"`
706712
}
707713

708714
// CustomLinterSettings encapsulates the meta-data of a private linter.

pkg/golinters/wsl.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,26 @@ func NewWSL(settings *config.WSLSettings) *goanalysis.Linter {
1919
var mu sync.Mutex
2020
var resIssues []goanalysis.Issue
2121

22-
conf := &wsl.Configuration{
23-
AllowCuddleWithCalls: []string{"Lock", "RLock"},
24-
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
25-
ErrorVariableNames: []string{"err"},
26-
}
22+
conf := wsl.DefaultConfig()
2723

2824
if settings != nil {
2925
conf.StrictAppend = settings.StrictAppend
3026
conf.AllowAssignAndCallCuddle = settings.AllowAssignAndCallCuddle
3127
conf.AllowAssignAndAnythingCuddle = settings.AllowAssignAndAnythingCuddle
3228
conf.AllowMultiLineAssignCuddle = settings.AllowMultiLineAssignCuddle
33-
conf.AllowCuddleDeclaration = settings.AllowCuddleDeclaration
29+
conf.ForceCaseTrailingWhitespaceLimit = settings.ForceCaseTrailingWhitespaceLimit
3430
conf.AllowTrailingComment = settings.AllowTrailingComment
3531
conf.AllowSeparatedLeadingComment = settings.AllowSeparatedLeadingComment
36-
conf.ForceCuddleErrCheckAndAssign = settings.ForceCuddleErrCheckAndAssign
37-
conf.ForceCaseTrailingWhitespaceLimit = settings.ForceCaseTrailingWhitespaceLimit
38-
conf.ForceExclusiveShortDeclarations = settings.ForceExclusiveShortDeclarations
32+
conf.AllowCuddleDeclaration = settings.AllowCuddleDeclaration
33+
conf.AllowCuddleWithCalls = settings.AllowCuddleWithCalls
34+
conf.AllowCuddleWithRHS = settings.AllowCuddleWithRHS
3935
}
4036

4137
analyzer := &analysis.Analyzer{
4238
Name: goanalysis.TheOnlyAnalyzerName,
4339
Doc: goanalysis.TheOnlyanalyzerDoc,
4440
Run: func(pass *analysis.Pass) (interface{}, error) {
45-
issues := runWSL(pass, conf)
41+
issues := runWSL(pass, &conf)
4642

4743
if len(issues) == 0 {
4844
return nil, nil

0 commit comments

Comments
 (0)