Drupal.CSS.ClassDefinitionNameSpacing sniff incorrectly removing the opening brace instead of removing a blank line for the BlankLinesFound error

Created on 16 March 2019, over 5 years ago
Updated 6 September 2023, 10 months ago

This issue originated from https://github.com/squizlabs/PHP_CodeSniffer/issues/2443

The final identification as posted by jrfnl is:

running phpcbf --standard=Drupal -vv ./error.css on

.test::-webkit-scrollbar-thumb
{
  font-size: 0;
}

If I then look at the -vv output of the Drupal phpcbf run, it shows that the problem is caused by the Drupal.CSS.ClassDefinitionNameSpacing sniff incorrectly removing the opening brace instead of removing a blank line for the BlankLinesFound error.

Drupal\Sniffs\CSS\ClassDefinitionNameSpacingSniff (line 103) replaced token 5 (T_WHITESPACE) "\n{" => " {"
Drupal\Sniffs\CSS\ClassDefinitionNameSpacingSniff (line 126) replaced token 6 (T_OPEN_CURLY_BRACKET) "{" => ""
πŸ› Bug report
Status

Active

Version

3.0

Component

Coder Sniffer

Created by

πŸ‡ΊπŸ‡ΈUnited States sdemi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States Todd Zebert Los Angeles, CA

    We're facing this same issue. I've narrowed it down to this code $fix = $phpcsFile->addFixableError($error, ($i + 1), 'BlankLinesFound'); returns TRUE, which makes the following conditional TRUE, so then the final line $phpcsFile->fixer->replaceToken(($i + 1), ''); replaces the brace with empty string. Unfortunately I'm not following the overall logic to know what's the real issue is.

    I've included screenshots of xdebug vars, so one should be able to make out what's happening here.

             // 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
                        && isset($endTokens[$tokens[$prev]['code']]) === false
                    ) {
                        $error = 'Blank lines are not allowed between class names';
                        $fix   = $phpcsFile->addFixableError($error, ($i + 1), 'BlankLinesFound');
                        if ($fix === true) {
                            $phpcsFile->fixer->replaceToken(($i + 1), '');
                        }
                    }
    
                    break;
                }
    
Production build 0.69.0 2024