Skip to content

Commit feb295d

Browse files
authored
Merge pull request #123 from bombsimon/plus-plus-minus-minus
Treat `IncDecStmt` as `AssignStmt`
2 parents 9f5e329 + ddb4332 commit feb295d

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

testdata/src/default_config/generic_handling.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,19 @@ func OnlyCheckTwoLinesAboveIfAssignment() {
557557
return result, err
558558
}
559559
}
560+
561+
func IncrementDecrement() {
562+
a := 1
563+
a++
564+
a--
565+
b := 2
566+
567+
if true {
568+
b--
569+
}
570+
b++ // want "assignments should only be cuddled with other assignments"
571+
572+
go func() {}()
573+
b++ // want "assignments should only be cuddled with other assignments"
574+
go func() {}() // want "only one cuddle assignment allowed before go statement"
575+
}

testdata/src/default_config/generic_handling.go.golden

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,22 @@ func OnlyCheckTwoLinesAboveIfAssignment() {
597597
return result, err
598598
}
599599
}
600+
601+
func IncrementDecrement() {
602+
a := 1
603+
a++
604+
a--
605+
b := 2
606+
607+
if true {
608+
b--
609+
}
610+
611+
b++ // want "assignments should only be cuddled with other assignments"
612+
613+
go func() {}()
614+
615+
b++ // want "assignments should only be cuddled with other assignments"
616+
617+
go func() {}() // want "only one cuddle assignment allowed before go statement"
618+
}

wsl.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ func (p *processor) parseBlockStatements(statements []ast.Stmt) {
508508
continue
509509
}
510510

511-
if _, ok := previousStatement.(*ast.AssignStmt); ok {
511+
switch previousStatement.(type) {
512+
case *ast.AssignStmt, *ast.IncDecStmt:
512513
continue
513514
}
514515

@@ -533,6 +534,14 @@ func (p *processor) parseBlockStatements(statements []ast.Stmt) {
533534
}
534535

535536
p.addWhitespaceBeforeError(t, reasonAssignsCuddleAssign)
537+
case *ast.IncDecStmt:
538+
switch previousStatement.(type) {
539+
case *ast.AssignStmt, *ast.IncDecStmt:
540+
continue
541+
}
542+
543+
p.addWhitespaceBeforeError(t, reasonAssignsCuddleAssign)
544+
536545
case *ast.DeclStmt:
537546
if !p.config.AllowCuddleDeclaration {
538547
p.addWhitespaceBeforeError(t, reasonNeverCuddleDeclare)

0 commit comments

Comments
 (0)