linters: add Godox linter support (#621)
Godox is linter for TODOs and FIXMEs left in the code. Signed-off-by: Matous Dzivjak <matous.dzivjak@kiwi.com>
This commit is contained in:
parent
c215cffd53
commit
58845813da
@ -186,6 +186,13 @@ linters-settings:
|
|||||||
paramsOnly: true
|
paramsOnly: true
|
||||||
rangeValCopy:
|
rangeValCopy:
|
||||||
sizeThreshold: 32
|
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:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
|
@ -51,6 +51,7 @@ linters:
|
|||||||
- dupl
|
- dupl
|
||||||
- errcheck
|
- errcheck
|
||||||
# - funlen - TODO: enable it when golangci.com will support it.
|
# - funlen - TODO: enable it when golangci.com will support it.
|
||||||
|
# - godox - TODO: enable it when golangci.com will support it.
|
||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- goconst
|
- goconst
|
||||||
- gocritic
|
- gocritic
|
||||||
|
11
README.md
11
README.md
@ -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]
|
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]
|
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]
|
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]
|
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]
|
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]
|
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
|
|||||||
- [gocritic](https://github.com/go-critic/go-critic) - The most opinionated Go source code linter
|
- [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
|
- [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
|
- [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
|
- [funlen](https://github.com/ultraware/funlen) - Tool for detection of long functions
|
||||||
- [whitespace](https://github.com/ultraware/whitespace) - Tool for detection of leading and trailing whitespace
|
- [whitespace](https://github.com/ultraware/whitespace) - Tool for detection of leading and trailing whitespace
|
||||||
|
|
||||||
@ -766,6 +768,13 @@ linters-settings:
|
|||||||
paramsOnly: true
|
paramsOnly: true
|
||||||
rangeValCopy:
|
rangeValCopy:
|
||||||
sizeThreshold: 32
|
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:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
@ -901,6 +910,7 @@ linters:
|
|||||||
- dupl
|
- dupl
|
||||||
- errcheck
|
- errcheck
|
||||||
# - funlen - TODO: enable it when golangci.com will support it.
|
# - funlen - TODO: enable it when golangci.com will support it.
|
||||||
|
# - godox - TODO: enable it when golangci.com will support it.
|
||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- goconst
|
- goconst
|
||||||
- gocritic
|
- gocritic
|
||||||
@ -1082,6 +1092,7 @@ Thanks to developers and authors of used linters:
|
|||||||
- [kyoh86](https://github.com/kyoh86)
|
- [kyoh86](https://github.com/kyoh86)
|
||||||
- [go-critic](https://github.com/go-critic)
|
- [go-critic](https://github.com/go-critic)
|
||||||
- [leighmcculloch](https://github.com/leighmcculloch)
|
- [leighmcculloch](https://github.com/leighmcculloch)
|
||||||
|
- [matoous](https://github.com/matoous)
|
||||||
- [ultraware](https://github.com/ultraware)
|
- [ultraware](https://github.com/ultraware)
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
1
go.mod
1
go.mod
@ -31,6 +31,7 @@ require (
|
|||||||
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce // indirect
|
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
github.com/magiconair/properties v1.7.6 // 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-colorable v0.0.9
|
||||||
github.com/mattn/go-isatty v0.0.3 // indirect
|
github.com/mattn/go-isatty v0.0.3 // indirect
|
||||||
github.com/mitchellh/go-homedir v1.0.0
|
github.com/mitchellh/go-homedir v1.0.0
|
||||||
|
2
go.sum
2
go.sum
@ -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/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 h1:U+1DqNen04MdEPgFiIwdOUiqZ8qPa37xgogX/sd3+54=
|
||||||
github.com/magiconair/properties v1.7.6/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
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 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
|
||||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
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=
|
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
|
||||||
|
@ -177,6 +177,7 @@ type LintersSettings struct {
|
|||||||
Prealloc PreallocSettings
|
Prealloc PreallocSettings
|
||||||
Errcheck ErrcheckSettings
|
Errcheck ErrcheckSettings
|
||||||
Gocritic GocriticSettings
|
Gocritic GocriticSettings
|
||||||
|
Godox GodoxSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
type GovetSettings struct {
|
type GovetSettings struct {
|
||||||
@ -211,6 +212,10 @@ type PreallocSettings struct {
|
|||||||
ForLoops bool `mapstructure:"for-loops"`
|
ForLoops bool `mapstructure:"for-loops"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GodoxSettings struct {
|
||||||
|
Keywords []string
|
||||||
|
}
|
||||||
|
|
||||||
var defaultLintersSettings = LintersSettings{
|
var defaultLintersSettings = LintersSettings{
|
||||||
Lll: LllSettings{
|
Lll: LllSettings{
|
||||||
LineLength: 120,
|
LineLength: 120,
|
||||||
@ -230,6 +235,9 @@ var defaultLintersSettings = LintersSettings{
|
|||||||
Gocritic: GocriticSettings{
|
Gocritic: GocriticSettings{
|
||||||
SettingsPerCheck: map[string]GocriticCheckSettings{},
|
SettingsPerCheck: map[string]GocriticCheckSettings{},
|
||||||
},
|
},
|
||||||
|
Godox: GodoxSettings{
|
||||||
|
Keywords: []string{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type Linters struct {
|
type Linters struct {
|
||||||
|
46
pkg/golinters/godox.go
Normal file
46
pkg/golinters/godox.go
Normal file
@ -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
|
||||||
|
}
|
@ -238,6 +238,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
|
|||||||
WithPresets(linter.PresetStyle).
|
WithPresets(linter.PresetStyle).
|
||||||
WithSpeed(10).
|
WithSpeed(10).
|
||||||
WithURL("https://github.com/leighmcculloch/gochecknoglobals"),
|
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{}).
|
linter.NewConfig(golinters.Funlen{}).
|
||||||
WithPresets(linter.PresetStyle).
|
WithPresets(linter.PresetStyle).
|
||||||
WithSpeed(10).
|
WithSpeed(10).
|
||||||
|
13
test/testdata/godox.go
vendored
Normal file
13
test/testdata/godox.go
vendored
Normal file
@ -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
vendor/github.com/matoous/godox/.gitignore
generated
vendored
Normal file
18
vendor/github.com/matoous/godox/.gitignore
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary, build with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||||
|
.glide/
|
||||||
|
|
||||||
|
.vscode/
|
||||||
|
debug
|
||||||
|
debug.test
|
68
vendor/github.com/matoous/godox/.golangci.yml
generated
vendored
Normal file
68
vendor/github.com/matoous/godox/.golangci.yml
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
linters-settings:
|
||||||
|
depguard:
|
||||||
|
list-type: blacklist
|
||||||
|
include-go-root: true
|
||||||
|
packages:
|
||||||
|
# we are using "github.com/json-iterator/go" instead of json encoder from stdlib
|
||||||
|
- "encoding/json"
|
||||||
|
dupl:
|
||||||
|
threshold: 100
|
||||||
|
gocritic:
|
||||||
|
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks.
|
||||||
|
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
|
||||||
|
enabled-tags:
|
||||||
|
- performance
|
||||||
|
- diagnostic
|
||||||
|
- style
|
||||||
|
disabled-checks:
|
||||||
|
- emptyStringTest
|
||||||
|
- unnamedResult # it is experimental currently and doesn't handle typed channels correctly
|
||||||
|
gocyclo:
|
||||||
|
min-complexity: 14 # TODO go lower
|
||||||
|
golint:
|
||||||
|
min-confidence: 0
|
||||||
|
govet:
|
||||||
|
check-shadowing: true
|
||||||
|
goconst:
|
||||||
|
min-len: 2
|
||||||
|
min-occurrences: 3
|
||||||
|
goimports:
|
||||||
|
local-prefixes: gitlab.skypicker.com/search-team/gonuts/conveyance-store
|
||||||
|
lll:
|
||||||
|
line-length: 140
|
||||||
|
maligned:
|
||||||
|
suggest-new: true
|
||||||
|
misspell:
|
||||||
|
locale: US
|
||||||
|
|
||||||
|
linters:
|
||||||
|
enable-all: true
|
||||||
|
disable:
|
||||||
|
# prealloc is not recommended by `golangci-lint` developers.
|
||||||
|
- prealloc
|
||||||
|
- gochecknoglobals
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude-rules:
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
- goconst
|
||||||
|
- dupl
|
||||||
|
|
||||||
|
- path: api/v1/
|
||||||
|
linters:
|
||||||
|
- dupl
|
||||||
|
|
||||||
|
run:
|
||||||
|
modules-download-mode: readonly
|
||||||
|
|
||||||
|
# output configuration options
|
||||||
|
output:
|
||||||
|
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
|
||||||
|
format: tab
|
||||||
|
|
||||||
|
# print lines of code with issue, default is true
|
||||||
|
print-issued-lines: true
|
||||||
|
|
||||||
|
# print linter name in the end of issue text, default is true
|
||||||
|
print-linter-name: true
|
135
vendor/github.com/matoous/godox/.revive.toml
generated
vendored
Normal file
135
vendor/github.com/matoous/godox/.revive.toml
generated
vendored
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
ignoreGeneratedHeader = false
|
||||||
|
severity = "warning"
|
||||||
|
|
||||||
|
# confidence <= 0.2 generate a lot of errors from package-comments rule. It marks files that do not contain
|
||||||
|
# package-level comments as a warning irrespective of existing package-level coment in one file.
|
||||||
|
confidence = 0.25
|
||||||
|
errorCode = 1
|
||||||
|
warningCode = 1
|
||||||
|
|
||||||
|
# Rules block.
|
||||||
|
# ⚠ Make sure to sort rules alpabetically for readability! ⚠
|
||||||
|
|
||||||
|
# argument-limit rule is setting up a maximum number of parameters that can be passed to the functions/methods.
|
||||||
|
[rule.argument-limit]
|
||||||
|
arguments = [5]
|
||||||
|
|
||||||
|
# atomic rule checks for commonly mistaken usages of the sync/atomic package.
|
||||||
|
[rule.atomic]
|
||||||
|
|
||||||
|
# blank-imports rule disallows blank imports.
|
||||||
|
[rule.blank-imports]
|
||||||
|
|
||||||
|
# bool-literal-in-expr suggests removing boolean literals from logic expressions like `bar == true`, `arg == false`,
|
||||||
|
# `r != true`, `false && boolExpr` and `boolExpr || true`.
|
||||||
|
[rule.bool-literal-in-expr]
|
||||||
|
|
||||||
|
# constant-logical-expr rule warns on constant logical expressions, like `name == name`.
|
||||||
|
[rule.constant-logical-expr]
|
||||||
|
|
||||||
|
# context-as-argument rule makes sure that context.Context is the first argument of a function.
|
||||||
|
[rule.context-as-argument]
|
||||||
|
|
||||||
|
# context-keys-type rule disallows the usage of basic types in context.WithValue
|
||||||
|
[rule.context-keys-type]
|
||||||
|
|
||||||
|
# confusing-naming rule warns on methods with names that differ only by capitalization.
|
||||||
|
[rule.confusing-naming]
|
||||||
|
|
||||||
|
# confusing-results rule suggests to name potentially confusing function results.
|
||||||
|
[rule.confusing-results]
|
||||||
|
|
||||||
|
# cyclomatic rule sets restriction for maximum Cyclomatic complexity.
|
||||||
|
[rule.cyclomatic]
|
||||||
|
arguments = [15]
|
||||||
|
|
||||||
|
# deep-exit rule looks for program exits in funcs other than `main()` or `init()`.
|
||||||
|
[rule.deep-exit]
|
||||||
|
|
||||||
|
# dot-imports rule forbids `.` imports.
|
||||||
|
[rule.dot-imports]
|
||||||
|
|
||||||
|
# empty-block warns on empty code blocks.
|
||||||
|
[rule.empty-block]
|
||||||
|
|
||||||
|
# error-return rule ensure that the error return parameter is the last.
|
||||||
|
[rule.error-return]
|
||||||
|
|
||||||
|
# error-strings rule ensure conventions around error strings.
|
||||||
|
[rule.error-strings]
|
||||||
|
|
||||||
|
# error-naming rule ensure naming of error variables (has `Err` or `err` prefix).
|
||||||
|
[rule.error-naming]
|
||||||
|
|
||||||
|
# errorf rule warns on usage errors.New(fmt.Sprintf()) instead of fmt.Errorf()
|
||||||
|
[rule.errorf]
|
||||||
|
|
||||||
|
# exported rule ensure naming and commenting conventions on exported symbols.
|
||||||
|
[rule.exported]
|
||||||
|
|
||||||
|
# flag-parameter rule warns on boolean parameters that create a control coupling.
|
||||||
|
[rule.flag-parameter]
|
||||||
|
|
||||||
|
# get-return rule warns on getters that do not yield any result.
|
||||||
|
[rule.get-return]
|
||||||
|
|
||||||
|
# if-return rule warns redundant if when returning an error.
|
||||||
|
[rule.if-return]
|
||||||
|
|
||||||
|
# increment-decrement rule forces to use `i++` and `i--` instead of `i += 1` and `i -= 1`.
|
||||||
|
[rule.increment-decrement]
|
||||||
|
|
||||||
|
# indent-error-flow rule prevents redundant else statements.
|
||||||
|
[rule.indent-error-flow]
|
||||||
|
|
||||||
|
# modifies-value-receiver warns on assignments to value-passed method receivers.
|
||||||
|
[rule.modifies-value-receiver]
|
||||||
|
|
||||||
|
# package-comments rule ensures package commenting conventions.
|
||||||
|
[rule.package-comments]
|
||||||
|
|
||||||
|
# range rule prevents redundant variables when iterating over a collection.
|
||||||
|
[rule.range]
|
||||||
|
|
||||||
|
# range-val-in-closure warns if range value is used in a closure dispatched as goroutine.
|
||||||
|
[rule.range-val-in-closure]
|
||||||
|
|
||||||
|
# receiver-naming ensures conventions around the naming of receivers.
|
||||||
|
[rule.receiver-naming]
|
||||||
|
|
||||||
|
# redefines-builtin-id warns on redefinitions of built-in (constants, variables, function and types) identifiers,
|
||||||
|
# like `true := "false"` etc.
|
||||||
|
[rule.redefines-builtin-id]
|
||||||
|
|
||||||
|
# rule.superfluous-else prevents redundant else statements (extends indent-error-flow). Checks for `if-then-else`where
|
||||||
|
# the then block ends with branching statement like `continue`, `break`, or `goto`.
|
||||||
|
[rule.superfluous-else]
|
||||||
|
|
||||||
|
# rule.struct-tag checks common struct tags like `json`, `xml`, `yaml`.
|
||||||
|
[rule.struct-tag]
|
||||||
|
|
||||||
|
# time-naming rule conventions around the naming of time variables. Like not to use unit suffixes (sec, min etc.) in
|
||||||
|
# naming variables of type `time.Time` or `time.Duration`.
|
||||||
|
[rule.time-naming]
|
||||||
|
|
||||||
|
# unexported-return rule warns when a public return is from unexported type.
|
||||||
|
[rule.unexported-return]
|
||||||
|
|
||||||
|
# unnecessary-stmt suggests removing or simplifying unnecessary statements like breaks at the end of cases or return at
|
||||||
|
# the end of bodies of functions returning nothing.
|
||||||
|
[rule.unnecessary-stmt]
|
||||||
|
|
||||||
|
# unreachable-code rule warns on the unreachable code.
|
||||||
|
[rule.unreachable-code]
|
||||||
|
|
||||||
|
# unused-parameter rule suggests to rename or remove unused function parameters.
|
||||||
|
[rule.unused-parameter]
|
||||||
|
|
||||||
|
# var-declaration rule reduces redundancies around variable declaration.
|
||||||
|
[rule.var-declaration]
|
||||||
|
|
||||||
|
# var-naming checks naming rules.
|
||||||
|
[rule.var-naming]
|
||||||
|
|
||||||
|
# waitgroup-by-value rule warns on functions taking `sync.WaitGroup` as a by-value parameter.
|
||||||
|
[rule.waitgroup-by-value]
|
21
vendor/github.com/matoous/godox/LICENSE
generated
vendored
Normal file
21
vendor/github.com/matoous/godox/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 Matous Dzivjak
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
15
vendor/github.com/matoous/godox/README.md
generated
vendored
Normal file
15
vendor/github.com/matoous/godox/README.md
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
GoDoX
|
||||||
|
===
|
||||||
|
|
||||||
|
[](https://travis-ci.org/matoous/godox)
|
||||||
|
[](https://godoc.org/github.com/matoous/godox)
|
||||||
|
[](https://goreportcard.com/report/github.com/matoous/godox)
|
||||||
|
[](https://github.com/matoous/godox/issues)
|
||||||
|
[](https://github.com/matoous/godox/LICENSE)
|
||||||
|
|
||||||
|
GoDoX extracts comments from Go code based on keywords.
|
||||||
|
|
||||||
|
Installation
|
||||||
|
---
|
||||||
|
|
||||||
|
go get github.com/matoous/godox
|
5
vendor/github.com/matoous/godox/go.mod
generated
vendored
Normal file
5
vendor/github.com/matoous/godox/go.mod
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module github.com/matoous/godox
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578
|
8
vendor/github.com/matoous/godox/go.sum
generated
vendored
Normal file
8
vendor/github.com/matoous/godox/go.sum
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578 h1:f0Gfd654rnnfXT1+BK1YHPTS1qQdKrPIaGQwWxNE44k=
|
||||||
|
golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
75
vendor/github.com/matoous/godox/godox.go
generated
vendored
Normal file
75
vendor/github.com/matoous/godox/godox.go
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package godox
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"go/ast"
|
||||||
|
"go/token"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
defaultKeywords = []string{"TODO", "BUG", "FIXME"}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Message contains a message and position
|
||||||
|
type Message struct {
|
||||||
|
Pos token.Position
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMessages(c *ast.Comment, fset *token.FileSet, keywords []string) []Message {
|
||||||
|
commentText := c.Text
|
||||||
|
switch commentText[1] {
|
||||||
|
case '/':
|
||||||
|
commentText = commentText[2:]
|
||||||
|
if len(commentText) > 0 && commentText[0] == ' ' {
|
||||||
|
commentText = commentText[1:]
|
||||||
|
}
|
||||||
|
case '*':
|
||||||
|
commentText = commentText[2 : len(commentText)-2]
|
||||||
|
}
|
||||||
|
|
||||||
|
b := bufio.NewReader(bytes.NewBufferString(commentText))
|
||||||
|
var comments []Message
|
||||||
|
|
||||||
|
for lineNum := 0; ; lineNum++ {
|
||||||
|
line, _, err := b.ReadLine()
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
sComment := bytes.TrimSpace(line)
|
||||||
|
if len(sComment) < 4 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, kw := range keywords {
|
||||||
|
if bytes.EqualFold([]byte(kw), sComment[0:len(kw)]) {
|
||||||
|
pos := fset.Position(c.Pos())
|
||||||
|
if len(sComment) > 40 {
|
||||||
|
sComment = []byte(fmt.Sprintf("%s...", sComment[:40]))
|
||||||
|
}
|
||||||
|
comments = append(comments, Message{
|
||||||
|
Pos: pos,
|
||||||
|
Message: fmt.Sprintf("%s:%d: Line contains %s: \"%s\"", filepath.Join(pos.Filename), pos.Line+lineNum, strings.Join(keywords, "/"), sComment),
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return comments
|
||||||
|
}
|
||||||
|
|
||||||
|
func Run(file *ast.File, fset *token.FileSet, keywords ...string) []Message {
|
||||||
|
if keywords == nil || len(keywords) == 0 {
|
||||||
|
keywords = defaultKeywords
|
||||||
|
}
|
||||||
|
var messages []Message
|
||||||
|
for _, c := range file.Comments {
|
||||||
|
for _, ci := range c.List {
|
||||||
|
messages = append(messages, getMessages(ci, fset, keywords)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messages
|
||||||
|
}
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -126,6 +126,8 @@ github.com/kisielk/gotool
|
|||||||
github.com/kisielk/gotool/internal/load
|
github.com/kisielk/gotool/internal/load
|
||||||
# github.com/magiconair/properties v1.7.6
|
# github.com/magiconair/properties v1.7.6
|
||||||
github.com/magiconair/properties
|
github.com/magiconair/properties
|
||||||
|
# github.com/matoous/godox v0.0.0-20190910121045-032ad8106c86
|
||||||
|
github.com/matoous/godox
|
||||||
# github.com/mattn/go-colorable v0.0.9
|
# github.com/mattn/go-colorable v0.0.9
|
||||||
github.com/mattn/go-colorable
|
github.com/mattn/go-colorable
|
||||||
# github.com/mattn/go-isatty v0.0.3
|
# github.com/mattn/go-isatty v0.0.3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user