Umherirrender has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/402605 )

Change subject: Fix SpaceyParenthesisSniff comment detection for ignore 
statements
......................................................................

Fix SpaceyParenthesisSniff comment detection for ignore statements

When changed all the @codingStandardsIgnore in
I92ef235849bcc349c69e53504e664a155dd162c8 I have to move some of them in
tests provider to different line due to this bug. I assumed it in
upstream and therefore not looking in it deeper.
But I found it a problem in our own sniff, so fixing it.

Change-Id: Ia99b628001de7c522db27ca1da706806157fad45
---
M MediaWiki/Sniffs/WhiteSpace/SpaceyParenthesisSniff.php
M MediaWiki/Tests/files/WhiteSpace/spacey_parenthesis.php
M MediaWiki/Tests/files/WhiteSpace/spacey_parenthesis.php.fixed
3 files changed, 49 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/codesniffer 
refs/changes/05/402605/1

diff --git a/MediaWiki/Sniffs/WhiteSpace/SpaceyParenthesisSniff.php 
b/MediaWiki/Sniffs/WhiteSpace/SpaceyParenthesisSniff.php
index ce1a704..9e84d58 100644
--- a/MediaWiki/Sniffs/WhiteSpace/SpaceyParenthesisSniff.php
+++ b/MediaWiki/Sniffs/WhiteSpace/SpaceyParenthesisSniff.php
@@ -56,6 +56,19 @@
        }
 
        /**
+        * @param int $token PHPCS token code.
+        * @return boolean Whether the token code is a comment.
+        */
+       private function isComment( $token ) {
+               return $token === T_COMMENT
+                       || $token === T_PHPCS_ENABLE
+                       || $token === T_PHPCS_DISABLE
+                       || $token === T_PHPCS_SET
+                       || $token === T_PHPCS_IGNORE
+                       || $token === T_PHPCS_IGNORE_FILE;
+       }
+
+       /**
         * @param File $phpcsFile File object.
         * @param int $stackPtr The current token index.
         * @return void
@@ -163,7 +176,7 @@
                if ( $this->isOpen( $previousToken['code'] )
                        || ( $previousToken['code'] === T_WHITESPACE
                                && $previousToken['content'] === ' ' )
-                       || ( $previousToken['code'] === T_COMMENT
+                       || ( $this->isComment( $previousToken['code'] )
                                && substr( $previousToken['content'], -1, 1 ) 
=== "\n" ) ) {
                        // If previous token was
                        // '(' or ' ' or a comment ending with a newline
@@ -180,7 +193,7 @@
                }
 
                // If the comment before all the whitespaces immediately 
preceding the ')' ends with a newline
-               if ( $tokens[$ptr]['code'] === T_COMMENT
+               if ( $this->isComment( $tokens[$ptr]['code'] )
                        && substr( $tokens[$ptr]['content'], -1, 1 ) === "\n" ) 
{
                        return;
                }
diff --git a/MediaWiki/Tests/files/WhiteSpace/spacey_parenthesis.php 
b/MediaWiki/Tests/files/WhiteSpace/spacey_parenthesis.php
index 0ebe73c..d5ba3c3 100644
--- a/MediaWiki/Tests/files/WhiteSpace/spacey_parenthesis.php
+++ b/MediaWiki/Tests/files/WhiteSpace/spacey_parenthesis.php
@@ -30,4 +30,21 @@
                // 'foo' => 'baz',
        ];
        (int)$arg->bar();
+
+       $fooArray = [
+               // phpcs:disable Generic.Files.LineLength
+               [
+                       'Some',
+                       'Parameter',
+                       'For',
+                       'Testprovider',
+               ],
+               [
+                       'Some very',
+                       
'lllllllllllllllllllllllloooooooooooooooooooooooooooonnnnnnnnnnnnnnggggggggggggg
 Parameter',
+                       'For',
+                       'Testprovider',
+               ],
+               // phpcs:enable
+       ];
 }
diff --git a/MediaWiki/Tests/files/WhiteSpace/spacey_parenthesis.php.fixed 
b/MediaWiki/Tests/files/WhiteSpace/spacey_parenthesis.php.fixed
index 84fd45b..8272978 100644
--- a/MediaWiki/Tests/files/WhiteSpace/spacey_parenthesis.php.fixed
+++ b/MediaWiki/Tests/files/WhiteSpace/spacey_parenthesis.php.fixed
@@ -30,4 +30,21 @@
                // 'foo' => 'baz',
        ];
        (int)$arg->bar();
+
+       $fooArray = [
+               // phpcs:disable Generic.Files.LineLength
+               [
+                       'Some',
+                       'Parameter',
+                       'For',
+                       'Testprovider',
+               ],
+               [
+                       'Some very',
+                       
'lllllllllllllllllllllllloooooooooooooooooooooooooooonnnnnnnnnnnnnnggggggggggggg
 Parameter',
+                       'For',
+                       'Testprovider',
+               ],
+               // phpcs:enable
+       ];
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/402605
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia99b628001de7c522db27ca1da706806157fad45
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/codesniffer
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <umherirrender_de...@web.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to