aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ultraware
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-07-04 11:12:55 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-07-04 15:05:30 +0200
commitc7d7f10bdff703e4a3c0414e8a33d4e45c91eb35 (patch)
tree0dff0ee1f98dbfa3ad8776112053a450d176592b /vendor/github.com/ultraware
parent9573094ce235bd9afe88f5da27a47dd6bcc1e13b (diff)
go.mod: vendor golangci-lint
Diffstat (limited to 'vendor/github.com/ultraware')
-rw-r--r--vendor/github.com/ultraware/funlen/LICENSE7
-rw-r--r--vendor/github.com/ultraware/funlen/README.md69
-rw-r--r--vendor/github.com/ultraware/funlen/main.go98
-rw-r--r--vendor/github.com/ultraware/whitespace/LICENSE7
-rw-r--r--vendor/github.com/ultraware/whitespace/README.md7
-rw-r--r--vendor/github.com/ultraware/whitespace/main.go158
6 files changed, 346 insertions, 0 deletions
diff --git a/vendor/github.com/ultraware/funlen/LICENSE b/vendor/github.com/ultraware/funlen/LICENSE
new file mode 100644
index 000000000..dca75556d
--- /dev/null
+++ b/vendor/github.com/ultraware/funlen/LICENSE
@@ -0,0 +1,7 @@
+Copyright 2018 Ultraware Consultancy and Development B.V.
+
+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/ultraware/funlen/README.md b/vendor/github.com/ultraware/funlen/README.md
new file mode 100644
index 000000000..ca7e9a0f7
--- /dev/null
+++ b/vendor/github.com/ultraware/funlen/README.md
@@ -0,0 +1,69 @@
+# Funlen linter
+
+Funlen is a linter that checks for long functions. It can checks both on the number of lines and the number of statements.
+
+The default limits are 50 lines and 35 statements. You can configure these with the `-l` and `-s` flags.
+
+Example code:
+
+```go
+package main
+
+import "fmt"
+
+func fiveStatements() {
+ fmt.Println(1)
+ fmt.Println(2)
+ fmt.Println(3)
+ fmt.Println(4)
+ fmt.Println(5)
+}
+
+func sevenLines() {
+ fmt.Println(1)
+
+ fmt.Println(2)
+
+ fmt.Println(3)
+
+ fmt.Println(4)
+}
+```
+
+Reults in:
+
+```
+$ funlen -l=6 -s=4 .
+main.go:5:6:Function 'fiveStatements' has too many statements (5 > 4)
+main.go:13:6:Function 'sevenLines' is too long (7 > 6)
+```
+
+## Installation guide
+
+```bash
+go get git.ultraware.nl/NiseVoid/funlen
+```
+
+### Gometalinter
+
+You can add funlen to gometalinter and enable it.
+
+`.gometalinter.json`:
+
+```json
+{
+ "Linters": {
+ "funlen": "funlen -l=50 -s=35:PATH:LINE:COL:MESSAGE"
+ },
+
+ "Enable": [
+ "funlen"
+ ]
+}
+```
+
+commandline:
+
+```bash
+gometalinter --linter "funlen:funlen -l=50 -s=35:PATH:LINE:COL:MESSAGE" --enable "funlen"
+```
diff --git a/vendor/github.com/ultraware/funlen/main.go b/vendor/github.com/ultraware/funlen/main.go
new file mode 100644
index 000000000..19e48e2ff
--- /dev/null
+++ b/vendor/github.com/ultraware/funlen/main.go
@@ -0,0 +1,98 @@
+package funlen
+
+import (
+ "fmt"
+ "go/ast"
+ "go/token"
+ "reflect"
+)
+
+const defaultLineLimit = 60
+const defaultStmtLimit = 40
+
+// Run runs this linter on the provided code
+func Run(file *ast.File, fset *token.FileSet, lineLimit, stmtLimit int) []Message {
+ if lineLimit == 0 {
+ lineLimit = defaultLineLimit
+ }
+ if stmtLimit == 0 {
+ stmtLimit = defaultStmtLimit
+ }
+
+ var msgs []Message
+ for _, f := range file.Decls {
+ decl, ok := f.(*ast.FuncDecl)
+ if !ok || decl.Body == nil { // decl.Body can be nil for e.g. cgo
+ continue
+ }
+
+ if stmts := parseStmts(decl.Body.List); stmts > stmtLimit {
+ msgs = append(msgs, makeStmtMessage(fset, decl.Name, stmts, stmtLimit))
+ continue
+ }
+
+ if lines := getLines(fset, decl); lines > lineLimit {
+ msgs = append(msgs, makeLineMessage(fset, decl.Name, lines, lineLimit))
+ }
+ }
+
+ return msgs
+}
+
+// Message contains a message
+type Message struct {
+ Pos token.Position
+ Message string
+}
+
+func makeLineMessage(fset *token.FileSet, funcInfo *ast.Ident, lines, lineLimit int) Message {
+ return Message{
+ fset.Position(funcInfo.Pos()),
+ fmt.Sprintf("Function '%s' is too long (%d > %d)\n", funcInfo.Name, lines, lineLimit),
+ }
+}
+
+func makeStmtMessage(fset *token.FileSet, funcInfo *ast.Ident, stmts, stmtLimit int) Message {
+ return Message{
+ fset.Position(funcInfo.Pos()),
+ fmt.Sprintf("Function '%s' has too many statements (%d > %d)\n", funcInfo.Name, stmts, stmtLimit),
+ }
+}
+
+func getLines(fset *token.FileSet, f *ast.FuncDecl) int { // nolint: interfacer
+ return fset.Position(f.End()).Line - fset.Position(f.Pos()).Line - 1
+}
+
+func parseStmts(s []ast.Stmt) (total int) {
+ for _, v := range s {
+ total++
+ switch stmt := v.(type) {
+ case *ast.BlockStmt:
+ total += parseStmts(stmt.List) - 1
+ case *ast.ForStmt, *ast.RangeStmt, *ast.IfStmt,
+ *ast.SwitchStmt, *ast.TypeSwitchStmt, *ast.SelectStmt:
+ total += parseBodyListStmts(stmt)
+ case *ast.CaseClause:
+ total += parseStmts(stmt.Body)
+ case *ast.AssignStmt:
+ total += checkInlineFunc(stmt.Rhs[0])
+ case *ast.GoStmt:
+ total += checkInlineFunc(stmt.Call.Fun)
+ case *ast.DeferStmt:
+ total += checkInlineFunc(stmt.Call.Fun)
+ }
+ }
+ return
+}
+
+func checkInlineFunc(stmt ast.Expr) int {
+ if block, ok := stmt.(*ast.FuncLit); ok {
+ return parseStmts(block.Body.List)
+ }
+ return 0
+}
+
+func parseBodyListStmts(t interface{}) int {
+ i := reflect.ValueOf(t).Elem().FieldByName(`Body`).Elem().FieldByName(`List`).Interface()
+ return parseStmts(i.([]ast.Stmt))
+}
diff --git a/vendor/github.com/ultraware/whitespace/LICENSE b/vendor/github.com/ultraware/whitespace/LICENSE
new file mode 100644
index 000000000..dca75556d
--- /dev/null
+++ b/vendor/github.com/ultraware/whitespace/LICENSE
@@ -0,0 +1,7 @@
+Copyright 2018 Ultraware Consultancy and Development B.V.
+
+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/ultraware/whitespace/README.md b/vendor/github.com/ultraware/whitespace/README.md
new file mode 100644
index 000000000..aed9a485f
--- /dev/null
+++ b/vendor/github.com/ultraware/whitespace/README.md
@@ -0,0 +1,7 @@
+# Whitespace linter
+
+Whitespace is a linter that checks for unnecessary newlines at the start and end of functions, if, for, etc.
+
+## Installation guide
+
+Whitespace is included in [https://github.com/golangci/golangci-lint/](golangci-lint). Install it and enable whitespace.
diff --git a/vendor/github.com/ultraware/whitespace/main.go b/vendor/github.com/ultraware/whitespace/main.go
new file mode 100644
index 000000000..c36086c0e
--- /dev/null
+++ b/vendor/github.com/ultraware/whitespace/main.go
@@ -0,0 +1,158 @@
+package whitespace
+
+import (
+ "go/ast"
+ "go/token"
+)
+
+// Message contains a message
+type Message struct {
+ Pos token.Position
+ Type MessageType
+ Message string
+}
+
+// MessageType describes what should happen to fix the warning
+type MessageType uint8
+
+// List of MessageTypes
+const (
+ MessageTypeLeading MessageType = iota + 1
+ MessageTypeTrailing
+ MessageTypeAddAfter
+)
+
+// Settings contains settings for edge-cases
+type Settings struct {
+ MultiIf bool
+ MultiFunc bool
+}
+
+// Run runs this linter on the provided code
+func Run(file *ast.File, fset *token.FileSet, settings Settings) []Message {
+ var messages []Message
+
+ for _, f := range file.Decls {
+ decl, ok := f.(*ast.FuncDecl)
+ if !ok || decl.Body == nil { // decl.Body can be nil for e.g. cgo
+ continue
+ }
+
+ vis := visitor{file.Comments, fset, nil, make(map[*ast.BlockStmt]bool), settings}
+ ast.Walk(&vis, decl)
+
+ messages = append(messages, vis.messages...)
+ }
+
+ return messages
+}
+
+type visitor struct {
+ comments []*ast.CommentGroup
+ fset *token.FileSet
+ messages []Message
+ wantNewline map[*ast.BlockStmt]bool
+ settings Settings
+}
+
+func (v *visitor) Visit(node ast.Node) ast.Visitor {
+ if node == nil {
+ return v
+ }
+
+ if stmt, ok := node.(*ast.IfStmt); ok && v.settings.MultiIf {
+ checkMultiLine(v, stmt.Body, stmt.Cond)
+ }
+
+ if stmt, ok := node.(*ast.FuncDecl); ok && v.settings.MultiFunc {
+ checkMultiLine(v, stmt.Body, stmt.Type)
+ }
+
+ if stmt, ok := node.(*ast.BlockStmt); ok {
+ wantNewline := v.wantNewline[stmt]
+
+ comments := v.comments
+ if wantNewline {
+ comments = nil // Comments also count as a newline if we want a newline
+ }
+ first, last := firstAndLast(comments, v.fset, stmt.Pos(), stmt.End(), stmt.List)
+
+ startMsg := checkStart(v.fset, stmt.Lbrace, first)
+
+ if wantNewline && startMsg == nil {
+ v.messages = append(v.messages, Message{v.fset.Position(stmt.Pos()), MessageTypeAddAfter, `multi-line statement should be followed by a newline`})
+ } else if !wantNewline && startMsg != nil {
+ v.messages = append(v.messages, *startMsg)
+ }
+
+ if msg := checkEnd(v.fset, stmt.Rbrace, last); msg != nil {
+ v.messages = append(v.messages, *msg)
+ }
+ }
+
+ return v
+}
+
+func checkMultiLine(v *visitor, body *ast.BlockStmt, stmtStart ast.Node) {
+ start, end := posLine(v.fset, stmtStart.Pos()), posLine(v.fset, stmtStart.End())
+
+ if end > start { // Check only multi line conditions
+ v.wantNewline[body] = true
+ }
+}
+
+func posLine(fset *token.FileSet, pos token.Pos) int {
+ return fset.Position(pos).Line
+}
+
+func firstAndLast(comments []*ast.CommentGroup, fset *token.FileSet, start, end token.Pos, stmts []ast.Stmt) (ast.Node, ast.Node) {
+ if len(stmts) == 0 {
+ return nil, nil
+ }
+
+ first, last := ast.Node(stmts[0]), ast.Node(stmts[len(stmts)-1])
+
+ for _, c := range comments {
+ if posLine(fset, c.Pos()) == posLine(fset, start) || posLine(fset, c.End()) == posLine(fset, end) {
+ continue
+ }
+
+ if c.Pos() < start || c.End() > end {
+ continue
+ }
+ if c.Pos() < first.Pos() {
+ first = c
+ }
+ if c.End() > last.End() {
+ last = c
+ }
+ }
+
+ return first, last
+}
+
+func checkStart(fset *token.FileSet, start token.Pos, first ast.Node) *Message {
+ if first == nil {
+ return nil
+ }
+
+ if posLine(fset, start)+1 < posLine(fset, first.Pos()) {
+ pos := fset.Position(start)
+ return &Message{pos, MessageTypeLeading, `unnecessary leading newline`}
+ }
+
+ return nil
+}
+
+func checkEnd(fset *token.FileSet, end token.Pos, last ast.Node) *Message {
+ if last == nil {
+ return nil
+ }
+
+ if posLine(fset, end)-1 > posLine(fset, last.End()) {
+ pos := fset.Position(end)
+ return &Message{pos, MessageTypeTrailing, `unnecessary trailing newline`}
+ }
+
+ return nil
+}