-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Changes from 17 commits
b2e534f
4039e8a
555891d
2ca57d6
48f46da
ae4a09c
d17483d
eb3a374
2880c7b
9ab406e
92f9705
ab5a793
79ed16d
a848178
341edcc
2887512
76358da
6475246
5fa214c
e6ca447
f8624de
66df312
38b7b2b
0e7b433
59b9894
0e5cc21
27276ac
7a20d49
e84694a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
--- | ||
# golangci-lint configuration file made by @ccoVeille | ||
# Source: https://github.com/ccoVeille/golangci-lint-config-examples/ | ||
# Author: @ccoVeille & @manuelarte | ||
# License: MIT | ||
# Variant: uberstyle | ||
# Version: v2.2.0 | ||
# | ||
version: "2" | ||
|
||
formatters: | ||
enable: | ||
# format the code | ||
- gofmt | ||
# format the block of imports | ||
- gci | ||
# checks if the code and import statements are formatted according to the 'goimports' command. | ||
- goimports | ||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
manuelarte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
settings: | ||
# format the code with Go standard library | ||
gofmt: | ||
# simplify the code | ||
# https://pkg.go.dev/cmd/gofmt#hdr-The_simplify_command | ||
simplify: true | ||
rewrite-rules: | ||
# replace `interface{}` with `any` in the code on format | ||
- pattern: "interface{}" | ||
replacement: "any" | ||
|
||
# make sure imports are always in a deterministic order | ||
# https://github.com/daixiang0/gci/ | ||
gci: # define the section orders for imports | ||
sections: | ||
# Standard section: captures all standard packages. | ||
- standard | ||
# Default section: catchall that is not standard or custom | ||
- default | ||
# linters that related to local tool, so they should be separated | ||
- localmodule | ||
|
||
linters: | ||
exclusions: | ||
# these presets where present in the v1 version of golangci-lint | ||
# it's interesting to keep them when migrating, but removing them should be the goal | ||
presets: | ||
# exclude check on comments format in godoc | ||
# These are common false positives in poor code | ||
# you should not use this on recent code you write from scratch | ||
# More information: https://golangci-lint.run/usage/false-positives/#comments | ||
# | ||
# Please uncomment the following line if your code is not using the godoc format | ||
- comments | ||
manuelarte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Common false positives | ||
# feel free to remove this if you don't have any false positives | ||
# More information: https://golangci-lint.run/usage/false-positives/#common-false-positives | ||
- common-false-positives | ||
|
||
# Legacy preset is not recommended anymore | ||
# More information: https://golangci-lint.run/usage/false-positives/#legacy | ||
- legacy | ||
|
||
# std-error-handling is a set of rules that avoid reporting unhandled errors on common functions/methods | ||
# More information: https://golangci-lint.run/usage/false-positives/#std-error-handling | ||
- std-error-handling | ||
|
||
# some linters are enabled by default | ||
# https://golangci-lint.run/usage/linters/ | ||
# | ||
# enable some extra linters | ||
enable: | ||
# Embeddedstructfieldcheck checks embedded types inside a struct. | ||
- embeddedstructfieldcheck | ||
|
||
# Errcheck is a program for checking for unchecked errors in Go code. | ||
- errcheck | ||
|
||
# Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. | ||
- errorlint | ||
|
||
# Errname Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error | ||
- errname | ||
|
||
# Vet examines Go source code and reports suspicious constructs. | ||
- govet | ||
|
||
# Detects when assignments to existing variables are not used. | ||
- ineffassign | ||
|
||
# It's a set of rules from staticcheck. See https://staticcheck.io/ | ||
- staticcheck | ||
|
||
# Checks Go code for unused constants, variables, functions and types. | ||
- unused | ||
|
||
# Fast, configurable, extensible, flexible, and beautiful linter for Go. | ||
# Drop-in replacement of golint. | ||
- revive | ||
|
||
# make sure to use t.Helper() when needed | ||
- thelper | ||
|
||
# Enforce field tags in (un)marshaled structs. | ||
- musttag | ||
|
||
# mirror suggests rewrites to avoid unnecessary []byte/string conversion | ||
- mirror | ||
|
||
# detect the possibility to use variables/constants from the Go standard library. | ||
- usestdlibvars | ||
|
||
# Finds commonly misspelled English words. | ||
- misspell | ||
|
||
# Checks for duplicate words in the source code. | ||
- dupword | ||
|
||
# LLL Reports long lines. | ||
- lll | ||
|
||
# linter to detect errors invalid key values count | ||
- loggercheck | ||
|
||
# detect when a package or method could be replaced by one from the standard library | ||
- exptostd | ||
|
||
# detects nested contexts in loops or function literals | ||
- fatcontext | ||
|
||
# Reports uses of functions with replacement inside the testing package. | ||
- usetesting | ||
|
||
# Funcorder Follows function/method order described in https://github.com/uber-go/guide/blob/master/style.md#function-grouping-and-ordering | ||
- funcorder | ||
|
||
# GoCheckNoInits Avoid init() https://github.com/uber-go/guide/blob/master/style.md#avoid-init | ||
- gochecknoinits | ||
|
||
# Perfsprint Checks that fmt.Sprintf can be replaced with a faster alternative. | ||
- perfsprint | ||
|
||
settings: | ||
forbidigo: | ||
forbid: | ||
# Don't panic https://github.com/uber-go/guide/blob/master/style.md#dont-panic | ||
- pattern: ^panic(ln)$ | ||
msg: Panics are a major source of cascading failures. | ||
lll: | ||
line-length: 99 | ||
revive: | ||
rules: | ||
# Blank import should be only in a main or test package, or have a comment justifying it. | ||
- name: blank-imports | ||
|
||
# context.Context() should be the first parameter of a function when provided as argument. | ||
- name: context-as-argument | ||
arguments: | ||
- allowTypesBefore: "*testing.T" | ||
|
||
# Basic types should not be used as a key in `context.WithValue` | ||
- name: context-keys-type | ||
|
||
# This rule looks for program exits in functions other than main() or init() | ||
# https://github.com/uber-go/guide/blob/master/style.md#exit-in-main | ||
- name: deep-exit | ||
|
||
# Importing with `.` makes the programs much harder to understand | ||
- name: dot-imports | ||
|
||
# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. | ||
- name: empty-block | ||
|
||
# Enforces consistent usage of make(map[type]type) | ||
- name: enforce-map-style | ||
arguments: | ||
- "make" | ||
|
||
# for better readability, variables of type `error` must be named with the prefix `err`. | ||
- name: error-naming | ||
|
||
# for better readability, the errors should be last in the list of returned values by a function. | ||
- name: error-return | ||
|
||
# for better readability, error messages should not be capitalized or end with punctuation or a newline. | ||
- name: error-strings | ||
|
||
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible | ||
- name: errorf | ||
|
||
# check naming and commenting conventions on exported symbols. | ||
- name: exported | ||
arguments: | ||
# make error messages clearer | ||
- "sayRepetitiveInsteadOfStutters" | ||
|
||
# incrementing an integer variable by 1 is recommended to be done using the `++` operator | ||
- name: increment-decrement | ||
|
||
# highlights redundant else-blocks that can be eliminated from the code | ||
- name: indent-error-flow | ||
|
||
# This rule suggests a shorter way of writing ranges that do not use the second value. | ||
- name: range | ||
|
||
# receiver names in a method should reflect the struct name (p for Person, for example) | ||
- name: receiver-naming | ||
|
||
# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect. | ||
- name: redefines-builtin-id | ||
|
||
# redundant else-blocks that can be eliminated from the code. | ||
- name: superfluous-else | ||
|
||
# prevent confusing name for variables when using `time` package | ||
- name: time-naming | ||
|
||
# warns when an exported function or method returns a value of an un-exported type. | ||
- name: unexported-return | ||
|
||
# spots and proposes to remove unreachable code. also helps to spot errors | ||
- name: unreachable-code | ||
|
||
# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug. | ||
- name: unused-parameter | ||
|
||
# report when a variable declaration can be simplified | ||
- name: var-declaration | ||
|
||
# warns when initialism, variable or package naming conventions are not followed. | ||
- name: var-naming | ||
|
||
misspell: | ||
# Correct spellings using locale preferences for US or UK. | ||
# Setting locale to US will correct the British spelling of 'colour' to 'color'. | ||
# Default ("") is to use a neutral variety of English. | ||
locale: US | ||
|
||
# List of words to ignore | ||
# among the one defined in https://github.com/golangci/misspell/blob/master/words.go | ||
ignore-rules: [] | ||
# - valor | ||
# - and | ||
|
||
# Extra word corrections. | ||
extra-words: [] | ||
# - typo: "whattever" | ||
# correction: "whatever" |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please link this one in README at root level There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is still needed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Safe Settings | ||
|
||
See [.golangci.yml](.golangci.yml) | ||
|
||
Linter that tries to follow [Uber Style Guidelines](https://github.com/uber-go/guide/blob/master/style.md) | ||
|
||
## License | ||
|
||
License: MIT | ||
|
||
Source: [@ccoVeille](https://github.com/ccoVeille/golangci-lint-config-examples) | ||
|
||
## Uber Style Guidelines | ||
|
||
- [Guidelines](https://github.com/uber-go/guide/blob/master/style.md#guidelines) | ||
- [Pointers to Interfaces](https://github.com/uber-go/guide/blob/master/style.md#pointers-to-interfaces) | ||
- [Verify Interface Compliance](https://github.com/uber-go/guide/blob/master/style.md#verify-interface-compliance) | ||
- [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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is something about defer in revive, go vet or go-critic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least revive.defer and it had a lot of options There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defer should be enabled in revive and documentation should mention it |
||
- [Channel Size is One or None](https://github.com/uber-go/guide/blob/master/style.md#channel-size-is-one-or-none) | ||
- [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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perfsprint helps here, you should mention the option name in the config and here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up |
||
- [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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revive unchecked-type-assertion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up |
||
- [x] [Don't Panic](https://github.com/uber-go/guide/blob/master/style.md#dont-panic) - Style applied through `forbidigo`. | ||
- [Use go.uber.org/atomic](https://github.com/uber-go/guide/blob/master/style.md#use-gouberorgatomic) | ||
- [Avoid Mutable Globals](https://github.com/uber-go/guide/blob/master/style.md#avoid-mutable-globals) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is something. The example in Golangci-lint documentation is about io.EOF You should be able to find it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found it https://golangci-lint.run/usage/linters/#reassign This will detect when a global variable is reassigned outside its package. It's not exactly what is described in the Uber Style Guidelines, but it is definitely related. |
||
- [x] [Avoid Embedding Types in Public Structs](https://github.com/uber-go/guide/blob/master/style.md#avoid-embedding-types-in-public-structs) - Style applied through `embeddedstructfieldcheck` | ||
- [Avoid Using Built-In Names](https://github.com/uber-go/guide/blob/master/style.md#avoid-using-built-in-names) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revive has:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up |
||
- [x] [Avoid `init()`](https://github.com/uber-go/guide/blob/master/style.md#avoid-init) - Style applied through `gochecknoinits`. | ||
- [x] [Exit in Main](https://github.com/uber-go/guide/blob/master/style.md#exit-in-main) - Style applied through `revive.deep-exit`. | ||
- [x] [Use field tags in marshaled structs](https://github.com/uber-go/guide/blob/master/style.md#use-field-tags-in-marshaled-structs) - Style applied through `musttag`. | ||
- [Don't fire-and-forget goroutines](https://github.com/uber-go/guide/blob/master/style.md#dont-fire-and-forget-goroutines) | ||
- [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.string-format`. | ||
- [Avoid repeated string-to-byte conversions](https://github.com/uber-go/guide/blob/master/style.md#avoid-repeated-string-to-byte-conversions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The text of the uber doc is not about it, but here with this title, I would recommend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up |
||
- [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) | ||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- [Group Similar Declarations](https://github.com/uber-go/guide/blob/master/style.md#group-similar-declarations) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is something about that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. grouper linter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up |
||
- [Import Group Ordering](https://github.com/uber-go/guide/blob/master/style.md#import-group-ordering) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done via gci, and it's configured There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. goimport might be enough, otherwise gci might be needed |
||
- [x] [Package Names](https://github.com/uber-go/guide/blob/master/style.md#package-names) - Style applied through linter `revive.var-naming`. | ||
- [x] [Function Names](https://github.com/uber-go/guide/blob/master/style.md#function-names) - Style applied through linter `revive.var-naming`. | ||
- [Import Aliasing](https://github.com/uber-go/guide/blob/master/style.md#import-aliasing) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is something about that in revive import-aliases rule It requires to be configured so std lib are not aliased There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or it might be via importas linter |
||
- [x] [Function Grouping and Ordering](https://github.com/uber-go/guide/blob/master/style.md#function-grouping-and-ordering) - Style applied through linter `funcorder`. | ||
- [x] [Reduce Nesting](https://github.com/uber-go/guide/blob/master/style.md#reduce-nesting) - Style applied through `nestif`. | ||
- [x] [Unnecessary Else](https://github.com/uber-go/guide/blob/master/style.md#unnecessary-else) - Style applied through `revive.superfluous-else`. | ||
- [Top-level Variable Declarations](https://github.com/uber-go/guide/blob/master/style.md#top-level-variable-declarations) | ||
- [Prefix Unexported Globals with _](https://github.com/uber-go/guide/blob/master/style.md#prefix-unexported-globals-with-_) | ||
- [Embedding in Structs](https://github.com/uber-go/guide/blob/master/style.md#embedding-in-structs) | ||
- [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) | ||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- [Use Raw String Literals to Avoid Escaping](https://github.com/uber-go/guide/blob/master/style.md#use-raw-string-literals-to-avoid-escaping) | ||
manuelarte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- [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) | ||
manuelarte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- [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) | ||
- [x] [Initializing Maps](https://github.com/uber-go/guide/blob/master/style.md#initializing-maps) - Style applied through `revive.enforce-slice-style`. | ||
- [Format Strings outside Printf](https://github.com/uber-go/guide/blob/master/style.md#format-strings-outside-printf) | ||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- [Naming Printf-style Functions](https://github.com/uber-go/guide/blob/master/style.md#naming-printf-style-functions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is something for this in revive, go vet, or go-critic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry @ccoVeille I don't understand the up? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
- [Patterns](https://github.com/uber-go/guide/blob/master/style.md#patterns) | ||
- [Test Tables](https://github.com/uber-go/guide/blob/master/style.md#test-tables) | ||
- [Functional Options](https://github.com/uber-go/guide/blob/master/style.md#functional-options) | ||
- [x] [Linting](https://github.com/uber-go/guide/blob/master/style.md#linting) - All the linter recommendations are enabled. |
Uh oh!
There was an error while loading. Please reload this page.