wsl: support all configs and update docs (#3202)
This commit is contained in:
		
							parent
							
								
									8f00a10ad7
								
							
						
					
					
						commit
						b1cec4755f
					
				| @ -701,11 +701,11 @@ linters-settings: | |||||||
|       # List of allowed modules. |       # List of allowed modules. | ||||||
|       # Default: [] |       # Default: [] | ||||||
|       modules: |       modules: | ||||||
|          - gopkg.in/yaml.v2 |         - gopkg.in/yaml.v2 | ||||||
|       # List of allowed module domains. |       # List of allowed module domains. | ||||||
|       # Default: [] |       # Default: [] | ||||||
|       domains: |       domains: | ||||||
|          - golang.org |         - golang.org | ||||||
|     blocked: |     blocked: | ||||||
|       # List of blocked modules. |       # List of blocked modules. | ||||||
|       # Default: [] |       # Default: [] | ||||||
| @ -1261,21 +1261,21 @@ linters-settings: | |||||||
|     # Please refer to https://github.com/yeya24/promlinter#usage for detailed usage. |     # Please refer to https://github.com/yeya24/promlinter#usage for detailed usage. | ||||||
|     # Default: [] |     # Default: [] | ||||||
|     disabled-linters: |     disabled-linters: | ||||||
|      - Help |       - Help | ||||||
|      - MetricUnits |       - MetricUnits | ||||||
|      - Counter |       - Counter | ||||||
|      - HistogramSummaryReserved |       - HistogramSummaryReserved | ||||||
|      - MetricTypeInName |       - MetricTypeInName | ||||||
|      - ReservedChars |       - ReservedChars | ||||||
|      - CamelCase |       - CamelCase | ||||||
|      - UnitAbbreviations |       - UnitAbbreviations | ||||||
| 
 | 
 | ||||||
|   reassign: |   reassign: | ||||||
|     # Patterns for global variable names that are checked for reassignment. |     # Patterns for global variable names that are checked for reassignment. | ||||||
|     # See https://github.com/curioswitch/go-reassign#usage |     # See https://github.com/curioswitch/go-reassign#usage | ||||||
|     # Default: ["EOF", "Err.*"] |     # Default: ["EOF", "Err.*"] | ||||||
|     patterns: |     patterns: | ||||||
|      - ".*" |       - ".*" | ||||||
| 
 | 
 | ||||||
|   revive: |   revive: | ||||||
|     # Maximum number of open files at the same time. |     # Maximum number of open files at the same time. | ||||||
| @ -1316,7 +1316,7 @@ linters-settings: | |||||||
|       - name: argument-limit |       - name: argument-limit | ||||||
|         severity: warning |         severity: warning | ||||||
|         disabled: false |         disabled: false | ||||||
|         arguments: [4] |         arguments: [ 4 ] | ||||||
|       # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#atomic |       # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#atomic | ||||||
|       - name: atomic |       - name: atomic | ||||||
|         severity: warning |         severity: warning | ||||||
| @ -1325,7 +1325,7 @@ linters-settings: | |||||||
|       - name: banned-characters |       - name: banned-characters | ||||||
|         severity: warning |         severity: warning | ||||||
|         disabled: false |         disabled: false | ||||||
|         arguments: ["Ω","Σ","σ", "7"] |         arguments: [ "Ω","Σ","σ", "7" ] | ||||||
|       # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bare-return |       # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bare-return | ||||||
|       - name: bare-return |       - name: bare-return | ||||||
|         severity: warning |         severity: warning | ||||||
| @ -1427,8 +1427,8 @@ linters-settings: | |||||||
|         severity: warning |         severity: warning | ||||||
|         disabled: false |         disabled: false | ||||||
|         arguments: |         arguments: | ||||||
|         - "checkPrivateReceivers" |           - "checkPrivateReceivers" | ||||||
|         - "sayRepetitiveInsteadOfStutters" |           - "sayRepetitiveInsteadOfStutters" | ||||||
|       # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#file-header |       # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#file-header | ||||||
|       - name: file-header |       - name: file-header | ||||||
|         severity: warning |         severity: warning | ||||||
| @ -1569,8 +1569,8 @@ linters-settings: | |||||||
|         severity: warning |         severity: warning | ||||||
|         disabled: false |         disabled: false | ||||||
|         arguments: |         arguments: | ||||||
|         - [ "ID" ] # AllowList |           - [ "ID" ] # AllowList | ||||||
|         - [ "VM" ] # DenyList |           - [ "VM" ] # DenyList | ||||||
|       # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-declaration |       # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-declaration | ||||||
|       - name: var-declaration |       - name: var-declaration | ||||||
|         severity: warning |         severity: warning | ||||||
| @ -1868,55 +1868,56 @@ linters-settings: | |||||||
|     # See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for documentation of available settings. |     # See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for documentation of available settings. | ||||||
|     # These are the defaults for `golangci-lint`. |     # These are the defaults for `golangci-lint`. | ||||||
| 
 | 
 | ||||||
|     # Controls if you may cuddle assignments and anything without needing an empty line between them. |     # Do strict checking when assigning from append (x = append(x, y)). If | ||||||
|     # Default: false |     # this is set to true - the append call must append either a variable | ||||||
|     allow-assign-and-anything: false |     # assigned, called or used on the line above. | ||||||
| 
 |  | ||||||
|     # Controls if you may cuddle assignments and calls without needing an empty line between them. |  | ||||||
|     # Default: true |  | ||||||
|     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 |  | ||||||
| 
 |  | ||||||
|     # Controls if you may cuddle assignments even if they span over multiple lines. |  | ||||||
|     # Default: true |  | ||||||
|     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 |  | ||||||
|     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 |  | ||||||
| 
 |  | ||||||
|     # 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 |  | ||||||
|     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 |     strict-append: 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 | ||||||
|  |      | ||||||
|  |     # Allows assignments to be cuddled with anything. | ||||||
|  |     allow-assign-and-anything: false | ||||||
|  |      | ||||||
|  |     # Allows cuddling to assignments even if they span over multiple lines. | ||||||
|  |     allow-multiline-assign: true | ||||||
|  |      | ||||||
|  |     # 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 | ||||||
|  |      | ||||||
|  |     # Allow blocks to end with comments. | ||||||
|  |     allow-trailing-comment: 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 | ||||||
| 
 | 
 | ||||||
|   # The custom section can be used to define linter plugins to be loaded at runtime. |   # The custom section can be used to define linter plugins to be loaded at runtime. | ||||||
|   # See README documentation for more info. |   # See README documentation for more info. | ||||||
| @ -2292,5 +2293,5 @@ severity: | |||||||
|   # Default: [] |   # Default: [] | ||||||
|   rules: |   rules: | ||||||
|     - linters: |     - linters: | ||||||
|       - dupl |         - dupl | ||||||
|       severity: info |       severity: info | ||||||
|  | |||||||
| @ -120,12 +120,15 @@ var defaultLintersSettings = LintersSettings{ | |||||||
| 		AllowAssignAndCallCuddle:         true, | 		AllowAssignAndCallCuddle:         true, | ||||||
| 		AllowAssignAndAnythingCuddle:     false, | 		AllowAssignAndAnythingCuddle:     false, | ||||||
| 		AllowMultiLineAssignCuddle:       true, | 		AllowMultiLineAssignCuddle:       true, | ||||||
| 		AllowCuddleDeclaration:           false, | 		ForceCaseTrailingWhitespaceLimit: 0, | ||||||
| 		AllowTrailingComment:             false, | 		AllowTrailingComment:             false, | ||||||
| 		AllowSeparatedLeadingComment:     false, | 		AllowSeparatedLeadingComment:     false, | ||||||
|  | 		AllowCuddleDeclaration:           false, | ||||||
|  | 		AllowCuddleWithCalls:             []string{"Lock", "RLock"}, | ||||||
|  | 		AllowCuddleWithRHS:               []string{"Unlock", "RUnlock"}, | ||||||
| 		ForceCuddleErrCheckAndAssign:     false, | 		ForceCuddleErrCheckAndAssign:     false, | ||||||
|  | 		ErrorVariableNames:               []string{"err"}, | ||||||
| 		ForceExclusiveShortDeclarations:  false, | 		ForceExclusiveShortDeclarations:  false, | ||||||
| 		ForceCaseTrailingWhitespaceLimit: 0, |  | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -693,16 +696,19 @@ type WrapcheckSettings struct { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type WSLSettings struct { | type WSLSettings struct { | ||||||
| 	StrictAppend                     bool `mapstructure:"strict-append"` | 	StrictAppend                     bool     `mapstructure:"strict-append"` | ||||||
| 	AllowAssignAndCallCuddle         bool `mapstructure:"allow-assign-and-call"` | 	AllowAssignAndCallCuddle         bool     `mapstructure:"allow-assign-and-call"` | ||||||
| 	AllowAssignAndAnythingCuddle     bool `mapstructure:"allow-assign-and-anything"` | 	AllowAssignAndAnythingCuddle     bool     `mapstructure:"allow-assign-and-anything"` | ||||||
| 	AllowMultiLineAssignCuddle       bool `mapstructure:"allow-multiline-assign"` | 	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"` | 	AllowTrailingComment             bool     `mapstructure:"allow-trailing-comment"` | ||||||
| 	AllowSeparatedLeadingComment     bool `mapstructure:"allow-separated-leading-comment"` | 	AllowSeparatedLeadingComment     bool     `mapstructure:"allow-separated-leading-comment"` | ||||||
| 	ForceCuddleErrCheckAndAssign     bool `mapstructure:"force-err-cuddling"` | 	AllowCuddleDeclaration           bool     `mapstructure:"allow-cuddle-declarations"` | ||||||
| 	ForceExclusiveShortDeclarations  bool `mapstructure:"force-short-decl-cuddling"` | 	AllowCuddleWithCalls             []string `mapstructure:"allow-cuddle-with-calls"` | ||||||
| 	ForceCaseTrailingWhitespaceLimit int  `mapstructure:"force-case-trailing-whitespace"` | 	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"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // CustomLinterSettings encapsulates the meta-data of a private linter. | // 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 mu sync.Mutex | ||||||
| 	var resIssues []goanalysis.Issue | 	var resIssues []goanalysis.Issue | ||||||
| 
 | 
 | ||||||
| 	conf := &wsl.Configuration{ | 	conf := wsl.DefaultConfig() | ||||||
| 		AllowCuddleWithCalls: []string{"Lock", "RLock"}, |  | ||||||
| 		AllowCuddleWithRHS:   []string{"Unlock", "RUnlock"}, |  | ||||||
| 		ErrorVariableNames:   []string{"err"}, |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	if settings != nil { | 	if settings != nil { | ||||||
| 		conf.StrictAppend = settings.StrictAppend | 		conf.StrictAppend = settings.StrictAppend | ||||||
| 		conf.AllowAssignAndCallCuddle = settings.AllowAssignAndCallCuddle | 		conf.AllowAssignAndCallCuddle = settings.AllowAssignAndCallCuddle | ||||||
| 		conf.AllowAssignAndAnythingCuddle = settings.AllowAssignAndAnythingCuddle | 		conf.AllowAssignAndAnythingCuddle = settings.AllowAssignAndAnythingCuddle | ||||||
| 		conf.AllowMultiLineAssignCuddle = settings.AllowMultiLineAssignCuddle | 		conf.AllowMultiLineAssignCuddle = settings.AllowMultiLineAssignCuddle | ||||||
| 		conf.AllowCuddleDeclaration = settings.AllowCuddleDeclaration | 		conf.ForceCaseTrailingWhitespaceLimit = settings.ForceCaseTrailingWhitespaceLimit | ||||||
| 		conf.AllowTrailingComment = settings.AllowTrailingComment | 		conf.AllowTrailingComment = settings.AllowTrailingComment | ||||||
| 		conf.AllowSeparatedLeadingComment = settings.AllowSeparatedLeadingComment | 		conf.AllowSeparatedLeadingComment = settings.AllowSeparatedLeadingComment | ||||||
| 		conf.ForceCuddleErrCheckAndAssign = settings.ForceCuddleErrCheckAndAssign | 		conf.AllowCuddleDeclaration = settings.AllowCuddleDeclaration | ||||||
| 		conf.ForceCaseTrailingWhitespaceLimit = settings.ForceCaseTrailingWhitespaceLimit | 		conf.AllowCuddleWithCalls = settings.AllowCuddleWithCalls | ||||||
| 		conf.ForceExclusiveShortDeclarations = settings.ForceExclusiveShortDeclarations | 		conf.AllowCuddleWithRHS = settings.AllowCuddleWithRHS | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	analyzer := &analysis.Analyzer{ | 	analyzer := &analysis.Analyzer{ | ||||||
| 		Name: goanalysis.TheOnlyAnalyzerName, | 		Name: goanalysis.TheOnlyAnalyzerName, | ||||||
| 		Doc:  goanalysis.TheOnlyanalyzerDoc, | 		Doc:  goanalysis.TheOnlyanalyzerDoc, | ||||||
| 		Run: func(pass *analysis.Pass) (interface{}, error) { | 		Run: func(pass *analysis.Pass) (interface{}, error) { | ||||||
| 			issues := runWSL(pass, conf) | 			issues := runWSL(pass, &conf) | ||||||
| 
 | 
 | ||||||
| 			if len(issues) == 0 { | 			if len(issues) == 0 { | ||||||
| 				return nil, nil | 				return nil, nil | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Anton Zinovyev
						Anton Zinovyev