wsl: support all configs and update docs (#3202)
This commit is contained in:
parent
8f00a10ad7
commit
b1cec4755f
@ -1868,56 +1868,57 @@ linters-settings:
|
||||
# See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for documentation of available settings.
|
||||
# These are the defaults for `golangci-lint`.
|
||||
|
||||
# Controls if you may cuddle assignments and anything without needing an empty line between them.
|
||||
# Default: false
|
||||
allow-assign-and-anything: false
|
||||
# Do strict checking when assigning from append (x = append(x, y)). If
|
||||
# this is set to true - the append call must append either a variable
|
||||
# assigned, called or used on the line above.
|
||||
strict-append: true
|
||||
|
||||
# Controls if you may cuddle assignments and calls without needing an empty line between them.
|
||||
# Default: true
|
||||
# Allows assignments to be cuddled with variables used in calls on
|
||||
# line above and calls to be cuddled with assignments of variables
|
||||
# used in call on line above.
|
||||
allow-assign-and-call: true
|
||||
|
||||
# Controls if you're allowed to cuddle multiple declarations.
|
||||
# This is false by default to encourage you to group them in one var block.
|
||||
# One major benefit with this is that if the variables are assigned the assignments will be tabulated.
|
||||
# Default: false
|
||||
allow-cuddle-declarations: false
|
||||
# Allows assignments to be cuddled with anything.
|
||||
allow-assign-and-anything: false
|
||||
|
||||
# Controls if you may cuddle assignments even if they span over multiple lines.
|
||||
# Default: true
|
||||
# Allows cuddling to assignments even if they span over multiple lines.
|
||||
allow-multiline-assign: true
|
||||
|
||||
# This option allows whitespace after each comment group that begins a block.
|
||||
# Default: false
|
||||
allow-separated-leading-comment: false
|
||||
|
||||
# Controls if blocks can end with comments.
|
||||
# This is not encouraged sine it's usually code smell but might be useful do improve understanding or learning purposes.
|
||||
# To be allowed there must be no whitespace between the comment and the last statement or the comment and the closing brace.
|
||||
# Default: false
|
||||
allow-trailing-comment: false
|
||||
|
||||
# Can be set to force trailing newlines at the end of case blocks to improve readability.
|
||||
# If the number of lines (including comments) in a case block exceeds this number
|
||||
# a linter error will be yielded if the case does not end with a newline.
|
||||
# Default: 0
|
||||
# If the number of lines in a case block is equal to or lager than this
|
||||
# number, the case *must* end white a newline.
|
||||
force-case-trailing-whitespace: 0
|
||||
|
||||
# Enforces that an `if` statement checking an error variable is cuddled
|
||||
# with the line that assigned that error variable.
|
||||
# Default: false
|
||||
force-err-cuddling: false
|
||||
# Allow blocks to end with comments.
|
||||
allow-trailing-comment: false
|
||||
|
||||
# Enforces that an assignment which is actually a short declaration (using `:=`)
|
||||
# is only allowed to cuddle with other short declarations, and not plain assignments, blocks, etc.
|
||||
# This rule helps make declarations stand out by themselves, much the same as grouping var statement.
|
||||
# Default: false
|
||||
# Allow multiple comments in the beginning of a block separated with newline.
|
||||
allow-separated-leading-comment: false
|
||||
|
||||
# Allow multiple var/declaration statements to be cuddled.
|
||||
allow-cuddle-declarations: false
|
||||
|
||||
# Aa list of call idents that everything can be cuddled with.
|
||||
# Defaults to calls looking like locks.
|
||||
allow-cuddle-with-calls: [ "Lock", "RLock" ]
|
||||
|
||||
# AllowCuddleWithRHS is a list of right hand side variables that is allowed
|
||||
# to be cuddled with anything. Defaults to assignments or calls looking
|
||||
# like unlocks.
|
||||
allow-cuddle-with-rhs: [ "Unlock", "RUnlock" ]
|
||||
|
||||
# Causes an error when an If statement that checks an error variable doesn't
|
||||
# cuddle with the assignment of that variable.
|
||||
enforce-err-cuddling: false
|
||||
|
||||
# When enforce-err-cuddling is enabled this is a list of names
|
||||
# used for error variables to check for in the conditional.
|
||||
error-variable-names: [ "err" ]
|
||||
|
||||
# Causes an error if a short declaration (:=) cuddles with anything other than
|
||||
# another short declaration.
|
||||
# This logic overrides enforce-err-cuddling among others.
|
||||
force-short-decl-cuddling: false
|
||||
|
||||
# Controls if the checks for slice append should be "strict"
|
||||
# in the sense that it will only allow these assignments to be cuddled with variables being appended.
|
||||
# Default: true
|
||||
strict-append: true
|
||||
|
||||
# The custom section can be used to define linter plugins to be loaded at runtime.
|
||||
# See README documentation for more info.
|
||||
custom:
|
||||
|
@ -120,12 +120,15 @@ var defaultLintersSettings = LintersSettings{
|
||||
AllowAssignAndCallCuddle: true,
|
||||
AllowAssignAndAnythingCuddle: false,
|
||||
AllowMultiLineAssignCuddle: true,
|
||||
AllowCuddleDeclaration: false,
|
||||
ForceCaseTrailingWhitespaceLimit: 0,
|
||||
AllowTrailingComment: false,
|
||||
AllowSeparatedLeadingComment: false,
|
||||
AllowCuddleDeclaration: false,
|
||||
AllowCuddleWithCalls: []string{"Lock", "RLock"},
|
||||
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
|
||||
ForceCuddleErrCheckAndAssign: false,
|
||||
ErrorVariableNames: []string{"err"},
|
||||
ForceExclusiveShortDeclarations: false,
|
||||
ForceCaseTrailingWhitespaceLimit: 0,
|
||||
},
|
||||
}
|
||||
|
||||
@ -697,12 +700,15 @@ type WSLSettings struct {
|
||||
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
|
||||
AllowAssignAndAnythingCuddle bool `mapstructure:"allow-assign-and-anything"`
|
||||
AllowMultiLineAssignCuddle bool `mapstructure:"allow-multiline-assign"`
|
||||
AllowCuddleDeclaration bool `mapstructure:"allow-cuddle-declarations"`
|
||||
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
|
||||
AllowTrailingComment bool `mapstructure:"allow-trailing-comment"`
|
||||
AllowSeparatedLeadingComment bool `mapstructure:"allow-separated-leading-comment"`
|
||||
ForceCuddleErrCheckAndAssign bool `mapstructure:"force-err-cuddling"`
|
||||
AllowCuddleDeclaration bool `mapstructure:"allow-cuddle-declarations"`
|
||||
AllowCuddleWithCalls []string `mapstructure:"allow-cuddle-with-calls"`
|
||||
AllowCuddleWithRHS []string `mapstructure:"allow-cuddle-with-rhs"`
|
||||
ForceCuddleErrCheckAndAssign bool `mapstructure:"enforce-err-cuddling"`
|
||||
ErrorVariableNames []string `mapstructure:"error-variable-names"`
|
||||
ForceExclusiveShortDeclarations bool `mapstructure:"force-short-decl-cuddling"`
|
||||
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
|
||||
}
|
||||
|
||||
// CustomLinterSettings encapsulates the meta-data of a private linter.
|
||||
|
@ -19,30 +19,26 @@ func NewWSL(settings *config.WSLSettings) *goanalysis.Linter {
|
||||
var mu sync.Mutex
|
||||
var resIssues []goanalysis.Issue
|
||||
|
||||
conf := &wsl.Configuration{
|
||||
AllowCuddleWithCalls: []string{"Lock", "RLock"},
|
||||
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
|
||||
ErrorVariableNames: []string{"err"},
|
||||
}
|
||||
conf := wsl.DefaultConfig()
|
||||
|
||||
if settings != nil {
|
||||
conf.StrictAppend = settings.StrictAppend
|
||||
conf.AllowAssignAndCallCuddle = settings.AllowAssignAndCallCuddle
|
||||
conf.AllowAssignAndAnythingCuddle = settings.AllowAssignAndAnythingCuddle
|
||||
conf.AllowMultiLineAssignCuddle = settings.AllowMultiLineAssignCuddle
|
||||
conf.AllowCuddleDeclaration = settings.AllowCuddleDeclaration
|
||||
conf.ForceCaseTrailingWhitespaceLimit = settings.ForceCaseTrailingWhitespaceLimit
|
||||
conf.AllowTrailingComment = settings.AllowTrailingComment
|
||||
conf.AllowSeparatedLeadingComment = settings.AllowSeparatedLeadingComment
|
||||
conf.ForceCuddleErrCheckAndAssign = settings.ForceCuddleErrCheckAndAssign
|
||||
conf.ForceCaseTrailingWhitespaceLimit = settings.ForceCaseTrailingWhitespaceLimit
|
||||
conf.ForceExclusiveShortDeclarations = settings.ForceExclusiveShortDeclarations
|
||||
conf.AllowCuddleDeclaration = settings.AllowCuddleDeclaration
|
||||
conf.AllowCuddleWithCalls = settings.AllowCuddleWithCalls
|
||||
conf.AllowCuddleWithRHS = settings.AllowCuddleWithRHS
|
||||
}
|
||||
|
||||
analyzer := &analysis.Analyzer{
|
||||
Name: goanalysis.TheOnlyAnalyzerName,
|
||||
Doc: goanalysis.TheOnlyanalyzerDoc,
|
||||
Run: func(pass *analysis.Pass) (interface{}, error) {
|
||||
issues := runWSL(pass, conf)
|
||||
issues := runWSL(pass, &conf)
|
||||
|
||||
if len(issues) == 0 {
|
||||
return nil, nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user