From 9ce051acb80b7c3b3339896dfcb90159f1e697c9 Mon Sep 17 00:00:00 2001 From: Simon Sawert Date: Mon, 14 Oct 2019 18:11:57 +0200 Subject: [PATCH] Update WSL to v1.2.5 * Support output comments for example functions --- go.mod | 2 +- go.sum | 4 ++-- test/testdata/wsl.go | 8 ++++++++ vendor/github.com/bombsimon/wsl/wsl.go | 21 +++++++++++++-------- vendor/modules.txt | 2 +- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 89fae2ec7df3..263d2c880699 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.12 require ( github.com/OpenPeeDeeP/depguard v1.0.1 - github.com/bombsimon/wsl v1.2.4 + github.com/bombsimon/wsl v1.2.5 github.com/fatih/color v1.7.0 github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db github.com/go-lintpack/lintpack v0.5.2 diff --git a/go.sum b/go.sum index ecca979c91e3..01daee958033 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/bombsimon/wsl v1.2.4 h1:QfZdYcCzHob9ZlHdC2rD+iZnhRVtncMebOifHhA3Wec= -github.com/bombsimon/wsl v1.2.4/go.mod h1:43lEF/i0kpXbLCeDXL9LMT8c92HyBywXb0AsgMHYngM= +github.com/bombsimon/wsl v1.2.5 h1:9gTOkIwVtoDZywvX802SDHokeX4kW1cKnV8ZTVAPkRs= +github.com/bombsimon/wsl v1.2.5/go.mod h1:43lEF/i0kpXbLCeDXL9LMT8c92HyBywXb0AsgMHYngM= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= diff --git a/test/testdata/wsl.go b/test/testdata/wsl.go index 729c5f220782..81fc71c8c38f 100644 --- a/test/testdata/wsl.go +++ b/test/testdata/wsl.go @@ -164,3 +164,11 @@ func allowTrailing(i int) { fmt.Println("three") } } + +// ExampleSomeOutput simulates an example function. +func ExampleSomeOutput() { + fmt.Println("Hello, world") + + // Output: + // Hello, world +} diff --git a/vendor/github.com/bombsimon/wsl/wsl.go b/vendor/github.com/bombsimon/wsl/wsl.go index 9bc0fe268427..fe62b62c602f 100644 --- a/vendor/github.com/bombsimon/wsl/wsl.go +++ b/vendor/github.com/bombsimon/wsl/wsl.go @@ -7,6 +7,7 @@ import ( "go/token" "io/ioutil" "reflect" + "strings" ) type Configuration struct { @@ -172,7 +173,7 @@ func (p *Processor) process(filename string, data []byte) { for _, d := range p.file.Decls { switch v := d.(type) { case *ast.FuncDecl: - p.parseBlockBody(v.Body) + p.parseBlockBody(v.Name, v.Body) case *ast.GenDecl: // `go fmt` will handle proper spacing for GenDecl such as imports, // constants etc. @@ -184,14 +185,14 @@ func (p *Processor) process(filename string, data []byte) { // parseBlockBody will parse any kind of block statements such as switch cases // and if statements. A list of Result is returned. -func (p *Processor) parseBlockBody(block *ast.BlockStmt) { +func (p *Processor) parseBlockBody(ident *ast.Ident, block *ast.BlockStmt) { // Nothing to do if there's no value. if reflect.ValueOf(block).IsNil() { return } // Start by finding leading and trailing whitespaces. - p.findLeadingAndTrailingWhitespaces(block, nil) + p.findLeadingAndTrailingWhitespaces(ident, block, nil) // Parse the block body contents. p.parseBlockStatements(block.List) @@ -207,7 +208,7 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) { if as, isAssignStmt := stmt.(*ast.AssignStmt); isAssignStmt { for _, rhs := range as.Rhs { if fl, isFuncLit := rhs.(*ast.FuncLit); isFuncLit { - p.parseBlockBody(fl.Body) + p.parseBlockBody(nil, fl.Body) } } } @@ -556,7 +557,7 @@ func (p *Processor) firstBodyStatement(i int, allStmt []ast.Stmt) ast.Node { } } - p.parseBlockBody(statementBodyContent) + p.parseBlockBody(nil, statementBodyContent) case []ast.Stmt: // The Body field for an *ast.CaseClause or *ast.CommClause is of type // []ast.Stmt. We must check leading and trailing whitespaces and then @@ -569,7 +570,7 @@ func (p *Processor) firstBodyStatement(i int, allStmt []ast.Stmt) ast.Node { nextStatement = allStmt[i+1] } - p.findLeadingAndTrailingWhitespaces(stmt, nextStatement) + p.findLeadingAndTrailingWhitespaces(nil, stmt, nextStatement) p.parseBlockStatements(statementBodyContent) default: p.addWarning( @@ -773,7 +774,7 @@ func atLeastOneInListsMatch(listOne, listTwo []string) bool { // in a node. The method takes comments in consideration which will make the // parser more gentle. // nolint: gocognit -func (p *Processor) findLeadingAndTrailingWhitespaces(stmt, nextStatement ast.Node) { +func (p *Processor) findLeadingAndTrailingWhitespaces(ident *ast.Ident, stmt, nextStatement ast.Node) { var ( allowedLinesBeforeFirstStatement = 1 commentMap = ast.NewCommentMap(p.fileSet, stmt, p.file.Comments) @@ -876,7 +877,7 @@ func (p *Processor) findLeadingAndTrailingWhitespaces(stmt, nextStatement ast.No blockEndLine = p.fileSet.Position(blockEndPos).Line } - if p.nodeEnd(lastStatement) != blockEndLine-1 { + if p.nodeEnd(lastStatement) != blockEndLine-1 && !isExampleFunc(ident) { p.addError( blockEndPos, "block should not end with a whitespace (or comment)", @@ -884,6 +885,10 @@ func (p *Processor) findLeadingAndTrailingWhitespaces(stmt, nextStatement ast.No } } +func isExampleFunc(ident *ast.Ident) bool { + return ident != nil && strings.HasPrefix(ident.Name, "Example") +} + func (p *Processor) nodeStart(node ast.Node) int { return p.fileSet.Position(node.Pos()).Line } diff --git a/vendor/modules.txt b/vendor/modules.txt index 4509e4e53a46..93b4abdc5cbc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -4,7 +4,7 @@ github.com/BurntSushi/toml github.com/OpenPeeDeeP/depguard # github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 github.com/StackExchange/wmi -# github.com/bombsimon/wsl v1.2.4 +# github.com/bombsimon/wsl v1.2.5 github.com/bombsimon/wsl # github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew/spew