Skip to content

Commit

Permalink
moves auxiliary func to the end of the source file
Browse files Browse the repository at this point in the history
  • Loading branch information
chavacava committed Dec 4, 2024
1 parent 58f8a7e commit 57e4695
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions rule/function_result_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,6 @@ type FunctionResultsLimitRule struct {
configureOnce sync.Once
}

const defaultResultsLimit = 3

func (r *FunctionResultsLimitRule) configure(arguments lint.Arguments) {
if len(arguments) < 1 {
r.max = defaultResultsLimit
return
}

maxResults, ok := arguments[0].(int64) // Alt. non panicking version
if !ok {
panic(fmt.Sprintf(`invalid value passed as return results number to the "function-result-limit" rule; need int64 but got %T`, arguments[0]))
}
if maxResults < 0 {
panic(`the value passed as return results number to the "function-result-limit" rule cannot be negative`)
}

r.max = int(maxResults)
}

// Apply applies the rule to given file.
func (r *FunctionResultsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
r.configureOnce.Do(func() { r.configure(arguments) })
Expand Down Expand Up @@ -67,3 +48,22 @@ func (r *FunctionResultsLimitRule) Apply(file *lint.File, arguments lint.Argumen
func (*FunctionResultsLimitRule) Name() string {
return "function-result-limit"
}

const defaultResultsLimit = 3

func (r *FunctionResultsLimitRule) configure(arguments lint.Arguments) {
if len(arguments) < 1 {
r.max = defaultResultsLimit
return
}

maxResults, ok := arguments[0].(int64) // Alt. non panicking version
if !ok {
panic(fmt.Sprintf(`invalid value passed as return results number to the "function-result-limit" rule; need int64 but got %T`, arguments[0]))
}
if maxResults < 0 {
panic(`the value passed as return results number to the "function-result-limit" rule cannot be negative`)
}

r.max = int(maxResults)
}

0 comments on commit 57e4695

Please sign in to comment.