Skip to content

Commit 56ee620

Browse files
committed
fix #132: support go-critic linter
1 parent ccac35a commit 56ee620

File tree

95 files changed

+7893
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+7893
-20
lines changed

.golangci.example.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,21 @@ linters-settings:
130130
simple: true
131131
range-loops: true # Report preallocation suggestions on range loops, true by default
132132
for-loops: false # Report preallocation suggestions on for loops, false by default
133-
133+
gocritic:
134+
# which checks should be enabled; can't be combined with 'disabled-checks';
135+
# default are: [appendAssign assignOp caseOrder dupArg dupBranchBody dupCase flagDeref
136+
# ifElseChain regexpMust singleCaseSwitch sloppyLen switchTrue typeSwitchVar underef unlambda unslice rangeValCopy];
137+
# all checks list: https://github.com/go-critic/checkers
138+
enabled-checks:
139+
- rangeValCopy
140+
# which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
141+
disabled-checks:
142+
- regexpMust
143+
settings: # settings passed to gocritic
144+
captLocal: # must be valid enabled check name
145+
checkLocals: true
146+
rangeValCopy:
147+
sizeThreshold: 32
134148

135149
linters:
136150
enable:

Gopkg.lock

Lines changed: 74 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ lll: Reports long lines [fast: true]
199199
unparam: Reports unused function parameters [fast: false]
200200
nakedret: Finds naked returns in functions greater than a specified function length [fast: true]
201201
prealloc: Finds slice declarations that could potentially be preallocated [fast: true]
202+
gocritic: The most opinionated Go source code linter [fast: true]
202203
```
203204
204205
Pass `-E/--enable` to enable linter and `-D/--disable` to disable:
@@ -398,6 +399,7 @@ golangci-lint help linters
398399
- [unparam](https://github.com/mvdan/unparam) - Reports unused function parameters
399400
- [nakedret](https://github.com/alexkohler/nakedret) - Finds naked returns in functions greater than a specified function length
400401
- [prealloc](https://github.com/alexkohler/prealloc) - Finds slice declarations that could potentially be preallocated
402+
- [gocritic](https://github.com/go-critic/go-critic) - The most opinionated Go source code linter
401403
402404
## Configuration
403405
@@ -637,7 +639,21 @@ linters-settings:
637639
simple: true
638640
range-loops: true # Report preallocation suggestions on range loops, true by default
639641
for-loops: false # Report preallocation suggestions on for loops, false by default
640-
642+
gocritic:
643+
# which checks should be enabled; can't be combined with 'disabled-checks';
644+
# default are: [appendAssign assignOp caseOrder dupArg dupBranchBody dupCase flagDeref
645+
# ifElseChain regexpMust singleCaseSwitch sloppyLen switchTrue typeSwitchVar underef unlambda unslice rangeValCopy];
646+
# all checks list: https://github.com/go-critic/checkers
647+
enabled-checks:
648+
- rangeValCopy
649+
# which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
650+
disabled-checks:
651+
- regexpMust
652+
settings: # settings passed to gocritic
653+
captLocal: # must be valid enabled check name
654+
checkLocals: true
655+
rangeValCopy:
656+
sizeThreshold: 32
641657
642658
linters:
643659
enable:
@@ -807,6 +823,7 @@ Thanks to developers and authors of used linters:
807823
- [client9](https://github.com/client9)
808824
- [walle](https://github.com/walle)
809825
- [alexkohler](https://github.com/alexkohler)
826+
- [go-critic](https://github.com/go-critic)
810827
811828
## Changelog
812829

go.mod

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ require (
66
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
77
github.com/davecgh/go-spew v1.1.0 // indirect
88
github.com/fatih/color v1.6.0
9+
github.com/go-critic/checkers v0.0.0-20181031185637-a14bc4b0b123
10+
github.com/go-lintpack/lintpack v0.0.0-20181105152233-7ff0297828fc
911
github.com/go-ole/go-ole v1.2.1 // indirect
12+
github.com/go-toolsmith/astcast v0.0.0-20181028201508-b7a89ed70af1 // indirect
13+
github.com/go-toolsmith/astcopy v0.0.0-20180903214859-79b422d080c4 // indirect
14+
github.com/go-toolsmith/astequal v0.0.0-20180903214952-dcb477bfacd6 // indirect
15+
github.com/go-toolsmith/astfmt v0.0.0-20180903215011-8f8ee99c3086 // indirect
16+
github.com/go-toolsmith/astp v0.0.0-20180903215135-0af7e3c24f30 // indirect
17+
github.com/go-toolsmith/strparse v0.0.0-20180903215201-830b6daa1241 // indirect
18+
github.com/go-toolsmith/typep v0.0.0-20181030061450-d63dc7650676 // indirect
1019
github.com/gobwas/glob v0.2.3 // indirect
1120
github.com/gogo/protobuf v1.0.0 // indirect
1221
github.com/golang/mock v1.1.1
@@ -17,7 +26,7 @@ require (
1726
github.com/golangci/go-tools v0.0.0-20180902103155-93eecd106a0b
1827
github.com/golangci/goconst v0.0.0-20180610141641-041c5f2b40f3
1928
github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee
20-
github.com/golangci/gofmt v0.0.0-20180506063654-f021c4179c82
29+
github.com/golangci/gofmt v0.0.0-20181105071733-f021c4179c82
2130
github.com/golangci/gosec v0.0.0-20180901114220-8afd9cbb6cfb
2231
github.com/golangci/govet v0.0.0-20180818181408-44ddbe260190
2332
github.com/golangci/ineffassign v0.0.0-20180808204949-2ee8f2867dde

go.sum

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,26 @@ github.com/fatih/color v1.6.0 h1:66qjqZk8kalYAvDRtM1AdAJQI0tj4Wrue3Eq3B3pmFU=
1010
github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
1111
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
1212
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
13+
github.com/go-critic/checkers v0.0.0-20181031185637-a14bc4b0b123 h1:Co3p1zLgyV82Rbcrh0bKkerAbotY9CjBA/F4G2/A1D4=
14+
github.com/go-critic/checkers v0.0.0-20181031185637-a14bc4b0b123/go.mod h1:Cg5JCP9M6m93z6fecpRcVgD2lZf2RvPtb85ldjiShZc=
15+
github.com/go-lintpack/lintpack v0.0.0-20181105152233-7ff0297828fc h1:1WRIbHnQimY5g784lRFOa93tWZdssXVtOp/E2use7as=
16+
github.com/go-lintpack/lintpack v0.0.0-20181105152233-7ff0297828fc/go.mod h1:1zNnkB6R9YD0l/ZxcCk0oOFbL9aEs6UtHeOyL+cpoHk=
1317
github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
1418
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
19+
github.com/go-toolsmith/astcast v0.0.0-20181028201508-b7a89ed70af1 h1:h+1eMw+tZAlgTVclcVN0/rdPaBI/RUzG0peblT6df+Q=
20+
github.com/go-toolsmith/astcast v0.0.0-20181028201508-b7a89ed70af1/go.mod h1:TEo3Ghaj7PsZawQHxT/oBvo4HK/sl1RcuUHDKTTju+o=
21+
github.com/go-toolsmith/astcopy v0.0.0-20180903214859-79b422d080c4 h1:wVs9OMjICHbAryp9hcIuWqUOi+NqEbUSZy9zMe3W//I=
22+
github.com/go-toolsmith/astcopy v0.0.0-20180903214859-79b422d080c4/go.mod h1:c9CPdq2AzM8oPomdlPniEfPAC6g1s7NqZzODt8y6ib8=
23+
github.com/go-toolsmith/astequal v0.0.0-20180903214952-dcb477bfacd6 h1:aTBUNRTatDDU24gbOEKEoLiDwxtc98ga6K/iMTm6fvs=
24+
github.com/go-toolsmith/astequal v0.0.0-20180903214952-dcb477bfacd6/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY=
25+
github.com/go-toolsmith/astfmt v0.0.0-20180903215011-8f8ee99c3086 h1:EIMuvbE9fbtQtimdLe5yeXjuC5CeKbQt8zH6GwtIrhM=
26+
github.com/go-toolsmith/astfmt v0.0.0-20180903215011-8f8ee99c3086/go.mod h1:mP93XdblcopXwlyN4X4uodxXQhldPGZbcEJIimQHrkg=
27+
github.com/go-toolsmith/astp v0.0.0-20180903215135-0af7e3c24f30 h1:zRJPftZJNLPDiOtvYbFRwjSbaJAcVOf80TeEmWGe2kQ=
28+
github.com/go-toolsmith/astp v0.0.0-20180903215135-0af7e3c24f30/go.mod h1:SV2ur98SGypH1UjcPpCatrV5hPazG6+IfNHbkDXBRrk=
29+
github.com/go-toolsmith/strparse v0.0.0-20180903215201-830b6daa1241 h1:ZRDeQioMGTBLeJxcPxXfFifEUgYxzR7fXw7w2WR+1bo=
30+
github.com/go-toolsmith/strparse v0.0.0-20180903215201-830b6daa1241/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8=
31+
github.com/go-toolsmith/typep v0.0.0-20181030061450-d63dc7650676 h1:6Qrsp0+25KEkaS2bB26UE0giFgRrIc8mYXboDL5OVMA=
32+
github.com/go-toolsmith/typep v0.0.0-20181030061450-d63dc7650676/go.mod h1:JSQCQMUPdRlMZFswiq3TGpNp1GMktqkR2Ns5AIQkATU=
1533
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
1634
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
1735
github.com/gogo/protobuf v1.0.0 h1:2jyBKDKU/8v3v2xVR2PtiWQviFUyiaGk2rpfyFT8rTM=
@@ -24,8 +42,6 @@ github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5
2442
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2/go.mod h1:k9Qvh+8juN+UKMCS/3jFtGICgW8O96FVaZsaxdzDkR4=
2543
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a h1:w8hkcTqaFpzKqonE9uMCefW1WDie15eSP/4MssdenaM=
2644
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a/go.mod h1:ryS0uhF+x9jgbj/N71xsEqODy9BN81/GonCZiOzirOk=
27-
github.com/golangci/errcheck v0.0.0-20180902071612-f726ab79eeeb h1:nIkmxOhujne45EXNG0EK88C4CgYNt90Dq5045+RYjtU=
28-
github.com/golangci/errcheck v0.0.0-20180902071612-f726ab79eeeb/go.mod h1:DbHgvLiFKX1Sh2T1w8Q/h4NAI8MHIpzCdnBUDTXU3I0=
2945
github.com/golangci/errcheck v0.0.0-20181003203344-1765131d5be5 h1:q7aCFiVt6gMxZseillOwgsyitdcxbqQz5oxA2rHIeMY=
3046
github.com/golangci/errcheck v0.0.0-20181003203344-1765131d5be5/go.mod h1:DbHgvLiFKX1Sh2T1w8Q/h4NAI8MHIpzCdnBUDTXU3I0=
3147
github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613 h1:WadunOE/TeHR8U7f0TXiJACHeU3cuFOXuKafw4rozqU=
@@ -36,10 +52,8 @@ github.com/golangci/goconst v0.0.0-20180610141641-041c5f2b40f3 h1:pe9JHs3cHHDQgO
3652
github.com/golangci/goconst v0.0.0-20180610141641-041c5f2b40f3/go.mod h1:JXrF4TWy4tXYn62/9x8Wm/K/dm06p8tCKwFRDPZG/1o=
3753
github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee h1:J2XAy40+7yz70uaOiMbNnluTg7gyQhtGqLQncQh+4J8=
3854
github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee/go.mod h1:ozx7R9SIwqmqf5pRP90DhR2Oay2UIjGuKheCBCNwAYU=
39-
github.com/golangci/gofmt v0.0.0-20180506063654-2076e05ced53 h1:8jBcdanEIu0YqTWHt9SUjObv3T0WnlTcmo/ZYm7qkRM=
40-
github.com/golangci/gofmt v0.0.0-20180506063654-2076e05ced53/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU=
41-
github.com/golangci/gofmt v0.0.0-20180506063654-231c3e6dba99/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU=
42-
github.com/golangci/gofmt v0.0.0-20180506063654-f021c4179c82/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU=
55+
github.com/golangci/gofmt v0.0.0-20181105071733-f021c4179c82 h1:GzPqZCXdBR/5zaqMWNsxRk60z16CaQjyytNTFpei3bw=
56+
github.com/golangci/gofmt v0.0.0-20181105071733-f021c4179c82/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU=
4357
github.com/golangci/gosec v0.0.0-20180901114220-8afd9cbb6cfb h1:Bi7BYmZVg4C+mKGi8LeohcP2GGUl2XJD4xCkJoZSaYc=
4458
github.com/golangci/gosec v0.0.0-20180901114220-8afd9cbb6cfb/go.mod h1:ON/c2UR0VAAv6ZEAFKhjCLplESSmRFfZcDLASbI1GWo=
4559
github.com/golangci/govet v0.0.0-20180818181408-44ddbe260190 h1:SLIgprnxQNjBpkz55PK1vfb64/gKU/TgVi0obFw8Lec=
@@ -61,9 +75,7 @@ github.com/golangci/prealloc v0.0.0-20180630174525-215b22d4de21 h1:leSNB7iYzLYSS
6175
github.com/golangci/prealloc v0.0.0-20180630174525-215b22d4de21/go.mod h1:tf5+bzsHdTM0bsB7+8mt0GUMvjCgwLpTapNZHU8AajI=
6276
github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0 h1:HVfrLniijszjS1aiNg8JbBMO2+E1WIQ+j/gL4SQqGPg=
6377
github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0/go.mod h1:qOQCunEYvmd/TLamH+7LlVccLvUH5kZNhbCgTHoBbp4=
64-
github.com/golangci/tools v0.0.0-20180902102414-01dd7756e01d/go.mod h1:zgj6NOYXOC1cexsdtDceI4/mj3aXK4JOVg9AV3C5LWI=
65-
github.com/golangci/tools v0.0.0-20180902102414-98e75f53b4b9 h1:JGHGJqnbD9OMyjgQqyja7DZd0/to1LKFpN31Fq8byxc=
66-
github.com/golangci/tools v0.0.0-20180902102414-98e75f53b4b9/go.mod h1:zgj6NOYXOC1cexsdtDceI4/mj3aXK4JOVg9AV3C5LWI=
78+
github.com/golangci/tools v0.0.0-20180902102414-ed64e33c8c8b h1:3a73k6ptEhiI9YA8cEe4i6nsLWQRjtBG97+tjhS+QBs=
6779
github.com/golangci/tools v0.0.0-20180902102414-ed64e33c8c8b/go.mod h1:zgj6NOYXOC1cexsdtDceI4/mj3aXK4JOVg9AV3C5LWI=
6880
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 h1:zwtduBRr5SSWhqsYNgcuWO2kFlpdOZbP0+yRjmvPGys=
6981
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4/go.mod h1:Izgrg8RkN3rCIMLGE9CyYmU9pY2Jer6DgANEnZ/L/cQ=
@@ -135,14 +147,8 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
135147
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
136148
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
137149
golang.org/x/tools v0.0.0-20180826000951-f6ba57429505/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
138-
golang.org/x/tools v0.0.0-20180831211245-3e7aa9e59977/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
139-
golang.org/x/tools v0.0.0-20180831211245-5d4988d199e2 h1:DpCOQ3KV1qfJ60hZlyxHUgKvOehh5A/F9Fznu08v5Yw=
140-
golang.org/x/tools v0.0.0-20180831211245-5d4988d199e2/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
150+
golang.org/x/tools v0.0.0-20180831211245-6c7e314b6563 h1:O7esB7nCcy+y8pwGEyEYSegt07MF0357oRStgxd2TDo=
141151
golang.org/x/tools v0.0.0-20180831211245-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
142-
golang.org/x/tools v0.0.0-20180831211245-7ca132754999 h1:mf2VYfMpSMTlp0I/UXrX13w5LejDx34QeUUHH4TrUA8=
143-
golang.org/x/tools v0.0.0-20180831211245-7ca132754999/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
144-
golang.org/x/tools v0.0.0-20180831211245-96e9e165b75e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
145-
golang.org/x/tools v0.0.0-20180831211245-f60e5f99f081/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
146152
gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo=
147153
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
148154
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

pkg/commands/executor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func NewExecutor(version, commit, date string) *Executor {
6565
e.log.Fatalf("Can't read config: %s", err)
6666
}
6767

68+
e.cfg.LintersSettings.Gocritic.InferEnabledChecks(e.log)
69+
if err := e.cfg.LintersSettings.Gocritic.Validate(e.log); err != nil {
70+
e.log.Fatalf("Invalid gocritic settings: %s", err)
71+
}
72+
6873
// Slice options must be explicitly set for proper merging of config and command-line options.
6974
fixSlicesFlags(e.runCmd.Flags())
7075

0 commit comments

Comments
 (0)