Skip to content

feat: adding uber style guidelines #48

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

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

manuelarte
Copy link

@manuelarte manuelarte commented Apr 14, 2025

Skeleton to create a .golangci-lint.yml with Uber Style Guidelines.

@manuelarte
Copy link
Author

I added goimports because I saw it here: https://github.com/uber-go/guide/blob/master/.golangci.yml

@manuelarte
Copy link
Author

Ok, I was checking what else to add, and to be honest, I don't know if more rules can be covered, any idea @ccoVeille ?

Copy link
Owner

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

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

Here are your homework

- [Initializing Struct References](https://github.com/uber-go/guide/blob/master/style.md#initializing-struct-references)
- [Initializing Maps](https://github.com/uber-go/guide/blob/master/style.md#initializing-maps)
- [Format Strings outside Printf](https://github.com/uber-go/guide/blob/master/style.md#format-strings-outside-printf)
- [Naming Printf-style Functions](https://github.com/uber-go/guide/blob/master/style.md#naming-printf-style-functions)
Copy link
Owner

Choose a reason for hiding this comment

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

There is something for this in revive, go vet, or go-critic

Copy link
Owner

Choose a reason for hiding this comment

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

up

Copy link
Author

Choose a reason for hiding this comment

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

sorry @ccoVeille I don't understand the up?

Copy link
Owner

Choose a reason for hiding this comment

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

I'm sorry. I'm used them to point the attention in them.

Here is Gemini explanation about "up"

To bring the thread "up" in the list: In forums, messaging apps, or other discussion platforms, threads often get pushed down as new posts are made. Typing "up" or "bump" is a way to make a new post in that thread, which in turn brings it back to the top of the list of active discussions.

Copy link
Owner

Choose a reason for hiding this comment

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

So here, I was somehow bringing spotlight on this comment

#48 (comment)

That you didn't react to

@manuelarte manuelarte marked this pull request as ready for review June 13, 2025 12:53
@manuelarte
Copy link
Author

manuelarte commented Jun 13, 2025

what do you think about merging it?
PS: The only issue is that, for example the linter embeddedstructfieldcheck is not "released" yet, but it's added to the .golangci.yml file.

@manuelarte manuelarte changed the title feat: adding uber style guidelines (WIP) feat: adding uber style guidelines Jun 13, 2025
@manuelarte manuelarte requested a review from ccoVeille June 13, 2025 12:55
Copy link
Owner

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

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

There are some remaining comments to address.

I'm fine with merging it as-is if you want. But I would prefer if they could be referenced in an issue

Copy link
Owner

Choose a reason for hiding this comment

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

This one is still needed

- [Receivers and Interfaces](https://github.com/uber-go/guide/blob/master/style.md#receivers-and-interfaces)
- [Zero-value Mutexes are Valid](https://github.com/uber-go/guide/blob/master/style.md#zero-value-mutexes-are-valid)
- [Copy Slices and Maps at Boundaries](https://github.com/uber-go/guide/blob/master/style.md#copy-slices-and-maps-at-boundaries)
- [Defer to Clean Up](https://github.com/uber-go/guide/blob/master/style.md#defer-to-clean-up)
Copy link
Owner

Choose a reason for hiding this comment

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

defer should be enabled in revive and documentation should mention it

- [x] [Error Wrapping](https://github.com/uber-go/guide/blob/master/style.md#error-wrapping) - Sytle applied through `errorlint`
- [x] [Error Naming](https://github.com/uber-go/guide/blob/master/style.md#error-naming) - Style applied through `errname`
- [Handle Errors Once](#handle-errors-once)
- [Handle Type Assertion Failures](#handle-type-assertion-failures)
Copy link
Owner

Choose a reason for hiding this comment

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

up

- [Start Enums at One](https://github.com/uber-go/guide/blob/master/style.md#start-enums-at-one)
- [Use `"time"` to handle time](https://github.com/uber-go/guide/blob/master/style.md#use-time-to-handle-time)
- [Errors](https://github.com/uber-go/guide/blob/master/style.md#errors)
- [Error Types](https://github.com/uber-go/guide/blob/master/style.md#error-types)
Copy link
Owner

Choose a reason for hiding this comment

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

up

- [No goroutines in `init()`](https://github.com/uber-go/guide/blob/master/style.md#no-goroutines-in-init)
- [Performance](https://github.com/uber-go/guide/blob/master/style.md#performance)
- [x] [Prefer strconv over fmt](https://github.com/uber-go/guide/blob/master/style.md#prefer-strconv-over-fmt) - Style applied through `perfsprint`
- [Avoid repeated string-to-byte conversions](https://github.com/uber-go/guide/blob/master/style.md#avoid-repeated-string-to-byte-conversions)
Copy link
Owner

Choose a reason for hiding this comment

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

up

- [Style](https://github.com/uber-go/guide/blob/master/style.md#style)
- [x] [Avoid overly long lines](https://github.com/uber-go/guide/blob/master/style.md#avoid-overly-long-lines) - Style applied through `lll`
- [Be Consistent](https://github.com/uber-go/guide/blob/master/style.md#be-consistent)
- [Group Similar Declarations](https://github.com/uber-go/guide/blob/master/style.md#group-similar-declarations)
Copy link
Owner

Choose a reason for hiding this comment

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

up

- [x] [Avoid overly long lines](https://github.com/uber-go/guide/blob/master/style.md#avoid-overly-long-lines) - Style applied through `lll`
- [Be Consistent](https://github.com/uber-go/guide/blob/master/style.md#be-consistent)
- [Group Similar Declarations](https://github.com/uber-go/guide/blob/master/style.md#group-similar-declarations)
- [Import Group Ordering](https://github.com/uber-go/guide/blob/master/style.md#import-group-ordering)
Copy link
Owner

Choose a reason for hiding this comment

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

goimport might be enough, otherwise gci might be needed

- [Initializing Struct References](https://github.com/uber-go/guide/blob/master/style.md#initializing-struct-references)
- [Initializing Maps](https://github.com/uber-go/guide/blob/master/style.md#initializing-maps)
- [Format Strings outside Printf](https://github.com/uber-go/guide/blob/master/style.md#format-strings-outside-printf)
- [Naming Printf-style Functions](https://github.com/uber-go/guide/blob/master/style.md#naming-printf-style-functions)
Copy link
Owner

Choose a reason for hiding this comment

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

up

@manuelarte
Copy link
Author

defer should be enabled in revive and documentation should mention it

I added revive.defer, but the uber rule is more about, don't forget to defer, and the revive.defer rule is to prevent defer mistakes, right?

@ccoVeille
Copy link
Owner

I added revive.defer, but the uber rule is more about, don't forget to defer, and the revive.defer rule is to prevent defer mistakes, right?

That's right indeed. There are some linters about adding closer when needed. I don't remember which one

@manuelarte
Copy link
Author

manuelarte commented Jun 17, 2025

goimport might be enough, otherwise gci might be needed

I added gci.

@ccoVeille
Copy link
Owner

I feel like I will add the things I requested and ask you to review.

But I'm unsure when

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 this pull request may close these issues.

2 participants