mgechev / revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
https://revive.run
MIT License
4.69k stars 273 forks source link

Add a linter rule to enforce omitting the type for the same type arguments in a function #948

Closed denisvmedia closed 6 months ago

denisvmedia commented 7 months ago

Is your feature request related to a problem? Please describe. Consider this function declaration:

func Dummy(arg1 string, arg2 string)

It can be simplified to

func Dummy(arg1, arg2 string)

essentially making the signature shorter.

This rule can be (and probably should be) also extended to the return values:

func Dummy() (ret1 string, ret2 string)

to

func Dummy() (ret1, ret2 string)

Note, on the opposite one might want to enforce to have the full signature all the time.

Describe the solution you'd like I'd like to have a linter rule to enforce the style. Proposed linter rule name is enforce-repeated-arg-type-style (I'm open to accept a better name though).

Simple configuration (applies to both: args and ret vals):

[rule.enforce-repeated-arg-type-style]
  arguments = [ "short" ] # can be any, short or full; default: any

Advanced configuration (individual configuration per type/local of val):

[rule.enforce-repeated-arg-type-style]
  # possible values for the style: any, short, full; default: any to both
  arguments = [ { funcArgStyle = "short", funcRetValStyle = "full" } ]

Describe alternatives you've considered I'm not aware of any existing alternatives.

Additional context This would bring a little bit more consistency to the code base. Suggested default value: "any" (this will make the rule essentially disabled by default even if all rules are enabled in the configuration, thus no impact on any existing system without explicit configuration).

I'm ready to provide a PR if there are no serious concerns (and no good alternatives that I might have overseen).

denisvmedia commented 7 months ago

Tagging @chavacava to discuss the idea.

denisvmedia commented 7 months ago

@chavacava do you have any opinion on this proposal?

chavacava commented 7 months ago

Hi, the proposal seems OK to me.