-
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
Open
manuelarte
wants to merge
29
commits into
ccoVeille:main
Choose a base branch
from
manuelarte:uber-style
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b2e534f
feat: adding uber style guidelines (WIP)
manuelarte 4039e8a
WIP: applying some comments
manuelarte 555891d
feat: adding uber style guidelines (WIP) (don't panic and avoid init())
manuelarte 2ca57d6
WIP: applying some comments
manuelarte 48f46da
WIP: applying some comments
manuelarte ae4a09c
WIP: errname and lll
manuelarte d17483d
WIP: perfsprint
manuelarte eb3a374
WIP: formatting README.md
manuelarte 2880c7b
WIP: fixing readme links
manuelarte 9ab406e
adding errorlinter
manuelarte 92f9705
adding musttag
manuelarte ab5a793
WIP: renaming to uberstyle
manuelarte 79ed16d
Merge remote-tracking branch 'origin/uber-style' into uber-style
manuelarte a848178
WIP: adding goimports
manuelarte 341edcc
WIP: applying comments
manuelarte 2887512
WIP: applying comments
manuelarte 76358da
WIP: adding embeddedstructfieldcheck
manuelarte 6475246
reverting version back
manuelarte 5fa214c
Update uberstyle/.golangci.yml
manuelarte e6ca447
removing gci
manuelarte f8624de
field names with go vet composites
manuelarte 66df312
embeddedstructfieldcheck
manuelarte 38b7b2b
importas.no-extra-aliases
manuelarte 0e7b433
reassign
manuelarte 59b9894
adding revive.enforce-slice-style
manuelarte 0e5cc21
adding revive.defer and uncommenting -comments
manuelarte 27276ac
adding gci linter for imports grouping
manuelarte 7a20d49
removing goimport
manuelarte e84694a
adding errcheck.check-type-assertion
manuelarte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
--- | ||
# golangci-lint configuration file made by @ccoVeille | ||
# Source: https://github.com/ccoVeille/golangci-lint-config-examples/ | ||
# Author: @ccoVeille & @manuelarte | ||
# License: MIT | ||
# Variant: 04-uber | ||
# Version: v2.1.0 | ||
# | ||
version: "2" | ||
|
||
formatters: | ||
enable: | ||
# format the code | ||
- gofmt | ||
# format the block of imports | ||
- gci | ||
|
||
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 | ||
|
||
# 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: | ||
# Errcheck is a program for checking for unchecked errors in Go code. | ||
- errcheck | ||
|
||
# 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 | ||
|
||
# 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 | ||
|
||
# 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 | ||
|
||
# Follows function/method order described in https://github.com/uber-go/guide/blob/master/style.md#function-grouping-and-ordering | ||
- funcorder | ||
|
||
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. | ||
# Avoid init() https://github.com/uber-go/guide/blob/master/style.md#avoid-init | ||
- pattern: ^init(ln)$ | ||
msg: Panics are a major source of cascading failures. | ||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
revive: | ||
rules: | ||
# these are the default revive rules | ||
# you can remove the whole "rules" node if you want | ||
# BUT | ||
# ! /!\ they all need to be present when you want to add more rules than the default ones | ||
# otherwise, you won't have the default rules, but only the ones you define in the "rules" node | ||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 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 | ||
|
||
# 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 | ||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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" | ||
|
||
output: | ||
# Order to use when sorting results. | ||
# Possible values: `file`, `linter`, and `severity`. | ||
# | ||
# If the severity values are inside the following list, they are ordered in this order: | ||
# 1. error | ||
# 2. warning | ||
# 3. high | ||
# 4. medium | ||
# 5. low | ||
# Either they are sorted alphabetically. | ||
# | ||
# Default: ["file"] | ||
sort-order: | ||
- linter | ||
- severity | ||
- file # filepath, line, and column. | ||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## License | ||
|
||
License: MIT | ||
|
||
Source: [@ccoVeille](https://github.com/ccoVeille/golangci-lint-config-examples) | ||
|
||
## Uber Style Guidelines | ||
|
||
- [Guidelines](#guidelines) | ||
ccoVeille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- [Pointers to Interfaces](#pointers-to-interfaces) | ||
- [Verify Interface Compliance](#verify-interface-compliance) | ||
- [Receivers and Interfaces](#receivers-and-interfaces) | ||
- [Zero-value Mutexes are Valid](#zero-value-mutexes-are-valid) | ||
- [Copy Slices and Maps at Boundaries](#copy-slices-and-maps-at-boundaries) | ||
- [Defer to Clean Up](#defer-to-clean-up) | ||
- [Channel Size is One or None](#channel-size-is-one-or-none) | ||
- [Start Enums at One](#start-enums-at-one) | ||
- [Use `"time"` to handle time](#use-time-to-handle-time) | ||
- [Errors](#errors) | ||
- [Error Types](#error-types) | ||
- [Error Wrapping](#error-wrapping) | ||
- [Error Naming](#error-naming) | ||
- [Handle Errors Once](#handle-errors-once) | ||
- [Handle Type Assertion Failures](#handle-type-assertion-failures) | ||
[x] [Don't Panic](#dont-panic) - Style applied through `forbidigo`. | ||
- [Use go.uber.org/atomic](#use-gouberorgatomic) | ||
- [Avoid Mutable Globals](#avoid-mutable-globals) | ||
- [Avoid Embedding Types in Public Structs](#avoid-embedding-types-in-public-structs) | ||
- [Avoid Using Built-In Names](#avoid-using-built-in-names) | ||
[x] [Avoid `init()`](#avoid-init) - Style applied through `forbidigo`. | ||
[x] [Exit in Main](#exit-in-main) - Style applied through `revive.deep-exit`. | ||
- [Use field tags in marshaled structs](#use-field-tags-in-marshaled-structs) | ||
- [Don't fire-and-forget goroutines](#dont-fire-and-forget-goroutines) | ||
- [Wait for goroutines to exit](#wait-for-goroutines-to-exit) | ||
- [No goroutines in `init()`](#no-goroutines-in-init) | ||
- [Performance](#performance) | ||
- [Prefer strconv over fmt](#prefer-strconv-over-fmt) | ||
- [Avoid repeated string-to-byte conversions](#avoid-repeated-string-to-byte-conversions) | ||
- [Prefer Specifying Container Capacity](#prefer-specifying-container-capacity) | ||
- [Style](#style) | ||
- [Avoid overly long lines](#avoid-overly-long-lines) | ||
- [Be Consistent](#be-consistent) | ||
- [Group Similar Declarations](#group-similar-declarations) | ||
- [Import Group Ordering](#import-group-ordering) | ||
- [Package Names](#package-names) | ||
- [Function Names](#function-names) | ||
- [Import Aliasing](#import-aliasing) | ||
[x] [Function Grouping and Ordering](#function-grouping-and-ordering) - Style applied through linter `funcorder`. | ||
- [Reduce Nesting](#reduce-nesting) | ||
- [Unnecessary Else](#unnecessary-else) | ||
- [Top-level Variable Declarations](#top-level-variable-declarations) | ||
- [Prefix Unexported Globals with _](#prefix-unexported-globals-with-_) | ||
- [Embedding in Structs](#embedding-in-structs) | ||
- [Local Variable Declarations](#local-variable-declarations) | ||
- [nil is a valid slice](#nil-is-a-valid-slice) | ||
- [Reduce Scope of Variables](#reduce-scope-of-variables) | ||
- [Avoid Naked Parameters](#avoid-naked-parameters) | ||
- [Use Raw String Literals to Avoid Escaping](#use-raw-string-literals-to-avoid-escaping) | ||
- [Initializing Structs](#initializing-structs) | ||
- [Use Field Names to Initialize Structs](#use-field-names-to-initialize-structs) | ||
- [Omit Zero Value Fields in Structs](#omit-zero-value-fields-in-structs) | ||
- [Use `var` for Zero Value Structs](#use-var-for-zero-value-structs) | ||
- [Initializing Struct References](#initializing-struct-references) | ||
- [Initializing Maps](#initializing-maps) | ||
- [Format Strings outside Printf](#format-strings-outside-printf) | ||
- [Naming Printf-style Functions](#naming-printf-style-functions) | ||
- [Patterns](#patterns) | ||
- [Test Tables](#test-tables) | ||
- [Functional Options](#functional-options) | ||
- [Linting](#linting) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.