aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/tetafro
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2022-09-05 14:27:54 +0200
committerGitHub <noreply@github.com>2022-09-05 12:27:54 +0000
commitb2f2446b46bf02821d90ebedadae2bf7ae0e880e (patch)
tree923cf42842918d6bebca1d6bbdc08abed54d274d /vendor/github.com/tetafro
parente6654faff4bcca4be92e9a8596fd4b77f747c39e (diff)
go.mod, vendor: update (#3358)
* go.mod, vendor: remove unnecessary dependencies Commands: 1. go mod tidy 2. go mod vendor * go.mod, vendor: update cloud.google.com/go Commands: 1. go get -u cloud.google.com/go 2. go mod tidy 3. go mod vendor * go.mod, vendor: update cloud.google.com/* Commands: 1. go get -u cloud.google.com/storage cloud.google.com/logging 2. go mod tidy 3. go mod vendor * go.mod, .golangci.yml, vendor: update *lint* Commands: 1. go get -u golang.org/x/tools github.com/golangci/golangci-lint@v1.47.0 2. go mod tidy 3. go mod vendor 4. edit .golangci.yml to suppress new errors (resolved in the same PR later) * all: fix lint errors hash.go: copy() recommended by gosimple parse.go: ent is never nil verifier.go: signal.Notify() with unbuffered channel is bad. Have no idea why. * .golangci.yml: adjust godot rules check-all is deprecated, but still work if you're hesitating too - I'll remove this commit
Diffstat (limited to 'vendor/github.com/tetafro')
-rw-r--r--vendor/github.com/tetafro/godot/.gitignore1
-rw-r--r--vendor/github.com/tetafro/godot/.godot.yaml (renamed from vendor/github.com/tetafro/godot/config.yaml)6
-rw-r--r--vendor/github.com/tetafro/godot/README.md7
-rw-r--r--vendor/github.com/tetafro/godot/checks.go83
-rw-r--r--vendor/github.com/tetafro/godot/getters.go27
-rw-r--r--vendor/github.com/tetafro/godot/go.mod2
-rw-r--r--vendor/github.com/tetafro/godot/godot.go8
7 files changed, 102 insertions, 32 deletions
diff --git a/vendor/github.com/tetafro/godot/.gitignore b/vendor/github.com/tetafro/godot/.gitignore
index db77fd15d..0b17eac4c 100644
--- a/vendor/github.com/tetafro/godot/.gitignore
+++ b/vendor/github.com/tetafro/godot/.gitignore
@@ -1,4 +1,5 @@
/dist/
+/tmp/
/vendor/
/godot
/profile.out
diff --git a/vendor/github.com/tetafro/godot/config.yaml b/vendor/github.com/tetafro/godot/.godot.yaml
index c459ca323..af36858f9 100644
--- a/vendor/github.com/tetafro/godot/config.yaml
+++ b/vendor/github.com/tetafro/godot/.godot.yaml
@@ -2,10 +2,12 @@
# declarations - for top level declaration comments (default);
# toplevel - for top level comments;
# all - for all comments.
-scope: toplevel
+scope: declarations
-# List pf regexps for excluding particular comment lines from check.
+# List of regexps for excluding particular comment lines from check.
+# Example: exclude comments which contain numbers.
exclude:
+ # - '[0-9]+'
# Check periods at the end of sentences.
period: true
diff --git a/vendor/github.com/tetafro/godot/README.md b/vendor/github.com/tetafro/godot/README.md
index 902678f54..3f97b0e39 100644
--- a/vendor/github.com/tetafro/godot/README.md
+++ b/vendor/github.com/tetafro/godot/README.md
@@ -28,7 +28,8 @@ or download binary from [releases page](https://github.com/tetafro/godot/release
## Config
-You can specify options using config file. If no config provided the following
+You can specify options using config file. Use default name `.godot.yaml`, or
+set it using `-c filename.yaml` argument. If no config provided the following
defaults are used:
```yaml
@@ -36,9 +37,9 @@ defaults are used:
# declarations - for top level declaration comments (default);
# toplevel - for top level comments;
# all - for all comments.
-scope: toplevel
+scope: declarations
-# List pf regexps for excluding particular comment lines from check.
+# List of regexps for excluding particular comment lines from check.
exclude:
# Check periods at the end of sentences.
diff --git a/vendor/github.com/tetafro/godot/checks.go b/vendor/github.com/tetafro/godot/checks.go
index 0e66add1d..cba54f310 100644
--- a/vendor/github.com/tetafro/godot/checks.go
+++ b/vendor/github.com/tetafro/godot/checks.go
@@ -16,7 +16,10 @@ const (
var (
// List of valid sentence ending.
// A sentence can be inside parenthesis, and therefore ends with parenthesis.
- lastChars = []string{".", "?", "!", ".)", "?)", "!)", specialReplacer}
+ lastChars = []string{".", "?", "!", ".)", "?)", "!)", "。", "?", "!", "。)", "?)", "!)", specialReplacer}
+
+ // Abbreviations to exclude from capital letters check.
+ abbreviations = []string{"i.e.", "i. e.", "e.g.", "e. g.", "etc."}
// Special tags in comments like "// nolint:", or "// +k8s:".
tags = regexp.MustCompile(`^\+?[a-z0-9]+:`)
@@ -55,18 +58,20 @@ func checkCommentForPeriod(c comment) *Issue {
return nil
}
- // Shift position by the length of comment's special symbols: /* or //
- isBlock := strings.HasPrefix(c.lines[0], "/*")
- if (isBlock && pos.line == 1) || !isBlock {
- pos.column += 2
- }
+ // Shift position to its real value. `c.text` doesn't contain comment's
+ // special symbols: /* or //, and line indentations inside. It also
+ // contains */ in the end in case of block comment.
+ pos.column += strings.Index(
+ c.lines[pos.line-1],
+ strings.Split(c.text, "\n")[pos.line-1],
+ )
iss := Issue{
Pos: token.Position{
Filename: c.start.Filename,
Offset: c.start.Offset,
Line: pos.line + c.start.Line - 1,
- Column: pos.column + c.start.Column - 1,
+ Column: pos.column,
},
Message: noPeriodMessage,
}
@@ -74,9 +79,13 @@ func checkCommentForPeriod(c comment) *Issue {
// Make a replacement. Use `pos.line` to get an original line from
// attached lines. Use `iss.Pos.Column` because it's a position in
// the original line.
- original := []rune(c.lines[pos.line-1])
- iss.Replacement = string(original[:iss.Pos.Column-1]) + "." +
- string(original[iss.Pos.Column-1:])
+ original := c.lines[pos.line-1]
+ if len(original) < iss.Pos.Column-1 {
+ // This should never happen. Avoid panics, skip this check.
+ return nil
+ }
+ iss.Replacement = original[:iss.Pos.Column-1] + "." +
+ original[iss.Pos.Column-1:]
// Save replacement to raw lines to be able to combine it with
// further replacements
@@ -85,7 +94,7 @@ func checkCommentForPeriod(c comment) *Issue {
return &iss
}
-// checkCommentForCapital checks that the each sentense of the comment starts with
+// checkCommentForCapital checks that each sentense of the comment starts with
// a capital letter.
// nolint: unparam
func checkCommentForCapital(c comment) []Issue {
@@ -112,12 +121,18 @@ func checkCommentForCapital(c comment) []Issue {
Message: noCapitalMessage,
}
- // Make a replacement. Use `pos.line` to get an original line from
+ // Make a replacement. Use `pos.original` to get an original original from
// attached lines. Use `iss.Pos.Column` because it's a position in
- // the original line.
- rep := []rune(c.lines[pos.line-1])
- rep[iss.Pos.Column-1] = unicode.ToTitle(rep[iss.Pos.Column-1])
- iss.Replacement = string(rep)
+ // the original original.
+ original := c.lines[pos.line-1]
+ col := byteToRuneColumn(original, iss.Pos.Column) - 1
+ rep := string(unicode.ToTitle([]rune(original)[col])) // capital letter
+ if len(original) < iss.Pos.Column-1+len(rep) {
+ // This should never happen. Avoid panics, skip this check.
+ continue
+ }
+ iss.Replacement = original[:iss.Pos.Column-1] + rep +
+ original[iss.Pos.Column-1+len(rep):]
// Save replacement to raw lines to be able to combine it with
// further replacements
@@ -155,15 +170,21 @@ func checkPeriod(comment string) (pos position, ok bool) {
return position{}, true
}
- pos.column = len([]rune(line)) + 1
+ pos.column = len(line) + 1
return pos, false
}
-// checkCapital checks that the each sentense of the text starts with
+// checkCapital checks that each sentense of the text starts with
// a capital letter.
// NOTE: First letter is not checked in declaration comments, because they
-// can describe unexported functions, which start from small letter.
+// can describe unexported functions, which start with small letter.
func checkCapital(comment string, skipFirst bool) (pp []position) {
+ // Remove common abbreviations from the comment
+ for _, abbr := range abbreviations {
+ repl := strings.ReplaceAll(abbr, ".", "_")
+ comment = strings.ReplaceAll(comment, abbr, repl)
+ }
+
// List of states during the scan: `empty` - nothing special,
// `endChar` - found one of sentence ending chars (.!?),
// `endOfSentence` - found `endChar`, and then space or newline.
@@ -200,7 +221,10 @@ func checkCapital(comment string, skipFirst bool) (pp []position) {
continue
}
if state == endOfSentence && unicode.IsLower(r) {
- pp = append(pp, position{line: pos.line, column: pos.column})
+ pp = append(pp, position{
+ line: pos.line,
+ column: runeToByteColumn(comment, pos.column),
+ })
}
state = empty
}
@@ -258,3 +282,22 @@ func hasSuffix(s string, suffixes []string) bool {
}
return false
}
+
+// The following two functions convert byte and rune indexes.
+//
+// Example:
+// text: a b c Ш e f
+// runes: 1 2 3 4 5 6
+// bytes: 0 1 2 3 5 6
+// The reason of the difference is that the size of "Ш" is 2 bytes.
+// NOTE: Works only for 1-based indexes (line columns).
+
+// byteToRuneColumn converts byte index inside the string to rune index.
+func byteToRuneColumn(s string, i int) int {
+ return len([]rune(s[:i-1])) + 1
+}
+
+// runeToByteColumn converts rune index inside the string to byte index.
+func runeToByteColumn(s string, i int) int {
+ return len(string([]rune(s)[:i-1])) + 1
+}
diff --git a/vendor/github.com/tetafro/godot/getters.go b/vendor/github.com/tetafro/godot/getters.go
index 02b8acec7..6153772bd 100644
--- a/vendor/github.com/tetafro/godot/getters.go
+++ b/vendor/github.com/tetafro/godot/getters.go
@@ -10,7 +10,10 @@ import (
"strings"
)
-var errEmptyInput = errors.New("empty input")
+var (
+ errEmptyInput = errors.New("empty input")
+ errUnsuitableInput = errors.New("unsuitable input")
+)
// specialReplacer is a replacer for some types of special lines in comments,
// which shouldn't be checked. For example, if comment ends with a block of
@@ -44,10 +47,21 @@ func newParsedFile(file *ast.File, fset *token.FileSet) (*parsedFile, error) {
return nil, fmt.Errorf("read file: %v", err)
}
+ // Dirty hack. For some cases Go generates temporary files during
+ // compilation process if there is a cgo block in the source file. Some of
+ // these temporary files are just copies of original source files but with
+ // new generated comments at the top. Because of them the content differs
+ // from AST. For some reason it differs only in golangci-lint. I failed to
+ // find out the exact description of the process, so let's just skip files
+ // generated by cgo.
+ if isCgoGenerated(pf.lines) {
+ return nil, errUnsuitableInput
+ }
+
// Check consistency to avoid checking slice indexes in each function
lastComment := pf.file.Comments[len(pf.file.Comments)-1]
if p := pf.fset.Position(lastComment.End()); len(pf.lines) < p.Line {
- return nil, fmt.Errorf("inconsistence between file and AST: %s", p.Filename)
+ return nil, fmt.Errorf("inconsistency between file and AST: %s", p.Filename)
}
return &pf, nil
@@ -258,3 +272,12 @@ func matchAny(s string, rr []*regexp.Regexp) bool {
}
return false
}
+
+func isCgoGenerated(lines []string) bool {
+ for i := range lines {
+ if strings.Contains(lines[i], "Code generated by cmd/cgo") {
+ return true
+ }
+ }
+ return false
+}
diff --git a/vendor/github.com/tetafro/godot/go.mod b/vendor/github.com/tetafro/godot/go.mod
index d0fa675b6..86ead9453 100644
--- a/vendor/github.com/tetafro/godot/go.mod
+++ b/vendor/github.com/tetafro/godot/go.mod
@@ -1,5 +1,5 @@
module github.com/tetafro/godot
-go 1.15
+go 1.16
require gopkg.in/yaml.v2 v2.4.0
diff --git a/vendor/github.com/tetafro/godot/godot.go b/vendor/github.com/tetafro/godot/godot.go
index 526a5f7d1..3a360a214 100644
--- a/vendor/github.com/tetafro/godot/godot.go
+++ b/vendor/github.com/tetafro/godot/godot.go
@@ -27,8 +27,8 @@ type Issue struct {
// position is a position inside a comment (might be multiline comment).
type position struct {
- line int
- column int
+ line int // starts at 1
+ column int // starts at 1, byte count
}
// comment is an internal representation of AST comment entity with additional
@@ -38,13 +38,13 @@ type comment struct {
lines []string // unmodified lines from file
text string // concatenated `lines` with special parts excluded
start token.Position // position of the first symbol in comment
- decl bool // whether comment is a special one (should not be checked)
+ decl bool // whether comment is a declaration comment
}
// Run runs this linter on the provided code.
func Run(file *ast.File, fset *token.FileSet, settings Settings) ([]Issue, error) {
pf, err := newParsedFile(file, fset)
- if err == errEmptyInput {
+ if err == errEmptyInput || err == errUnsuitableInput {
return nil, nil
}
if err != nil {