Skip to content

Commit dd57647

Browse files
authored
fix(phpcs): Remove support for CSS and JS files, remove deprecated MySource.Debug.DebugCode sniff, rename deprecated Squiz.WhiteSpace.LanguageConstructSpacing sniff (#3524264)
1 parent 5db17e3 commit dd57647

20 files changed

+178
-698
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464

6565
- name: Run Cspell
6666
if: ${{ matrix.extra-tests == '1' }}
67-
uses: streetsidesoftware/cspell-action@v6
67+
uses: streetsidesoftware/cspell-action@v7
6868
with:
6969
incremental_files_only: false
7070

coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php

Lines changed: 50 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@
1111

1212
use PHP_CodeSniffer\Files\File;
1313
use PHP_CodeSniffer\Sniffs\Sniff;
14-
use PHP_CodeSniffer\Util\Tokens;
1514

1615
/**
17-
* Ensure there are no blank lines between the names of classes/IDs. Copied from
18-
* \PHP_CodeSniffer\Standards\Squiz\Sniffs\CSS\ClassDefinitionNameSpacingSniff
19-
* because we also check for comma separated selectors on their own line.
16+
* Disabled sniff. Previously ensured that there are no blank lines between the
17+
* names of classes/IDs.
18+
*
19+
* We cannot implement DeprecatedSniff here because that would show deprecation
20+
* messages to Coder users although they cannot fix them.
21+
*
22+
* @deprecated in Coder 8.3.30 and will be removed in Coder 9.0.0. Checking CSS
23+
* coding standards is not supported anymore, use Stylelint instead with the
24+
* Drupal core .stylelintrc.json configuration file.
25+
* @see https://git.drupalcode.org/project/drupal/-/blob/11.x/core/.stylelintrc.json
2026
*
2127
* @category PHP
2228
* @package PHP_CodeSniffer
@@ -25,13 +31,6 @@
2531
class ClassDefinitionNameSpacingSniff implements Sniff
2632
{
2733

28-
/**
29-
* A list of tokenizers this sniff supports.
30-
*
31-
* @var array<string>
32-
*/
33-
public $supportedTokenizers = ['CSS'];
34-
3534

3635
/**
3736
* Returns the token types that this sniff is interested in.
@@ -40,7 +39,7 @@ class ClassDefinitionNameSpacingSniff implements Sniff
4039
*/
4140
public function register()
4241
{
43-
return [T_OPEN_CURLY_BRACKET];
42+
return [T_OPEN_TAG];
4443

4544
}//end register()
4645

@@ -52,90 +51,50 @@ public function register()
5251
* @param int $stackPtr The position in the stack where
5352
* the token was found.
5453
*
55-
* @return void
54+
* @return int
5655
*/
5756
public function process(File $phpcsFile, $stackPtr)
5857
{
59-
$tokens = $phpcsFile->getTokens();
60-
61-
// Do not check nested style definitions as, for example, in @media style rules.
62-
$nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']);
63-
if ($nested !== false) {
64-
return;
65-
}
66-
67-
// Find the first blank line before this opening brace, unless we get
68-
// to another style definition, comment or the start of the file.
69-
$endTokens = [
70-
T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
71-
T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
72-
T_OPEN_TAG => T_OPEN_TAG,
73-
];
74-
$endTokens += Tokens::$commentTokens;
75-
76-
$foundContent = false;
77-
$currentLine = $tokens[$stackPtr]['line'];
78-
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
79-
if (isset($endTokens[$tokens[$i]['code']]) === true) {
80-
break;
81-
}
82-
83-
// A comma must be followed by a new line character.
84-
if ($tokens[$i]['code'] === T_COMMA
85-
&& strpos($tokens[($i + 1)]['content'], $phpcsFile->eolChar) === false
86-
) {
87-
$error = 'Multiple selectors should each be on a single line';
88-
$fix = $phpcsFile->addFixableError($error, ($i + 1), 'MultipleSelectors');
89-
if ($fix === true) {
90-
$phpcsFile->fixer->addNewline($i);
91-
}
92-
}
93-
94-
// Selectors must be on the same line.
95-
if ($tokens[$i]['code'] === T_WHITESPACE
96-
&& strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false
97-
&& isset($endTokens[$tokens[($i - 1)]['code']]) === false
98-
&& in_array($tokens[($i - 1)]['code'], [T_WHITESPACE, T_COMMA]) === false
99-
) {
100-
$error = 'Selectors must be on a single line';
101-
// cspell:ignore SeletorSingleLine
102-
$fix = $phpcsFile->addFixableError($error, $i, 'SeletorSingleLine');
103-
if ($fix === true) {
104-
$phpcsFile->fixer->replaceToken($i, str_replace($phpcsFile->eolChar, ' ', $tokens[$i]['content']));
105-
}
106-
}
107-
108-
if ($tokens[$i]['line'] === $currentLine) {
109-
if ($tokens[$i]['code'] !== T_WHITESPACE) {
110-
$foundContent = true;
111-
}
112-
113-
continue;
114-
}
115-
116-
// We changed lines.
117-
if ($foundContent === false) {
118-
// Before we throw an error, make sure we are not looking
119-
// at a gap before the style definition.
120-
$prev = $phpcsFile->findPrevious(T_WHITESPACE, $i, null, true);
121-
if ($prev !== false
122-
&& isset($endTokens[$tokens[$prev]['code']]) === false
123-
) {
124-
$error = 'Blank lines are not allowed between class names';
125-
$fix = $phpcsFile->addFixableError($error, ($i + 1), 'BlankLinesFound');
126-
if ($fix === true) {
127-
$phpcsFile->fixer->replaceToken(($i + 1), '');
128-
}
129-
}
130-
131-
break;
132-
}
133-
134-
$foundContent = false;
135-
$currentLine = $tokens[$i]['line'];
136-
}//end for
58+
// This sniff is deprecated and disabled - do nothing.
59+
return ($phpcsFile->numTokens + 1);
13760

13861
}//end process()
13962

14063

64+
/**
65+
* {@inheritdoc}
66+
*
67+
* @return string
68+
*/
69+
public function getDeprecationVersion(): string
70+
{
71+
return 'Coder 8.3.30';
72+
73+
}//end getDeprecationVersion()
74+
75+
76+
/**
77+
* {@inheritdoc}
78+
*
79+
* @return string
80+
*/
81+
public function getRemovalVersion(): string
82+
{
83+
return 'Coder 9.0.0';
84+
85+
}//end getRemovalVersion()
86+
87+
88+
/**
89+
* {@inheritdoc}
90+
*
91+
* @return string
92+
*/
93+
public function getDeprecationMessage(): string
94+
{
95+
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';
96+
97+
}//end getDeprecationMessage()
98+
99+
141100
}//end class

coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
use PHP_CodeSniffer\Sniffs\Sniff;
1414

1515
/**
16-
* \Drupal\Sniffs\CSS\ColourDefinitionSniff.
16+
* Disabled sniff. Previously ensured that colors are defined in lower-case.
17+
*
18+
* We cannot implement DeprecatedSniff here because that would show deprecation
19+
* messages to Coder users although they cannot fix them.
1720
*
18-
* Ensure colors are defined in lower-case.
21+
* @deprecated in Coder 8.3.30 and will be removed in Coder 9.0.0. Checking CSS
22+
* coding standards is not supported anymore, use Stylelint instead with the
23+
* Drupal core .stylelintrc.json configuration file.
24+
* @see https://git.drupalcode.org/project/drupal/-/blob/11.x/core/.stylelintrc.json
1925
*
2026
* @category PHP
2127
* @package PHP_CodeSniffer
@@ -24,13 +30,6 @@
2430
class ColourDefinitionSniff implements Sniff
2531
{
2632

27-
/**
28-
* A list of tokenizers this sniff supports.
29-
*
30-
* @var array<string>
31-
*/
32-
public $supportedTokenizers = ['CSS'];
33-
3433

3534
/**
3635
* Returns the token types that this sniff is interested in.
@@ -39,7 +38,7 @@ class ColourDefinitionSniff implements Sniff
3938
*/
4039
public function register()
4140
{
42-
return [T_COLOUR];
41+
return [T_OPEN_TAG];
4342

4443
}//end register()
4544

@@ -51,27 +50,50 @@ public function register()
5150
* @param int $stackPtr The position in the stack where
5251
* the token was found.
5352
*
54-
* @return void
53+
* @return int
5554
*/
5655
public function process(File $phpcsFile, $stackPtr)
5756
{
58-
$tokens = $phpcsFile->getTokens();
59-
$color = $tokens[$stackPtr]['content'];
60-
61-
$expected = strtolower($color);
62-
if ($color !== $expected) {
63-
$error = 'CSS colors must be defined in lowercase; expected %s but found %s';
64-
$data = [
65-
$expected,
66-
$color,
67-
];
68-
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotLower', $data);
69-
if ($fix === true) {
70-
$phpcsFile->fixer->replaceToken($stackPtr, $expected);
71-
}
72-
}
57+
// This sniff is deprecated and disabled - do nothing.
58+
return ($phpcsFile->numTokens + 1);
7359

7460
}//end process()
7561

7662

63+
/**
64+
* {@inheritdoc}
65+
*
66+
* @return string
67+
*/
68+
public function getDeprecationVersion(): string
69+
{
70+
return 'Coder 8.3.30';
71+
72+
}//end getDeprecationVersion()
73+
74+
75+
/**
76+
* {@inheritdoc}
77+
*
78+
* @return string
79+
*/
80+
public function getRemovalVersion(): string
81+
{
82+
return 'Coder 9.0.0';
83+
84+
}//end getRemovalVersion()
85+
86+
87+
/**
88+
* {@inheritdoc}
89+
*
90+
* @return string
91+
*/
92+
public function getDeprecationMessage(): string
93+
{
94+
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';
95+
96+
}//end getDeprecationMessage()
97+
98+
7799
}//end class

coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ public function process(File $phpcsFile, $stackPtr)
5454

5555
// We are only interested in function/class/interface doc block comments.
5656
$ignore = Tokens::$emptyTokens;
57-
if ($phpcsFile->tokenizerType === 'JS') {
58-
$ignore[] = T_EQUAL;
59-
$ignore[] = T_STRING;
60-
$ignore[] = T_OBJECT_OPERATOR;
61-
}
6257

6358
$nextToken = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true);
6459
$ignore = [

coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public function process(File $phpcsFile, $stackPtr)
8383
}
8484

8585
// The first line of the comment should just be the /** code.
86-
// In JSDoc there are cases with @lends that are on the same line as code.
87-
if ($tokens[$short]['line'] === $tokens[$stackPtr]['line'] && $phpcsFile->tokenizerType !== 'JS') {
86+
if ($tokens[$short]['line'] === $tokens[$stackPtr]['line']) {
8887
$error = 'The open comment tag must be the only content on the line';
8988
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpen');
9089
if ($fix === true) {
@@ -137,12 +136,6 @@ public function process(File $phpcsFile, $stackPtr)
137136

138137
// Check for a comment description.
139138
if ($tokens[$short]['code'] !== T_DOC_COMMENT_STRING) {
140-
// JSDoc has many cases of @type declaration that don't have a
141-
// description.
142-
if ($phpcsFile->tokenizerType === 'JS') {
143-
return;
144-
}
145-
146139
// PHPUnit test methods are allowed to skip the short description and
147140
// only provide an @covers annotation.
148141
if ($tokens[$short]['content'] === '@covers') {
@@ -528,9 +521,6 @@ public function process(File $phpcsFile, $stackPtr)
528521
// of @code, @todo and link tags.
529522
if ($paramGroupid !== null && $paramGroupid !== 0
530523
&& in_array($tokens[$tokens[$commentStart]['comment_tags'][0]]['content'], ['@code', '@todo', '@link', '@endlink', '@codingStandardsIgnoreStart']) === false
531-
// In JSDoc we can have many other valid tags like @function or
532-
// tags like @constructor before the param tags.
533-
&& $phpcsFile->tokenizerType !== 'JS'
534524
) {
535525
$error = 'Parameter tags must be defined first in a doc comment';
536526
$phpcsFile->addError($error, $tagGroups[$paramGroupid][0], 'ParamNotFirst');

coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,6 @@ public function process(File $phpcsFile, $stackPtr)
9999
return;
100100
}
101101

102-
if ($phpcsFile->tokenizerType === 'JS') {
103-
// We allow block comments if a function or object
104-
// is being assigned to a variable.
105-
$ignore = Tokens::$emptyTokens;
106-
$ignore[] = T_EQUAL;
107-
$ignore[] = T_STRING;
108-
$ignore[] = T_OBJECT_OPERATOR;
109-
$nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true);
110-
if ($tokens[$nextToken]['code'] === T_FUNCTION
111-
|| $tokens[$nextToken]['code'] === T_CLOSURE
112-
|| $tokens[$nextToken]['code'] === T_OBJECT
113-
|| $tokens[$nextToken]['code'] === T_PROTOTYPE
114-
) {
115-
return;
116-
}
117-
}
118-
119102
$prevToken = $phpcsFile->findPrevious(
120103
Tokens::$emptyTokens,
121104
($stackPtr - 1),
@@ -127,8 +110,7 @@ public function process(File $phpcsFile, $stackPtr)
127110
return;
128111
}
129112

130-
// Inline doc blocks are allowed in JSDoc.
131-
if ($tokens[$stackPtr]['content'] === '/**' && $phpcsFile->tokenizerType !== 'JS') {
113+
if ($tokens[$stackPtr]['content'] === '/**') {
132114
// The only exception to inline doc blocks is the /** @var */
133115
// declaration. Allow that in any form.
134116
$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)
155137
if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) {
156138
return;
157139
}
158-
159-
// Special case for JS files.
160-
if ($tokens[$previousContent]['code'] === T_COMMA
161-
|| $tokens[$previousContent]['code'] === T_SEMICOLON
162-
) {
163-
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true);
164-
if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
165-
return;
166-
}
167-
}
168140
}
169141

170142
// Only want inline comments.

0 commit comments

Comments
 (0)