Skip to content
New issue

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

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

Already on GitHub? # to your account

Linter rule to enforce empty slice declaration/initialization style #898

Closed
denisvmedia opened this issue Sep 18, 2023 · 2 comments · Fixed by #900
Closed

Linter rule to enforce empty slice declaration/initialization style #898

denisvmedia opened this issue Sep 18, 2023 · 2 comments · Fixed by #900
Labels
rule proposal Issue proposing a new rule

Comments

@denisvmedia
Copy link
Collaborator

denisvmedia commented Sep 18, 2023

Is your feature request related to a problem? Please describe.
Styles:

  1. slice := make([]type)
  2. slice := []type{}

There is also a way of having a non-initialized slice (which should be preferred over the empty slice w/o len and cap in most cases), but this is beyond the scope of this linter

Describe the solution you'd like
I'd like to introduce a new linter that will enforce a particular style of these 3 to be used.

Things to take into account:

  • slices with elements (i.e. []type{el1, el2, elN}) - they should be ignored by the linter.
  • slices with explicit len and (optionally) capacity: i.e. make([]type, len), make([]type, len, cap) - they should be ignored by the linter.

Describe alternatives you've considered
I wasn't able to find any working alternative.

Additional context
This can be considered as a follow up feature for #892.

@chavacava
Copy link
Collaborator

Hi @denisvmedia, thanks for the proposal. Do you plan to push a PR?

@denisvmedia
Copy link
Collaborator Author

Yes, if you think this might be useful, I can submit a PR.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
rule proposal Issue proposing a new rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants