aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/bombsimon
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/bombsimon
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/bombsimon')
-rw-r--r--vendor/github.com/bombsimon/wsl/v3/README.md1
-rw-r--r--vendor/github.com/bombsimon/wsl/v3/wsl.go135
2 files changed, 125 insertions, 11 deletions
diff --git a/vendor/github.com/bombsimon/wsl/v3/README.md b/vendor/github.com/bombsimon/wsl/v3/README.md
index c5068a8ac..9812f94a7 100644
--- a/vendor/github.com/bombsimon/wsl/v3/README.md
+++ b/vendor/github.com/bombsimon/wsl/v3/README.md
@@ -121,5 +121,6 @@ feel free to raise an [issue](https://github.com/bombsimon/wsl/issues/new).
* [Only one cuddle assignment allowed before type switch statement](doc/rules.md#only-one-cuddle-assignment-allowed-before-type-switch-statement)
* [Ranges should only be cuddled with assignments used in the iteration](doc/rules.md#ranges-should-only-be-cuddled-with-assignments-used-in-the-iteration)
* [Return statements should not be cuddled if block has more than two lines](doc/rules.md#return-statements-should-not-be-cuddled-if-block-has-more-than-two-lines)
+* [Short declarations should cuddle only with other short declarations](doc/rules.md#short-declaration-should-cuddle-only-with-other-short-declarations)
* [Switch statements should only be cuddled with variables switched](doc/rules.md#switch-statements-should-only-be-cuddled-with-variables-switched)
* [Type switch statements should only be cuddled with variables switched](doc/rules.md#type-switch-statements-should-only-be-cuddled-with-variables-switched)
diff --git a/vendor/github.com/bombsimon/wsl/v3/wsl.go b/vendor/github.com/bombsimon/wsl/v3/wsl.go
index 31520fb43..313b52787 100644
--- a/vendor/github.com/bombsimon/wsl/v3/wsl.go
+++ b/vendor/github.com/bombsimon/wsl/v3/wsl.go
@@ -41,6 +41,7 @@ const (
reasonBlockStartsWithWS = "block should not start with a whitespace"
reasonBlockEndsWithWS = "block should not end with a whitespace (or comment)"
reasonCaseBlockTooCuddly = "case block should end with newline at this size"
+ reasonShortDeclNotExclusive = "short declaration should cuddle only with other short declarations"
)
// Warning strings
@@ -81,6 +82,16 @@ type Configuration struct {
// x = AnotherAssign()
AllowAssignAndCallCuddle bool
+ // AllowAssignAndCallCuddle allows assignments to be cuddled with anything.
+ // Example supported with this set to true:
+ // if x == 1 {
+ // x = 0
+ // }
+ // z := x + 2
+ // fmt.Println("x")
+ // y := "x"
+ AllowAssignAndAnythingCuddle bool
+
// AllowMultiLineAssignCuddle allows cuddling to assignments even if they
// span over multiple lines. This defaults to true which allows the
// following example:
@@ -149,6 +160,20 @@ type Configuration struct {
// used for error variables to check for in the conditional.
// Defaults to just "err"
ErrorVariableNames []string
+
+ // ForceExclusiveShortDeclarations will cause an error if a short declaration
+ // (:=) cuddles with anything other than another short declaration. For example
+ //
+ // a := 2
+ // b := 3
+ //
+ // is allowed, but
+ //
+ // a := 2
+ // b = 3
+ //
+ // is not allowed. This logic overrides ForceCuddleErrCheckAndAssign among others.
+ ForceExclusiveShortDeclarations bool
}
// DefaultConfig returns default configuration
@@ -156,10 +181,12 @@ func DefaultConfig() Configuration {
return Configuration{
StrictAppend: true,
AllowAssignAndCallCuddle: true,
+ AllowAssignAndAnythingCuddle: false,
AllowMultiLineAssignCuddle: true,
AllowTrailingComment: false,
AllowSeparatedLeadingComment: false,
ForceCuddleErrCheckAndAssign: false,
+ ForceExclusiveShortDeclarations: false,
ForceCaseTrailingWhitespaceLimit: 0,
AllowCuddleWithCalls: []string{"Lock", "RLock"},
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
@@ -284,6 +311,7 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
}
previousStatement := statements[i-1]
+ previousStatementIsMultiline := p.nodeStart(previousStatement) != p.nodeEnd(previousStatement)
cuddledWithLastStmt := p.nodeEnd(previousStatement) == p.nodeStart(stmt)-1
// If we're not cuddled and we don't need to enforce err-check cuddling
@@ -292,6 +320,11 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
continue
}
+ // We don't force error cuddling for multilines. (#86)
+ if p.config.ForceCuddleErrCheckAndAssign && previousStatementIsMultiline && !cuddledWithLastStmt {
+ continue
+ }
+
// Extract assigned variables on the line above
// which is the only thing we allow cuddling with. If the assignment is
// made over multiple lines we should not allow cuddling.
@@ -321,10 +354,10 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
// We could potentially have a block which require us to check the first
// argument before ruling out an allowed cuddle.
- var assignedFirstInBlock []string
+ var calledOrAssignedFirstInBlock []string
if firstBodyStatement != nil {
- assignedFirstInBlock = p.findLHS(firstBodyStatement)
+ calledOrAssignedFirstInBlock = append(p.findLHS(firstBodyStatement), p.findRHS(firstBodyStatement)...)
}
var (
@@ -374,6 +407,18 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
return false
}
+ // If it's a short declaration we should not cuddle with anything else
+ // if ForceExclusiveShortDeclarations is set on; either this or the
+ // previous statement could be the short decl, so we'll find out which
+ // it was and use *that* statement's position
+ if p.config.ForceExclusiveShortDeclarations && cuddledWithLastStmt {
+ if p.isShortDecl(stmt) && !p.isShortDecl(previousStatement) {
+ p.addError(stmt.Pos(), reasonShortDeclNotExclusive)
+ } else if p.isShortDecl(previousStatement) && !p.isShortDecl(stmt) {
+ p.addError(previousStatement.Pos(), reasonShortDeclNotExclusive)
+ }
+ }
+
// If it's not an if statement and we're not cuddled move on. The only
// reason we need to keep going for if statements is to check if we
// should be cuddled with an error check.
@@ -436,7 +481,7 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
continue
}
- if atLeastOneInListsMatch(assignedOnLineAbove, assignedFirstInBlock) {
+ if atLeastOneInListsMatch(assignedOnLineAbove, calledOrAssignedFirstInBlock) {
continue
}
@@ -470,6 +515,14 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
continue
}
+ if p.config.AllowAssignAndAnythingCuddle {
+ continue
+ }
+
+ if _, ok := previousStatement.(*ast.DeclStmt); ok && p.config.AllowCuddleDeclaration {
+ continue
+ }
+
// If the assignment is from a type or variable called on the line
// above we can allow it by setting AllowAssignAndCallCuddle to
// true.
@@ -490,6 +543,10 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
case *ast.ExprStmt:
switch previousStatement.(type) {
case *ast.DeclStmt, *ast.ReturnStmt:
+ if p.config.AllowAssignAndCallCuddle && p.config.AllowCuddleDeclaration {
+ continue
+ }
+
p.addError(t.Pos(), reasonExpressionCuddledWithDeclOrRet)
case *ast.IfStmt, *ast.RangeStmt, *ast.SwitchStmt:
p.addError(t.Pos(), reasonExpressionCuddledWithBlock)
@@ -519,7 +576,7 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
}
if !atLeastOneInListsMatch(rightAndLeftHandSide, assignedOnLineAbove) {
- if !atLeastOneInListsMatch(assignedOnLineAbove, assignedFirstInBlock) {
+ if !atLeastOneInListsMatch(assignedOnLineAbove, calledOrAssignedFirstInBlock) {
p.addError(t.Pos(), reasonRangeCuddledWithoutUse)
}
}
@@ -562,6 +619,24 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
continue
}
+ // Allow use to cuddled defer func literals with usages on line
+ // abouve. Example:
+ // b := getB()
+ // defer func() {
+ // makesSenseToUse(b)
+ // }()
+ if c, ok := t.Call.Fun.(*ast.FuncLit); ok {
+ funcLitFirstStmt := append(p.findLHS(c.Body), p.findRHS(c.Body)...)
+
+ if atLeastOneInListsMatch(assignedOnLineAbove, funcLitFirstStmt) {
+ continue
+ }
+ }
+
+ if atLeastOneInListsMatch(assignedOnLineAbove, calledOrAssignedFirstInBlock) {
+ continue
+ }
+
if !atLeastOneInListsMatch(rightAndLeftHandSide, assignedOnLineAbove) {
p.addError(t.Pos(), reasonDeferCuddledWithOtherVar)
}
@@ -582,7 +657,7 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
// comments regarding variable usages on the line before or as the
// first line in the block for details.
if !atLeastOneInListsMatch(rightAndLeftHandSide, assignedOnLineAbove) {
- if !atLeastOneInListsMatch(assignedOnLineAbove, assignedFirstInBlock) {
+ if !atLeastOneInListsMatch(assignedOnLineAbove, calledOrAssignedFirstInBlock) {
p.addError(t.Pos(), reasonForCuddledAssignWithoutUse)
}
}
@@ -625,7 +700,7 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
if !atLeastOneInListsMatch(rightHandSide, assignedOnLineAbove) {
// Allow type assertion on variables used in the first case
// immediately.
- if !atLeastOneInListsMatch(assignedOnLineAbove, assignedFirstInBlock) {
+ if !atLeastOneInListsMatch(assignedOnLineAbove, calledOrAssignedFirstInBlock) {
p.addError(t.Pos(), reasonTypeSwitchCuddledWithoutUse)
}
}
@@ -841,6 +916,14 @@ func (p *Processor) findRHS(node ast.Node) []string {
return rhs
}
+func (p *Processor) isShortDecl(node ast.Node) bool {
+ if t, ok := node.(*ast.AssignStmt); ok {
+ return t.Tok == token.DEFINE
+ }
+
+ return false
+}
+
func (p *Processor) findBlockStmt(node ast.Node) []*ast.BlockStmt {
var blocks []*ast.BlockStmt
@@ -987,8 +1070,17 @@ func (p *Processor) findLeadingAndTrailingWhitespaces(ident *ast.Ident, stmt, ne
}
// We store number of seen comment groups because we allow multiple
- // groups with a newline between them.
- seenCommentGroups++
+ // groups with a newline between them; but if the first one has WS
+ // before it, we're not going to count it to force an error.
+ if p.config.AllowSeparatedLeadingComment {
+ cg := p.fileSet.Position(commentGroup.Pos()).Line
+
+ if seenCommentGroups > 0 || cg == blockStartLine+1 {
+ seenCommentGroups++
+ }
+ } else {
+ seenCommentGroups++
+ }
// Support both /* multiline */ and //single line comments
for _, c := range commentGroup.List {
@@ -997,14 +1089,18 @@ func (p *Processor) findLeadingAndTrailingWhitespaces(ident *ast.Ident, stmt, ne
}
}
- // If we have multiple groups, add support for newline between each group.
+ // If we allow separated comments, allow for a space after each group
if p.config.AllowSeparatedLeadingComment {
if seenCommentGroups > 1 {
allowedLinesBeforeFirstStatement += seenCommentGroups - 1
+ } else if seenCommentGroups == 1 {
+ allowedLinesBeforeFirstStatement += 1
}
}
- if p.nodeStart(firstStatement) != blockStartLine+allowedLinesBeforeFirstStatement {
+ // And now if the first statement is passed the number of allowed lines,
+ // then we had extra WS, possibly before the first comment group.
+ if p.nodeStart(firstStatement) > blockStartLine+allowedLinesBeforeFirstStatement {
p.addError(
blockStartPos,
reasonBlockStartsWithWS,
@@ -1109,7 +1205,24 @@ func (p *Processor) nodeStart(node ast.Node) int {
}
func (p *Processor) nodeEnd(node ast.Node) int {
- return p.fileSet.Position(node.End()).Line
+ var line = p.fileSet.Position(node.End()).Line
+
+ if isEmptyLabeledStmt(node) {
+ return p.fileSet.Position(node.Pos()).Line
+ }
+
+ return line
+}
+
+func isEmptyLabeledStmt(node ast.Node) bool {
+ v, ok := node.(*ast.LabeledStmt)
+ if !ok {
+ return false
+ }
+
+ _, empty := v.Stmt.(*ast.EmptyStmt)
+
+ return empty
}
// Add an error for the file and line number for the current token.Pos with the