Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
denisvmedia opened this issue Dec 4, 2023 · 3 comments · Fixed by #953
Closed
Assignees

Comments

@denisvmedia
Copy link
Collaborator

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
Copy link
Collaborator Author

Tagging @chavacava to discuss the idea.

@denisvmedia
Copy link
Collaborator Author

@chavacava do you have any opinion on this proposal?

@chavacava
Copy link
Collaborator

Hi, the proposal seems OK to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants