Skip to content

Commit 6cd9b30

Browse files
committed
2 parents 9ccd5a7 + 8e5dab8 commit 6cd9b30

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,15 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
8888
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data);
8989
if ($fix === true) {
9090
$phpcsFile->fixer->beginChangeset();
91-
for ($i = ($stackPtr - 1); $i > $nonSpace; $i--) {
91+
$i = ($stackPtr - 1);
92+
while (($tokens[$i]['code'] === T_WHITESPACE) && ($i > $nonSpace)) {
9293
$phpcsFile->fixer->replaceToken($i, '');
94+
$i--;
9395
}
9496

97+
$phpcsFile->fixer->addContent($nonSpace, ';');
98+
$phpcsFile->fixer->replaceToken($stackPtr, '');
99+
95100
$phpcsFile->fixer->endChangeset();
96101
}
97102

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ $test = $this->testThis() /* comment here */;
99
$test = $this->testThis() /* comment here */ ;
1010

1111
$hello ='foo';
12+
;
13+
14+
$sum = $a /* + $b */;
15+
$sum = $a // + $b
1216
;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
$test = $this->testThis();
3+
$test = $this->testThis();
4+
$test = $this->testThis();
5+
for ($var = 1; $var < 10; $var++) {
6+
echo $var;
7+
}
8+
$test = $this->testThis(); /* comment here */
9+
$test = $this->testThis(); /* comment here */
10+
11+
$hello ='foo';
12+
;
13+
14+
$sum = $a; /* + $b */
15+
$sum = $a; // + $b

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/SemicolonSpacingUnitTest.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ for (i=0 ; i<3 ; i++) {
1414
}
1515
}
1616
alert('hi');
17+
;
18+
19+
var sum = a /* + b */;
20+
21+
var sum = a // +b
1722
;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var x = {
2+
a: function () {
3+
alert('thats right');
4+
x = (x?a:x);
5+
},
6+
};
7+
8+
id = id.replace(/row\/:;/gi, '');
9+
10+
for (i=0; i<3; i++) {
11+
for (j=0; j<5; j++) {
12+
if (j==x)
13+
break;
14+
}
15+
}
16+
alert('hi');
17+
;
18+
19+
var sum = a; /* + b */
20+
21+
var sum = a; // +b

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/SemicolonSpacingUnitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function getErrorList($testFile='SemicolonSpacingUnitTest.inc')
5353
6 => 1,
5454
8 => 1,
5555
9 => 1,
56+
14 => 1,
57+
16 => 1,
5658
);
5759
break;
5860
case 'SemicolonSpacingUnitTest.js':
@@ -63,6 +65,8 @@ public function getErrorList($testFile='SemicolonSpacingUnitTest.inc')
6365
10 => 2,
6466
11 => 1,
6567
13 => 1,
68+
19 => 1,
69+
22 => 1,
6670
);
6771
break;
6872
default:

0 commit comments

Comments
 (0)