EBernhardson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/163898

Change subject: The coding conventions for php state:
......................................................................

The coding conventions for php state:

    Control structures such as if, while, for, foreach, and switch,
    as well as the catch keyword, should be followed by a space:

This patch adds a sniffer to assert the space exists.  There is only
a single failure within mediawiki/core, which is repaired in
I4b2ad5961a09a9423a9f86432f9c1dbb7eff1c56 . As such this is safe to
go straight to strict mode in terms of voters.

Change-Id: I602cb6cfe910fc0a9bc371c512ddc591a6a13b26
---
A MediaWiki/Sniffs/WhiteSpace/SpaceAfterKeywordSniff.php
1 file changed, 27 insertions(+), 0 deletions(-)


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

diff --git a/MediaWiki/Sniffs/WhiteSpace/SpaceAfterKeywordSniff.php 
b/MediaWiki/Sniffs/WhiteSpace/SpaceAfterKeywordSniff.php
new file mode 100644
index 0000000..1d6165b
--- /dev/null
+++ b/MediaWiki/Sniffs/WhiteSpace/SpaceAfterKeywordSniff.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Verify specific control structures are followed by a single space.
+ */
+class MediaWiki_Sniffs_WhiteSpace_SpaceAfterKeywordSniff implements 
PHP_CodeSniffer_Sniff {
+       public function register() {
+               // Per 
https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#Spaces
+               return array(
+                               T_IF,
+                               T_WHILE,
+                               T_FOR,
+                               T_FOREACH,
+                               T_SWITCH
+               );
+       }
+
+       public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {
+               $tokens = $phpcsFile->getTokens();
+               $nextToken = $tokens[$stackPtr + 1];
+               if ( $nextToken['code'] !== T_WHITESPACE || 
$nextToken['content'] !== ' ' ) {
+                       $error = 'Control structure "%s" must be followed by a 
single space';
+                       $data = array( $tokens[$stackPtr]['content'] );
+                       $phpcsFile->addError( $error, $stackPtr, 'Incorrect', 
$data );
+               }
+       }
+}
+

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I602cb6cfe910fc0a9bc371c512ddc591a6a13b26
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/codesniffer
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to