Skip to content
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

Disallow space indents. http://dev.kohanaframework.org/issues/4775 #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Kohana_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Thomas Ernest <[email protected]>
* @copyright 2011 Thomas ERNEST
* @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
*/

/**
* Kohana_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
*
* Ensures the use of tabs for indentation.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Thomas Ernest <[email protected]>
* @copyright 2011 Thomas ERNEST
* @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
{

/**
* 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

?>