Initial Commit
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff.
|
||||
*
|
||||
* Ensure there is a single blank line after the closing brace of a class definition.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_CLOSE_CURLY_BRACKET);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
|
||||
if ($next === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($tokens[$next]['code'] !== T_CLOSE_TAG) {
|
||||
$found = (($tokens[$next]['line'] - $tokens[$stackPtr]['line']) - 1);
|
||||
if ($found !== 1) {
|
||||
$error = 'Expected one blank line after closing brace of class definition; %s found';
|
||||
$data = array($found);
|
||||
$phpcsFile->addError($error, $stackPtr, 'SpacingAfterClose', $data);
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore nested style definitions from here on. The spacing before the closing brace
|
||||
// (a single blank line) will be enforced by the above check, which ensures there is a
|
||||
// blank line after the last nested class.
|
||||
$found = $phpcsFile->findPrevious(
|
||||
T_CLOSE_CURLY_BRACKET,
|
||||
($stackPtr - 1),
|
||||
$tokens[$stackPtr]['bracket_opener']
|
||||
);
|
||||
if ($found !== false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
|
||||
if ($prev !== false && $tokens[$prev]['line'] !== ($tokens[$stackPtr]['line'] - 1)) {
|
||||
$num = ($tokens[$stackPtr]['line'] - $tokens[$prev]['line'] - 1);
|
||||
$error = 'Expected 0 blank lines before closing brace of class definition; %s found';
|
||||
$data = array($num);
|
||||
$phpcsFile->addError($error, $stackPtr, 'SpacingBeforeClose', $data);
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_ClassDefinitionNameSpacingSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_ClassDefinitionNameSpacingSniff.
|
||||
*
|
||||
* Ensure there are no blank lines between the names of classes/IDs.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_ClassDefinitionNameSpacingSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_OPEN_CURLY_BRACKET);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Do not check nested style definitions as, for example, in @media style rules.
|
||||
$nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']);
|
||||
if ($nested !== false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the first blank line before this openning brace, unless we get
|
||||
// to another style definition, comment or the start of the file.
|
||||
$endTokens = array(
|
||||
T_OPEN_CURLY_BRACKET,
|
||||
T_CLOSE_CURLY_BRACKET,
|
||||
T_COMMENT,
|
||||
T_DOC_COMMENT,
|
||||
T_OPEN_TAG,
|
||||
);
|
||||
|
||||
$foundContent = false;
|
||||
$currentLine = $tokens[$stackPtr]['line'];
|
||||
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
|
||||
if (in_array($tokens[$i]['code'], $endTokens) === true) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($tokens[$i]['line'] === $currentLine) {
|
||||
if ($tokens[$i]['code'] !== T_WHITESPACE) {
|
||||
$foundContent = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// We changed lines.
|
||||
if ($foundContent === false) {
|
||||
// Before we throw an error, make sure we are not looking
|
||||
// at a gap before the style definition.
|
||||
$prev = $phpcsFile->findPrevious(T_WHITESPACE, $i, null, true);
|
||||
if ($prev !== false
|
||||
&& in_array($tokens[$prev]['code'], $endTokens) === false
|
||||
) {
|
||||
$error = 'Blank lines are not allowed between class names';
|
||||
$phpcsFile->addError($error, ($i + 1), 'BlankLinesFound');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$foundContent = false;
|
||||
$currentLine = $tokens[$i]['line'];
|
||||
}//end for
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_ClassDefinitionOpeningBraceSpaceSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_ClassDefinitionOpeningBraceSpaceSniff.
|
||||
*
|
||||
* Ensure there is a single space before the opening brace in a class definition
|
||||
* and the content starts on the next line.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_ClassDefinitionOpeningBraceSpaceSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_OPEN_CURLY_BRACKET);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) {
|
||||
$error = 'Expected 1 space before opening brace of class definition; 0 found';
|
||||
$phpcsFile->addError($error, $stackPtr, 'NoneBefore');
|
||||
} else {
|
||||
$content = $tokens[($stackPtr - 1)]['content'];
|
||||
if ($content !== ' ') {
|
||||
$length = strlen($content);
|
||||
if ($length === 1) {
|
||||
$length = 'tab';
|
||||
}
|
||||
|
||||
$error = 'Expected 1 space before opening brace of class definition; %s found';
|
||||
$data = array($length);
|
||||
$phpcsFile->addError($error, $stackPtr, 'Before', $data);
|
||||
}
|
||||
}//end if
|
||||
|
||||
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
|
||||
if ($next === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for nested class definitions.
|
||||
$nested = false;
|
||||
$found = $phpcsFile->findNext(
|
||||
T_OPEN_CURLY_BRACKET,
|
||||
($stackPtr + 1),
|
||||
$tokens[$stackPtr]['bracket_closer']
|
||||
);
|
||||
if ($found !== false) {
|
||||
$nested = true;
|
||||
}
|
||||
|
||||
$foundLines = ($tokens[$next]['line'] - $tokens[$stackPtr]['line'] - 1);
|
||||
if ($nested === true) {
|
||||
if ($foundLines !== 1) {
|
||||
$error = 'Expected 1 blank line after opening brace of nesting class definition; %s found';
|
||||
$data = array($foundLines);
|
||||
$phpcsFile->addError($error, $stackPtr, 'AfterNesting', $data);
|
||||
}
|
||||
} else {
|
||||
if ($foundLines !== 0) {
|
||||
$error = 'Expected 0 blank lines after opening brace of class definition; %s found';
|
||||
$data = array($foundLines);
|
||||
$phpcsFile->addError($error, $stackPtr, 'After', $data);
|
||||
}
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_ColonSpacingSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_ColonSpacingSniff.
|
||||
*
|
||||
* Ensure there is no space before a colon and one space after it.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_ColonSpacingSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_COLON);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
|
||||
if ($tokens[$prev]['code'] !== T_STYLE) {
|
||||
// The colon is not part of a style definition.
|
||||
return;
|
||||
}
|
||||
|
||||
if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) {
|
||||
$error = 'There must be no space before a colon in a style definition';
|
||||
$phpcsFile->addError($error, $stackPtr, 'Before');
|
||||
}
|
||||
|
||||
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
|
||||
$error = 'Expected 1 space after colon in style definition; 0 found';
|
||||
$phpcsFile->addError($error, $stackPtr, 'NoneAfter');
|
||||
} else {
|
||||
$content = $tokens[($stackPtr + 1)]['content'];
|
||||
if (strpos($content, $phpcsFile->eolChar) === false) {
|
||||
$length = strlen($content);
|
||||
if ($length !== 1) {
|
||||
$error = 'Expected 1 space after colon in style definition; %s found';
|
||||
$data = array($length);
|
||||
$phpcsFile->addError($error, $stackPtr, 'After', $data);
|
||||
}
|
||||
} else {
|
||||
$error = 'Expected 1 space after colon in style definition; newline found';
|
||||
$phpcsFile->addError($error, $stackPtr, 'AfterNewline');
|
||||
}
|
||||
}//end if
|
||||
|
||||
}//end process()
|
||||
|
||||
}//end class
|
||||
?>
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_ColourDefinitionSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_ColourDefinitionSniff.
|
||||
*
|
||||
* Ensure colours are defined in upper-case and use shortcuts where possible.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_ColourDefinitionSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_COLOUR);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$colour = $tokens[$stackPtr]['content'];
|
||||
|
||||
$expected = strtoupper($colour);
|
||||
if ($colour !== $expected) {
|
||||
$error = 'CSS colours must be defined in uppercase; expected %s but found %s';
|
||||
$data = array(
|
||||
$expected,
|
||||
$colour,
|
||||
);
|
||||
$phpcsFile->addError($error, $stackPtr, 'NotUpper', $data);
|
||||
}
|
||||
|
||||
// Now check if shorthand can be used.
|
||||
if (strlen($colour) !== 7) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($colour{1} === $colour{2} && $colour{3} === $colour{4} && $colour{5} === $colour{6}) {
|
||||
$expected = '#'.$colour{1}.$colour{3}.$colour{5};
|
||||
$error = 'CSS colours must use shorthand if available; expected %s but found %s';
|
||||
$data = array(
|
||||
$expected,
|
||||
$colour,
|
||||
);
|
||||
$phpcsFile->addError($error, $stackPtr, 'Shorthand', $data);
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
}//end class
|
||||
?>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_DisallowMultipleStyleDefinitionsSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_DisallowMultipleStyleDefinitionsSniff.
|
||||
*
|
||||
* Ensure that each style definition is on a line by itself.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_DisallowMultipleStyleDefinitionsSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_STYLE);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$next = $phpcsFile->findNext(T_STYLE, ($stackPtr + 1));
|
||||
if ($next === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) {
|
||||
$error = 'Each style definition must be on a line by itself';
|
||||
$phpcsFile->addError($error, $next, 'Found');
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
}//end class
|
||||
?>
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_DuplicateClassDefinitionSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_DuplicateClassDefinitionSniff.
|
||||
*
|
||||
* Check for duplicate class definitions that can be merged into one.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_DuplicateClassDefinitionSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_OPEN_TAG);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Find the content of each class definition name.
|
||||
$classNames = array();
|
||||
$next = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1));
|
||||
if ($next === false) {
|
||||
// No class definitions in the file.
|
||||
return;
|
||||
}
|
||||
|
||||
$find = array(
|
||||
T_CLOSE_CURLY_BRACKET,
|
||||
T_COMMENT,
|
||||
T_OPEN_TAG,
|
||||
);
|
||||
|
||||
while ($next !== false) {
|
||||
$prev = $phpcsFile->findPrevious($find, ($next - 1));
|
||||
|
||||
// Create a sorted name for the class so we can compare classes
|
||||
// even when the individual names are all over the place.
|
||||
$name = '';
|
||||
for ($i = ($prev + 1); $i < $next; $i++) {
|
||||
$name .= $tokens[$i]['content'];
|
||||
}
|
||||
|
||||
$name = trim($name);
|
||||
$name = str_replace("\n", ' ', $name);
|
||||
$name = preg_replace('|[\s]+|', ' ', $name);
|
||||
$name = str_replace(', ', ',', $name);
|
||||
|
||||
$names = explode(',', $name);
|
||||
sort($names);
|
||||
$name = implode(',', $names);
|
||||
|
||||
if (isset($classNames[$name]) === true) {
|
||||
$first = $classNames[$name];
|
||||
$error = 'Duplicate class definition found; first defined on line %s';
|
||||
$data = array($tokens[$first]['line']);
|
||||
$phpcsFile->addError($error, $next, 'Found', $data);
|
||||
} else {
|
||||
$classNames[$name] = $next;
|
||||
}
|
||||
|
||||
$next = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($next + 1));
|
||||
}//end while
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
?>
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_DuplicateStyleDefinitionSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_DuplicateStyleDefinitionSniff.
|
||||
*
|
||||
* Check for duplicate style definitions in the same class.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_DuplicateStyleDefinitionSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_OPEN_CURLY_BRACKET);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Find the content of each style definition name.
|
||||
$end = $tokens[$stackPtr]['bracket_closer'];
|
||||
$next = $phpcsFile->findNext(T_STYLE, ($stackPtr + 1), $end);
|
||||
if ($next === false) {
|
||||
// Class definition is empty.
|
||||
return;
|
||||
}
|
||||
|
||||
$styleNames = array();
|
||||
|
||||
while ($next !== false) {
|
||||
$name = $tokens[$next]['content'];
|
||||
if (isset($styleNames[$name]) === true) {
|
||||
$first = $styleNames[$name];
|
||||
$error = 'Duplicate style definition found; first defined on line %s';
|
||||
$data = array($tokens[$first]['line']);
|
||||
$phpcsFile->addError($error, $next, 'Found', $data);
|
||||
} else {
|
||||
$styleNames[$name] = $next;
|
||||
}
|
||||
|
||||
$next = $phpcsFile->findNext(T_STYLE, ($next + 1), $end);
|
||||
}//end while
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_EmptyClassDefinitionSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_EmptyClassDefinitionSniff.
|
||||
*
|
||||
* Ensure that class definitions are not empty.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_EmptyClassDefinitionSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_OPEN_CURLY_BRACKET);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
|
||||
|
||||
if ($next === false || $tokens[$next]['code'] === T_CLOSE_CURLY_BRACKET) {
|
||||
$error = 'Class definition is empty';
|
||||
$phpcsFile->addError($error, $stackPtr, 'Found');
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
}//end class
|
||||
?>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_EmptyStyleDefinitionSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_EmptyStyleDefinitionSniff.
|
||||
*
|
||||
* Ensure that style definitions are not empty.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_EmptyStyleDefinitionSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_STYLE);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$next = $phpcsFile->findNext(array(T_WHITESPACE, T_COLON), ($stackPtr + 1), null, true);
|
||||
|
||||
if ($next === false || $tokens[$next]['code'] === T_SEMICOLON || $tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
|
||||
$error = 'Style definition is empty';
|
||||
$phpcsFile->addError($error, $stackPtr, 'Found');
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
}//end class
|
||||
?>
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_IndentationSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_IndentationSniff.
|
||||
*
|
||||
* Ensures styles are indented 4 spaces.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_IndentationSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_OPEN_TAG);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$numTokens = (count($tokens) - 2);
|
||||
$currentLine = 0;
|
||||
$indentLevel = 0;
|
||||
$nestingLevel = 0;
|
||||
for ($i = 1; $i < $numTokens; $i++) {
|
||||
if ($tokens[$i]['code'] === T_COMMENT) {
|
||||
// Dont check the indent of comments.
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) {
|
||||
$indentLevel++;
|
||||
|
||||
// Check for nested class definitions.
|
||||
$found = $phpcsFile->findNext(
|
||||
T_OPEN_CURLY_BRACKET,
|
||||
($i + 1),
|
||||
$tokens[$i]['bracket_closer']
|
||||
);
|
||||
if ($found !== false) {
|
||||
$nestingLevel = $indentLevel;
|
||||
}
|
||||
} else if ($tokens[($i + 1)]['code'] === T_CLOSE_CURLY_BRACKET) {
|
||||
$indentLevel--;
|
||||
}
|
||||
|
||||
if ($tokens[$i]['line'] === $currentLine) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We started a new line, so check indent.
|
||||
if ($tokens[$i]['code'] === T_WHITESPACE) {
|
||||
$content = str_replace($phpcsFile->eolChar, '', $tokens[$i]['content']);
|
||||
$foundIndent = strlen($content);
|
||||
} else {
|
||||
$foundIndent = 0;
|
||||
}
|
||||
|
||||
$expectedIndent = ($indentLevel * 4);
|
||||
if ($expectedIndent > 0 && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false
|
||||
) {
|
||||
if ($nestingLevel !== $indentLevel) {
|
||||
$error = 'Blank lines are not allowed in class definitions';
|
||||
$phpcsFile->addError($error, $i, 'BlankLine');
|
||||
}
|
||||
} else if ($foundIndent !== $expectedIndent) {
|
||||
$error = 'Line indented incorrectly; expected %s spaces, found %s';
|
||||
$data = array(
|
||||
$expectedIndent,
|
||||
$foundIndent,
|
||||
);
|
||||
$phpcsFile->addError($error, $i, 'Incorrect', $data);
|
||||
}
|
||||
|
||||
$currentLine = $tokens[$i]['line'];
|
||||
}//end foreach
|
||||
|
||||
}//end process()
|
||||
|
||||
}//end class
|
||||
?>
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_LowercaseStyleDefinitionSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_LowercaseStyleDefinitionSniff.
|
||||
*
|
||||
* Ensure that all style definitions are in lowercase.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_LowercaseStyleDefinitionSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_OPEN_CURLY_BRACKET);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$start = ($stackPtr + 1);
|
||||
$end = ($tokens[$stackPtr]['bracket_closer'] - 1);
|
||||
|
||||
for ($i = $start; $i <= $end; $i++) {
|
||||
if ($tokens[$i]['code'] === T_STRING || $tokens[$i]['code'] === T_STYLE) {
|
||||
$expected = strtolower($tokens[$i]['content']);
|
||||
if ($expected !== $tokens[$i]['content']) {
|
||||
$error = 'Style definitions must be lowercase; expected %s but found %s';
|
||||
$data = array(
|
||||
$expected,
|
||||
$tokens[$i]['content'],
|
||||
);
|
||||
$phpcsFile->addError($error, $i, 'FoundUpper', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
}//end class
|
||||
?>
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_MissingColonSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_MissingColonSniff.
|
||||
*
|
||||
* Ensure that all style definitions have a colon.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_MissingColonSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_OPEN_CURLY_BRACKET);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$lastLine = $tokens[$stackPtr]['line'];
|
||||
$end = $tokens[$stackPtr]['bracket_closer'];
|
||||
$endLine = $tokens[$end]['line'];
|
||||
|
||||
// Do not check nested style definitions as, for example, in @media style rules.
|
||||
$nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $end);
|
||||
if ($nested !== false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$foundColon = false;
|
||||
$foundString = false;
|
||||
for ($i = ($stackPtr + 1); $i <= $end; $i++) {
|
||||
if ($tokens[$i]['line'] !== $lastLine) {
|
||||
// We changed lines.
|
||||
if ($foundColon === false && $foundString !== false) {
|
||||
// We didn't find a colon on the previous line.
|
||||
$error = 'No style definition found on line; check for missing colon';
|
||||
$phpcsFile->addError($error, $foundString, 'Found');
|
||||
}
|
||||
|
||||
$foundColon = false;
|
||||
$foundString = false;
|
||||
$lastLine = $tokens[$i]['line'];
|
||||
}
|
||||
|
||||
if ($tokens[$i]['code'] === T_STRING) {
|
||||
$foundString = $i;
|
||||
} else if ($tokens[$i]['code'] === T_COLON) {
|
||||
$foundColon = $i;
|
||||
}
|
||||
}//end for
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_OpacitySniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_OpacitySniff.
|
||||
*
|
||||
* Ensure that opacity values start with a 0 if it is not a whole number.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_OpacitySniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_STYLE);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
if ($tokens[$stackPtr]['content'] !== 'opacity') {
|
||||
return;
|
||||
}
|
||||
|
||||
$next = $phpcsFile->findNext(array(T_COLON, T_WHITESPACE), ($stackPtr + 1), null, true);
|
||||
$numbers = array(
|
||||
T_DNUMBER,
|
||||
T_LNUMBER,
|
||||
);
|
||||
|
||||
if ($next === false || in_array($tokens[$next]['code'], $numbers) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$value = $tokens[$next]['content'];
|
||||
if ($tokens[$next]['code'] === T_LNUMBER) {
|
||||
if ($value !== '0' && $value !== '1') {
|
||||
$error = 'Opacity values must be between 0 and 1';
|
||||
$phpcsFile->addError($error, $next, 'Invalid');
|
||||
}
|
||||
} else {
|
||||
if (strlen($value) > 3) {
|
||||
$error = 'Opacity values must have a single value after the decimal point';
|
||||
$phpcsFile->addError($error, $next, 'SpacingAfterPoint');
|
||||
} else if ($value === '0.0' || $value === '1.0') {
|
||||
$error = 'Opacity value does not require decimal point; use %s instead';
|
||||
$data = array($value{0});
|
||||
$phpcsFile->addError($error, $next, 'PointNotRequired', $data);
|
||||
} else if ($value{0} === '.') {
|
||||
$error = 'Opacity values must not start with a decimal point; use 0%s instead';
|
||||
$data = array($value);
|
||||
$phpcsFile->addError($error, $next, 'StartWithPoint', $data);
|
||||
} else if ($value{0} !== '0') {
|
||||
$error = 'Opacity values must be between 0 and 1';
|
||||
$phpcsFile->addError($error, $next, 'Invalid');
|
||||
}
|
||||
}//end if
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_SemicolonSpacingSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Squiz_Sniffs_CSS_SemicolonSpacingSniff.
|
||||
*
|
||||
* Ensure each style definition has a semi-colon and it is spaced correctly.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.3
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Squiz_Sniffs_CSS_SemicolonSpacingSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array('CSS');
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return array(int)
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_STYLE);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$semicolon = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
|
||||
if ($semicolon === false || $tokens[$semicolon]['line'] !== $tokens[$stackPtr]['line']) {
|
||||
$error = 'Style definitions must end with a semicolon';
|
||||
$phpcsFile->addError($error, $stackPtr, 'NotAtEnd');
|
||||
return;
|
||||
}
|
||||
|
||||
if ($tokens[($semicolon - 1)]['code'] === T_WHITESPACE) {
|
||||
$length = strlen($tokens[($semicolon - 1)]['content']);
|
||||
$error = 'Expected 0 spaces before semicolon in style definition; %s found';
|
||||
$data = array($length);
|
||||
$phpcsFile->addError($error, $stackPtr, 'SpaceFound', $data);
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
}//end class
|
||||
?>
|
||||
Reference in New Issue
Block a user