Run all linters per package. It allows unloading package data when it's
processed. It dramatically reduces memory (and CPU because of GC) usage.
Relates: #337
Some analyzers are not intended for direct usage and are
just build blocks for other analyzers.
Seems like we can distinguish them by ResultType nillness.
Set analysis pass results to nil early to garbage collect them
soon.
Memory can be reduced for the following linters:
- staticcheck
- stylecheck
- gosimple
- govet
- bodyclose
- any future go/analysis linter
Relates: #712, #634, #628, #598, #509, #483, #337
* update staticcheck
Don't fork staticcheck: use the upstream version.
Remove unneeded SSA loading.
* Cache go/analysis facts
Don't load unneeded packages for go/analysis.
Repeated run of go/analysis linters now 10x faster
(2s vs 20s on this repo) than before.
Don't perform extra go env calls in go/packages.
Load only needed go env vars in golangci-lint.
Stay in sync by enabled analyzers in go vet: remove nilness and
atomicalign analyzers, add errorsas analyzer.
Don't build SSA for govet.
Standalone govet runs 25% faster than before. All runs can be 5-10% faster
than before.
Relates: #208
This false-positive is not present in the upstream stand-alone 'unused'
2019.1.1 program that golangci-lint uses.
pkg/lint.ContextLoader.filterPackages() did two things:
1. It removed synthetic "testmain" packages (packages with .Name=="main"
and .PkgPath ending with ".test")
2. It removed pruned subsumed copies of packages; if a package with files
"a.go" and "a_test.go", it results in packages.Load giving us two
packages:
- ID=".../a" GoFiles=[a.go]
- ID=".../a [.../a.test]" GoFiles=[a.go a_test.go]
The first package is subsumed in the second, and leaving it around
results in duplicated work, and confuses the 'deadcode' linter.
However, the 'unused' linter relies on both the ".../a" and
".../a [.../a.test]" packages being present. Pruning them causes it to
panic in some situations, which lead to this workaround:
af6baa5dc1
While that workaround got it to not panic, it causes incorrect results.
So, split filterPackages() in to two functions: filterTestMainPackages()
and filterDuplicatePackages(). The linter.Context.Packages list only
gets filterTestMainPackages() called on it, while linter.Context.Program
and linter.Context.SSAProgram get both filters applied.
With the source of the panic fixed, roll back a few now-unnecessary
commits in go-tools.
Significantly improve CPU and memory usage when not using SSA-powered linters.
Improve readability of go/packages errors.
Improve debugging capabilities and write doc about debugging.
Treat Go source files as plain text files by misspell: it allows detecting
issues in strings, variable names, etc. Also, it's the default mode of
a standalone misspell tool.
Also, implement richer and more stable auto-fix of misspell issues:
now it can fix multiple issues in one line.
The bug was introduced in golangci-lint when migrating staticcheck to go/packages.
Also, thanks to pkg.IllTyped we can analyze as max as we can by
staticcheck.
Relates: #418, #369, #429, #489
This updates the unparam linter to the current version that has fewer
false positives. The go.{mod,sum} files and the vendor folder are
updated as follows:
export GO111MODULE=on
go get -u mvdan.cc/unparam
go mod tidy
go mod vendor
The unparam callgraph algorithm is no longer selectable. Ref:
https://github.com/mvdan/unparam/commit/e6a6d1c5
This is the reason for removing the c.CallgraphAlgorithm(us.Algo) line
from pkg/golinters/unparam.go.
Fix#324, relates #314
1. Update gocritic to the latest version
2. Use proper gocritic checkers repo, old repo was archived
3. Get enabled by default gocritic checks in sync with go-critic: don't
enable performance, experimental and opinionated checks by default
4. Support of `enabled-tags` options for gocritic
5. Enable almost all gocritic checks for the project
6. Make rich debugging for gocritic
7. Meticulously validate gocritic checks config
Also do following improvements:
- show proper sublinter name for megacheck sublinters
- refactor and make more simple and robust megacheck
merging/optimizing
- improve handling of unknown linter names in //nolint directives
- minimize diff of our megacheck version from the upstream,
https://github.com/golang/go/issues/29612 blocks usage of the upstream
version
- support the new `stylecheck` linter
- improve tests coverage for megacheck and nolint related cases
- update and use upstream versions of unparam and interfacer instead of forked
ones
- don't use golangci/tools repo anymore
- fix newly found issues after updating linters
Also should be noted that megacheck works much faster and consumes less
memory in the newest release, therefore golangci-lint works noticeably
faster and consumes less memory for large repos.
Relates: #314