Skip to content

feat: adding uber style guidelines (WIP) #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

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

manuelarte
Copy link

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

- [Local Variable Declarations](https://github.com/uber-go/guide/blob/master/style.md#local-variable-declarations)
- [nil is a valid slice](https://github.com/uber-go/guide/blob/master/style.md#nil-is-a-valid-slice)
- [Reduce Scope of Variables](https://github.com/uber-go/guide/blob/master/style.md#reduce-scope-of-variables)
- [Avoid Naked Parameters](https://github.com/uber-go/guide/blob/master/style.md#avoid-naked-parameters)
Copy link
Owner

Choose a reason for hiding this comment

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

Something was discussed lately in nakedreturn linter I think

- [nil is a valid slice](https://github.com/uber-go/guide/blob/master/style.md#nil-is-a-valid-slice)
- [Reduce Scope of Variables](https://github.com/uber-go/guide/blob/master/style.md#reduce-scope-of-variables)
- [Avoid Naked Parameters](https://github.com/uber-go/guide/blob/master/style.md#avoid-naked-parameters)
- [Use Raw String Literals to Avoid Escaping](https://github.com/uber-go/guide/blob/master/style.md#use-raw-string-literals-to-avoid-escaping)
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, I plan to create a linter.

There is one rule in staticcheck, but only for regexp

- [Omit Zero Value Fields in Structs](https://github.com/uber-go/guide/blob/master/style.md#omit-zero-value-fields-in-structs)
- [Use `var` for Zero Value Structs](https://github.com/uber-go/guide/blob/master/style.md#use-var-for-zero-value-structs)
- [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)
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

maybe revive.enforce-slice-style

- [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

Comment on lines +51 to +52
- [Package Names](https://github.com/uber-go/guide/blob/master/style.md#package-names)
- [Function Names](https://github.com/uber-go/guide/blob/master/style.md#function-names)
Copy link
Owner

Choose a reason for hiding this comment

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

revive.var-naming does that for packages and function

- [Wait for goroutines to exit](https://github.com/uber-go/guide/blob/master/style.md#wait-for-goroutines-to-exit)
- [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`
Copy link
Owner

@ccoVeille ccoVeille Apr 26, 2025

Choose a reason for hiding this comment

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

Please mention the name of the option

- [Prefer Specifying Container Capacity](https://github.com/uber-go/guide/blob/master/style.md#prefer-specifying-container-capacity)
- [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)
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe revive.enforce-slice-style make sense here

- [Avoid Naked Parameters](https://github.com/uber-go/guide/blob/master/style.md#avoid-naked-parameters)
- [Use Raw String Literals to Avoid Escaping](https://github.com/uber-go/guide/blob/master/style.md#use-raw-string-literals-to-avoid-escaping)
- [Initializing Structs](https://github.com/uber-go/guide/blob/master/style.md#initializing-structs)
- [Use Field Names to Initialize Structs](https://github.com/uber-go/guide/blob/master/style.md#use-field-names-to-initialize-structs)
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

Try to find it with daredevil

- [Use `var` for Zero Value Structs](https://github.com/uber-go/guide/blob/master/style.md#use-var-for-zero-value-structs)
- [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)
Copy link
Owner

Choose a reason for hiding this comment

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

Perfsprint here maybe, this one might be about str-concat option

- [Function Names](https://github.com/uber-go/guide/blob/master/style.md#function-names)
- [Import Aliasing](https://github.com/uber-go/guide/blob/master/style.md#import-aliasing)
- [x] [Function Grouping and Ordering](https://github.com/uber-go/guide/blob/master/style.md#function-grouping-and-ordering) - Style applied through linter `funcorder`.
- [Reduce Nesting](https://github.com/uber-go/guide/blob/master/style.md#reduce-nesting)
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 revive.max-control-nesting and revive.cyclomatic

But also everything listed in #48 (comment)

Copy link
Owner

Choose a reason for hiding this comment

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

nestif linter also

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