wsl: support all configs and update docs (#3202)
This commit is contained in:
		
							parent
							
								
									8f00a10ad7
								
							
						
					
					
						commit
						b1cec4755f
					
				| @ -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 | ||||||
| @ -1868,56 +1868,57 @@ 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. | ||||||
|  |     strict-append: true | ||||||
|      |      | ||||||
|     # Controls if you may cuddle assignments and calls without needing an empty line between them. |     # Allows assignments to be cuddled with variables used in calls on | ||||||
|     # Default: true |     # line above and calls to be cuddled with assignments of variables | ||||||
|  |     # used in call on line above. | ||||||
|     allow-assign-and-call: true |     allow-assign-and-call: true | ||||||
|      |      | ||||||
|     # Controls if you're allowed to cuddle multiple declarations. |     # Allows assignments to be cuddled with anything. | ||||||
|     # This is false by default to encourage you to group them in one var block. |     allow-assign-and-anything: false | ||||||
|     # 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. |     # Allows cuddling to assignments even if they span over multiple lines. | ||||||
|     # Default: true |  | ||||||
|     allow-multiline-assign: true |     allow-multiline-assign: true | ||||||
|      |      | ||||||
|     # This option allows whitespace after each comment group that begins a block. |     # If the number of lines in a case block is equal to or lager than this | ||||||
|     # Default: false |     # number, the case *must* end white a newline. | ||||||
|     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 |     force-case-trailing-whitespace: 0 | ||||||
|      |      | ||||||
|     # Enforces that an `if` statement checking an error variable is cuddled |     # Allow blocks to end with comments. | ||||||
|     # with the line that assigned that error variable. |     allow-trailing-comment: false | ||||||
|     # Default: false |  | ||||||
|     force-err-cuddling: false |  | ||||||
|      |      | ||||||
|     # Enforces that an assignment which is actually a short declaration (using `:=`) |     # Allow multiple comments in the beginning of a block separated with newline. | ||||||
|     # is only allowed to cuddle with other short declarations, and not plain assignments, blocks, etc. |     allow-separated-leading-comment: false | ||||||
|     # This rule helps make declarations stand out by themselves, much the same as grouping var statement. |      | ||||||
|     # Default: 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 |     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. |   # 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. | ||||||
|   custom: |   custom: | ||||||
|  | |||||||
| @ -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, |  | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -697,12 +700,15 @@ type WSLSettings struct { | |||||||
| 	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"` | ||||||
|  | 	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"` | 	ForceExclusiveShortDeclarations  bool     `mapstructure:"force-short-decl-cuddling"` | ||||||
| 	ForceCaseTrailingWhitespaceLimit int  `mapstructure:"force-case-trailing-whitespace"` |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // 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