39 Commits

Author SHA1 Message Date
sayboras
93c0eebfa1 Fixed test deadline unit test 2019-11-07 17:22:13 -05:00
Daniel Caballero
98f60ebaa3 deadline is now deprecated, but should be taking its value from the configuration if set (#822)
* test that demostrates that deadline is not working if comes from the config

* overriding timeout with deadline when only deadline is different from its default value

* tests were not passing. default value for Deadline, that now only comes from config, is 0. Plus static check is going to fail because of deprecated cfg used

* golangci should use the latest golangci-lint version, that is the one deprecating deadline in favour of timeout

* README updated - looks the ci config in this project is used to generate usage instructions.. great!
2019-10-15 14:11:14 +03:00
Denis Titusov
0cc87df732 Rename deadline option to timeout and mark deadline as deprecated. (#793) 2019-10-08 09:37:54 +03:00
Trevor Pounds
6d786b50ae Group imports by package. 2019-10-01 18:09:47 -04:00
Denis Isaev
3aade55e05 Reduce memory usage of go/analysis 2019-09-23 09:52:54 +03:00
Trevor Pounds
a653032409 Fix flaky cgo test failures. (#716)
Fixes flaky cgo test failures caused by duplicate printf
format checks in staticcheck and go vet that use slightly
different reporting formats.
2019-09-20 19:05:01 +03:00
Isaev Denis
6163a8a790
Support go1.13 (#670)
Setup Travis CI to run on go 1.12 and 1.13.
Update info about go versions in README.
Rebuild go.mod,go.sum on go1.13.
2019-09-09 21:54:56 +03:00
Luke Shumaker
e87a1cfb83 Fix a false-positive from 'unused' (#585)
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.
2019-09-09 16:10:49 +03:00
Luke Shumaker
9ce337296b Makefile: Set GO111MODULE=on for consistency, adjust tests accordingly 2019-06-05 00:52:23 -04:00
Denis Isaev
39f46be460 Fix staticcheck panic on packages that do not compile
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
2019-04-21 11:48:33 +03:00
Denis Isaev
ed0b551070 Fix linting of preprocessed files
Preprocessed files like .qtpl.go quicktemplate Go files can have
//line directives. They map to a source .qtpl file.
This commit fixes linting of such files:
1. don't fail on AST cache loading
2. output Go filename not .qtpl or similar

Also, here we update golint to the upstream version.

Relates: #316, #466, #467, #468
2019-04-20 21:50:26 +03:00
Denis Isaev
fd825488bf
dev: add test for govet custom formatter 2019-03-18 00:31:30 +03:00
Denis Isaev
8c1237b667 Use the newest go vet
The newest go vet based on go/analysis
2019-03-17 23:12:44 +03:00
Denis Isaev
d437ac8629 Implement auto-fixing for gofmt,goimports,misspell
Also, add more identifier marking patterns.
2019-02-17 20:31:31 +03:00
Denis Isaev
4f0fddf4fe
add tests for abs path args 2018-12-22 14:16:31 +03:00
Denis Isaev
7dfb9cff3d rework skip dir algorithm 2018-12-22 12:24:43 +03:00
Denis Isaev
dba3907ff3 improve typecheck errors parsing 2018-11-23 18:40:25 +03:00
Denis Isaev
ac77eaac68 Fix #282, fix #209: revert goimports commit
ed64e33c8c8bc9a919e2b85a1a08225b5ae59d70. Also add tests
for local mode of goimports and do refactoring of tests.
2018-11-10 11:46:37 +03:00
Denis Isaev
7836034ecf dev: fix tests 2018-11-07 11:53:30 +03:00
Denis Isaev
84c9c65f39 fix #243: support Scopelint linter 2018-11-06 08:11:25 +03:00
Denis Isaev
ccac35a87e Fix false positives with unused identifiers
Issue #265: don't report unused warning when an identifier is
used only in tests.
2018-11-05 14:11:14 +03:00
Denis Isaev
8fceb7fc47
Fix #209: support goimports.local-prefix option for goimports 2018-10-28 18:47:56 +03:00
Denis Isaev
0421bac259 Fix #237, fix #178: use go/packages
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!
2018-10-28 17:55:15 +03:00
Cezar Sa Espinola
b307cc3765 Fix formatting with updated goimports version 2018-10-20 10:40:40 +03:00
Denis Isaev
8a478c47ac Prepare for #164: rename GAS to gosec
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
2018-09-02 09:34:35 +03:00
Denis Isaev
47440bc2cc don't print config parsing info logs twice 2018-09-02 09:34:35 +03:00
Denis Isaev
b900926bfc Fix #121, fix #186: remove --silent,-s flag: be silent by default 2018-08-08 23:55:01 +03:00
Denis Isaev
3ce87e6245 Fix #139: don't fail govet on cgo 2018-06-30 09:23:31 +03:00
Denis Isaev
5514c4393e Fix #17, #87: govet becomes SLOW linter by default
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)
2018-06-18 09:47:15 +03:00
Henrik Johansson
f239b80ce1 disable the congrats message
There is now an extra switch '-s' to disable the congrats message when
there are no issues detected

Fixes: #110
2018-06-17 00:17:48 +03:00
Denis Isaev
9181ca7175 Fix #78: log all warnings
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"
2018-06-14 23:09:04 +03:00
Denis Isaev
adb6be78bb
Fix #72: match more autogenerated files patterns.
We skip all issues from autogenerated files.
Also reuse AST parsing for nolint and autogenerated exclude processors:
decrease processing time on golang source code from 3s to 800ms.
2018-06-11 00:51:23 +03:00
Isaev Denis
46088deacf
Merge pull request #81 from golangci/feature/fix-common-failures
Feature/fix common failures
2018-06-10 23:53:30 +03:00
Denis Isaev
2b587b63d6
Load AST for fast linters in different way.
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
2018-06-10 23:46:24 +03:00
Alec Thomas
581a3564ff Allow --enable, --enable-all and --fast to coexist.
This is useful to first enable all linters (including fast ones), then
only enable fast linters, then add extra linters. eg.

```
golangci-lint run --no-config --enable-all --fast --print-issued-lines=false \
    --exclude-use-default=false --tests --enable typecheck .
```
2018-06-09 19:49:24 +10:00
Denis Isaev
afc4b4344f
#66: properly merge (not overwrite) slice flags from config and command-line 2018-06-06 09:11:21 +03:00
Denis Isaev
0f6213dbc2
#60: search config file in directories from file path up to root 2018-06-02 20:28:53 +03:00
Denis Isaev
b0826710b5
#52: #36: lint test files by default: set --tests=false to disable it 2018-06-02 18:24:00 +03:00
golangci
0a111acaab refactor and don't print congrats if timeouted 2018-06-02 00:30:39 +03:00