Last active
April 11, 2022 05:42
-
-
Save coreyog/66bd23bf9c4c0b92a81433018c53ac91 to your computer and use it in GitHub Desktop.
A good base to start with for Go linting
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
# This file contains all available configuration options | |
# with their default values. | |
# options for analysis running | |
run: | |
# default concurrency is a available CPU number | |
concurrency: 4 | |
# timeout for analysis, e.g. 30s, 5m, default is 1m | |
timeout: 1m | |
# exit code when at least one issue was found, default is 1 | |
issues-exit-code: 1 | |
# include test files or not, default is true | |
tests: true | |
# default is true. Enables skipping of directories: | |
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ | |
skip-dirs-use-default: true | |
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": | |
# If invoked with -mod=readonly, the go command is disallowed from the implicit | |
# automatic updating of go.mod described above. Instead, it fails when any changes | |
# to go.mod are needed. This setting is most useful to check that go.mod does | |
# not need updates, such as in a continuous integration and testing system. | |
# If invoked with -mod=vendor, the go command assumes that the vendor | |
# directory holds the correct copies of dependencies and ignores | |
# the dependency descriptions in go.mod. | |
#modules-download-mode: mod | |
# Allow multiple parallel golangci-lint instances running. | |
# If false (default) - golangci-lint acquires file lock on start. | |
allow-parallel-runners: false | |
# output configuration options | |
output: | |
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions | |
# default is "colored-line-number" | |
format: colored-line-number | |
# print lines of code with issue, default is true | |
print-issued-lines: true | |
# print linter name in the end of issue text, default is true | |
print-linter-name: true | |
# make issues output unique by line, default is true | |
uniq-by-line: true | |
# sorts results by: filepath, line and column | |
sort-results: true | |
# all available settings of specific linters | |
linters-settings: | |
errcheck: | |
# report about not checking of errors in type assertions: `a := b.(MyStruct)`; | |
# default is false: such cases aren't reported by default. | |
check-type-assertions: false | |
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; | |
# default is false: such cases aren't reported by default. | |
check-blank: false | |
# [deprecated] comma-separated list of pairs of the form pkg:regex | |
# the regex is used to ignore names within pkg. (default "fmt:.*"). | |
# see https://github.com/kisielk/errcheck#the-deprecated-method for details | |
ignore: fmt:.*,io/ioutil:^Read.* | |
# [deprecated] use exclude-functions instead. | |
# path to a file containing a list of functions to exclude from checking | |
# see https://github.com/kisielk/errcheck#excluding-functions for details | |
#exclude: /path/to/file.txt | |
# list of functions to exclude from checking, where each entry is a single function to exclude. | |
# see https://github.com/kisielk/errcheck#excluding-functions for details | |
#exclude-functions: | |
# - io/ioutil.ReadFile | |
# - io.Copy(*bytes.Buffer) | |
# - io.Copy(os.Stdout) | |
errorlint: | |
# Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats | |
errorf: true | |
# Check for plain type assertions and type switches | |
asserts: true | |
# Check for plain error comparisons | |
comparison: true | |
goconst: | |
# minimal length of string constant, 3 by default | |
min-len: 3 | |
# minimum occurrences of constant string count to trigger issue, 3 by default | |
min-occurrences: 3 | |
# ignore test files, false by default | |
ignore-tests: false | |
# look for existing constants matching the values, true by default | |
match-constant: true | |
# search also for duplicated numbers, false by default | |
numbers: false | |
# minimum value, only works with goconst.numbers, 3 by default | |
min: 3 | |
# maximum value, only works with goconst.numbers, 3 by default | |
max: 3 | |
# ignore when constant is not used as function argument, true by default | |
ignore-calls: true | |
gocritic: | |
# Which checks should be enabled; can't be combined with 'disabled-checks'; | |
# See https://go-critic.github.io/overview#checks-overview | |
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` | |
# By default list of stable checks is used. | |
enabled-checks: | |
- nestingReduce | |
- unnamedresult | |
- ruleguard | |
- truncateCmp | |
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty | |
disabled-checks: | |
- regexpMust | |
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. | |
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". | |
enabled-tags: | |
- performance | |
disabled-tags: | |
- experimental | |
# Settings passed to gocritic. | |
# The settings key is the name of a supported gocritic checker. | |
# The list of supported checkers can be find in https://go-critic.github.io/overview. | |
settings: | |
captLocal: # must be valid enabled check name | |
# whether to restrict checker to params only (default true) | |
paramsOnly: true | |
elseif: | |
# whether to skip balanced if-else pairs (default true) | |
skipBalanced: true | |
hugeParam: | |
# size in bytes that makes the warning trigger (default 80) | |
sizeThreshold: 80 | |
nestingReduce: | |
# min number of statements inside a branch to trigger a warning (default 5) | |
bodyWidth: 5 | |
rangeExprCopy: | |
# size in bytes that makes the warning trigger (default 512) | |
sizeThreshold: 512 | |
# whether to check test functions (default true) | |
skipTestFuncs: true | |
rangeValCopy: | |
# size in bytes that makes the warning trigger (default 128) | |
sizeThreshold: 32 | |
# whether to check test functions (default true) | |
skipTestFuncs: true | |
ruleguard: | |
# Enable debug to identify which 'Where' condition was rejected. | |
# The value of the parameter is the name of a function in a ruleguard file. | |
# | |
# When a rule is evaluated: | |
# If: | |
# The Match() clause is accepted; and | |
# One of the conditions in the Where() clause is rejected, | |
# Then: | |
# ruleguard prints the specific Where() condition that was rejected. | |
# | |
# The flag is passed to the ruleguard 'debug-group' argument. | |
debug: 'emptyDecl' | |
# Deprecated, use 'failOn' param. | |
# If set to true, identical to failOn='all', otherwise failOn='' | |
failOnError: false | |
# Determines the behavior when an error occurs while parsing ruleguard files. | |
# If flag is not set, log error and skip rule files that contain an error. | |
# If flag is set, the value must be a comma-separated list of error conditions. | |
# - 'all': fail on all errors. | |
# - 'import': ruleguard rule imports a package that cannot be found. | |
# - 'dsl': gorule file does not comply with the ruleguard DSL. | |
failOn: dsl | |
# Comma-separated list of file paths containing ruleguard rules. | |
# If a path is relative, it is relative to the directory where the golangci-lint command is executed. | |
# The special '${configDir}' variable is substituted with the absolute directory containing the golangci config file. | |
# Glob patterns such as 'rules-*.go' may be specified. | |
# rules: '${configDir}/ruleguard/rules-*.go,${configDir}/myrule1.go' | |
truncateCmp: | |
# whether to skip int/uint/uintptr types (default true) | |
skipArchDependent: true | |
underef: | |
# whether to skip (*x).method() calls where x is a pointer receiver (default true) | |
skipRecvDeref: true | |
unnamedResult: | |
# whether to check exported functions | |
checkExported: true | |
gofmt: | |
# simplify code: gofmt with `-s` option, true by default | |
simplify: true | |
gomoddirectives: | |
# Allow local `replace` directives. Default is false. | |
replace-local: false | |
# List of allowed `replace` directives. Default is empty. | |
replace-allow-list: | |
- launchpad.net/gocheck | |
# Allow to not explain why the version has been retracted in the `retract` directives. Default is false. | |
retract-allow-no-explanation: false | |
# Forbid the use of the `exclude` directives. Default is false. | |
exclude-forbidden: false | |
gosec: | |
# To select a subset of rules to run. | |
# Available rules: https://github.com/securego/gosec#available-rules | |
includes: | |
- G401 | |
- G306 | |
- G101 | |
# To specify a set of rules to explicitly exclude. | |
# Available rules: https://github.com/securego/gosec#available-rules | |
excludes: | |
- G204 | |
# Exclude generated files | |
exclude-generated: true | |
# Filter out the issues with a lower severity than the given value. Valid options are: low, medium, high. | |
severity: "low" | |
# Filter out the issues with a lower confidence than the given value. Valid options are: low, medium, high. | |
confidence: "low" | |
# To specify the configuration of rules. | |
# The configuration of rules is not fully documented by gosec: | |
# https://github.com/securego/gosec#configuration | |
# https://github.com/securego/gosec/blob/569328eade2ccbad4ce2d0f21ee158ab5356a5cf/rules/rulelist.go#L60-L102 | |
config: | |
G306: "0600" | |
G101: | |
pattern: "(?i)example" | |
ignore_entropy: false | |
entropy_threshold: "80.0" | |
per_char_threshold: "3.0" | |
truncate: "32" | |
gosimple: | |
# Select the Go version to target. The default is '1.13'. | |
go: "1.15" | |
# https://staticcheck.io/docs/options#checks | |
checks: [ "all" ] | |
govet: | |
# report about shadowed variables | |
check-shadowing: true | |
# settings per analyzer | |
settings: | |
printf: # analyzer name, run `go tool vet help` to see all analyzers | |
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer | |
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof | |
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf | |
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf | |
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf | |
# enable or disable analyzers by name | |
# run `go tool vet help` to see all analyzers | |
enable: | |
- atomicalign | |
enable-all: false | |
disable: | |
- shadow | |
disable-all: false | |
importas: | |
# if set to `true`, force to use alias. | |
no-unaliased: true | |
# List of aliases | |
alias: | |
# using `servingv1` alias for `knative.dev/serving/pkg/apis/serving/v1` package | |
- pkg: knative.dev/serving/pkg/apis/serving/v1 | |
alias: servingv1 | |
# using `autoscalingv1alpha1` alias for `knative.dev/serving/pkg/apis/autoscaling/v1alpha1` package | |
- pkg: knative.dev/serving/pkg/apis/autoscaling/v1alpha1 | |
alias: autoscalingv1alpha1 | |
# You can specify the package path by regular expression, | |
# and alias by regular expression expansion syntax like below. | |
# see https://github.com/julz/importas#use-regular-expression for details | |
- pkg: knative.dev/serving/pkg/apis/(\w+)/(v[\w\d]+) | |
alias: $1$2 | |
nakedret: | |
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30 | |
max-func-lines: 0 | |
nolintlint: | |
# Disable to ensure that all nolint directives actually have an effect. Default is false. | |
allow-unused: false | |
# Disable to ensure that nolint directives don't have a leading space. Default is true. | |
allow-leading-space: true | |
# Exclude following linters from requiring an explanation. Default is []. | |
allow-no-explanation: [ ] | |
# Enable to require an explanation of nonzero length after each nolint directive. Default is false. | |
require-explanation: true | |
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false. | |
require-specific: true | |
prealloc: | |
# XXX: we don't recommend using this linter before doing performance profiling. | |
# For most programs usage of prealloc will be a premature optimization. | |
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. | |
# True by default. | |
simple: true | |
range-loops: true # Report preallocation suggestions on range loops, true by default | |
for-loops: false # Report preallocation suggestions on for loops, false by default | |
whitespace: | |
multi-if: false # Enforces newlines (or comments) after every multi-line if statement | |
multi-func: false # Enforces newlines (or comments) after every multi-line function signature | |
wsl: | |
# See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for | |
# documentation of available settings. These are the defaults for | |
# `golangci-lint`. | |
allow-assign-and-anything: false | |
allow-assign-and-call: true | |
allow-cuddle-declarations: false | |
allow-multiline-assign: true | |
allow-separated-leading-comment: false | |
allow-trailing-comment: false | |
force-case-trailing-whitespace: 0 | |
force-err-cuddling: false | |
force-short-decl-cuddling: false | |
strict-append: true | |
linters: | |
disable-all: true | |
enable: | |
- bodyclose | |
- deadcode | |
- errcheck | |
- errname | |
- errorlint | |
- exportloopref | |
- goconst | |
- gocritic | |
- godot | |
- gofmt | |
- gosec | |
- gosimple | |
- govet | |
- govet | |
- importas | |
- ineffassign | |
- nakedret | |
- noctx | |
- nolintlint | |
- paralleltest | |
- prealloc | |
- rowserrcheck | |
- sqlclosecheck | |
- tparallel | |
- unconvert | |
- unused | |
- varcheck | |
- whitespace | |
- wsl | |
issues: | |
exclude: | |
- "undeclared name" | |
- "undefined \\(type .*? has no field or method .*?\\)" | |
- "only one cuddle assignment allowed before defer statement" | |
- "only cuddled expressions if assigning variable or using from line above" | |
- "declarations should never be cuddled" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment