Skip to content

Conversation

ccoVeille
Copy link
Contributor

Here is the result

$ GL_DEBUG=revive go run cmd/golangci-lint/main.go run --enable-only=revive

DEBU [revive] All available analyzers checks (81): [add-constant argument-limit atomic banned-characters bare-return blank-imports bool-literal-in-expr call-to-gc cognitive-complexity comment-spacings comments-density confusing-naming confusing-results constant-logical-expr context-as-argument context-keys-type cyclomatic datarace deep-exit defer dot-imports duplicated-imports early-return empty-block empty-lines enforce-map-style enforce-repeated-arg-type-style enforce-slice-style error-naming error-return error-strings errorf exported file-header file-length-limit filename-format flag-parameter function-length function-result-limit get-return identical-branches if-return import-alias-naming import-shadowing imports-blocklist increment-decrement indent-error-flow line-length-limit max-control-nesting max-public-structs modifies-parameter modifies-value-receiver nested-structs optimize-operands-order package-comments range range-val-address range-val-in-closure receiver-naming redefines-builtin-id redundant-import-alias string-format string-of-int struct-tag superfluous-else time-equal time-naming unchecked-type-assertion unconditional-recursion unexported-naming unexported-return unhandled-error unnecessary-stmt unreachable-code unused-parameter unused-receiver use-any useless-break var-declaration var-naming waitgroup-by-value] 
DEBU [revive] Default analyzers checks (23): [blank-imports context-as-argument context-keys-type dot-imports empty-block error-naming error-return error-strings errorf exported increment-decrement indent-error-flow package-comments range receiver-naming redefines-builtin-id superfluous-else time-naming unexported-return unreachable-code unused-parameter var-declaration var-naming] 
DEBU [revive] Enabled by config analyzers checks (3): [indent-error-flow unused-parameter unused-receiver] 
DEBU [revive] revive configuration: &lint.Config{IgnoreGeneratedHeader:false, Confidence:0.8, Severity:"warning", EnableAllRules:false, Rules:map[string]lint.RuleConfig{"indent-error-flow":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:false, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}, "unexported-return":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:true, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}, "unused-parameter":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:false, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}, "unused-receiver":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:false, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}}, ErrorCode:0, WarningCode:0, Directives:map[string]lint.DirectiveConfig(nil), Exclude:[]string(nil), GoVersion:(*version.Version)(nil)} 

The last line comes from the existing debug message available for revive linter.

$ GL_DEBUG=revive golangci-lint run --enable-only=revive

DEBU [revive] revive configuration: &lint.Config{IgnoreGeneratedHeader:false, Confidence:0.8, Severity:"warning", EnableAllRules:false, Rules:map[string]lint.RuleConfig{"indent-error-flow":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:false, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}, "unexported-return":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:true, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}, "unused-parameter":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:false, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}, "unused-receiver":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:false, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}}, ErrorCode:0, WarningCode:0, Directives:map[string]lint.DirectiveConfig(nil), Exclude:[]string(nil), GoVersion:(*version.Version)(nil)} 

It was kept for compatibility purpose.

@ldez ldez self-requested a review January 15, 2025 14:27
@ldez ldez changed the title dev: update GL_DEBUG=revive to see enabled analyzers dev: update GL_DEBUG=revive to see revive rules Jan 15, 2025
@ldez
Copy link
Member

ldez commented Jan 15, 2025

New render:

$ GL_DEBUG=revive go run ./cmd/golangci-lint/ run --enable-only=revive
DEBU [revive] All available rules (81): add-constant, argument-limit, atomic, banned-characters, bare-return, blank-imports, bool-literal-in-expr, call-to-gc, cognitive-complexity, comment-spacings, comments-density, confusing-naming, confusing-results, constant-logical-expr, context-as-argument, context-keys-type, cyclomatic, datarace, deep-exit, defer, dot-imports, duplicated-imports, early-return, empty-block, empty-lines, enforce-map-style, enforce-repeated-arg-type-style, enforce-slice-style, error-naming, error-return, error-strings, errorf, exported, file-header, file-length-limit, filename-format, flag-parameter, function-length, function-result-limit, get-return, identical-branches, if-return, import-alias-naming, import-shadowing, imports-blocklist, increment-decrement, indent-error-flow, line-length-limit, max-control-nesting, max-public-structs, modifies-parameter, modifies-value-receiver, nested-structs, optimize-operands-order, package-comments, range, range-val-address, range-val-in-closure, receiver-naming, redefines-builtin-id, redundant-import-alias, string-format, string-of-int, struct-tag, superfluous-else, time-equal, time-naming, unchecked-type-assertion, unconditional-recursion, unexported-naming, unexported-return, unhandled-error, unnecessary-stmt, unreachable-code, unused-parameter, unused-receiver, use-any, useless-break, var-declaration, var-naming, waitgroup-by-value. 
DEBU [revive] Default rules (81): add-constant, argument-limit, atomic, banned-characters, bare-return, blank-imports, bool-literal-in-expr, call-to-gc, cognitive-complexity, comment-spacings, comments-density, confusing-naming, confusing-results, constant-logical-expr, context-as-argument, context-keys-type, cyclomatic, datarace, deep-exit, defer, dot-imports, duplicated-imports, early-return, empty-block, empty-lines, enforce-map-style, enforce-repeated-arg-type-style, enforce-slice-style, error-naming, error-return, error-strings, errorf, exported, file-header, file-length-limit, filename-format, flag-parameter, function-length, function-result-limit, get-return, identical-branches, if-return, import-alias-naming, import-shadowing, imports-blocklist, increment-decrement, indent-error-flow, line-length-limit, max-control-nesting, max-public-structs, modifies-parameter, modifies-value-receiver, nested-structs, optimize-operands-order, package-comments, range, range-val-address, range-val-in-closure, receiver-naming, redefines-builtin-id, redundant-import-alias, string-format, string-of-int, struct-tag, superfluous-else, time-equal, time-naming, unchecked-type-assertion, unconditional-recursion, unexported-naming, unexported-return, unhandled-error, unnecessary-stmt, unreachable-code, unused-parameter, unused-receiver, use-any, useless-break, var-declaration, var-naming, waitgroup-by-value. 
DEBU [revive] Enabled by config rules (3): indent-error-flow, unused-parameter, unused-receiver. 
DEBU [revive] revive configuration: &lint.Config{IgnoreGeneratedHeader:false, Confidence:0.8, Severity:"warning", EnableAllRules:false, Rules:map[string]lint.RuleConfig{"indent-error-flow":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:false, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}, "unexported-return":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:true, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}, "unused-parameter":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:false, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}, "unused-receiver":lint.RuleConfig{Arguments:[]interface {}(nil), Severity:"warning", Disabled:false, Exclude:[]string(nil), excludeFilters:[]*lint.FileFilter(nil)}}, ErrorCode:0, WarningCode:0, Directives:map[string]lint.DirectiveConfig(nil), Exclude:[]string(nil), GoVersion:(*version.Version)(nil)} 

Some notes:

  • literal empty slice declaration should be avoided:
    • wrong: enabledRules := []string{}
    • right: var enabledRules []string
  • when using debug: every computation (like extracting something) should be done after the evaluation of the debug state.
    • For ex: in debug(extract(foo)) the function extract is always evaluated.
  • when a code is "extracted" from somewhere else, the modifications should be avoided/limited.

Also, the last log, with the full configuration, is not kept for "compatibility" but because this is an important log as revive configuration parsing is not trivial.

@ldez ldez added topic: cosmetic changes contain cosmetic improvements linter: update Update the linter implementation inside golangci-lint labels Jan 15, 2025
@ldez ldez added this to the next milestone Jan 15, 2025
@alexandear alexandear self-requested a review January 15, 2025 15:23
@ldez ldez changed the title dev: update GL_DEBUG=revive to see revive rules dev: displays revive rules inside debug logs Jan 15, 2025
@ldez ldez requested a review from alexandear January 15, 2025 16:00
Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ldez ldez merged commit d45036a into golangci:master Jan 15, 2025
15 checks passed
@ccoVeille ccoVeille deleted the revive-debug branch January 15, 2025 17:01
@ldez ldez modified the milestones: next, v1.64 Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linter: update Update the linter implementation inside golangci-lint topic: cosmetic changes contain cosmetic improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants