diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index a55080e0467e..6b3886532590 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,7 +1,43 @@ 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: -1. Version of golangci-lint: `golangci-lint --version` (or git commit if you don't use binary distribution) -2. Config file: `cat .golangci.yml` -3. Go environment: `go version && go env` -4. Verbose output of running: `golangci-lint run -v` \ No newline at end of file + +
Version of golangci-lint + +```bash +$ golangci-lint --version +# paste output here +``` + +
+ +
Config file + +```bash +$ cat .golangci.yml +# paste output here +``` + +
+ +
Go environment + +```bash +$ go version && go env +# paste output here +``` + +
+ +
Verbose output of running + +```bash +$ golangci-lint run -v +# paste output here +``` + +
diff --git a/.golangci.example.yml b/.golangci.example.yml index 2d3feb9e0bd5..1c4aff5a7f5d 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -225,7 +225,6 @@ linters: enable: - megacheck - govet - enable-all: false disable: - maligned - prealloc diff --git a/.golangci.yml b/.golangci.yml index a46c27edfea2..c306f183ed3a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -48,6 +48,7 @@ linters-settings: statements: 50 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 disable-all: true enable: diff --git a/README.md b/README.md index 7241958b4411..be9d2166113e 100644 --- a/README.md +++ b/README.md @@ -14,24 +14,42 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint -* [Demo](#demo) -* [Install](#install) -* [Trusted By](#trusted-by) -* [Quick Start](#quick-start) -* [Editor Integration](#editor-integration) -* [Shell Completion](#shell-completion) -* [Comparison](#comparison) -* [Performance](#performance) -* [Internals](#internals) -* [Supported Linters](#supported-linters) -* [Configuration](#configuration) -* [False Positives](#false-positives) -* [FAQ](#faq) -* [Thanks](#thanks) -* [Changelog](#changelog) -* [Debug](#debug) -* [Future Plans](#future-plans) -* [Contact Information](#contact-information) +- [GolangCI-Lint](#golangci-lint) + - [Demo](#demo) + - [Install](#install) + - [Binary Release](#binary-release) + - [MacOS](#macos) + - [By Docker](#by-docker) + - [go get](#go-get) + - [Trusted By](#trusted-by) + - [Quick Start](#quick-start) + - [Editor Integration](#editor-integration) + - [Shell Completion](#shell-completion) + - [Mac OS X](#mac-os-x) + - [Linux](#linux) + - [Comparison](#comparison) + - [`golangci-lint` vs `gometalinter`](#golangci-lint-vs-gometalinter) + - [`golangci-lint` vs Running Linters Manually](#golangci-lint-vs-running-linters-manually) + - [Performance](#performance) + - [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 @@ -44,28 +62,28 @@ Short 1.5 min video demo of analyzing [beego](https://github.com/astaxie/beego). ## Install -### CI Installation +### Binary Release 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 -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. 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 # 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/ -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) -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 ``` @@ -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 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. - -#### 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/): +You can also install a binary release on MacOS using [brew](https://brew.sh/): ```bash brew install golangci/tap/golangci-lint brew upgrade golangci/tap/golangci-lint ``` -#### `--version` - -If you need your local `golangci-lint --version` to show proper version additionally run: +### By Docker ```bash -cd $(go env GOPATH)/src/github.com/golangci/golangci-lint/cmd/golangci-lint -go install -ldflags "-X 'main.version=$(git describe --tags)' -X 'main.commit=$(git rev-parse --short HEAD)' -X 'main.date=$(date)'" +docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.20.0 golangci-lint run -v ``` -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 @@ -515,7 +522,6 @@ Flags: --skip-files strings Regexps of files to skip -E, --enable strings Enable specific linter -D, --disable strings Disable specific linter - --enable-all Enable 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 --fast Run only fast linters from enabled linters set (first run won't be fast) @@ -818,7 +824,6 @@ linters: enable: - megacheck - govet - enable-all: false disable: - maligned - prealloc @@ -945,6 +950,7 @@ linters-settings: statements: 50 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 disable-all: true enable: @@ -1097,7 +1103,7 @@ Long answer: **`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. 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. diff --git a/README.tmpl.md b/README.tmpl.md index 0f47ff13cd8e..bb11b99a788b 100644 --- a/README.tmpl.md +++ b/README.tmpl.md @@ -14,24 +14,42 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint -* [Demo](#demo) -* [Install](#install) -* [Trusted By](#trusted-by) -* [Quick Start](#quick-start) -* [Editor Integration](#editor-integration) -* [Shell Completion](#shell-completion) -* [Comparison](#comparison) -* [Performance](#performance) -* [Internals](#internals) -* [Supported Linters](#supported-linters) -* [Configuration](#configuration) -* [False Positives](#false-positives) -* [FAQ](#faq) -* [Thanks](#thanks) -* [Changelog](#changelog) -* [Debug](#debug) -* [Future Plans](#future-plans) -* [Contact Information](#contact-information) +- [GolangCI-Lint](#golangci-lint) + - [Demo](#demo) + - [Install](#install) + - [Binary Release](#binary-release) + - [MacOS](#macos) + - [By Docker](#by-docker) + - [go get](#go-get) + - [Trusted By](#trusted-by) + - [Quick Start](#quick-start) + - [Editor Integration](#editor-integration) + - [Shell Completion](#shell-completion) + - [Mac OS X](#mac-os-x) + - [Linux](#linux) + - [Comparison](#comparison) + - [`golangci-lint` vs `gometalinter`](#golangci-lint-vs-gometalinter) + - [`golangci-lint` vs Running Linters Manually](#golangci-lint-vs-running-linters-manually) + - [Performance](#performance) + - [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 @@ -44,28 +62,28 @@ Short 1.5 min video demo of analyzing [beego](https://github.com/astaxie/beego). ## Install -### CI Installation +### Binary Release 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 -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. 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 # 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/ -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) -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 ``` @@ -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 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. - -#### 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/): +You can also install a binary release on MacOS using [brew](https://brew.sh/): ```bash brew install golangci/tap/golangci-lint brew upgrade golangci/tap/golangci-lint ``` -#### `--version` - -If you need your local `golangci-lint --version` to show proper version additionally run: +### By Docker ```bash -cd $(go env GOPATH)/src/github.com/golangci/golangci-lint/cmd/golangci-lint -go install -ldflags "-X 'main.version=$(git describe --tags)' -X 'main.commit=$(git rev-parse --short HEAD)' -X 'main.date=$(date)'" +docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:{{.LatestVersion}} golangci-lint run -v ``` -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 @@ -542,7 +549,7 @@ Long answer: **`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. 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. diff --git a/go.mod b/go.mod index 5c60f37673fe..88d5878c8c16 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( github.com/ultraware/whitespace v0.0.4 github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517 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 honnef.co/go/tools v0.0.1-2019.2.3 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/160 -// https://github.com/golang/tools/pull/162 replace golang.org/x/tools => github.com/golangci/tools v0.0.0-20190915081525-6aa350649b1c diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 7e5f429d1b8d..729996adae48 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -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.Disable, "disable", "D", nil, wh("Disable specific linter")) 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.StringSliceVarP(&lc.Presets, "presets", "p", nil, wh(fmt.Sprintf("Enable presets (%s) of linters. Run 'golangci-lint linters' to see "+ diff --git a/scripts/gen_readme/main.go b/scripts/gen_readme/main.go index 50d0bc7b0d5a..aa777497e152 100644 --- a/scripts/gen_readme/main.go +++ b/scripts/gen_readme/main.go @@ -42,6 +42,16 @@ func genReadme(tmplPath, outPath string) error { 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) { golangciYaml, err := ioutil.ReadFile(".golangci.yml") if err != nil { @@ -79,6 +89,11 @@ func buildTemplateContext() (map[string]interface{}, error) { return nil, err } + latestVersion, err := getLatestVersion() + if err != nil { + return nil, fmt.Errorf("failed to get latest version: %w", err) + } + return map[string]interface{}{ "GolangciYaml": strings.TrimSpace(string(golangciYaml)), "GolangciYamlExample": strings.TrimSpace(string(golangciYamlExample)), @@ -89,6 +104,7 @@ func buildTemplateContext() (map[string]interface{}, error) { "ThanksList": getThanksList(), "RunHelpText": string(shortHelp), "ChangeLog": string(changeLog), + "LatestVersion": latestVersion, }, nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index a4c616e541a6..0f4b2f108b26 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -185,7 +185,7 @@ golang.org/x/sys/windows golang.org/x/text/transform golang.org/x/text/unicode/norm 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/passes/asmdecl golang.org/x/tools/go/analysis/passes/assign