Skip to content

Commit 5884581

Browse files
matoousjirfag
authored andcommitted
linters: add Godox linter support (#621)
Godox is linter for TODOs and FIXMEs left in the code. Signed-off-by: Matous Dzivjak <[email protected]>
1 parent c215cff commit 5884581

File tree

18 files changed

+440
-0
lines changed

18 files changed

+440
-0
lines changed

.golangci.example.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ linters-settings:
186186
paramsOnly: true
187187
rangeValCopy:
188188
sizeThreshold: 32
189+
godox:
190+
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
191+
# might be left in the code accidentally and should be resolved before merging
192+
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
193+
- NOTE
194+
- OPTIMIZE # marks code that should be optimized before merging
195+
- HACK # marks hack-arounds that should be removed before merging
189196

190197
linters:
191198
enable:

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ linters:
5151
- dupl
5252
- errcheck
5353
# - funlen - TODO: enable it when golangci.com will support it.
54+
# - godox - TODO: enable it when golangci.com will support it.
5455
- gochecknoinits
5556
- goconst
5657
- gocritic

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ gochecknoinits: Checks that no init functions are present in Go code [fast: true
202202
goconst: Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
203203
gocritic: The most opinionated Go source code linter [fast: true, auto-fix: false]
204204
gocyclo: Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
205+
godox: Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
205206
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]
206207
goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true]
207208
golint: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false]
@@ -459,6 +460,7 @@ golangci-lint help linters
459460
- [gocritic](https://github.com/go-critic/go-critic) - The most opinionated Go source code linter
460461
- [gochecknoinits](https://github.com/leighmcculloch/gochecknoinits) - Checks that no init functions are present in Go code
461462
- [gochecknoglobals](https://github.com/leighmcculloch/gochecknoglobals) - Checks that no globals are present in Go code
463+
- [godox](https://github.com/matoous/godox) - Tool for detection of FIXME, TODO and other comment keywords
462464
- [funlen](https://github.com/ultraware/funlen) - Tool for detection of long functions
463465
- [whitespace](https://github.com/ultraware/whitespace) - Tool for detection of leading and trailing whitespace
464466
@@ -766,6 +768,13 @@ linters-settings:
766768
paramsOnly: true
767769
rangeValCopy:
768770
sizeThreshold: 32
771+
godox:
772+
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
773+
# might be left in the code accidentally and should be resolved before merging
774+
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
775+
- NOTE
776+
- OPTIMIZE # marks code that should be optimized before merging
777+
- HACK # marks hack-arounds that should be removed before merging
769778
770779
linters:
771780
enable:
@@ -901,6 +910,7 @@ linters:
901910
- dupl
902911
- errcheck
903912
# - funlen - TODO: enable it when golangci.com will support it.
913+
# - godox - TODO: enable it when golangci.com will support it.
904914
- gochecknoinits
905915
- goconst
906916
- gocritic
@@ -1082,6 +1092,7 @@ Thanks to developers and authors of used linters:
10821092
- [kyoh86](https://github.com/kyoh86)
10831093
- [go-critic](https://github.com/go-critic)
10841094
- [leighmcculloch](https://github.com/leighmcculloch)
1095+
- [matoous](https://github.com/matoous)
10851096
- [ultraware](https://github.com/ultraware)
10861097
10871098
## Changelog

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce // indirect
3232
github.com/inconshreveable/mousetrap v1.0.0 // indirect
3333
github.com/magiconair/properties v1.7.6 // indirect
34+
github.com/matoous/godox v0.0.0-20190910121045-032ad8106c86
3435
github.com/mattn/go-colorable v0.0.9
3536
github.com/mattn/go-isatty v0.0.3 // indirect
3637
github.com/mitchellh/go-homedir v1.0.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
106106
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
107107
github.com/magiconair/properties v1.7.6 h1:U+1DqNen04MdEPgFiIwdOUiqZ8qPa37xgogX/sd3+54=
108108
github.com/magiconair/properties v1.7.6/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
109+
github.com/matoous/godox v0.0.0-20190910121045-032ad8106c86 h1:q6SrfsK4FojRnJ1j8+8OJzyq3g9Y1oSVyL6nYGJXXBk=
110+
github.com/matoous/godox v0.0.0-20190910121045-032ad8106c86/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
109111
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
110112
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
111113
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=

pkg/config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ type LintersSettings struct {
177177
Prealloc PreallocSettings
178178
Errcheck ErrcheckSettings
179179
Gocritic GocriticSettings
180+
Godox GodoxSettings
180181
}
181182

182183
type GovetSettings struct {
@@ -211,6 +212,10 @@ type PreallocSettings struct {
211212
ForLoops bool `mapstructure:"for-loops"`
212213
}
213214

215+
type GodoxSettings struct {
216+
Keywords []string
217+
}
218+
214219
var defaultLintersSettings = LintersSettings{
215220
Lll: LllSettings{
216221
LineLength: 120,
@@ -230,6 +235,9 @@ var defaultLintersSettings = LintersSettings{
230235
Gocritic: GocriticSettings{
231236
SettingsPerCheck: map[string]GocriticCheckSettings{},
232237
},
238+
Godox: GodoxSettings{
239+
Keywords: []string{},
240+
},
233241
}
234242

235243
type Linters struct {

pkg/golinters/godox.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package golinters
2+
3+
import (
4+
"context"
5+
"go/token"
6+
"strings"
7+
8+
"github.com/golangci/golangci-lint/pkg/lint/linter"
9+
"github.com/golangci/golangci-lint/pkg/result"
10+
11+
"github.com/matoous/godox"
12+
)
13+
14+
type Godox struct{}
15+
16+
func (Godox) Name() string {
17+
return "godox"
18+
}
19+
20+
func (Godox) Desc() string {
21+
return "Tool for detection of FIXME, TODO and other comment keywords"
22+
}
23+
24+
func (f Godox) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
25+
var issues []godox.Message
26+
for _, file := range lintCtx.ASTCache.GetAllValidFiles() {
27+
issues = append(issues, godox.Run(file.F, file.Fset, lintCtx.Settings().Godox.Keywords...)...)
28+
}
29+
30+
if len(issues) == 0 {
31+
return nil, nil
32+
}
33+
34+
res := make([]result.Issue, len(issues))
35+
for k, i := range issues {
36+
res[k] = result.Issue{
37+
Pos: token.Position{
38+
Filename: i.Pos.Filename,
39+
Line: i.Pos.Line,
40+
},
41+
Text: strings.TrimRight(i.Message, "\n"),
42+
FromLinter: f.Name(),
43+
}
44+
}
45+
return res, nil
46+
}

pkg/lint/lintersdb/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
238238
WithPresets(linter.PresetStyle).
239239
WithSpeed(10).
240240
WithURL("https://github.com/leighmcculloch/gochecknoglobals"),
241+
linter.NewConfig(golinters.Godox{}).
242+
WithPresets(linter.PresetStyle).
243+
WithSpeed(10).
244+
WithURL("https://github.com/matoous/godox"),
241245
linter.NewConfig(golinters.Funlen{}).
242246
WithPresets(linter.PresetStyle).
243247
WithSpeed(10).

test/testdata/godox.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//args: -Egodox
2+
//config: linters-settings.godox.keywords=FIXME,TODO
3+
package testdata
4+
5+
func todoLeftInCode() {
6+
// TODO implement me // ERROR godox.go:6: Line contains FIXME/TODO: "TODO implement me"
7+
//TODO no space // ERROR godox.go:7: Line contains FIXME/TODO: "TODO no space"
8+
// TODO(author): 123 // ERROR godox.go:8: Line contains FIXME/TODO: "TODO\(author\): 123 // ERROR godox.go:8: L..."
9+
//TODO(author): 123 // ERROR godox.go:9: Line contains FIXME/TODO: "TODO\(author\): 123 // ERROR godox.go:9: L..."
10+
//TODO(author) 456 // ERROR godox.go:10: Line contains FIXME/TODO: "TODO\(author\) 456 // ERROR godox.go:10: L..."
11+
// TODO: qwerty // ERROR godox.go:11: Line contains FIXME/TODO: "TODO: qwerty // ERROR godox.go:11: Line ..."
12+
// todo 789 // ERROR godox.go:12: Line contains FIXME/TODO: "todo 789"
13+
}

vendor/github.com/matoous/godox/.gitignore

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/matoous/godox/.golangci.yml

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)