Replace .golangci.yml with .golangci.enforced.yml (#19568)

This commit replaces the current .golangci.yml with
.golangci.enforced.yml so editors will display the same errors as CI.

Additionally, it removes references to .golangci.enforced.yml from the
documentation.
This commit is contained in:
Camden Cheek 2021-03-30 17:43:56 -06:00 committed by GitHub
parent a695c81cd3
commit b5da3f82fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 99 deletions

View File

@ -1,50 +0,0 @@
# This file contains the configuration of the enforced linters for the project.
# Eventually, the goal is to unify this with .golangci.yml.
# https://github.com/sourcegraph/sourcegraph/issues/18720
# See explanation of linters at https://golangci-lint.run/usage/linters/
linters:
disable-all: true
enable:
- bodyclose
- gocritic
- goimports
- gosimple
- govet
- ineffassign
- nolintlint
- staticcheck
- typecheck
- unconvert
- unused
linters-settings:
gocritic:
disabled-checks:
- appendAssign # Too many false positives
- assignOp # Maybe worth adding, but likely not worth the noise
- commentFormatting # No strong benefit
- deprecatedComment # Unnecessary
- exitAfterDefer # Only occurs in auxiliary tools
- ifElseChain # Noisy for not much gain
- singleCaseSwitch # Noisy for not much gain
govet:
disable:
- composites
issues:
exclude-rules:
# Exclude bodyclose lint from tests because leaking connections in tests
# is a non-issue, and checking that adds unnecessary noise
- path: _test\.go
linters:
- bodyclose
run:
timeout: 5m
skip-dirs:
- client
- ui
- vendor
- node_modules

View File

@ -1,63 +1,40 @@
linters-settings:
dupl:
threshold: 100
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
golint:
min-confidence: 0
govet:
check-shadowing: false
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
# See explanation of linters at https://golangci-lint.run/usage/linters/
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- dogsled
- dupl
- errcheck
- gocritic
- goimports
- golint
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- nakedret
- nolintlint
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
linters-settings:
gocritic:
disabled-checks:
- appendAssign # Too many false positives
- assignOp # Maybe worth adding, but likely not worth the noise
- commentFormatting # No strong benefit
- deprecatedComment # Unnecessary
- exitAfterDefer # Only occurs in auxiliary tools
- ifElseChain # Noisy for not much gain
- singleCaseSwitch # Noisy for not much gain
govet:
disable:
- composites
issues:
exclude-rules:
# Exclude bodyclose lint from tests because leaking connections in tests
# is a non-issue, and checking that adds unnecessary noise
- path: _test\.go
linters:
- bodyclose
run:
timeout: 5m

View File

@ -18,4 +18,4 @@ else
fi
echo "--- lint"
"./dev/golangci-lint.sh" --config .golangci.enforced.yml run "${pkgs[@]}"
"./dev/golangci-lint.sh" --config .golangci.yml run "${pkgs[@]}"

View File

@ -4,14 +4,12 @@
Linting is the process of running static checks on the codebase to catch common mistakes and provide an automatically-enforceable set of best practices. We use a tool called [`golangci-lint`](https://golangci-lint.run/), which bundles a large number of common linters into a single binary.
`golangci-lint` is configured using the `.golangci.yml` and `.golangci.enforced.yml` files in the root of the repository. `.golangci.enforced.yml` contains a subset of the lints in `.golangci.yml`. In CI, the only lints that will cause a failure are the ones in `.golangci.enforced.yml`. By default, `golangci-lint` uses `.golangci.yml`, so you may see warnings in your editor or by running `golangci-lint run` that will not cause failures in CI. Eventually, we hope to unify these two configurations. A tracking issue with the progress can be found here: [#18720](https://github.com/sourcegraph/sourcegraph/issues/18720).
`golangci-lint` is configured using the `.golangci.yml` in the root of the repository.
## Running the linters
The easiest way to check locally if your changes will pass the lint step in CI is to run `./dev/check/go-lint.sh`. This is run as part of `./dev/check/all.sh`, so if it passes, linting should be good in CI as well.
To run the extended set of linters (all enforced lints + some currently unenforced but recommended lints), you can run `golangci-lint run`, which will automatically pick up the config in `.golangci.yml`.
## Ignoring lints
We do our best to only enable lints that either reduce minor change churn (like `goimports`) or find common issues in our code (like `ineffassign`), but occasionally there will be false positives from the linters. In these cases, `golangci-lint` provides a way to ignore lint issues with a comment: `//nolint:lintname`. For more information on how to use `//nolint`, see the [`golangci-lint` false positives page](https://golangci-lint.run/usage/false-positives/).