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
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
1. Fix crash if deps of analyzed packages weren't compiled.
2. Print deps typechecking errors
3. Fix all issues filtering because of empty go env GOCACHE for go < 1.10
Use go/packages instead of x/tools/loader: it allows to work
with go modules and speedups loading of packages with the help
of build cache.
A lot of linters became "fast": they are enabled by --fast now and
work in 1-2 seconds. Only unparam, interfacer and megacheck
are "slow" linters now.
Average project is analyzed 20-40% faster than before if all linters are
enabled! If we enable all linters except unparam, interfacer and
megacheck analysis is 10-20x faster!
Motivation: Make it clear that the message is indicating packages
*which do not compile*, rather than packages which *won't be
compiled [for some unknown reason]*.
1. Rename in a backward compatible way
2. Remove gosec default exclude list because gosec is already disabled
by default.
3. Warn about unmatched linter names in //nolint directives
4. Process linter names in //nolint directives in upper case
5. Disable gosec for golangci-lint in .golangci.yml
1. Support unparam linter and fix found issues
2. Replace forked mvdan.cc/lint and mvdan.cc/interfacer with the
upstream ones
3. Minimize forked megacheck: move the most of it's code to this repo
4. Use golang.org/x/tools/go/ssa import path instead of custom fork
paths
5. In golang.org/x/tools/go/{ssa,callgraph} use changed code from
honnef.co/go/tools
6. Add megacheck.check-unexported option: it found some issues in
the repo, fixed them all
1. Allow govet to work in 2 modes: fast and slow. Default is slow.
In fast mode golangci-lint runs `go install -i` and `go test -i`
for analyzed packages. But it's fast only when:
- go >= 1.10
- it's repeated run or $GOPATH/pkg or `go env GOCACHE` is cached
between CI builds
In slow mode we load program from source code like for another linters
and do it only once for all linters.
3. Patch govet code to warn about any troubles with the type
information. Default behaviour of govet was to hide such warnings.
Fail analysis if there are any troubles with type loading: it will
prevent false-positives and false-negatives from govet.
4. Describe almost all options in .golangci.example.yml and
include it into README. Describe when to use slow or fast mode of govet.
5. Speed up govet: reuse AST parsing: it's already parsed once by
golangci-lint.
For "slow" runs (when we run at least one slow linter) speedup by
not loading type information second time.
6. Improve logging, debug logging
7. Fix crash in logging of AST cache warnings (#118)
1. Log all warnings, don't hide none of them
2. Write fatal messages (stop analysis) with error log level
3. Remove ugly timestamp counter from logrus output
4. Print nested module prefix in log
5. Make logger abstraction: no global logging anymore
6. Refactor config reading to config.FileReader struct to avoid passing
logger into every function
7. Replace exit codes hardcoding with constants in exitcodes package
8. Fail test if any warning was logged
9. Fix calculation of relative path if we analyze parent dir ../
10. Move Runner initialization from Executor to NewRunner func
11. Log every AST parsing error
12. Properly print used config file path in verbose mode
13. Print package files if only 1 package is analyzedin verbose mode,
print not compiling packages in verbose mode
14. Forbid usage of github.com/sirupsen/logrus by DepGuard linter
15. Add default ignore pattern to folint: "comment on exported const"
Don't typecheck func bodies for non-local packages.
Works only if megacheck and interfacer are disabled: they require all
func bodies to build SSA repr.
Export GL_DEBUG=load to get logs for this feature.
Use build.Import instead of manual parser.ParseFile and paths traversal. It allows:
1. support build tags for all linters.
2. analyze files only for current GOOS/GOARCH: less false-positives.
3. analyze xtest packages (*_test) by golint: upstream golint and
gometalinter can't do it! And don't break analysis on the first xtest
package like it was before.
4. proper handling of xtest packages for linters like goconst where
package boundary is important: less false-positives is expected.
Also:
1. reuse AST parsing for golint and goconst: minor speedup.
2. allow to specify path (not only name) regexp for --skip-files and
--skip-dirs
3. add more default exclude filters for golint about commits:
`(comment on exported (method|function)|should have( a package)?
comment|comment should be of the form)`
4. print skipped dir in verbose (-v) mode
5. refactor per-linter tests: declare arguments in comments, run only
one linter and in combination with slow linter