Skip to content

Commit 1c11ca7

Browse files
authored
Merge pull request #1273 from WordPress-Coding-Standards/feature/bug-fix-precision-alignment
PrecisionAlignment: fix various bugs
2 parents b605c77 + 933b973 commit 1c11ca7

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class PrecisionAlignmentSniff extends Sniff {
7474
public function register() {
7575
return array(
7676
T_OPEN_TAG,
77+
T_OPEN_TAG_WITH_ECHO,
7778
);
7879
}
7980

@@ -99,18 +100,17 @@ public function process_token( $stackPtr ) {
99100
T_COMMENT => true,
100101
);
101102

102-
for ( $i = ( $stackPtr + 1 ); $i < $this->phpcsFile->numTokens; $i++ ) {
103-
if ( ! isset( $this->tokens[ ( $i + 1 ) ] ) ) {
104-
break;
105-
}
103+
for ( $i = 0; $i < $this->phpcsFile->numTokens; $i++ ) {
106104

107105
if ( 1 !== $this->tokens[ $i ]['column'] ) {
108106
continue;
109107
} elseif ( isset( $check_tokens[ $this->tokens[ $i ]['code'] ] ) === false
110-
|| T_WHITESPACE === $this->tokens[ ( $i + 1 ) ]['code']
108+
|| ( isset( $this->tokens[ ( $i + 1 ) ] )
109+
&& T_WHITESPACE === $this->tokens[ ( $i + 1 ) ]['code'] )
111110
|| $this->tokens[ $i ]['content'] === $this->phpcsFile->eolChar
112111
|| isset( $this->ignoreAlignmentTokens[ $this->tokens[ $i ]['type'] ] )
113-
|| isset( $this->ignoreAlignmentTokens[ $this->tokens[ ( $i + 1 ) ]['type'] ] )
112+
|| ( isset( $this->tokens[ ( $i + 1 ) ] )
113+
&& isset( $this->ignoreAlignmentTokens[ $this->tokens[ ( $i + 1 ) ]['type'] ] ) )
114114
) {
115115
continue;
116116
}
@@ -125,8 +125,9 @@ public function process_token( $stackPtr ) {
125125
$length = $this->tokens[ $i ]['length'];
126126
$spaces = ( $length % $this->tab_width );
127127

128-
if ( ( T_DOC_COMMENT_STAR === $this->tokens[ ( $i + 1 ) ]['code']
129-
|| T_DOC_COMMENT_CLOSE_TAG === $this->tokens[ ( $i + 1 ) ]['code'] )
128+
if ( isset( $this->tokens[ ( $i + 1 ) ] )
129+
&& ( T_DOC_COMMENT_STAR === $this->tokens[ ( $i + 1 ) ]['code']
130+
|| T_DOC_COMMENT_CLOSE_TAG === $this->tokens[ ( $i + 1 ) ]['code'] )
130131
&& 0 !== $spaces
131132
) {
132133
// One alignment space expected before the *.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div><!-- Bad.-->
2+
<p><a href="http://url/"><!-- Bad.-->
3+
<?= 'print this string' ?><!-- Bad.-->
4+
</a/></p><!-- Bad.-->
5+
</div><!-- Bad.-->

WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public function getWarningList( $testFile = '' ) {
8282
39 => 1,
8383
);
8484

85+
case 'PrecisionAlignmentUnitTest.4.inc':
86+
return array(
87+
1 => 1, // Will show a `Internal.NoCodeFound` warning in PHP 5.3 with short open tags off.
88+
2 => ( PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1,
89+
3 => ( PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1,
90+
4 => ( PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1,
91+
5 => ( PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1,
92+
);
93+
8594
case 'PrecisionAlignmentUnitTest.css':
8695
return array(
8796
4 => 1,

0 commit comments

Comments
 (0)