From c7d7f10bdff703e4a3c0414e8a33d4e45c91eb35 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 4 Jul 2020 11:12:55 +0200 Subject: go.mod: vendor golangci-lint --- vendor/github.com/tetafro/godot/.gitignore | 2 + vendor/github.com/tetafro/godot/.goreleaser.yml | 12 ++ vendor/github.com/tetafro/godot/LICENSE | 21 ++++ vendor/github.com/tetafro/godot/Makefile | 11 ++ vendor/github.com/tetafro/godot/README.md | 54 +++++++++ vendor/github.com/tetafro/godot/go.mod | 3 + vendor/github.com/tetafro/godot/godot.go | 151 ++++++++++++++++++++++++ 7 files changed, 254 insertions(+) create mode 100644 vendor/github.com/tetafro/godot/.gitignore create mode 100644 vendor/github.com/tetafro/godot/.goreleaser.yml create mode 100644 vendor/github.com/tetafro/godot/LICENSE create mode 100644 vendor/github.com/tetafro/godot/Makefile create mode 100644 vendor/github.com/tetafro/godot/README.md create mode 100644 vendor/github.com/tetafro/godot/go.mod create mode 100644 vendor/github.com/tetafro/godot/godot.go (limited to 'vendor/github.com/tetafro') diff --git a/vendor/github.com/tetafro/godot/.gitignore b/vendor/github.com/tetafro/godot/.gitignore new file mode 100644 index 000000000..2b87e3915 --- /dev/null +++ b/vendor/github.com/tetafro/godot/.gitignore @@ -0,0 +1,2 @@ +/dist/ +/godot diff --git a/vendor/github.com/tetafro/godot/.goreleaser.yml b/vendor/github.com/tetafro/godot/.goreleaser.yml new file mode 100644 index 000000000..87a05a2a7 --- /dev/null +++ b/vendor/github.com/tetafro/godot/.goreleaser.yml @@ -0,0 +1,12 @@ +builds: + - dir: ./cmd/godot +checksum: + name_template: checksums.txt +snapshot: + name_template: "{{ .Tag }}" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/vendor/github.com/tetafro/godot/LICENSE b/vendor/github.com/tetafro/godot/LICENSE new file mode 100644 index 000000000..120c6d502 --- /dev/null +++ b/vendor/github.com/tetafro/godot/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Denis Krivak + +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. diff --git a/vendor/github.com/tetafro/godot/Makefile b/vendor/github.com/tetafro/godot/Makefile new file mode 100644 index 000000000..fee7693ae --- /dev/null +++ b/vendor/github.com/tetafro/godot/Makefile @@ -0,0 +1,11 @@ +.PHONY: test +test: + go test ./... + +.PHONY: build +build: + go build -o godot ./cmd/godot + +.PHONY: release +release: + goreleaser release --rm-dist diff --git a/vendor/github.com/tetafro/godot/README.md b/vendor/github.com/tetafro/godot/README.md new file mode 100644 index 000000000..e2d2f6b0d --- /dev/null +++ b/vendor/github.com/tetafro/godot/README.md @@ -0,0 +1,54 @@ +# godot + +[![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/tetafro/godot/master/LICENSE) +[![Github CI](https://img.shields.io/github/workflow/status/tetafro/godot/Test)](https://github.com/tetafro/godot/actions?query=workflow%3ATest) +[![Go Report](https://goreportcard.com/badge/github.com/tetafro/godot)](https://goreportcard.com/report/github.com/tetafro/godot) +[![Codecov](https://codecov.io/gh/tetafro/godot/branch/master/graph/badge.svg)](https://codecov.io/gh/tetafro/godot) + +Linter that checks if all top-level comments contain a period at the +end of the last sentence if needed. + +[CodeReviewComments](https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences) quote: + +> Comments should begin with the name of the thing being described +> and end in a period + +## Install and run + +*NOTE: Godot is available as a part of [GolangCI Lint](https://github.com/golangci/golangci-lint) +(disabled by default).* + +Build from source +```sh +go get -u github.com/tetafro/godot/cmd/godot +``` + +or download binary from [releases page](https://github.com/tetafro/godot/releases). + +Run +```sh +godot ./myproject +``` + +## Examples + +Code + +```go +package math + +// Sum sums two integers +func Sum(a, b int) int { + return a + b // result +} +``` + +Output + +```sh +Top level comment should end in a period: math/math.go:3:1 +``` + +See more examples in test files: +- [for default mode](testdata/example_default.go) +- [for using --all flag](testdata/example_checkall.go) diff --git a/vendor/github.com/tetafro/godot/go.mod b/vendor/github.com/tetafro/godot/go.mod new file mode 100644 index 000000000..d86531c42 --- /dev/null +++ b/vendor/github.com/tetafro/godot/go.mod @@ -0,0 +1,3 @@ +module github.com/tetafro/godot + +go 1.14 diff --git a/vendor/github.com/tetafro/godot/godot.go b/vendor/github.com/tetafro/godot/godot.go new file mode 100644 index 000000000..5eec83579 --- /dev/null +++ b/vendor/github.com/tetafro/godot/godot.go @@ -0,0 +1,151 @@ +// Package godot checks if all top-level comments contain a period at the +// end of the last sentence if needed. +package godot + +import ( + "go/ast" + "go/token" + "regexp" + "strings" +) + +const noPeriodMessage = "Top level comment should end in a period" + +// Message contains a message of linting error. +type Message struct { + Pos token.Position + Message string +} + +// Settings contains linter settings. +type Settings struct { + // Check all top-level comments, not only declarations + CheckAll bool +} + +var ( + // List of valid last characters. + lastChars = []string{".", "?", "!"} + + // Special tags in comments like "nolint" or "build". + tags = regexp.MustCompile("^[a-z]+:") + + // Special hashtags in comments like "#nosec". + hashtags = regexp.MustCompile("^#[a-z]+ ") + + // URL at the end of the line. + endURL = regexp.MustCompile(`[a-z]+://[^\s]+$`) +) + +// Run runs this linter on the provided code. +func Run(file *ast.File, fset *token.FileSet, settings Settings) []Message { + msgs := []Message{} + + // Check all top-level comments + if settings.CheckAll { + for _, group := range file.Comments { + if ok, msg := check(fset, group); !ok { + msgs = append(msgs, msg) + } + } + return msgs + } + + // Check only declaration comments + for _, decl := range file.Decls { + switch d := decl.(type) { + case *ast.GenDecl: + if ok, msg := check(fset, d.Doc); !ok { + msgs = append(msgs, msg) + } + case *ast.FuncDecl: + if ok, msg := check(fset, d.Doc); !ok { + msgs = append(msgs, msg) + } + } + } + return msgs +} + +func check(fset *token.FileSet, group *ast.CommentGroup) (ok bool, msg Message) { + if group == nil || len(group.List) == 0 { + return true, Message{} + } + + // Check only top-level comments + if fset.Position(group.Pos()).Column > 1 { + return true, Message{} + } + + // Get last element from comment group - it can be either + // last (or single) line for "//"-comment, or multiline string + // for "/*"-comment + last := group.List[len(group.List)-1] + + line, ok := checkComment(last.Text) + if ok { + return true, Message{} + } + pos := fset.Position(last.Slash) + pos.Line += line + return false, Message{ + Pos: pos, + Message: noPeriodMessage, + } +} + +func checkComment(comment string) (line int, ok bool) { + // Check last line of "//"-comment + if strings.HasPrefix(comment, "//") { + comment = strings.TrimPrefix(comment, "//") + return 0, checkLastChar(comment) + } + + // Skip cgo code blocks + // TODO: Find a better way to detect cgo code. + if strings.Contains(comment, "#include") || strings.Contains(comment, "#define") { + return 0, true + } + + // Check last non-empty line in multiline "/*"-comment block + lines := strings.Split(comment, "\n") + var i int + for i = len(lines) - 1; i >= 0; i-- { + if s := strings.TrimSpace(lines[i]); s == "*/" || s == "" { + continue + } + break + } + comment = strings.TrimPrefix(lines[i], "/*") + comment = strings.TrimSuffix(comment, "*/") + return i, checkLastChar(comment) +} + +func checkLastChar(s string) bool { + // Don't check comments starting with space indentation - they may + // contain code examples, which shouldn't end with period + if strings.HasPrefix(s, " ") || strings.HasPrefix(s, " \t") || strings.HasPrefix(s, "\t") { + return true + } + // Skip cgo export tags: https://golang.org/cmd/cgo/#hdr-C_references_to_Go + if strings.HasPrefix(s, "export") { + return true + } + s = strings.TrimSpace(s) + if tags.MatchString(s) || + hashtags.MatchString(s) || + endURL.MatchString(s) || + strings.HasPrefix(s, "+build") { + return true + } + // Don't check empty lines + if s == "" { + return true + } + for _, ch := range lastChars { + if string(s[len(s)-1]) == ch { + return true + } + } + return false +} -- cgit mrf-deployment