From d573872c00d81a2e3f65493ae2c1985979d68927 Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Wed, 14 Aug 2013 07:40:48 +0800 Subject: [PATCH 1/2] Disallow space indents. http://dev.kohanaframework.org/issues/4775 --- .../WhiteSpace/DisallowSpaceIndentSniff.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 PHP/CodeSniffer/Standards/Kohana/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php diff --git a/PHP/CodeSniffer/Standards/Kohana/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php b/PHP/CodeSniffer/Standards/Kohana/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php new file mode 100755 index 0000000..6a9a860 --- /dev/null +++ b/PHP/CodeSniffer/Standards/Kohana/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php @@ -0,0 +1,83 @@ + + * @copyright 2011 Thomas ERNEST + * @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License + * @link http://pear.php.net/package/PHP_CodeSniffer + * @link https://github.com/thomas-ernest/CodeIgniter-for-PHP_CodeSniffer/blob/master/src/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php + */ + +/** + * CodeIgniter_Sniffs_WhiteSpace_DisallowSpaceIndentSniff. + * + * Ensures the use of tabs for indentation. + * + * @category PHP + * @package PHP_CodeSniffer + * @author Thomas Ernest + * @copyright 2011 Thomas ERNEST + * @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License + * @link http://pear.php.net/package/PHP_CodeSniffer + */ +class Kohana_Sniffs_WhiteSpace_DisallowSpaceIndentSniff implements PHP_CodeSniffer_Sniff +{ + + /** + * A list of tokenizers this sniff supports. + * + * @var array + */ + public $supportedTokenizers = array( + 'PHP', + 'JS', + 'CSS', + ); + + + /** + * Returns an array of tokens this test wants to listen for. + * + * @return array + */ + public function register() + { + return array(T_WHITESPACE); + }//end register() + + + /** + * Processes this test, when one of its tokens is encountered. + * + * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + * + * @return void + */ + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + + // Make sure this is whitespace used for indentation. + $line = $tokens[$stackPtr]['line']; + if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line) { + return; + } + + if (strpos($tokens[$stackPtr]['content'], " ") !== false) { + $error = 'Tabs must be used to indent lines; ' + .'spaces are not allowed for code intendetion'; + $phpcsFile->addError($error, $stackPtr); + } + }//end process() + + +}//end class + +?> From 50cbe2a4e2bac3d394d463944cebd3e6d247ff6f Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Wed, 14 Aug 2013 07:46:41 +0800 Subject: [PATCH 2/2] Documentation updated. --- .../Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/PHP/CodeSniffer/Standards/Kohana/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php b/PHP/CodeSniffer/Standards/Kohana/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php index 6a9a860..ca65dd2 100755 --- a/PHP/CodeSniffer/Standards/Kohana/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php +++ b/PHP/CodeSniffer/Standards/Kohana/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php @@ -1,6 +1,6 @@ * @copyright 2011 Thomas ERNEST - * @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License + * @license https://gnu.org/licenses/gpl.html GNU General Public License * @link http://pear.php.net/package/PHP_CodeSniffer * @link https://github.com/thomas-ernest/CodeIgniter-for-PHP_CodeSniffer/blob/master/src/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php */ /** - * CodeIgniter_Sniffs_WhiteSpace_DisallowSpaceIndentSniff. + * Kohana_Sniffs_WhiteSpace_DisallowSpaceIndentSniff. * * Ensures the use of tabs for indentation. * @@ -22,8 +22,9 @@ * @package PHP_CodeSniffer * @author Thomas Ernest * @copyright 2011 Thomas ERNEST - * @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License + * @license https://gnu.org/licenses/gpl.html GNU General Public License * @link http://pear.php.net/package/PHP_CodeSniffer + * @link http://kohanaframework.org/3.3/guide/kohana/conventions#indentation */ class Kohana_Sniffs_WhiteSpace_DisallowSpaceIndentSniff implements PHP_CodeSniffer_Sniff {