diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 01c3a23e..8e88de36 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -64,7 +64,7 @@ jobs: - name: Run Cspell if: ${{ matrix.extra-tests == '1' }} - uses: streetsidesoftware/cspell-action@v6 + uses: streetsidesoftware/cspell-action@v7 with: incremental_files_only: false diff --git a/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php index 33d0450c..49762065 100644 --- a/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php @@ -11,12 +11,18 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; -use PHP_CodeSniffer\Util\Tokens; /** - * Ensure there are no blank lines between the names of classes/IDs. Copied from - * \PHP_CodeSniffer\Standards\Squiz\Sniffs\CSS\ClassDefinitionNameSpacingSniff - * because we also check for comma separated selectors on their own line. + * Disabled sniff. Previously ensured that there are no blank lines between the + * names of classes/IDs. + * + * We cannot implement DeprecatedSniff here because that would show deprecation + * messages to Coder users although they cannot fix them. + * + * @deprecated in Coder 8.3.30 and will be removed in Coder 9.0.0. Checking CSS + * coding standards is not supported anymore, use Stylelint instead with the + * Drupal core .stylelintrc.json configuration file. + * @see https://git.drupalcode.org/project/drupal/-/blob/11.x/core/.stylelintrc.json * * @category PHP * @package PHP_CodeSniffer @@ -25,13 +31,6 @@ class ClassDefinitionNameSpacingSniff implements Sniff { - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = ['CSS']; - /** * Returns the token types that this sniff is interested in. @@ -40,7 +39,7 @@ class ClassDefinitionNameSpacingSniff implements Sniff */ public function register() { - return [T_OPEN_CURLY_BRACKET]; + return [T_OPEN_TAG]; }//end register() @@ -52,90 +51,50 @@ public function register() * @param int $stackPtr The position in the stack where * the token was found. * - * @return void + * @return int */ public function process(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 opening brace, unless we get - // to another style definition, comment or the start of the file. - $endTokens = [ - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_OPEN_TAG => T_OPEN_TAG, - ]; - $endTokens += Tokens::$commentTokens; - - $foundContent = false; - $currentLine = $tokens[$stackPtr]['line']; - for ($i = ($stackPtr - 1); $i >= 0; $i--) { - if (isset($endTokens[$tokens[$i]['code']]) === true) { - break; - } - - // A comma must be followed by a new line character. - if ($tokens[$i]['code'] === T_COMMA - && strpos($tokens[($i + 1)]['content'], $phpcsFile->eolChar) === false - ) { - $error = 'Multiple selectors should each be on a single line'; - $fix = $phpcsFile->addFixableError($error, ($i + 1), 'MultipleSelectors'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($i); - } - } - - // Selectors must be on the same line. - if ($tokens[$i]['code'] === T_WHITESPACE - && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false - && isset($endTokens[$tokens[($i - 1)]['code']]) === false - && in_array($tokens[($i - 1)]['code'], [T_WHITESPACE, T_COMMA]) === false - ) { - $error = 'Selectors must be on a single line'; - // cspell:ignore SeletorSingleLine - $fix = $phpcsFile->addFixableError($error, $i, 'SeletorSingleLine'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($i, str_replace($phpcsFile->eolChar, ' ', $tokens[$i]['content'])); - } - } - - 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 - && 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; - } - - $foundContent = false; - $currentLine = $tokens[$i]['line']; - }//end for + // This sniff is deprecated and disabled - do nothing. + return ($phpcsFile->numTokens + 1); }//end process() + /** + * {@inheritdoc} + * + * @return string + */ + public function getDeprecationVersion(): string + { + return 'Coder 8.3.30'; + + }//end getDeprecationVersion() + + + /** + * {@inheritdoc} + * + * @return string + */ + public function getRemovalVersion(): string + { + return 'Coder 9.0.0'; + + }//end getRemovalVersion() + + + /** + * {@inheritdoc} + * + * @return string + */ + public function getDeprecationMessage(): string + { + return 'Checking CSS coding standards is not supported anymore, use Stylelint instead with the Drupal core .stylelintrc.json configuration file. https://git.drupalcode.org/project/drupal/-/blob/11.x/core/.stylelintrc.json'; + + }//end getDeprecationMessage() + + }//end class diff --git a/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php b/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php index 884ddc4a..64a71f18 100644 --- a/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php +++ b/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php @@ -13,9 +13,15 @@ use PHP_CodeSniffer\Sniffs\Sniff; /** - * \Drupal\Sniffs\CSS\ColourDefinitionSniff. + * Disabled sniff. Previously ensured that colors are defined in lower-case. + * + * We cannot implement DeprecatedSniff here because that would show deprecation + * messages to Coder users although they cannot fix them. * - * Ensure colors are defined in lower-case. + * @deprecated in Coder 8.3.30 and will be removed in Coder 9.0.0. Checking CSS + * coding standards is not supported anymore, use Stylelint instead with the + * Drupal core .stylelintrc.json configuration file. + * @see https://git.drupalcode.org/project/drupal/-/blob/11.x/core/.stylelintrc.json * * @category PHP * @package PHP_CodeSniffer @@ -24,13 +30,6 @@ class ColourDefinitionSniff implements Sniff { - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = ['CSS']; - /** * Returns the token types that this sniff is interested in. @@ -39,7 +38,7 @@ class ColourDefinitionSniff implements Sniff */ public function register() { - return [T_COLOUR]; + return [T_OPEN_TAG]; }//end register() @@ -51,27 +50,50 @@ public function register() * @param int $stackPtr The position in the stack where * the token was found. * - * @return void + * @return int */ public function process(File $phpcsFile, $stackPtr) { - $tokens = $phpcsFile->getTokens(); - $color = $tokens[$stackPtr]['content']; - - $expected = strtolower($color); - if ($color !== $expected) { - $error = 'CSS colors must be defined in lowercase; expected %s but found %s'; - $data = [ - $expected, - $color, - ]; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotLower', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, $expected); - } - } + // This sniff is deprecated and disabled - do nothing. + return ($phpcsFile->numTokens + 1); }//end process() + /** + * {@inheritdoc} + * + * @return string + */ + public function getDeprecationVersion(): string + { + return 'Coder 8.3.30'; + + }//end getDeprecationVersion() + + + /** + * {@inheritdoc} + * + * @return string + */ + public function getRemovalVersion(): string + { + return 'Coder 9.0.0'; + + }//end getRemovalVersion() + + + /** + * {@inheritdoc} + * + * @return string + */ + public function getDeprecationMessage(): string + { + return 'Checking CSS coding standards is not supported anymore, use Stylelint instead with the Drupal core .stylelintrc.json configuration file. https://git.drupalcode.org/project/drupal/-/blob/11.x/core/.stylelintrc.json'; + + }//end getDeprecationMessage() + + }//end class diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php index c455f66f..469d083a 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php @@ -54,11 +54,6 @@ public function process(File $phpcsFile, $stackPtr) // We are only interested in function/class/interface doc block comments. $ignore = Tokens::$emptyTokens; - if ($phpcsFile->tokenizerType === 'JS') { - $ignore[] = T_EQUAL; - $ignore[] = T_STRING; - $ignore[] = T_OBJECT_OPERATOR; - } $nextToken = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true); $ignore = [ diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php index c58c97aa..86e0a399 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php @@ -83,8 +83,7 @@ public function process(File $phpcsFile, $stackPtr) } // The first line of the comment should just be the /** code. - // In JSDoc there are cases with @lends that are on the same line as code. - if ($tokens[$short]['line'] === $tokens[$stackPtr]['line'] && $phpcsFile->tokenizerType !== 'JS') { + if ($tokens[$short]['line'] === $tokens[$stackPtr]['line']) { $error = 'The open comment tag must be the only content on the line'; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpen'); if ($fix === true) { @@ -137,12 +136,6 @@ public function process(File $phpcsFile, $stackPtr) // Check for a comment description. if ($tokens[$short]['code'] !== T_DOC_COMMENT_STRING) { - // JSDoc has many cases of @type declaration that don't have a - // description. - if ($phpcsFile->tokenizerType === 'JS') { - return; - } - // PHPUnit test methods are allowed to skip the short description and // only provide an @covers annotation. if ($tokens[$short]['content'] === '@covers') { @@ -528,9 +521,6 @@ public function process(File $phpcsFile, $stackPtr) // of @code, @todo and link tags. if ($paramGroupid !== null && $paramGroupid !== 0 && in_array($tokens[$tokens[$commentStart]['comment_tags'][0]]['content'], ['@code', '@todo', '@link', '@endlink', '@codingStandardsIgnoreStart']) === false - // In JSDoc we can have many other valid tags like @function or - // tags like @constructor before the param tags. - && $phpcsFile->tokenizerType !== 'JS' ) { $error = 'Parameter tags must be defined first in a doc comment'; $phpcsFile->addError($error, $tagGroups[$paramGroupid][0], 'ParamNotFirst'); diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php index f226d61f..b5974574 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php @@ -99,23 +99,6 @@ public function process(File $phpcsFile, $stackPtr) return; } - if ($phpcsFile->tokenizerType === 'JS') { - // We allow block comments if a function or object - // is being assigned to a variable. - $ignore = Tokens::$emptyTokens; - $ignore[] = T_EQUAL; - $ignore[] = T_STRING; - $ignore[] = T_OBJECT_OPERATOR; - $nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true); - if ($tokens[$nextToken]['code'] === T_FUNCTION - || $tokens[$nextToken]['code'] === T_CLOSURE - || $tokens[$nextToken]['code'] === T_OBJECT - || $tokens[$nextToken]['code'] === T_PROTOTYPE - ) { - return; - } - } - $prevToken = $phpcsFile->findPrevious( Tokens::$emptyTokens, ($stackPtr - 1), @@ -127,8 +110,7 @@ public function process(File $phpcsFile, $stackPtr) return; } - // Inline doc blocks are allowed in JSDoc. - if ($tokens[$stackPtr]['content'] === '/**' && $phpcsFile->tokenizerType !== 'JS') { + if ($tokens[$stackPtr]['content'] === '/**') { // The only exception to inline doc blocks is the /** @var */ // declaration. Allow that in any form. $varTag = $phpcsFile->findNext([T_DOC_COMMENT_TAG], ($stackPtr + 1), $tokens[$stackPtr]['comment_closer'], false, '@var'); @@ -155,16 +137,6 @@ public function process(File $phpcsFile, $stackPtr) if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) { return; } - - // Special case for JS files. - if ($tokens[$previousContent]['code'] === T_COMMA - || $tokens[$previousContent]['code'] === T_SEMICOLON - ) { - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true); - if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) { - return; - } - } } // Only want inline comments. diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php index 262f9594..2623fefa 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php @@ -65,16 +65,6 @@ public function process(File $phpcsFile, $stackPtr) return; } - // Special case for JS files. - if ($tokens[$lastContent]['code'] === T_COMMA - || $tokens[$lastContent]['code'] === T_SEMICOLON - ) { - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($lastContent - 1), null, true); - if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) { - return; - } - } - $error = 'Comments may not appear after statements'; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); if ($fix === true) { diff --git a/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php b/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php index 2556afef..ee00e532 100644 --- a/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php +++ b/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php @@ -209,38 +209,6 @@ public function process(File $phpcsFile, $stackPtr) if (isset($tokens[$stackPtr]['scope_closer']) === true) { $closer = $tokens[$stackPtr]['scope_closer']; } - - // Do-while loops should have curly braces. This is optional in - // Javascript. - if ($closer === false && $tokens[$stackPtr]['code'] === T_DO && $phpcsFile->tokenizerType === 'JS') { - $error = 'The code block in a do-while loop should be surrounded by curly braces'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'DoWhileCurlyBraces'); - $closer = $phpcsFile->findNext(T_WHILE, $stackPtr); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - // Append an opening curly brace followed by a newline after - // the DO. - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($next !== ($stackPtr + 1)) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ''); - } - - $phpcsFile->fixer->addContent($stackPtr, ' {'.$phpcsFile->eolChar); - - // Prepend a closing curly brace before the WHILE and ensure - // it is on a new line. - $prepend = $phpcsFile->eolChar; - if ($tokens[($closer - 1)]['code'] === T_WHITESPACE) { - $prepend = ''; - if ($tokens[($closer - 1)]['content'] !== $phpcsFile->eolChar) { - $phpcsFile->fixer->replaceToken(($closer - 1), $phpcsFile->eolChar); - } - } - - $phpcsFile->fixer->addContentBefore($closer, $prepend.'} '); - $phpcsFile->fixer->endChangeset(); - }//end if - }//end if } else if ($tokens[$stackPtr]['code'] === T_ELSE || $tokens[$stackPtr]['code'] === T_ELSEIF || $tokens[$stackPtr]['code'] === T_CATCH diff --git a/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php b/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php index aa47b82f..deb38402 100644 --- a/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php @@ -26,18 +26,6 @@ class EndFileNewlineSniff implements Sniff { - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = [ - 'PHP', - 'JS', - 'CSS', - ]; - - /** * Returns an array of tokens this test wants to listen for. * @@ -65,14 +53,8 @@ public function register() public function process(File $phpcsFile, $stackPtr) { // Skip to the end of the file. - $tokens = $phpcsFile->getTokens(); - if ($phpcsFile->tokenizerType === 'PHP') { - $lastToken = ($phpcsFile->numTokens - 1); - } else { - // JS and CSS have an artificial token at the end which we have to - // ignore. - $lastToken = ($phpcsFile->numTokens - 2); - } + $tokens = $phpcsFile->getTokens(); + $lastToken = ($phpcsFile->numTokens - 1); // Hard-coding the expected \n in this sniff as it is PSR-2 specific and // PSR-2 enforces the use of unix style newlines. diff --git a/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php b/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php index 8603d9f4..005021c6 100644 --- a/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php @@ -9,88 +9,89 @@ namespace Drupal\Sniffs\Strings; -use Drupal\Sniffs\Files\LineLengthSniff; use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Standards\Generic\Sniffs\Strings\UnnecessaryStringConcatSniff as GenericUnnecessaryStringConcatSniff; -use PHP_CodeSniffer\Util\Tokens; +use PHP_CodeSniffer\Sniffs\Sniff; /** * Checks that two strings are not concatenated together; suggests using one string instead. * + * We cannot implement DeprecatedSniff here because that would show deprecation + * messages to Coder users although they cannot fix them. + * + * @deprecated in Coder 8.3.30 and will be removed in Coder 9.0.0. Use + * Generic.Strings.UnnecessaryStringConcat instead. + * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class UnnecessaryStringConcatSniff extends GenericUnnecessaryStringConcatSniff +class UnnecessaryStringConcatSniff implements Sniff { + /** + * Returns the token types that this sniff is interested in. + * + * @return array + */ + public function register() + { + return [T_OPEN_TAG]; + + }//end register() + + /** - * Processes this sniff, when one of its tokens is encountered. + * Processes the tokens that this sniff is interested in. * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. * - * @return void + * @return int */ public function process(File $phpcsFile, $stackPtr) { - // Work out which type of file this is for. - $tokens = $phpcsFile->getTokens(); - if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) { - if ($phpcsFile->tokenizerType === 'JS') { - return; - } - } else { - if ($phpcsFile->tokenizerType === 'PHP') { - return; - } - } - - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($prev === false || $next === false) { - return; - } - - $stringTokens = Tokens::$stringTokens; - if (in_array($tokens[$prev]['code'], $stringTokens) === true - && in_array($tokens[$next]['code'], $stringTokens) === true - ) { - if ($tokens[$prev]['content'][0] === $tokens[$next]['content'][0]) { - // Before we throw an error for PHP, allow strings to be - // combined if they would have < and ? next to each other because - // this trick is sometimes required in PHP strings. - if ($phpcsFile->tokenizerType === 'PHP') { - $prevChar = substr($tokens[$prev]['content'], -2, 1); - $nextChar = $tokens[$next]['content'][1]; - $combined = $prevChar.$nextChar; - if ($combined === '?'.'>' || $combined === '<'.'?') { - return; - } - } - - // Before we throw an error check if the string is longer than - // the line length limit. - $lineLengthLimitSniff = new LineLengthSniff; - - $lineLength = $lineLengthLimitSniff->getLineLength($phpcsFile, $tokens[$prev]['line']); - $stringLength = ($lineLength + strlen($tokens[$next]['content']) - 4); - if ($stringLength > $lineLengthLimitSniff->lineLimit) { - return; - } - - $error = 'String concat is not required here; use a single string instead'; - if ($this->error === true) { - $phpcsFile->addError($error, $stackPtr, 'Found'); - } else { - $phpcsFile->addWarning($error, $stackPtr, 'Found'); - } - }//end if - }//end if + // This sniff is deprecated and disabled - do nothing. + return ($phpcsFile->numTokens + 1); }//end process() + /** + * {@inheritdoc} + * + * @return string + */ + public function getDeprecationVersion(): string + { + return 'Coder 8.3.30'; + + }//end getDeprecationVersion() + + + /** + * {@inheritdoc} + * + * @return string + */ + public function getRemovalVersion(): string + { + return 'Coder 9.0.0'; + + }//end getRemovalVersion() + + + /** + * {@inheritdoc} + * + * @return string + */ + public function getDeprecationMessage(): string + { + return 'The custom UnnecessaryStringConcatSniff is deprecated and will be removed in Coder 9.0.0. Use Generic.Strings.UnnecessaryStringConcat instead.'; + + }//end getDeprecationMessage() + + }//end class diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php index 2bdfd007..7d839937 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php @@ -55,13 +55,6 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - // Ignore curly brackets in javascript files. - if ($tokens[$stackPtr]['code'] === T_CLOSE_CURLY_BRACKET - && $phpcsFile->tokenizerType === 'JS' - ) { - return; - } - if (isset($tokens[($stackPtr - 1)]) === true && $tokens[($stackPtr - 1)]['code'] === T_WHITESPACE ) { diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php index 341c27e9..b2f1239b 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php @@ -24,17 +24,6 @@ class EmptyLinesSniff implements Sniff { - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = [ - 'PHP', - 'JS', - 'CSS', - ]; - /** * Returns an array of tokens this test wants to listen for. diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php index 9d038ecc..531778ec 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php @@ -54,13 +54,6 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - // Ignore curly brackets in javascript files. - if ($tokens[$stackPtr]['code'] === T_OPEN_CURLY_BRACKET - && $phpcsFile->tokenizerType === 'JS' - ) { - return; - } - if (isset($tokens[($stackPtr + 1)]) === true && $tokens[($stackPtr + 1)]['code'] === T_WHITESPACE && strpos($tokens[($stackPtr + 1)]['content'], $phpcsFile->eolChar) === false diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php index 8a4f4b27..ab930c99 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php @@ -691,113 +691,6 @@ public function process(File $phpcsFile, $stackPtr) }//end if }//end if - // Handle scope for JS object notation. - if ($phpcsFile->tokenizerType === 'JS' - && (($checkToken !== null - && $tokens[$checkToken]['code'] === T_CLOSE_OBJECT - && $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['bracket_opener']]['line']) - || ($checkToken === null - && $tokens[$i]['code'] === T_CLOSE_OBJECT - && $tokens[$i]['line'] !== $tokens[$tokens[$i]['bracket_opener']]['line'])) - ) { - if ($this->debug === true) { - $line = $tokens[$i]['line']; - echo "Close JS object on line $line".PHP_EOL; - } - - $scopeCloser = $checkToken; - if ($scopeCloser === null) { - $scopeCloser = $i; - } else { - $conditionToken = array_pop($openScopes); - if ($this->debug === true) { - $line = $tokens[$conditionToken]['line']; - $type = $tokens[$conditionToken]['type']; - echo "\t=> removed open scope $conditionToken ($type) on line $line".PHP_EOL; - } - } - - $parens = 0; - if (isset($tokens[$scopeCloser]['nested_parenthesis']) === true - && empty($tokens[$scopeCloser]['nested_parenthesis']) === false - ) { - $parens = $tokens[$scopeCloser]['nested_parenthesis']; - end($parens); - $parens = key($parens); - if ($this->debug === true) { - $line = $tokens[$parens]['line']; - echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL; - } - } - - $condition = 0; - if (isset($tokens[$scopeCloser]['conditions']) === true - && empty($tokens[$scopeCloser]['conditions']) === false - ) { - $condition = $tokens[$scopeCloser]['conditions']; - end($condition); - $condition = key($condition); - if ($this->debug === true) { - $line = $tokens[$condition]['line']; - $type = $tokens[$condition]['type']; - echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL; - } - } - - if ($parens > $condition) { - if ($this->debug === true) { - echo "\t* using parenthesis *".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parens, true); - $condition = 0; - } else if ($condition > 0) { - if ($this->debug === true) { - echo "\t* using condition *".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $condition, true); - $parens = 0; - } else { - if ($this->debug === true) { - $line = $tokens[$tokens[$scopeCloser]['bracket_opener']]['line']; - echo "\t* token is not in parenthesis or condition; using opener on line $line *".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['bracket_opener'], true); - }//end if - - $currentIndent = ($tokens[$first]['column'] - 1); - if (isset($adjustments[$first]) === true) { - $currentIndent += $adjustments[$first]; - } - - if ($parens > 0 || $condition > 0) { - $checkIndent = ($tokens[$first]['column'] - 1); - if (isset($adjustments[$first]) === true) { - $checkIndent += $adjustments[$first]; - } - - if ($condition > 0) { - $checkIndent += $this->indent; - $currentIndent += $this->indent; - $exact = true; - } - } else { - $checkIndent = $currentIndent; - } - - // Make sure it is divisible by our expected indent. - $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); - $checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent); - $setIndents[$first] = $currentIndent; - - if ($this->debug === true) { - $type = $tokens[$first]['type']; - echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL; - } - }//end if - if ($checkToken !== null && isset(Tokens::$scopeOpeners[$tokens[$checkToken]['code']]) === true && in_array($tokens[$checkToken]['code'], $this->nonIndentingScopes, true) === false @@ -895,12 +788,6 @@ public function process(File $phpcsFile, $stackPtr) }//end if }//end if - // JS property indentation has to be exact or else if will break - // things like function and object indentation. - if ($checkToken !== null && $tokens[$checkToken]['code'] === T_PROPERTY) { - $exact = true; - } - // Open PHP tags needs to be indented to exact column positions // so they don't cause problems with indent checks for the code // within them, but they don't need to line up with the current indent @@ -1344,44 +1231,6 @@ public function process(File $phpcsFile, $stackPtr) }//end if }//end if - // JS objects set the indent level. - if ($phpcsFile->tokenizerType === 'JS' - && $tokens[$i]['code'] === T_OBJECT - ) { - $closer = $tokens[$i]['bracket_closer']; - if ($tokens[$i]['line'] === $tokens[$closer]['line']) { - if ($this->debug === true) { - $line = $tokens[$i]['line']; - echo "* ignoring single-line JS object on line $line *".PHP_EOL; - } - - $i = $closer; - continue; - } - - if ($this->debug === true) { - $line = $tokens[$i]['line']; - echo "Open JS object on line $line".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true); - $currentIndent = (($tokens[$first]['column'] - 1) + $this->indent); - if (isset($adjustments[$first]) === true) { - $currentIndent += $adjustments[$first]; - } - - // Make sure it is divisible by our expected indent. - $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); - $setIndents[$first] = $currentIndent; - - if ($this->debug === true) { - $type = $tokens[$first]['type']; - echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL; - } - - continue; - }//end if - // Closing an anon class, closure, or match. // Each may be returned, which can confuse control structures that // use return as a closer, like CASE statements. @@ -1399,23 +1248,6 @@ public function process(File $phpcsFile, $stackPtr) $prev = false; - $object = 0; - if ($phpcsFile->tokenizerType === 'JS') { - $conditions = $tokens[$i]['conditions']; - krsort($conditions, SORT_NUMERIC); - foreach ($conditions as $token => $condition) { - if ($condition === T_OBJECT) { - $object = $token; - break; - } - } - - if ($this->debug === true && $object !== 0) { - $line = $tokens[$object]['line']; - echo "\t* token is inside JS object $object on line $line *".PHP_EOL; - } - } - $parens = 0; if (isset($tokens[$i]['nested_parenthesis']) === true && empty($tokens[$i]['nested_parenthesis']) === false @@ -1443,21 +1275,12 @@ public function process(File $phpcsFile, $stackPtr) } } - if ($parens > $object && $parens > $condition) { + if ($parens > $condition) { if ($this->debug === true) { echo "\t* using parenthesis *".PHP_EOL; } $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parens - 1), null, true); - $object = 0; - $condition = 0; - } else if ($object > 0 && $object >= $condition) { - if ($this->debug === true) { - echo "\t* using object *".PHP_EOL; - } - - $prev = $object; - $parens = 0; $condition = 0; } else if ($condition > 0) { if ($this->debug === true) { @@ -1465,7 +1288,6 @@ public function process(File $phpcsFile, $stackPtr) } $prev = $condition; - $object = 0; $parens = 0; }//end if @@ -1510,7 +1332,7 @@ public function process(File $phpcsFile, $stackPtr) } $currentIndent = ($tokens[$first]['column'] - 1); - if ($object > 0 || $condition > 0) { + if ($condition > 0) { $currentIndent += $this->indent; } diff --git a/coder_sniffer/Drupal/ruleset.xml b/coder_sniffer/Drupal/ruleset.xml index f16e12c6..cb0dcafc 100644 --- a/coder_sniffer/Drupal/ruleset.xml +++ b/coder_sniffer/Drupal/ruleset.xml @@ -23,13 +23,14 @@ *.tpl.php - + 0 0 + @@ -65,9 +66,13 @@ + + + + + - - + @@ -225,26 +230,6 @@ 0 - - - 0 - - - - 0 - - - - - - - - - - - - - @@ -267,7 +252,6 @@ - @@ -287,7 +271,4 @@ */\.svn/* */\.hg/* */\.bzr/* - - - *\.min\.css$ diff --git a/composer.json b/composer.json index 506d8fce..5858f899 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1 || ^1.0.0", "sirbrillig/phpcs-variable-analysis": "^2.11.7", "slevomat/coding-standard": "^8.11", - "squizlabs/php_codesniffer": "^3.12.2", + "squizlabs/php_codesniffer": "^3.13", "symfony/yaml": ">=3.4.0" }, "autoload": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 5c26d17e..32177b29 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -6,7 +6,7 @@ tests - tests/*\.(inc|css|js|api\.php|tpl\.php)$ + tests/*\.(inc|api\.php|tpl\.php)$ tests/*/(good|bad)\.php$ tests/*/drupal(6|7|8)/*\.php$ diff --git a/tests/Drupal/bad/BadUnitTest.php b/tests/Drupal/bad/BadUnitTest.php index e9a855ce..b0edb702 100644 --- a/tests/Drupal/bad/BadUnitTest.php +++ b/tests/Drupal/bad/BadUnitTest.php @@ -32,26 +32,6 @@ protected function getErrorList(string $testFile): array 1 => 2, 8 => 1, ]; - case 'bad.css': - return [ - 1 => 1, - 2 => 1, - 3 => 2, - 4 => 1, - 5 => 1, - 6 => 1, - 7 => 1, - 8 => 1, - 9 => 1, - 12 => 3, - 16 => 1, - 17 => 1, - 21 => 1, - 26 => 1, - 27 => 1, - 31 => 1, - 36 => 1, - ]; case 'bad.info': return [ 1 => 3, diff --git a/tests/Drupal/bad/bad.css b/tests/Drupal/bad/bad.css deleted file mode 100644 index 0686f529..00000000 --- a/tests/Drupal/bad/bad.css +++ /dev/null @@ -1,39 +0,0 @@ -#forum .description{ - color: #EFEFEF; /* Colors should be lower case. Blank lines in class definitions are not allowed. */ - - font-size:0.9em; /* There should be a space after the colon. */ - margin: 0.5em; /* Indentation error. */ - background: ; /* Empty style definitions are not allowed. */ - font-weight normal; /* Missing colon. */ - font-family: helvetica, sans-serif /* Mising semicolon. */ - padding-left: 2em ; /* Space before semicolon. */ -} - -.testselector {display: table; border: none;} - -/* Blank lines between selectors are not allowed. */ -#forum td.posts, - -#forum td.pager { -} - -/* Empty definitions are not allowed. */ -.book-navigation .page-previous { -} - -/* Missing colon in style definition */ -.selector { - - foobar; -} - -/* Multiple selectors should be on separate lines. */ -#forum td.posts, #forum td.pager { - font-size: 0.9em; -} - -/* Selectors must be on a single line. */ -.book-navigation -.page-previous { - font-size: 0.9em; -} diff --git a/tests/Drupal/good/good.css b/tests/Drupal/good/good.css deleted file mode 100644 index 2a0178ea..00000000 --- a/tests/Drupal/good/good.css +++ /dev/null @@ -1,118 +0,0 @@ -/** - * @file - * Valid example CSS file. - */ - -#forum .description { - color: #efefef; - font-size: 0.9em; - margin: 0.5em; -} - -.testselector { - border: none; - display: table; -} - -#forum td.posts, -#forum td.pager { - color: #efefef; -} - -@media screen and (max-device-width: 769px) { - - header #logo img { - max-width: 100%; - } - - .inner { - max-width: 1500px; - min-width: 1281px; - } - -} - -.progressive-enhancement { - background: #000 none; - background-color: rgba(0, 0, 0, 0.9); -} -.progressive-prefixes { - background-color: #003471; - background-image: -webkit-gradient(linear, left top, left bottom, from(#003471), to(#448ccb)); - background-image: -webkit-linear-gradient(top, #003471, #448ccb); - background-image: -moz-linear-gradient(top, #003471, #448ccb); - background-image: -ms-linear-gradient(top, #003471, #448ccb); - background-image: -o-linear-gradient(top, #003471, #448ccb); - background-image: linear-gradient(to bottom, #003471, #448ccb); -} -.vendor-prefixes { - -moz-border-radius: 5px; - -webkit-border-radius: 5px; - border-radius: 5px; - -moz-box-shadow: 0 3px 20px #000; - -webkit-box-shadow: 0 3px 20px #000; - box-shadow: 0 3px 20px #000; -} - -#node-admin-buttons { - clear: right; /* LTR */ - float: left; /* LTR */ - margin-left: 0.5em; /* LTR */ -} - -.gigantic { - /* 110px / 120px */ - font-size: 6.875em; - line-height: 1.0909090909090908em; -} - -/* A comment describing the ruleset. */ -.selector-1, -.selector-2, -.selector-3[type="text"] { - -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; - box-sizing: border-box; - display: block; - margin: 0; - font-family: Times, "Times New Roman", sans-serif; - color: #333; - background: #fff; - background: linear-gradient(#fff, rgba(0, 0, 0, 0.8)); -} - -/** -* A longer comment describing this ruleset. Note -* the blank line before the docblock. -*/ -.selector-4, -.selector-5 { - padding: 10px; -} - -/* This logical grouping of rulesets has no interleaving blank lines. */ -.profile { - margin: 1em 0; -} -.profile__picture { - float: right; /* LTR */ -} - -@media screen and (max-width: 1152px) { - #wrapper { - max-width: 960px; - } - #top-area .column:last-child { - margin-right: 0; - } - #copyright { - padding: 0 10px; - } -} - -@media (min-width: 320px) and (max-width: 961px) { - .tooltipsrt:hover span.tltp, - .tooltipstp:hover span.tltp { - visibility: hidden; - } -}