From 63a0088380b7677e4cdeeb65b0898c1893dee68a Mon Sep 17 00:00:00 2001 From: Marcin Federowicz Date: Sun, 17 Nov 2024 15:30:09 +0100 Subject: [PATCH] replace configureErr with local variable --- rule/add_constant.go | 9 ++++----- rule/argument_limit.go | 9 ++++----- rule/banned_characters.go | 12 +++++------- rule/cognitive_complexity.go | 10 ++++------ rule/comment_spacings.go | 12 +++++------- rule/comments_density.go | 13 +++++-------- rule/context_as_argument.go | 10 ++++------ rule/cyclomatic.go | 10 ++++------ rule/defer.go | 11 ++++------- rule/dot_imports.go | 10 ++++------ rule/enforce_map_style.go | 12 +++++------- rule/enforce_repeated_arg_type_style.go | 13 +++++-------- rule/enforce_slice_style.go | 12 +++++------- rule/error_strings.go | 11 ++++------- rule/exported.go | 12 +++++------- rule/file_header.go | 12 +++++------- rule/file_length_limit.go | 12 +++++------- rule/filename_format.go | 12 +++++------- rule/function_length.go | 14 ++++++-------- rule/function_result_limit.go | 12 +++++------- rule/import_alias_naming.go | 14 ++++++-------- rule/imports_blocklist.go | 12 +++++------- rule/line_length_limit.go | 9 ++++----- rule/max_control_nesting.go | 12 +++++------- rule/max_public_structs.go | 9 ++++----- rule/receiver_naming.go | 12 +++++------- rule/struct_tag.go | 12 +++++------- rule/unchecked_type_assertion.go | 12 +++++------- rule/unhandled_error.go | 12 +++++------- rule/unused_param.go | 14 ++++++-------- rule/unused_receiver.go | 14 ++++++-------- rule/var_naming.go | 12 +++++------- 32 files changed, 154 insertions(+), 218 deletions(-) diff --git a/rule/add_constant.go b/rule/add_constant.go index 7116ff323..a469438c3 100644 --- a/rule/add_constant.go +++ b/rule/add_constant.go @@ -38,16 +38,15 @@ type AddConstantRule struct { allowList allowList ignoreFunctions []*regexp.Regexp strLitLimit int - configureErr error configureOnce sync.Once } // Apply applies the rule to given file. func (r *AddConstantRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/argument_limit.go b/rule/argument_limit.go index d86eb7409..f2c105a93 100644 --- a/rule/argument_limit.go +++ b/rule/argument_limit.go @@ -13,7 +13,6 @@ import ( // ArgumentsLimitRule lints given else constructs. type ArgumentsLimitRule struct { max int - configureErr error configureOnce sync.Once } @@ -35,10 +34,10 @@ func (r *ArgumentsLimitRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/banned_characters.go b/rule/banned_characters.go index 3d7885a85..15c79ff3e 100644 --- a/rule/banned_characters.go +++ b/rule/banned_characters.go @@ -13,9 +13,7 @@ import ( // BannedCharsRule checks if a file contains banned characters. type BannedCharsRule struct { bannedCharList []string - - configureErr error - configureOnce sync.Once + configureOnce sync.Once } const bannedCharsRuleName = "banned-characters" @@ -38,10 +36,10 @@ func (r *BannedCharsRule) configure(arguments lint.Arguments) error { // Apply applied the rule to the given file. func (r *BannedCharsRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/cognitive_complexity.go b/rule/cognitive_complexity.go index a27d78c1a..c6151a599 100644 --- a/rule/cognitive_complexity.go +++ b/rule/cognitive_complexity.go @@ -14,8 +14,6 @@ import ( // CognitiveComplexityRule lints given else constructs. type CognitiveComplexityRule struct { maxComplexity int - - configureErr error configureOnce sync.Once } @@ -38,10 +36,10 @@ func (r *CognitiveComplexityRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *CognitiveComplexityRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/comment_spacings.go b/rule/comment_spacings.go index 0209c399f..7265be360 100644 --- a/rule/comment_spacings.go +++ b/rule/comment_spacings.go @@ -12,9 +12,7 @@ import ( // CommentSpacingsRule check the whether there is a space between // the comment symbol( // ) and the start of the comment text type CommentSpacingsRule struct { - allowList []string - - configureErr error + allowList []string configureOnce sync.Once } @@ -32,10 +30,10 @@ func (r *CommentSpacingsRule) configure(arguments lint.Arguments) error { // Apply the rule. func (r *CommentSpacingsRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/comments_density.go b/rule/comments_density.go index 7cae10858..e177268b8 100644 --- a/rule/comments_density.go +++ b/rule/comments_density.go @@ -13,9 +13,7 @@ import ( // CommentsDensityRule lints given else constructs. type CommentsDensityRule struct { minimumCommentsDensity int64 - - configureErr error - configureOnce sync.Once + configureOnce sync.Once } const defaultMinimumCommentsPercentage = 0 @@ -36,12 +34,11 @@ func (r *CommentsDensityRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *CommentsDensityRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } - commentsLines := countDocLines(file.AST.Comments) statementsCount := countStatements(file.AST) density := (float32(commentsLines) / float32(statementsCount+commentsLines)) * 100 diff --git a/rule/context_as_argument.go b/rule/context_as_argument.go index ecc100790..105442748 100644 --- a/rule/context_as_argument.go +++ b/rule/context_as_argument.go @@ -13,17 +13,15 @@ import ( // ContextAsArgumentRule lints given else constructs. type ContextAsArgumentRule struct { allowTypesLUT map[string]struct{} - - configureErr error configureOnce sync.Once } // Apply applies the rule to given file. func (r *ContextAsArgumentRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/cyclomatic.go b/rule/cyclomatic.go index 33f7769dd..9cdf7e996 100644 --- a/rule/cyclomatic.go +++ b/rule/cyclomatic.go @@ -15,8 +15,6 @@ import ( // CyclomaticRule lints given else constructs. type CyclomaticRule struct { maxComplexity int - - configureErr error configureOnce sync.Once } @@ -38,10 +36,10 @@ func (r *CyclomaticRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *CyclomaticRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/defer.go b/rule/defer.go index c4d841aaa..3caed5309 100644 --- a/rule/defer.go +++ b/rule/defer.go @@ -12,8 +12,6 @@ import ( // DeferRule lints unused params in functions. type DeferRule struct { allow map[string]bool - - configureErr error configureOnce sync.Once } @@ -28,12 +26,11 @@ func (r *DeferRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *DeferRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } - var failures []lint.Failure onFailure := func(failure lint.Failure) { failures = append(failures, failure) diff --git a/rule/dot_imports.go b/rule/dot_imports.go index 1a939da17..468cf7f3b 100644 --- a/rule/dot_imports.go +++ b/rule/dot_imports.go @@ -12,17 +12,15 @@ import ( // DotImportsRule lints given else constructs. type DotImportsRule struct { allowedPackages allowPackages - - configureErr error configureOnce sync.Once } // Apply applies the rule to given file. func (r *DotImportsRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/enforce_map_style.go b/rule/enforce_map_style.go index 3e6816ebc..c37289925 100644 --- a/rule/enforce_map_style.go +++ b/rule/enforce_map_style.go @@ -41,9 +41,7 @@ func mapStyleFromString(s string) (enforceMapStyleType, error) { // EnforceMapStyleRule implements a rule to enforce `make(map[type]type)` over `map[type]type{}`. type EnforceMapStyleRule struct { enforceMapStyle enforceMapStyleType - - configureErr error - configureOnce sync.Once + configureOnce sync.Once } func (r *EnforceMapStyleRule) configure(arguments lint.Arguments) error { @@ -68,10 +66,10 @@ func (r *EnforceMapStyleRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *EnforceMapStyleRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } if r.enforceMapStyle == enforceMapStyleTypeAny { diff --git a/rule/enforce_repeated_arg_type_style.go b/rule/enforce_repeated_arg_type_style.go index 57fbe5dc3..983629aa4 100644 --- a/rule/enforce_repeated_arg_type_style.go +++ b/rule/enforce_repeated_arg_type_style.go @@ -44,9 +44,7 @@ func repeatedArgTypeStyleFromString(s string) (enforceRepeatedArgTypeStyleType, type EnforceRepeatedArgTypeStyleRule struct { funcArgStyle enforceRepeatedArgTypeStyleType funcRetValStyle enforceRepeatedArgTypeStyleType - - configureErr error - configureOnce sync.Once + configureOnce sync.Once } func (r *EnforceRepeatedArgTypeStyleRule) configure(arguments lint.Arguments) error { @@ -104,12 +102,11 @@ func (r *EnforceRepeatedArgTypeStyleRule) configure(arguments lint.Arguments) er // Apply applies the rule to a given file. func (r *EnforceRepeatedArgTypeStyleRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } - if r.funcArgStyle == enforceRepeatedArgTypeStyleTypeAny && r.funcRetValStyle == enforceRepeatedArgTypeStyleTypeAny { // This linter is not configured, return no failures. return nil, nil diff --git a/rule/enforce_slice_style.go b/rule/enforce_slice_style.go index 8180116bc..04d44ab39 100644 --- a/rule/enforce_slice_style.go +++ b/rule/enforce_slice_style.go @@ -45,9 +45,7 @@ func sliceStyleFromString(s string) (enforceSliceStyleType, error) { // EnforceSliceStyleRule implements a rule to enforce `make([]type)` over `[]type{}`. type EnforceSliceStyleRule struct { enforceSliceStyle enforceSliceStyleType - - configureErr error - configureOnce sync.Once + configureOnce sync.Once } func (r *EnforceSliceStyleRule) configure(arguments lint.Arguments) error { @@ -71,10 +69,10 @@ func (r *EnforceSliceStyleRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *EnforceSliceStyleRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } if r.enforceSliceStyle == enforceSliceStyleTypeAny { diff --git a/rule/error_strings.go b/rule/error_strings.go index 5b568fc56..6c0074710 100644 --- a/rule/error_strings.go +++ b/rule/error_strings.go @@ -17,8 +17,6 @@ import ( // ErrorStringsRule lints given else constructs. type ErrorStringsRule struct { errorFunctions map[string]map[string]struct{} - - configureErr error configureOnce sync.Once } @@ -57,11 +55,10 @@ func (r *ErrorStringsRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *ErrorStringsRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { var failures []lint.Failure - - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } fileAst := file.AST diff --git a/rule/exported.go b/rule/exported.go index f188d7a93..c50e6d683 100644 --- a/rule/exported.go +++ b/rule/exported.go @@ -58,9 +58,7 @@ func (dc *disabledChecks) isDisabled(checkName string) bool { type ExportedRule struct { stuttersMsg string disabledChecks disabledChecks - - configureErr error - configureOnce sync.Once + configureOnce sync.Once } func (r *ExportedRule) configure(arguments lint.Arguments) error { @@ -101,10 +99,10 @@ func (r *ExportedRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *ExportedRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/file_header.go b/rule/file_header.go index de8fc7408..b0051b98c 100644 --- a/rule/file_header.go +++ b/rule/file_header.go @@ -11,9 +11,7 @@ import ( // FileHeaderRule lints given else constructs. type FileHeaderRule struct { - header string - - configureErr error + header string configureOnce sync.Once } @@ -37,10 +35,10 @@ func (r *FileHeaderRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *FileHeaderRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } if r.header == "" { diff --git a/rule/file_length_limit.go b/rule/file_length_limit.go index b2f71fd60..ed949c88c 100644 --- a/rule/file_length_limit.go +++ b/rule/file_length_limit.go @@ -21,17 +21,15 @@ type FileLengthLimitRule struct { skipComments bool // skipBlankLines indicates whether to skip blank lines when counting lines. skipBlankLines bool - - configureErr error - configureOnce sync.Once + configureOnce sync.Once } // Apply applies the rule to given file. func (r *FileLengthLimitRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } if r.max <= 0 { diff --git a/rule/filename_format.go b/rule/filename_format.go index ac184916c..1e8cea517 100644 --- a/rule/filename_format.go +++ b/rule/filename_format.go @@ -13,18 +13,16 @@ import ( // FilenameFormatRule lints source filenames according to a set of regular expressions given as arguments type FilenameFormatRule struct { - format *regexp.Regexp - - configureErr error + format *regexp.Regexp configureOnce sync.Once } // Apply applies the rule to the given file. func (r *FilenameFormatRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } filename := filepath.Base(file.Name) diff --git a/rule/function_length.go b/rule/function_length.go index 3aa963635..d156a74da 100644 --- a/rule/function_length.go +++ b/rule/function_length.go @@ -12,10 +12,8 @@ import ( // FunctionLength lint. type FunctionLength struct { - maxStmt int - maxLines int - - configureErr error + maxStmt int + maxLines int configureOnce sync.Once } @@ -31,10 +29,10 @@ func (r *FunctionLength) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *FunctionLength) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/function_result_limit.go b/rule/function_result_limit.go index 5e2743c58..1fcce30b0 100644 --- a/rule/function_result_limit.go +++ b/rule/function_result_limit.go @@ -12,9 +12,7 @@ import ( // FunctionResultsLimitRule lints given else constructs. type FunctionResultsLimitRule struct { - max int - - configureErr error + max int configureOnce sync.Once } @@ -40,10 +38,10 @@ func (r *FunctionResultsLimitRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *FunctionResultsLimitRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/import_alias_naming.go b/rule/import_alias_naming.go index c448ba79f..fa295d5bb 100644 --- a/rule/import_alias_naming.go +++ b/rule/import_alias_naming.go @@ -11,10 +11,8 @@ import ( // ImportAliasNamingRule lints import alias naming. type ImportAliasNamingRule struct { - allowRegexp *regexp.Regexp - denyRegexp *regexp.Regexp - - configureErr error + allowRegexp *regexp.Regexp + denyRegexp *regexp.Regexp configureOnce sync.Once } @@ -64,10 +62,10 @@ func (r *ImportAliasNamingRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *ImportAliasNamingRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/imports_blocklist.go b/rule/imports_blocklist.go index ab34882aa..f935432fe 100644 --- a/rule/imports_blocklist.go +++ b/rule/imports_blocklist.go @@ -11,9 +11,7 @@ import ( // ImportsBlocklistRule lints given else constructs. type ImportsBlocklistRule struct { - blocklist []*regexp.Regexp - - configureErr error + blocklist []*regexp.Regexp configureOnce sync.Once } @@ -46,10 +44,10 @@ func (r *ImportsBlocklistRule) isBlocklisted(path string) bool { // Apply applies the rule to given file. func (r *ImportsBlocklistRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configureErr error + r.configureOnce.Do(func() { configureErr = r.configure(arguments) }) + if configureErr != nil { + return nil, configureErr } var failures []lint.Failure diff --git a/rule/line_length_limit.go b/rule/line_length_limit.go index d82a32c0d..8c559572d 100644 --- a/rule/line_length_limit.go +++ b/rule/line_length_limit.go @@ -17,7 +17,6 @@ import ( // LineLengthLimitRule lints given else constructs. type LineLengthLimitRule struct { max int - configureErr error configureOnce sync.Once } @@ -40,10 +39,10 @@ func (r *LineLengthLimitRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *LineLengthLimitRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configErr error + r.configureOnce.Do(func() { configErr = r.configure(arguments) }) + if configErr != nil { + return nil, configErr } var failures []lint.Failure diff --git a/rule/max_control_nesting.go b/rule/max_control_nesting.go index 3ad532d3e..8f64083ee 100644 --- a/rule/max_control_nesting.go +++ b/rule/max_control_nesting.go @@ -12,9 +12,7 @@ import ( // MaxControlNestingRule lints given else constructs. type MaxControlNestingRule struct { - max int64 - - configureErr error + max int64 configureOnce sync.Once } @@ -22,10 +20,10 @@ const defaultMaxControlNesting = 5 // Apply applies the rule to given file. func (r *MaxControlNestingRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configErr error + r.configureOnce.Do(func() { configErr = r.configure(arguments) }) + if configErr != nil { + return nil, configErr } var failures []lint.Failure diff --git a/rule/max_public_structs.go b/rule/max_public_structs.go index 6fae4a682..688fc48d8 100644 --- a/rule/max_public_structs.go +++ b/rule/max_public_structs.go @@ -14,7 +14,6 @@ import ( // MaxPublicStructsRule lints given else constructs. type MaxPublicStructsRule struct { max int64 - configureErr error configureOnce sync.Once } @@ -41,10 +40,10 @@ func (r *MaxPublicStructsRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *MaxPublicStructsRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configErr error + r.configureOnce.Do(func() { configErr = r.configure(arguments) }) + if configErr != nil { + return nil, configErr } var failures []lint.Failure diff --git a/rule/receiver_naming.go b/rule/receiver_naming.go index 87973294e..85121db02 100644 --- a/rule/receiver_naming.go +++ b/rule/receiver_naming.go @@ -13,9 +13,7 @@ import ( // ReceiverNamingRule lints given else constructs. type ReceiverNamingRule struct { receiverNameMaxLength int - - configureErr error - configureOnce sync.Once + configureOnce sync.Once } const defaultReceiverNameMaxLength = -1 // thus will not check @@ -48,10 +46,10 @@ func (r *ReceiverNamingRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *ReceiverNamingRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configErr error + r.configureOnce.Do(func() { configErr = r.configure(arguments) }) + if configErr != nil { + return nil, configErr } var failures []lint.Failure diff --git a/rule/struct_tag.go b/rule/struct_tag.go index d084156b4..6eece838b 100644 --- a/rule/struct_tag.go +++ b/rule/struct_tag.go @@ -14,9 +14,7 @@ import ( // StructTagRule lints struct tags. type StructTagRule struct { - userDefined map[string][]string // map: key -> []option - - configureErr error + userDefined map[string][]string // map: key -> []option configureOnce sync.Once } @@ -50,10 +48,10 @@ func (r *StructTagRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *StructTagRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configErr error + r.configureOnce.Do(func() { configErr = r.configure(arguments) }) + if configErr != nil { + return nil, configErr } var failures []lint.Failure diff --git a/rule/unchecked_type_assertion.go b/rule/unchecked_type_assertion.go index da0ad4dc0..839035e01 100644 --- a/rule/unchecked_type_assertion.go +++ b/rule/unchecked_type_assertion.go @@ -18,9 +18,7 @@ const ( // UncheckedTypeAssertionRule lints missing or ignored `ok`-value in dynamic type casts. type UncheckedTypeAssertionRule struct { acceptIgnoredAssertionResult bool - - configureErr error - configureOnce sync.Once + configureOnce sync.Once } func (r *UncheckedTypeAssertionRule) configure(arguments lint.Arguments) error { @@ -49,10 +47,10 @@ func (r *UncheckedTypeAssertionRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *UncheckedTypeAssertionRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configErr error + r.configureOnce.Do(func() { configErr = r.configure(arguments) }) + if configErr != nil { + return nil, configErr } var failures []lint.Failure diff --git a/rule/unhandled_error.go b/rule/unhandled_error.go index d8b9dc46a..69a368327 100644 --- a/rule/unhandled_error.go +++ b/rule/unhandled_error.go @@ -15,9 +15,7 @@ import ( // UnhandledErrorRule lints given else constructs. type UnhandledErrorRule struct { - ignoreList []*regexp.Regexp - - configureErr error + ignoreList []*regexp.Regexp configureOnce sync.Once } @@ -45,10 +43,10 @@ func (r *UnhandledErrorRule) configure(arguments lint.Arguments) error { // Apply applies the rule to given file. func (r *UnhandledErrorRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configErr error + r.configureOnce.Do(func() { configErr = r.configure(arguments) }) + if configErr != nil { + return nil, configErr } var failures []lint.Failure diff --git a/rule/unused_param.go b/rule/unused_param.go index de869097c..036f81e6c 100644 --- a/rule/unused_param.go +++ b/rule/unused_param.go @@ -13,10 +13,8 @@ import ( // UnusedParamRule lints unused params in functions. type UnusedParamRule struct { // regex to check if some name is valid for unused parameter, "^_$" by default - allowRegex *regexp.Regexp - failureMsg string - - configureErr error + allowRegex *regexp.Regexp + failureMsg string configureOnce sync.Once } @@ -53,10 +51,10 @@ func (r *UnusedParamRule) configure(args lint.Arguments) error { // Apply applies the rule to given file. func (r *UnusedParamRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configErr error + r.configureOnce.Do(func() { configErr = r.configure(arguments) }) + if configErr != nil { + return nil, configErr } var failures []lint.Failure diff --git a/rule/unused_receiver.go b/rule/unused_receiver.go index a8f9839ca..ea6cfd683 100644 --- a/rule/unused_receiver.go +++ b/rule/unused_receiver.go @@ -13,10 +13,8 @@ import ( // UnusedReceiverRule lints unused params in functions. type UnusedReceiverRule struct { // regex to check if some name is valid for unused parameter, "^_$" by default - allowRegex *regexp.Regexp - failureMsg string - - configureErr error + allowRegex *regexp.Regexp + failureMsg string configureOnce sync.Once } @@ -52,10 +50,10 @@ func (r *UnusedReceiverRule) configure(args lint.Arguments) error { // Apply applies the rule to given file. func (r *UnusedReceiverRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configErr error + r.configureOnce.Do(func() { configErr = r.configure(arguments) }) + if configErr != nil { + return nil, configErr } var failures []lint.Failure diff --git a/rule/var_naming.go b/rule/var_naming.go index ad0448204..c25461673 100644 --- a/rule/var_naming.go +++ b/rule/var_naming.go @@ -23,9 +23,7 @@ type VarNamingRule struct { blockList []string allowUpperCaseConst bool // if true - allows to use UPPER_SOME_NAMES for constants skipPackageNameChecks bool - - configureErr error - configureOnce sync.Once + configureOnce sync.Once } func (r *VarNamingRule) configure(arguments lint.Arguments) error { @@ -87,10 +85,10 @@ func (r *VarNamingRule) applyPackageCheckRules(walker *lintNames) { // Apply applies the rule to given file. func (r *VarNamingRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) { - r.configureOnce.Do(func() { r.configureErr = r.configure(arguments) }) - - if r.configureErr != nil { - return nil, r.configureErr + var configErr error + r.configureOnce.Do(func() { configErr = r.configure(arguments) }) + if configErr != nil { + return nil, configErr } var failures []lint.Failure