dev: discourage bad practices (#803)

This commit is contained in:
Isaev Denis 2019-10-12 12:36:03 +03:00 committed by GitHub
parent 7004896cab
commit ca6effbeec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 179 additions and 110 deletions

View File

@ -1,7 +1,43 @@
Thank you for creating the issue! Thank you for creating the issue!
- [ ] Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
- [ ] Yes, I've searched similar issues on GitHub and didn't find any.
- [ ] Yes, I've included all information below (version, config, etc).
Please include the following information: Please include the following information:
1. Version of golangci-lint: `golangci-lint --version` (or git commit if you don't use binary distribution)
2. Config file: `cat .golangci.yml` <details><summary>Version of golangci-lint</summary>
3. Go environment: `go version && go env`
4. Verbose output of running: `golangci-lint run -v` ```bash
$ golangci-lint --version
# paste output here
```
</details>
<details><summary>Config file</summary>
```bash
$ cat .golangci.yml
# paste output here
```
</details>
<details><summary>Go environment</summary>
```bash
$ go version && go env
# paste output here
```
</details>
<details><summary>Verbose output of running</summary>
```bash
$ golangci-lint run -v
# paste output here
```
</details>

View File

@ -225,7 +225,6 @@ linters:
enable: enable:
- megacheck - megacheck
- govet - govet
enable-all: false
disable: disable:
- maligned - maligned
- prealloc - prealloc

View File

@ -48,6 +48,7 @@ linters-settings:
statements: 50 statements: 50
linters: linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true disable-all: true
enable: enable:

110
README.md
View File

@ -14,24 +14,42 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint
<a href="https://golangci.com/"><img src="docs/go.png" width="250px"></a> <a href="https://golangci.com/"><img src="docs/go.png" width="250px"></a>
* [Demo](#demo) - [GolangCI-Lint](#golangci-lint)
* [Install](#install) - [Demo](#demo)
* [Trusted By](#trusted-by) - [Install](#install)
* [Quick Start](#quick-start) - [Binary Release](#binary-release)
* [Editor Integration](#editor-integration) - [MacOS](#macos)
* [Shell Completion](#shell-completion) - [By Docker](#by-docker)
* [Comparison](#comparison) - [go get](#go-get)
* [Performance](#performance) - [Trusted By](#trusted-by)
* [Internals](#internals) - [Quick Start](#quick-start)
* [Supported Linters](#supported-linters) - [Editor Integration](#editor-integration)
* [Configuration](#configuration) - [Shell Completion](#shell-completion)
* [False Positives](#false-positives) - [Mac OS X](#mac-os-x)
* [FAQ](#faq) - [Linux](#linux)
* [Thanks](#thanks) - [Comparison](#comparison)
* [Changelog](#changelog) - [`golangci-lint` vs `gometalinter`](#golangci-lint-vs-gometalinter)
* [Debug](#debug) - [`golangci-lint` vs Running Linters Manually](#golangci-lint-vs-running-linters-manually)
* [Future Plans](#future-plans) - [Performance](#performance)
* [Contact Information](#contact-information) - [Comparison with gometalinter](#comparison-with-gometalinter)
- [Why golangci-lint is faster](#why-golangci-lint-is-faster)
- [Memory Usage of Golangci-lint](#memory-usage-of-golangci-lint)
- [Internals](#internals)
- [Supported Linters](#supported-linters)
- [Enabled By Default Linters](#enabled-by-default-linters)
- [Disabled By Default Linters (`-E/--enable`)](#disabled-by-default-linters--e--enable)
- [Configuration](#configuration)
- [Command-Line Options](#command-line-options)
- [Config File](#config-file)
- [False Positives](#false-positives)
- [Nolint](#nolint)
- [FAQ](#faq)
- [Thanks](#thanks)
- [Changelog](#changelog)
- [Debug](#debug)
- [Future Plans](#future-plans)
- [Contact Information](#contact-information)
- [License Scan](#license-scan)
## Demo ## Demo
@ -44,28 +62,28 @@ Short 1.5 min video demo of analyzing [beego](https://github.com/astaxie/beego).
## Install ## Install
### CI Installation ### Binary Release
Most installations are done for CI (travis, circleci etc). It's important to have reproducible CI: Most installations are done for CI (travis, circleci etc). It's important to have reproducible CI:
don't start to fail all builds at the same time. With golangci-lint this can happen if you don't start to fail all builds at the same time. With golangci-lint this can happen if you
use `--enable-all` and a new linter is added or even without `--enable-all`: when one upstream linter is upgraded. use deprecated option `--enable-all` and a new linter is added or even without `--enable-all`: when one upstream linter is upgraded.
It's highly recommended to install a fixed version of golangci-lint. It's highly recommended to install a fixed version of golangci-lint.
Releases are available on the [releases page](https://github.com/golangci/golangci-lint/releases). Releases are available on the [releases page](https://github.com/golangci/golangci-lint/releases).
Latest version: ![GitHub release](https://img.shields.io/github/release/golangci/golangci-lint.svg) Latest version: [v1.20.0](https://github.com/golangci/golangci-lint/releases/tag/v1.20.0)
Here is the recommended way to install golangci-lint (replace `vX.Y.Z` with the latest version): Here is the recommended way to install golangci-lint:
```bash ```bash
# binary will be $(go env GOPATH)/bin/golangci-lint # binary will be $(go env GOPATH)/bin/golangci-lint
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin vX.Y.Z curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.20.0
# or install it into ./bin/ # or install it into ./bin/
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s vX.Y.Z curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.20.0
# In alpine linux (as it does not come with curl by default) # In alpine linux (as it does not come with curl by default)
wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s vX.Y.Z wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.20.0
golangci-lint --version golangci-lint --version
``` ```
@ -74,41 +92,30 @@ Periodically update version of golangci-lint: the project is under active develo
and is constantly being improved. But please always check for newly found issues and and is constantly being improved. But please always check for newly found issues and
update if needed. update if needed.
### Local Installation ### MacOS
Local installation is not recommended for your CI pipeline. Only install the linter this way in a local development environment. You can also install a binary release on MacOS using [brew](https://brew.sh/):
#### Windows, MacOS and Linux
```bash
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
```
With `go1.12` or later you can get a particular version
```bash
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.18.0
```
#### MacOS
You can also install it on MacOS using [brew](https://brew.sh/):
```bash ```bash
brew install golangci/tap/golangci-lint brew install golangci/tap/golangci-lint
brew upgrade golangci/tap/golangci-lint brew upgrade golangci/tap/golangci-lint
``` ```
#### `--version` ### By Docker
If you need your local `golangci-lint --version` to show proper version additionally run:
```bash ```bash
cd $(go env GOPATH)/src/github.com/golangci/golangci-lint/cmd/golangci-lint docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.20.0 golangci-lint run -v
go install -ldflags "-X 'main.version=$(git describe --tags)' -X 'main.commit=$(git rev-parse --short HEAD)' -X 'main.date=$(date)'"
``` ```
On Windows, you can run the above commands with Git Bash, which comes with [Git for Windows](https://git-scm.com/download/win). ### go get
Please, do not install `golangci-lint` by `go get`:
1. [`go.mod`](https://github.com/golangci/golangci-lint/blob/master/go.mod) replacement directive doesn't apply. It means you will be using patched version of `golangci-lint`.
2. it's much slower than binary installation
3. it's stability depends on your Go version (e.g. on [this compiler Go <= 1.12 bug](https://github.com/golang/go/issues/29612)).
4. it's not guaranteed to work: e.g. we've encountered a lot of issues with Go modules hashes.
5. it allows installation from `master` branch which can't be considered stable.
## Trusted By ## Trusted By
@ -515,7 +522,6 @@ Flags:
--skip-files strings Regexps of files to skip --skip-files strings Regexps of files to skip
-E, --enable strings Enable specific linter -E, --enable strings Enable specific linter
-D, --disable strings Disable specific linter -D, --disable strings Disable specific linter
--enable-all Enable all linters
--disable-all Disable all linters --disable-all Disable all linters
-p, --presets strings Enable presets (bugs|complexity|format|performance|style|unused) of linters. Run 'golangci-lint linters' to see them. This option implies option --disable-all -p, --presets strings Enable presets (bugs|complexity|format|performance|style|unused) of linters. Run 'golangci-lint linters' to see them. This option implies option --disable-all
--fast Run only fast linters from enabled linters set (first run won't be fast) --fast Run only fast linters from enabled linters set (first run won't be fast)
@ -818,7 +824,6 @@ linters:
enable: enable:
- megacheck - megacheck
- govet - govet
enable-all: false
disable: disable:
- maligned - maligned
- prealloc - prealloc
@ -945,6 +950,7 @@ linters-settings:
statements: 50 statements: 50
linters: linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true disable-all: true
enable: enable:
@ -1097,7 +1103,7 @@ Long answer:
**`golangci-lint` doesn't work** **`golangci-lint` doesn't work**
1. Update it: `go get -u github.com/golangci/golangci-lint/cmd/golangci-lint` 1. Please, ensure you are using the latest binary release.
2. Run it with `-v` option and check the output. 2. Run it with `-v` option and check the output.
3. If it doesn't help create a [GitHub issue](https://github.com/golangci/golangci-lint/issues/new) with the output from the error and #2 above. 3. If it doesn't help create a [GitHub issue](https://github.com/golangci/golangci-lint/issues/new) with the output from the error and #2 above.

View File

@ -14,24 +14,42 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint
<a href="https://golangci.com/"><img src="docs/go.png" width="250px"></a> <a href="https://golangci.com/"><img src="docs/go.png" width="250px"></a>
* [Demo](#demo) - [GolangCI-Lint](#golangci-lint)
* [Install](#install) - [Demo](#demo)
* [Trusted By](#trusted-by) - [Install](#install)
* [Quick Start](#quick-start) - [Binary Release](#binary-release)
* [Editor Integration](#editor-integration) - [MacOS](#macos)
* [Shell Completion](#shell-completion) - [By Docker](#by-docker)
* [Comparison](#comparison) - [go get](#go-get)
* [Performance](#performance) - [Trusted By](#trusted-by)
* [Internals](#internals) - [Quick Start](#quick-start)
* [Supported Linters](#supported-linters) - [Editor Integration](#editor-integration)
* [Configuration](#configuration) - [Shell Completion](#shell-completion)
* [False Positives](#false-positives) - [Mac OS X](#mac-os-x)
* [FAQ](#faq) - [Linux](#linux)
* [Thanks](#thanks) - [Comparison](#comparison)
* [Changelog](#changelog) - [`golangci-lint` vs `gometalinter`](#golangci-lint-vs-gometalinter)
* [Debug](#debug) - [`golangci-lint` vs Running Linters Manually](#golangci-lint-vs-running-linters-manually)
* [Future Plans](#future-plans) - [Performance](#performance)
* [Contact Information](#contact-information) - [Comparison with gometalinter](#comparison-with-gometalinter)
- [Why golangci-lint is faster](#why-golangci-lint-is-faster)
- [Memory Usage of Golangci-lint](#memory-usage-of-golangci-lint)
- [Internals](#internals)
- [Supported Linters](#supported-linters)
- [Enabled By Default Linters](#enabled-by-default-linters)
- [Disabled By Default Linters (`-E/--enable`)](#disabled-by-default-linters--e--enable)
- [Configuration](#configuration)
- [Command-Line Options](#command-line-options)
- [Config File](#config-file)
- [False Positives](#false-positives)
- [Nolint](#nolint)
- [FAQ](#faq)
- [Thanks](#thanks)
- [Changelog](#changelog)
- [Debug](#debug)
- [Future Plans](#future-plans)
- [Contact Information](#contact-information)
- [License Scan](#license-scan)
## Demo ## Demo
@ -44,28 +62,28 @@ Short 1.5 min video demo of analyzing [beego](https://github.com/astaxie/beego).
## Install ## Install
### CI Installation ### Binary Release
Most installations are done for CI (travis, circleci etc). It's important to have reproducible CI: Most installations are done for CI (travis, circleci etc). It's important to have reproducible CI:
don't start to fail all builds at the same time. With golangci-lint this can happen if you don't start to fail all builds at the same time. With golangci-lint this can happen if you
use `--enable-all` and a new linter is added or even without `--enable-all`: when one upstream linter is upgraded. use deprecated option `--enable-all` and a new linter is added or even without `--enable-all`: when one upstream linter is upgraded.
It's highly recommended to install a fixed version of golangci-lint. It's highly recommended to install a fixed version of golangci-lint.
Releases are available on the [releases page](https://github.com/golangci/golangci-lint/releases). Releases are available on the [releases page](https://github.com/golangci/golangci-lint/releases).
Latest version: ![GitHub release](https://img.shields.io/github/release/golangci/golangci-lint.svg) Latest version: [{{.LatestVersion}}](https://github.com/golangci/golangci-lint/releases/tag/{{.LatestVersion}})
Here is the recommended way to install golangci-lint (replace `vX.Y.Z` with the latest version): Here is the recommended way to install golangci-lint:
```bash ```bash
# binary will be $(go env GOPATH)/bin/golangci-lint # binary will be $(go env GOPATH)/bin/golangci-lint
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin vX.Y.Z curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin {{.LatestVersion}}
# or install it into ./bin/ # or install it into ./bin/
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s vX.Y.Z curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s {{.LatestVersion}}
# In alpine linux (as it does not come with curl by default) # In alpine linux (as it does not come with curl by default)
wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s vX.Y.Z wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s {{.LatestVersion}}
golangci-lint --version golangci-lint --version
``` ```
@ -74,41 +92,30 @@ Periodically update version of golangci-lint: the project is under active develo
and is constantly being improved. But please always check for newly found issues and and is constantly being improved. But please always check for newly found issues and
update if needed. update if needed.
### Local Installation ### MacOS
Local installation is not recommended for your CI pipeline. Only install the linter this way in a local development environment. You can also install a binary release on MacOS using [brew](https://brew.sh/):
#### Windows, MacOS and Linux
```bash
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
```
With `go1.12` or later you can get a particular version
```bash
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.18.0
```
#### MacOS
You can also install it on MacOS using [brew](https://brew.sh/):
```bash ```bash
brew install golangci/tap/golangci-lint brew install golangci/tap/golangci-lint
brew upgrade golangci/tap/golangci-lint brew upgrade golangci/tap/golangci-lint
``` ```
#### `--version` ### By Docker
If you need your local `golangci-lint --version` to show proper version additionally run:
```bash ```bash
cd $(go env GOPATH)/src/github.com/golangci/golangci-lint/cmd/golangci-lint docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:{{.LatestVersion}} golangci-lint run -v
go install -ldflags "-X 'main.version=$(git describe --tags)' -X 'main.commit=$(git rev-parse --short HEAD)' -X 'main.date=$(date)'"
``` ```
On Windows, you can run the above commands with Git Bash, which comes with [Git for Windows](https://git-scm.com/download/win). ### go get
Please, do not install `golangci-lint` by `go get`:
1. [`go.mod`](https://github.com/golangci/golangci-lint/blob/master/go.mod) replacement directive doesn't apply. It means you will be using patched version of `golangci-lint`.
2. it's much slower than binary installation
3. it's stability depends on your Go version (e.g. on [this compiler Go <= 1.12 bug](https://github.com/golang/go/issues/29612)).
4. it's not guaranteed to work: e.g. we've encountered a lot of issues with Go modules hashes.
5. it allows installation from `master` branch which can't be considered stable.
## Trusted By ## Trusted By
@ -542,7 +549,7 @@ Long answer:
**`golangci-lint` doesn't work** **`golangci-lint` doesn't work**
1. Update it: `go get -u github.com/golangci/golangci-lint/cmd/golangci-lint` 1. Please, ensure you are using the latest binary release.
2. Run it with `-v` option and check the output. 2. Run it with `-v` option and check the output.
3. If it doesn't help create a [GitHub issue](https://github.com/golangci/golangci-lint/issues/new) with the output from the error and #2 above. 3. If it doesn't help create a [GitHub issue](https://github.com/golangci/golangci-lint/issues/new) with the output from the error and #2 above.

3
go.mod
View File

@ -40,7 +40,7 @@ require (
github.com/ultraware/whitespace v0.0.4 github.com/ultraware/whitespace v0.0.4
github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517 github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517
github.com/valyala/quicktemplate v1.2.0 github.com/valyala/quicktemplate v1.2.0
golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0 golang.org/x/tools v0.0.0-20191010075000-0337d82405ff
gopkg.in/yaml.v2 v2.2.4 gopkg.in/yaml.v2 v2.2.4
honnef.co/go/tools v0.0.1-2019.2.3 honnef.co/go/tools v0.0.1-2019.2.3
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed
@ -50,5 +50,4 @@ require (
// https://github.com/golang/tools/pull/156 // https://github.com/golang/tools/pull/156
// https://github.com/golang/tools/pull/160 // https://github.com/golang/tools/pull/160
// https://github.com/golang/tools/pull/162
replace golang.org/x/tools => github.com/golangci/tools v0.0.0-20190915081525-6aa350649b1c replace golang.org/x/tools => github.com/golangci/tools v0.0.0-20190915081525-6aa350649b1c

View File

@ -166,6 +166,11 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
fs.StringSliceVarP(&lc.Enable, "enable", "E", nil, wh("Enable specific linter")) fs.StringSliceVarP(&lc.Enable, "enable", "E", nil, wh("Enable specific linter"))
fs.StringSliceVarP(&lc.Disable, "disable", "D", nil, wh("Disable specific linter")) fs.StringSliceVarP(&lc.Disable, "disable", "D", nil, wh("Disable specific linter"))
fs.BoolVar(&lc.EnableAll, "enable-all", false, wh("Enable all linters")) fs.BoolVar(&lc.EnableAll, "enable-all", false, wh("Enable all linters"))
if err := fs.MarkHidden("enable-all"); err != nil {
panic(err)
}
// TODO: run hideFlag("enable-all") to print deprecation message.
fs.BoolVar(&lc.DisableAll, "disable-all", false, wh("Disable all linters")) fs.BoolVar(&lc.DisableAll, "disable-all", false, wh("Disable all linters"))
fs.StringSliceVarP(&lc.Presets, "presets", "p", nil, fs.StringSliceVarP(&lc.Presets, "presets", "p", nil,
wh(fmt.Sprintf("Enable presets (%s) of linters. Run 'golangci-lint linters' to see "+ wh(fmt.Sprintf("Enable presets (%s) of linters. Run 'golangci-lint linters' to see "+

View File

@ -42,6 +42,16 @@ func genReadme(tmplPath, outPath string) error {
return tmpl.Execute(out, ctx) return tmpl.Execute(out, ctx)
} }
func getLatestVersion() (string, error) {
out, err := exec.Command("git", "tag", "-l", "--sort=-v:refname").Output()
if err != nil {
return "", fmt.Errorf("failed to run git tag: %w", err)
}
lines := bytes.Split(out, []byte("\n"))
return string(lines[0]), nil
}
func buildTemplateContext() (map[string]interface{}, error) { func buildTemplateContext() (map[string]interface{}, error) {
golangciYaml, err := ioutil.ReadFile(".golangci.yml") golangciYaml, err := ioutil.ReadFile(".golangci.yml")
if err != nil { if err != nil {
@ -79,6 +89,11 @@ func buildTemplateContext() (map[string]interface{}, error) {
return nil, err return nil, err
} }
latestVersion, err := getLatestVersion()
if err != nil {
return nil, fmt.Errorf("failed to get latest version: %w", err)
}
return map[string]interface{}{ return map[string]interface{}{
"GolangciYaml": strings.TrimSpace(string(golangciYaml)), "GolangciYaml": strings.TrimSpace(string(golangciYaml)),
"GolangciYamlExample": strings.TrimSpace(string(golangciYamlExample)), "GolangciYamlExample": strings.TrimSpace(string(golangciYamlExample)),
@ -89,6 +104,7 @@ func buildTemplateContext() (map[string]interface{}, error) {
"ThanksList": getThanksList(), "ThanksList": getThanksList(),
"RunHelpText": string(shortHelp), "RunHelpText": string(shortHelp),
"ChangeLog": string(changeLog), "ChangeLog": string(changeLog),
"LatestVersion": latestVersion,
}, nil }, nil
} }

2
vendor/modules.txt vendored
View File

@ -185,7 +185,7 @@ golang.org/x/sys/windows
golang.org/x/text/transform golang.org/x/text/transform
golang.org/x/text/unicode/norm golang.org/x/text/unicode/norm
golang.org/x/text/width golang.org/x/text/width
# golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0 => github.com/golangci/tools v0.0.0-20190915081525-6aa350649b1c # golang.org/x/tools v0.0.0-20191010075000-0337d82405ff => github.com/golangci/tools v0.0.0-20190915081525-6aa350649b1c
golang.org/x/tools/go/analysis golang.org/x/tools/go/analysis
golang.org/x/tools/go/analysis/passes/asmdecl golang.org/x/tools/go/analysis/passes/asmdecl
golang.org/x/tools/go/analysis/passes/assign golang.org/x/tools/go/analysis/passes/assign