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

Squiz.CSS.EmptyStyleDefinition sees comment as style definition and fails to report error #1737

Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/Standards/Squiz/Sniffs/CSS/EmptyStyleDefinitionSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;

class EmptyStyleDefinitionSniff implements Sniff
{
Expand Down Expand Up @@ -47,8 +48,11 @@ public function register()
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$next = $phpcsFile->findNext([T_WHITESPACE, T_COLON], ($stackPtr + 1), null, true);

$ignore = Tokens::$emptyTokens;
$ignore[] = T_COLON;

$next = $phpcsFile->findNext($ignore, ($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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
margin-right:
float: ;
}

#MetadataAdminScreen-addField-fieldType li {
margin-right: /* @todo */
margin-left: 10px;
float: /* Some comment. */ ;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class EmptyStyleDefinitionUnitTest extends AbstractSniffUnitTest
public function getErrorList()
{
return [
3 => 1,
4 => 1,
3 => 1,
4 => 1,
8 => 1,
10 => 1,
];

}//end getErrorList()
Expand Down