File tree Expand file tree Collapse file tree 3 files changed +45
-1
lines changed
testdata/src/default_config Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -557,3 +557,19 @@ func OnlyCheckTwoLinesAboveIfAssignment() {
557
557
return result , err
558
558
}
559
559
}
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
+ }
Original file line number Diff line number Diff line change @@ -597,3 +597,22 @@ func OnlyCheckTwoLinesAboveIfAssignment() {
597
597
return result, err
598
598
}
599
599
}
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
+ }
Original file line number Diff line number Diff line change @@ -508,7 +508,8 @@ func (p *processor) parseBlockStatements(statements []ast.Stmt) {
508
508
continue
509
509
}
510
510
511
- if _ , ok := previousStatement .(* ast.AssignStmt ); ok {
511
+ switch previousStatement .(type ) {
512
+ case * ast.AssignStmt , * ast.IncDecStmt :
512
513
continue
513
514
}
514
515
@@ -533,6 +534,14 @@ func (p *processor) parseBlockStatements(statements []ast.Stmt) {
533
534
}
534
535
535
536
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
+
536
545
case * ast.DeclStmt :
537
546
if ! p .config .AllowCuddleDeclaration {
538
547
p .addWhitespaceBeforeError (t , reasonNeverCuddleDeclare )
You can’t perform that action at this time.
0 commit comments