Skip to content

Commit

Permalink
Add new linter: godot
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krivak committed Mar 16, 2020
1 parent 4958e50 commit 58572c7
Show file tree
Hide file tree
Showing 14 changed files with 288 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ linters-settings:
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10
godot:
# check all top-level comments, not only declarations
check-all: false
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
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ gocognit: Computes and checks the cognitive complexity of functions [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]
godot: Check if comments end in a period [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]
Expand Down Expand Up @@ -488,6 +489,7 @@ golangci-lint help linters
- [wsl](https://github.com/bombsimon/wsl) - Whitespace Linter - Forces you to use empty lines!
- [goprintffuncname](https://github.com/jirfag/go-printf-func-name) - Checks that printf-like functions are named with `f` at the end
- [gomnd](https://github.com/tommy-muehle/go-mnd) - An analyzer to detect magic numbers.
- [godot](https://github.com/tetafro/godot) - Check if comments end in a period
## Configuration
Expand Down Expand Up @@ -736,6 +738,9 @@ linters-settings:
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10
godot:
# check all top-level comments, not only declarations
check-all: false
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
Expand Down Expand Up @@ -1261,6 +1266,7 @@ Thanks to developers and authors of used linters:
- [bombsimon](https://github.com/bombsimon)
- [jirfag](https://github.com/jirfag)
- [tommy-muehle](https://github.com/tommy-muehle)
- [tetafro](https://github.com/tetafro)
## Changelog
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.6.1
github.com/stretchr/testify v1.5.1
github.com/tetafro/godot v0.2.5
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e
github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa
github.com/ultraware/funlen v0.0.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tetafro/godot v0.2.5 h1:7+EYJM/Z4gYZhBFdRrVm6JTj5ZLw/QI1j4RfEOXJviE=
github.com/tetafro/godot v0.2.5/go.mod h1:pT6/T8+h6//L/LwQcFc4C0xpfy1euZwzS1sHdrFCms0=
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ type LintersSettings struct {
Godox GodoxSettings
Dogsled DogsledSettings
Gocognit GocognitSettings
Godot GodotSettings

Custom map[string]CustomLinterSettings
}
Expand Down Expand Up @@ -273,6 +274,10 @@ type WSLSettings struct {
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
}

type GodotSettings struct {
CheckAll bool `mapstructure:"check-all"`
}

//nolint:gomnd
var defaultLintersSettings = LintersSettings{
Lll: LllSettings{
Expand Down
64 changes: 64 additions & 0 deletions pkg/golinters/godot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package golinters

import (
"sync"

"github.com/tetafro/godot"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/result"
)

const godotName = "godot"

func NewGodot() *goanalysis.Linter {
var mu sync.Mutex
var resIssues []goanalysis.Issue

analyzer := &analysis.Analyzer{
Name: godotName,
Doc: goanalysis.TheOnlyanalyzerDoc,
}
return goanalysis.NewLinter(
godotName,
"Check if comments end in a period",
[]*analysis.Analyzer{analyzer},
nil,
).WithContextSetter(func(lintCtx *linter.Context) {
cfg := lintCtx.Cfg.LintersSettings.Godot
settings := godot.Settings{CheckAll: cfg.CheckAll}

analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
var issues []godot.Message
for _, file := range pass.Files {
issues = append(issues, godot.Run(file, pass.Fset, settings)...)
}

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

res := make([]goanalysis.Issue, len(issues))
for k, i := range issues {
issue := result.Issue{
Pos: i.Pos,
Text: i.Message,
FromLinter: godotName,
Replacement: &result.Replacement{},
}

res[k] = goanalysis.NewIssue(&issue, pass)
}

mu.Lock()
resIssues = append(resIssues, res...)
mu.Unlock()

return nil, nil
}
}).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
return resIssues
}).WithLoadMode(goanalysis.LoadModeSyntax)
}
3 changes: 3 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
linter.NewConfig(golinters.NewGoMND(m.cfg)).
WithPresets(linter.PresetStyle).
WithURL("https://github.com/tommy-muehle/go-mnd"),
linter.NewConfig(golinters.NewGodot()).
WithPresets(linter.PresetStyle).
WithURL("https://github.com/tetafro/godot"),
}

isLocalRun := os.Getenv("GOLANGCI_COM_RUN") == ""
Expand Down
7 changes: 7 additions & 0 deletions test/testdata/godot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//args: -Egodot
package testdata

// Godot checks top-level comments // ERROR "Top level comment should end in a period"
func Godot() {
// nothing to do here
}
1 change: 1 addition & 0 deletions vendor/github.com/tetafro/godot/.gitignore

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

21 changes: 21 additions & 0 deletions vendor/github.com/tetafro/godot/LICENSE

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

40 changes: 40 additions & 0 deletions vendor/github.com/tetafro/godot/README.md

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

3 changes: 3 additions & 0 deletions vendor/github.com/tetafro/godot/go.mod

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

130 changes: 130 additions & 0 deletions vendor/github.com/tetafro/godot/godot.go

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

2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ github.com/stretchr/testify/mock
github.com/stretchr/testify/require
# github.com/subosito/gotenv v1.2.0
github.com/subosito/gotenv
# github.com/tetafro/godot v0.2.5
github.com/tetafro/godot
# github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e
github.com/timakin/bodyclose/passes/bodyclose
# github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa
Expand Down

0 comments on commit 58572c7

Please sign in to comment.