Skip to content

Commit 04fe6f7

Browse files
xobotyiSeigeC
authored andcommitted
wsl: support all configs and update docs (golangci#3202)
1 parent ef48dff commit 04fe6f7

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: []
@@ -1286,21 +1286,21 @@ linters-settings:
12861286
# Please refer to https://github.com/yeya24/promlinter#usage for detailed usage.
12871287
# Default: []
12881288
disabled-linters:
1289-
- Help
1290-
- MetricUnits
1291-
- Counter
1292-
- HistogramSummaryReserved
1293-
- MetricTypeInName
1294-
- ReservedChars
1295-
- CamelCase
1296-
- UnitAbbreviations
1289+
- Help
1290+
- MetricUnits
1291+
- Counter
1292+
- HistogramSummaryReserved
1293+
- MetricTypeInName
1294+
- ReservedChars
1295+
- CamelCase
1296+
- UnitAbbreviations
12971297

12981298
reassign:
12991299
# Patterns for global variable names that are checked for reassignment.
13001300
# See https://github.com/curioswitch/go-reassign#usage
13011301
# Default: ["EOF", "Err.*"]
13021302
patterns:
1303-
- ".*"
1303+
- ".*"
13041304

13051305
revive:
13061306
# Maximum number of open files at the same time.
@@ -1341,7 +1341,7 @@ linters-settings:
13411341
- name: argument-limit
13421342
severity: warning
13431343
disabled: false
1344-
arguments: [4]
1344+
arguments: [ 4 ]
13451345
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#atomic
13461346
- name: atomic
13471347
severity: warning
@@ -1350,7 +1350,7 @@ linters-settings:
13501350
- name: banned-characters
13511351
severity: warning
13521352
disabled: false
1353-
arguments: ["Ω","Σ","σ", "7"]
1353+
arguments: [ "Ω","Σ","σ", "7" ]
13541354
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bare-return
13551355
- name: bare-return
13561356
severity: warning
@@ -1452,8 +1452,8 @@ linters-settings:
14521452
severity: warning
14531453
disabled: false
14541454
arguments:
1455-
- "checkPrivateReceivers"
1456-
- "sayRepetitiveInsteadOfStutters"
1455+
- "checkPrivateReceivers"
1456+
- "sayRepetitiveInsteadOfStutters"
14571457
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#file-header
14581458
- name: file-header
14591459
severity: warning
@@ -1594,8 +1594,8 @@ linters-settings:
15941594
severity: warning
15951595
disabled: false
15961596
arguments:
1597-
- [ "ID" ] # AllowList
1598-
- [ "VM" ] # DenyList
1597+
- [ "ID" ] # AllowList
1598+
- [ "VM" ] # DenyList
15991599
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-declaration
16001600
- name: var-declaration
16011601
severity: warning
@@ -1893,56 +1893,57 @@ linters-settings:
18931893
# See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for documentation of available settings.
18941894
# These are the defaults for `golangci-lint`.
18951895

1896-
# Controls if you may cuddle assignments and anything without needing an empty line between them.
1897-
# Default: false
1898-
allow-assign-and-anything: false
1899-
1900-
# Controls if you may cuddle assignments and calls without needing an empty line between them.
1901-
# Default: true
1896+
# Do strict checking when assigning from append (x = append(x, y)). If
1897+
# this is set to true - the append call must append either a variable
1898+
# assigned, called or used on the line above.
1899+
strict-append: true
1900+
1901+
# Allows assignments to be cuddled with variables used in calls on
1902+
# line above and calls to be cuddled with assignments of variables
1903+
# used in call on line above.
19021904
allow-assign-and-call: true
1903-
1904-
# Controls if you're allowed to cuddle multiple declarations.
1905-
# This is false by default to encourage you to group them in one var block.
1906-
# One major benefit with this is that if the variables are assigned the assignments will be tabulated.
1907-
# Default: false
1908-
allow-cuddle-declarations: false
1909-
1910-
# Controls if you may cuddle assignments even if they span over multiple lines.
1911-
# Default: true
1905+
1906+
# Allows assignments to be cuddled with anything.
1907+
allow-assign-and-anything: false
1908+
1909+
# Allows cuddling to assignments even if they span over multiple lines.
19121910
allow-multiline-assign: true
1913-
1914-
# This option allows whitespace after each comment group that begins a block.
1915-
# Default: false
1916-
allow-separated-leading-comment: false
1917-
1918-
# Controls if blocks can end with comments.
1919-
# This is not encouraged sine it's usually code smell but might be useful do improve understanding or learning purposes.
1920-
# To be allowed there must be no whitespace between the comment and the last statement or the comment and the closing brace.
1921-
# Default: false
1922-
allow-trailing-comment: false
1923-
1924-
# Can be set to force trailing newlines at the end of case blocks to improve readability.
1925-
# If the number of lines (including comments) in a case block exceeds this number
1926-
# a linter error will be yielded if the case does not end with a newline.
1927-
# Default: 0
1911+
1912+
# If the number of lines in a case block is equal to or lager than this
1913+
# number, the case *must* end white a newline.
19281914
force-case-trailing-whitespace: 0
1929-
1930-
# Enforces that an `if` statement checking an error variable is cuddled
1931-
# with the line that assigned that error variable.
1932-
# Default: false
1933-
force-err-cuddling: false
1934-
1935-
# Enforces that an assignment which is actually a short declaration (using `:=`)
1936-
# is only allowed to cuddle with other short declarations, and not plain assignments, blocks, etc.
1937-
# This rule helps make declarations stand out by themselves, much the same as grouping var statement.
1938-
# Default: false
1915+
1916+
# Allow blocks to end with comments.
1917+
allow-trailing-comment: false
1918+
1919+
# Allow multiple comments in the beginning of a block separated with newline.
1920+
allow-separated-leading-comment: false
1921+
1922+
# Allow multiple var/declaration statements to be cuddled.
1923+
allow-cuddle-declarations: false
1924+
1925+
# Aa list of call idents that everything can be cuddled with.
1926+
# Defaults to calls looking like locks.
1927+
allow-cuddle-with-calls: [ "Lock", "RLock" ]
1928+
1929+
# AllowCuddleWithRHS is a list of right hand side variables that is allowed
1930+
# to be cuddled with anything. Defaults to assignments or calls looking
1931+
# like unlocks.
1932+
allow-cuddle-with-rhs: [ "Unlock", "RUnlock" ]
1933+
1934+
# Causes an error when an If statement that checks an error variable doesn't
1935+
# cuddle with the assignment of that variable.
1936+
enforce-err-cuddling: false
1937+
1938+
# When enforce-err-cuddling is enabled this is a list of names
1939+
# used for error variables to check for in the conditional.
1940+
error-variable-names: [ "err" ]
1941+
1942+
# Causes an error if a short declaration (:=) cuddles with anything other than
1943+
# another short declaration.
1944+
# This logic overrides enforce-err-cuddling among others.
19391945
force-short-decl-cuddling: false
19401946

1941-
# Controls if the checks for slice append should be "strict"
1942-
# in the sense that it will only allow these assignments to be cuddled with variables being appended.
1943-
# Default: true
1944-
strict-append: true
1945-
19461947
# The custom section can be used to define linter plugins to be loaded at runtime.
19471948
# See README documentation for more info.
19481949
custom:
@@ -2317,5 +2318,5 @@ severity:
23172318
# Default: []
23182319
rules:
23192320
- linters:
2320-
- dupl
2321+
- dupl
23212322
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)