Skip to content

PrecisionAlignment: fix various bugs #1273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class PrecisionAlignmentSniff extends Sniff {
public function register() {
return array(
T_OPEN_TAG,
T_OPEN_TAG_WITH_ECHO,
);
}

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

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

if ( 1 !== $this->tokens[ $i ]['column'] ) {
continue;
} elseif ( isset( $check_tokens[ $this->tokens[ $i ]['code'] ] ) === false
|| T_WHITESPACE === $this->tokens[ ( $i + 1 ) ]['code']
|| ( isset( $this->tokens[ ( $i + 1 ) ] )
&& T_WHITESPACE === $this->tokens[ ( $i + 1 ) ]['code'] )
|| $this->tokens[ $i ]['content'] === $this->phpcsFile->eolChar
|| isset( $this->ignoreAlignmentTokens[ $this->tokens[ $i ]['type'] ] )
|| isset( $this->ignoreAlignmentTokens[ $this->tokens[ ( $i + 1 ) ]['type'] ] )
|| ( isset( $this->tokens[ ( $i + 1 ) ] )
&& isset( $this->ignoreAlignmentTokens[ $this->tokens[ ( $i + 1 ) ]['type'] ] ) )
) {
continue;
}
Expand All @@ -125,8 +125,9 @@ public function process_token( $stackPtr ) {
$length = $this->tokens[ $i ]['length'];
$spaces = ( $length % $this->tab_width );

if ( ( T_DOC_COMMENT_STAR === $this->tokens[ ( $i + 1 ) ]['code']
|| T_DOC_COMMENT_CLOSE_TAG === $this->tokens[ ( $i + 1 ) ]['code'] )
if ( isset( $this->tokens[ ( $i + 1 ) ] )
&& ( T_DOC_COMMENT_STAR === $this->tokens[ ( $i + 1 ) ]['code']
|| T_DOC_COMMENT_CLOSE_TAG === $this->tokens[ ( $i + 1 ) ]['code'] )
&& 0 !== $spaces
) {
// One alignment space expected before the *.
Expand Down
5 changes: 5 additions & 0 deletions WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.4.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div><!-- Bad.-->
<p><a href="http://url/"><!-- Bad.-->
<?= 'print this string' ?><!-- Bad.-->
</a/></p><!-- Bad.-->
</div><!-- Bad.-->
9 changes: 9 additions & 0 deletions WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public function getWarningList( $testFile = '' ) {
39 => 1,
);

case 'PrecisionAlignmentUnitTest.4.inc':
return array(
1 => 1, // Will show a `Internal.NoCodeFound` warning in PHP 5.3 with short open tags off.
2 => ( PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1,
3 => ( PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1,
4 => ( PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1,
5 => ( PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1,
);

case 'PrecisionAlignmentUnitTest.css':
return array(
4 => 1,
Expand Down