Skip to content

linters: add Godox linter support #621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ linters-settings:
paramsOnly: true
rangeValCopy:
sizeThreshold: 32
godox:
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
# might be left in the code accidentally and should be resolved before merging
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
- NOTE
- OPTIMIZE # marks code that should be optimized before merging
- HACK # marks hack-arounds that should be removed before merging

linters:
enable:
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ linters:
- dupl
- errcheck
# - funlen - TODO: enable it when golangci.com will support it.
# - godox - TODO: enable it when golangci.com will support it.
- gochecknoinits
- goconst
- gocritic
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ gochecknoinits: Checks that no init functions are present in Go code [fast: true
goconst: Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
gocritic: The most opinionated Go source code linter [fast: true, auto-fix: false]
gocyclo: Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
godox: Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
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]
goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true]
golint: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false]
Expand Down Expand Up @@ -458,6 +459,7 @@ golangci-lint help linters
- [gocritic](https://github.com/go-critic/go-critic) - The most opinionated Go source code linter
- [gochecknoinits](https://github.com/leighmcculloch/gochecknoinits) - Checks that no init functions are present in Go code
- [gochecknoglobals](https://github.com/leighmcculloch/gochecknoglobals) - Checks that no globals are present in Go code
- [godox](https://github.com/matoous/godox) - Tool for detection of FIXME, TODO and other comment keywords
- [funlen](https://github.com/ultraware/funlen) - Tool for detection of long functions

## Configuration
Expand Down Expand Up @@ -764,6 +766,13 @@ linters-settings:
paramsOnly: true
rangeValCopy:
sizeThreshold: 32
godox:
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
# might be left in the code accidentally and should be resolved before merging
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
- NOTE
- OPTIMIZE # marks code that should be optimized before merging
- HACK # marks hack-arounds that should be removed before merging

linters:
enable:
Expand Down Expand Up @@ -899,6 +908,7 @@ linters:
- dupl
- errcheck
# - funlen - TODO: enable it when golangci.com will support it.
# - godox - TODO: enable it when golangci.com will support it.
- gochecknoinits
- goconst
- gocritic
Expand Down Expand Up @@ -1079,6 +1089,7 @@ Thanks to developers and authors of used linters:
- [kyoh86](https://github.com/kyoh86)
- [go-critic](https://github.com/go-critic)
- [leighmcculloch](https://github.com/leighmcculloch)
- [matoous](https://github.com/matoous)
- [ultraware](https://github.com/ultraware)

## Changelog
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.7.6 // indirect
github.com/matoous/godox v0.0.0-20190910121045-032ad8106c86
github.com/mattn/go-colorable v0.0.9
github.com/mattn/go-isatty v0.0.3 // indirect
github.com/mitchellh/go-homedir v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/magiconair/properties v1.7.6 h1:U+1DqNen04MdEPgFiIwdOUiqZ8qPa37xgogX/sd3+54=
github.com/magiconair/properties v1.7.6/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/matoous/godox v0.0.0-20190910121045-032ad8106c86 h1:q6SrfsK4FojRnJ1j8+8OJzyq3g9Y1oSVyL6nYGJXXBk=
github.com/matoous/godox v0.0.0-20190910121045-032ad8106c86/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ type LintersSettings struct {
Prealloc PreallocSettings
Errcheck ErrcheckSettings
Gocritic GocriticSettings
Godox GodoxSettings
}

type GovetSettings struct {
Expand Down Expand Up @@ -211,6 +212,10 @@ type PreallocSettings struct {
ForLoops bool `mapstructure:"for-loops"`
}

type GodoxSettings struct {
Keywords []string
}

var defaultLintersSettings = LintersSettings{
Lll: LllSettings{
LineLength: 120,
Expand All @@ -230,6 +235,9 @@ var defaultLintersSettings = LintersSettings{
Gocritic: GocriticSettings{
SettingsPerCheck: map[string]GocriticCheckSettings{},
},
Godox: GodoxSettings{
Keywords: []string{},
},
}

type Linters struct {
Expand Down
46 changes: 46 additions & 0 deletions pkg/golinters/godox.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package golinters

import (
"context"
"go/token"
"strings"

"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/result"

"github.com/matoous/godox"
)

type Godox struct{}

func (Godox) Name() string {
return "godox"
}

func (Godox) Desc() string {
return "Tool for detection of FIXME, TODO and other comment keywords"
}

func (f Godox) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
var issues []godox.Message
for _, file := range lintCtx.ASTCache.GetAllValidFiles() {
issues = append(issues, godox.Run(file.F, file.Fset, lintCtx.Settings().Godox.Keywords...)...)
}

if len(issues) == 0 {
return nil, nil
}

res := make([]result.Issue, len(issues))
for k, i := range issues {
res[k] = result.Issue{
Pos: token.Position{
Filename: i.Pos.Filename,
Line: i.Pos.Line,
},
Text: strings.TrimRight(i.Message, "\n"),
FromLinter: f.Name(),
}
}
return res, nil
}
4 changes: 4 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle).
WithSpeed(10).
WithURL("https://github.com/leighmcculloch/gochecknoglobals"),
linter.NewConfig(golinters.Godox{}).
WithPresets(linter.PresetStyle).
WithSpeed(10).
WithURL("https://github.com/matoous/godox"),
linter.NewConfig(golinters.Funlen{}).
WithPresets(linter.PresetStyle).
WithSpeed(10).
Expand Down
13 changes: 13 additions & 0 deletions test/testdata/godox.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//args: -Egodox
//config: linters-settings.godox.keywords=FIXME,TODO
package testdata

func todoLeftInCode() {
// TODO implement me // ERROR godox.go:6: Line contains FIXME/TODO: "TODO implement me"
//TODO no space // ERROR godox.go:7: Line contains FIXME/TODO: "TODO no space"
// TODO(author): 123 // ERROR godox.go:8: Line contains FIXME/TODO: "TODO\(author\): 123 // ERROR godox.go:8: L..."
//TODO(author): 123 // ERROR godox.go:9: Line contains FIXME/TODO: "TODO\(author\): 123 // ERROR godox.go:9: L..."
//TODO(author) 456 // ERROR godox.go:10: Line contains FIXME/TODO: "TODO\(author\) 456 // ERROR godox.go:10: L..."
// TODO: qwerty // ERROR godox.go:11: Line contains FIXME/TODO: "TODO: qwerty // ERROR godox.go:11: Line ..."
// todo 789 // ERROR godox.go:12: Line contains FIXME/TODO: "todo 789"
}
18 changes: 18 additions & 0 deletions vendor/github.com/matoous/godox/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions vendor/github.com/matoous/godox/.golangci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading