diff --git a/CHANGELOG.md b/CHANGELOG.md index a7c688ce..667df670 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,14 @@ There is the most valuable changes log: ### April 2020 -1. Add new linters: `testpackage`, `nestif`, `godot`, `gomodguard` +1. Add new linters: `testpackage`, `nestif`, `godot`, `gomodguard`, `asciicheck` 2. Add github actions output format -3. Update linters: `wsl` +3. Update linters: `wsl`, `gomodguard`, `gosec` 4. Support `disabled-tags` setting for `gocritic` 5. Mitigate OOM and "failed prerequisites" 6. Self-isolate due to unexpected pandemics +7. Support case-sensitive excludes +8. Allow granular re-enabling excludes by ID, e.g. `EXC0002` ### September 2019 diff --git a/README.md b/README.md index 5b212cd8..2af4e3d4 100644 --- a/README.md +++ b/README.md @@ -73,17 +73,17 @@ use deprecated option `--enable-all` and a new linter is added or even without ` It's highly recommended to install a specific version of golangci-lint available on the [releases page](https://github.com/golangci/golangci-lint/releases). -Here is the recommended way to install golangci-lint v1.25.0: +Here is the recommended way to install golangci-lint v1.25.1: ```bash # binary will be $(go env GOPATH)/bin/golangci-lint -curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.25.0 +curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.25.1 # or install it into ./bin/ -curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.25.0 +curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.25.1 # In alpine linux (as it does not come with curl by default) -wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.25.0 +wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.25.1 golangci-lint --version ``` @@ -103,7 +103,7 @@ brew upgrade golangci/tap/golangci-lint ### Docker ```bash -docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.25.0 golangci-lint run -v +docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.25.1 golangci-lint run -v ``` ### Go @@ -111,7 +111,7 @@ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.25.0 golangci-l Go source installations are supported for the two most recent Go releases. ```bash -GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.25.0 +GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.25.1 ``` ## Trusted By @@ -218,6 +218,7 @@ gocritic: The most opinionated Go source code linter [fast: true, auto-fix: fals gocyclo: Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] godot: Check if comments end in a period [fast: true, auto-fix: false] godox: Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false] +goerr113: Golang linter to check the errors handling expressions [fast: true, auto-fix: false] gofmt: Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true] golint: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false] @@ -493,6 +494,7 @@ golangci-lint help linters - [wsl](https://github.com/bombsimon/wsl) - Whitespace Linter - Forces you to use empty lines! - [goprintffuncname](https://github.com/jirfag/go-printf-func-name) - Checks that printf-like functions are named with `f` at the end - [gomnd](https://github.com/tommy-muehle/go-mnd) - An analyzer to detect magic numbers. +- [goerr113](https://github.com/Djarvur/go-err113) - Golang linter to check the errors handling expressions - [gomodguard](https://github.com/ryancurrah/gomodguard) - Allow and block list linter for direct Go module dependencies. - [godot](https://github.com/tetafro/godot) - Check if comments end in a period - [testpackage](https://github.com/maratori/testpackage) - linter that makes you use a separate _test package @@ -570,7 +572,7 @@ Flags: - Subprocess launch(ed with variable|ing should be audited) # EXC0008 gosec: Duplicated errcheck checks - - G104 + - (G104|G307) # EXC0009 gosec: Too many issues in popular repos - (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) @@ -1313,6 +1315,7 @@ Thanks to developers and authors of used linters: - [bombsimon](https://github.com/bombsimon) - [jirfag](https://github.com/jirfag) - [tommy-muehle](https://github.com/tommy-muehle) +- [Djarvur](https://github.com/Djarvur) - [ryancurrah](https://github.com/ryancurrah) - [tetafro](https://github.com/tetafro) - [maratori](https://github.com/maratori) @@ -1326,12 +1329,14 @@ There is the most valuable changes log: ### April 2020 -1. Add new linters: `testpackage`, `nestif`, `godot`, `gomodguard` +1. Add new linters: `testpackage`, `nestif`, `godot`, `gomodguard`, `asciicheck` 2. Add github actions output format -3. Update linters: `wsl` +3. Update linters: `wsl`, `gomodguard`, `gosec` 4. Support `disabled-tags` setting for `gocritic` 5. Mitigate OOM and "failed prerequisites" 6. Self-isolate due to unexpected pandemics +7. Support case-sensitive excludes +8. Allow granular re-enabling excludes by ID, e.g. `EXC0002` ### September 2019 diff --git a/go.mod b/go.mod index d0cc95d4..cf4ec2b5 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/golangci/golangci-lint go 1.12 require ( + github.com/Djarvur/go-err113 v0.0.0-20200410182137-af658d038157 github.com/OpenPeeDeeP/depguard v1.0.1 github.com/bombsimon/wsl/v3 v3.0.0 github.com/fatih/color v1.7.0 @@ -33,7 +34,7 @@ require ( github.com/nakabonne/nestif v0.3.0 github.com/pkg/errors v0.8.1 github.com/ryancurrah/gomodguard v1.0.4 - github.com/securego/gosec v0.0.0-20200103095621-79fbf3af8d83 + github.com/securego/gosec v0.0.0-20200316084457-7da9f46445fd github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada // v2.19.8 github.com/sirupsen/logrus v1.4.2 github.com/sourcegraph/go-diff v0.5.1 diff --git a/go.sum b/go.sum index c9b4fdd6..3acb05f5 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Djarvur/go-err113 v0.0.0-20200410182137-af658d038157 h1:hY39LwQHh+1kaovmIjOrlqnXNX6tygSRfLkkK33IkZU= +github.com/Djarvur/go-err113 v0.0.0-20200410182137-af658d038157/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OpenPeeDeeP/depguard v1.0.1 h1:VlW4R6jmBIv3/u1JNlawEvJMM4J+dPORPaZasQee8Us= github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmUx/1V+TNhjQvM= @@ -184,7 +186,7 @@ github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b h1:9+ke9YJ9KGWw5AN github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk= +github.com/mozilla/tls-observatory v0.0.0-20200220173314-aae45faa4006/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nakabonne/nestif v0.3.0 h1:+yOViDGhg8ygGrmII72nV9B/zGxY188TYpfolntsaPw= github.com/nakabonne/nestif v0.3.0/go.mod h1:dI314BppzXjJ4HsCnbo7XzrJHPszZsjnk5wEBSYHI2c= @@ -194,10 +196,11 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw= -github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.8.1 h1:C5Dqfs/LeauYDX0jJXIe2SWmwCbGzx9yF8C8xy3Lh34= -github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= +github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU= +github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= +github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= @@ -223,8 +226,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/ryancurrah/gomodguard v1.0.4 h1:oCreMAt9GuFXDe9jW4HBpc3GjdX3R/sUEcLAGh1zPx8= github.com/ryancurrah/gomodguard v1.0.4/go.mod h1:9T/Cfuxs5StfsocWr4WzDL36HqnX0fVb9d5fSEaLhoE= -github.com/securego/gosec v0.0.0-20200103095621-79fbf3af8d83 h1:AtnWoOvTioyDXFvu96MWEeE8qj4COSQnJogzLy/u41A= -github.com/securego/gosec v0.0.0-20200103095621-79fbf3af8d83/go.mod h1:vvbZ2Ae7AzSq3/kywjUDxSNq2SJ27RxCz2un0H3ePqE= +github.com/securego/gosec v0.0.0-20200316084457-7da9f46445fd h1:qB+l4fYZsH78xORC1aqVS0zNmgkQp4rkj2rvfxQMtzc= +github.com/securego/gosec v0.0.0-20200316084457-7da9f46445fd/go.mod h1:NurAFZsWJAEZjogSwdVPlHkOZB3DOAU7gsPP8VFZCHc= github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada h1:WokF3GuxBeL+n4Lk4Fa8v9mbdjlrl7bHuneF4N1bk2I= github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U= @@ -295,6 +298,7 @@ github.com/valyala/quicktemplate v1.2.0/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOV github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -307,6 +311,7 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= @@ -343,8 +348,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 h1:rOhMmluY6kLMhdnrivzec6lLgaVbMHMn2ISQXJeJ5EM= -golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -366,8 +371,9 @@ golang.org/x/tools v0.0.0-20190719005602-e377ae9d6386/go.mod h1:jcCCGcm9btYwXyDq golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200102140908-9497f49d5709 h1:AfG1EmoRkFK24HWWLxSrRKNg2G+oA3JVOG8GJsHWypQ= -golang.org/x/tools v0.0.0-20200102140908-9497f49d5709/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200228224639-71482053b885/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200324003944-a576cf524670/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200414032229-332987a829c3/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e h1:3Dzrrxi54Io7Aoyb0PYLsI47K2TxkRQg+cqUn+m04do= golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -402,8 +408,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= -gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pkg/config/config.go b/pkg/config/config.go index 48ea13f3..2315f308 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -83,7 +83,7 @@ var DefaultExcludePatterns = []ExcludePattern{ }, { ID: "EXC0008", - Pattern: "G104", + Pattern: "(G104|G307)", Linter: "gosec", Why: "Duplicated errcheck checks", }, diff --git a/pkg/golinters/goerr113.go b/pkg/golinters/goerr113.go new file mode 100644 index 00000000..0c10005a --- /dev/null +++ b/pkg/golinters/goerr113.go @@ -0,0 +1,19 @@ +package golinters + +import ( + "github.com/Djarvur/go-err113" + "golang.org/x/tools/go/analysis" + + "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" +) + +func NewGoerr113() *goanalysis.Linter { + return goanalysis.NewLinter( + "goerr113", + "Golang linter to check the errors handling expressions", + []*analysis.Analyzer{ + err113.NewAnalyzer(), + }, + nil, + ).WithLoadMode(goanalysis.LoadModeTypesInfo) +} diff --git a/pkg/golinters/unused.go b/pkg/golinters/unused.go index 982d6759..ac5a90d4 100644 --- a/pkg/golinters/unused.go +++ b/pkg/golinters/unused.go @@ -33,7 +33,7 @@ func NewUnused() *goanalysis.Linter { for _, ur := range u.Result() { p := u.ProblemObject(lintCtx.Packages[0].Fset, ur) pkg := typesToPkg[ur.Pkg()] - issues = append(issues, goanalysis.NewIssue(&result.Issue{ + i := &result.Issue{ FromLinter: name, Text: p.Message, Pos: p.Pos, @@ -42,11 +42,16 @@ func NewUnused() *goanalysis.Linter { From: p.Pos.Line, To: p.End.Line, }, - Replacement: &result.Replacement{ + } + // See https://github.com/golangci/golangci-lint/issues/1048 + // If range is invalid, this will break `--fix` mode. + if i.LineRange.To >= i.LineRange.From { + i.Replacement = &result.Replacement{ // Suggest deleting unused stuff. NeedOnlyDelete: true, - }, - }, nil)) + } + } + issues = append(issues, goanalysis.NewIssue(i, nil)) } return issues }).WithContextSetter(func(lintCtx *linter.Context) { diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index c70729f8..492b9225 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -252,6 +252,9 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { linter.NewConfig(golinters.NewGoMND(m.cfg)). WithPresets(linter.PresetStyle). WithURL("https://github.com/tommy-muehle/go-mnd"), + linter.NewConfig(golinters.NewGoerr113()). + WithPresets(linter.PresetStyle). + WithURL("https://github.com/Djarvur/go-err113"), linter.NewConfig(golinters.NewGomodguard()). WithPresets(linter.PresetStyle). WithLoadForGoAnalysis(). diff --git a/pkg/result/processors/fixer.go b/pkg/result/processors/fixer.go index 98a4bf5c..75fdc93f 100644 --- a/pkg/result/processors/fixer.go +++ b/pkg/result/processors/fixer.go @@ -223,6 +223,12 @@ func (f Fixer) writeFixedFile(origFileLines [][]byte, issues []result.Issue, tmp } else { nextIssueIndex++ rng := nextIssue.GetLineRange() + if rng.From > rng.To { + // Maybe better decision is to skip such issues, re-evaluate if regressed. + f.log.Warnf("[fixer]: issue line range is probably invalid, fix can be incorrect (from=%d, to=%d, linter=%s)", + rng.From, rng.To, nextIssue.FromLinter, + ) + } i += rng.To - rng.From if nextIssue.Replacement.NeedOnlyDelete { continue diff --git a/test/testdata/fix/in/unused.go b/test/testdata/fix/in/unused.go new file mode 100644 index 00000000..fa8979c2 --- /dev/null +++ b/test/testdata/fix/in/unused.go @@ -0,0 +1,8 @@ +//args: -Eunused +package p + +type ( + unused struct{} +) + +func X() {} diff --git a/test/testdata/fix/out/unused.go b/test/testdata/fix/out/unused.go new file mode 100644 index 00000000..fa8979c2 --- /dev/null +++ b/test/testdata/fix/out/unused.go @@ -0,0 +1,8 @@ +//args: -Eunused +package p + +type ( + unused struct{} +) + +func X() {} diff --git a/test/testdata/goerr113.go b/test/testdata/goerr113.go new file mode 100644 index 00000000..3154e7cf --- /dev/null +++ b/test/testdata/goerr113.go @@ -0,0 +1,10 @@ +//args: -Egoerr113 +package testdata + +func SimpleEqual(e1, e2 error) bool { + return e1 == e2 // ERROR `err113: do not compare errors directly, use errors.Is() instead: "e1 == e2"` +} + +func SimpleNotEqual(e1, e2 error) bool { + return e1 != e2 // ERROR `err113: do not compare errors directly, use errors.Is() instead: "e1 != e2"` +}