Skip to content

Commit 94737f0

Browse files
committed
don't use deprecated sniff, not fixable by users
1 parent db603af commit 94737f0

File tree

5 files changed

+46
-138
lines changed

5 files changed

+46
-138
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ jobs:
8484
# core is updated to that version.
8585
run: |
8686
cd drupal/core
87-
../../vendor/bin/phpcs -p -s --exclude=Drupal.Commenting.FunctionComment,Drupal.Strings.UnnecessaryStringConcat --ignore=lib/Drupal/Core/Entity/EntityType.php,lib/Drupal/Core/Recipe/RecipeInputFormTrait.php,lib/Drupal/Core/Form/FormState.php,modules/migrate/src/Plugin/Migration.php,modules/views/src/ViewExecutable.php,modules/views/src/Plugin/views/style/StylePluginBase.php,core/lib/Drupal/Core/FileTransfer/FTP.php,core/lib/Drupal/Core/FileTransfer/SSH.php,modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php,modules/views/src/Plugin/views/pager/PagerPluginBase.php,lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderInterface.php
87+
../../vendor/bin/phpcs -p -s --exclude=Drupal.Commenting.FunctionComment --ignore=lib/Drupal/Core/Entity/EntityType.php,lib/Drupal/Core/Recipe/RecipeInputFormTrait.php,lib/Drupal/Core/Form/FormState.php,modules/migrate/src/Plugin/Migration.php,modules/views/src/ViewExecutable.php,modules/views/src/Plugin/views/style/StylePluginBase.php,core/lib/Drupal/Core/FileTransfer/FTP.php,core/lib/Drupal/Core/FileTransfer/SSH.php,modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php,modules/views/src/Plugin/views/pager/PagerPluginBase.php,lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderInterface.php

coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php

Lines changed: 9 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
namespace Drupal\Sniffs\CSS;
1111

1212
use PHP_CodeSniffer\Files\File;
13-
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
1413
use PHP_CodeSniffer\Sniffs\Sniff;
15-
use PHP_CodeSniffer\Util\Tokens;
1614

1715
/**
18-
* Ensure there are no blank lines between the names of classes/IDs. Copied from
19-
* \PHP_CodeSniffer\Standards\Squiz\Sniffs\CSS\ClassDefinitionNameSpacingSniff
20-
* 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.
2121
*
2222
* @deprecated in Coder 8.3.30 and will be removed in Coder 9.0.0. Checking CSS
2323
* coding standards is not supported anymore, use Stylelint instead with the
@@ -28,16 +28,9 @@
2828
* @package PHP_CodeSniffer
2929
* @link http://pear.php.net/package/PHP_CodeSniffer
3030
*/
31-
class ClassDefinitionNameSpacingSniff implements Sniff, DeprecatedSniff
31+
class ClassDefinitionNameSpacingSniff implements Sniff
3232
{
3333

34-
/**
35-
* A list of tokenizers this sniff supports.
36-
*
37-
* @var array<string>
38-
*/
39-
public $supportedTokenizers = ['CSS'];
40-
4134

4235
/**
4336
* Returns the token types that this sniff is interested in.
@@ -46,7 +39,7 @@ class ClassDefinitionNameSpacingSniff implements Sniff, DeprecatedSniff
4639
*/
4740
public function register()
4841
{
49-
return [T_OPEN_CURLY_BRACKET];
42+
return [T_OPEN_TAG];
5043

5144
}//end register()
5245

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

14461
}//end process()
14562

coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
namespace Drupal\Sniffs\CSS;
1111

1212
use PHP_CodeSniffer\Files\File;
13-
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
1413
use PHP_CodeSniffer\Sniffs\Sniff;
1514

1615
/**
17-
* \Drupal\Sniffs\CSS\ColourDefinitionSniff.
16+
* Disabled sniff. Previously ensured that colors are defined in lower-case.
1817
*
19-
* Ensure colors are defined in lower-case.
18+
* We cannot implement DeprecatedSniff here because that would show deprecation
19+
* messages to Coder users although they cannot fix them.
2020
*
2121
* @deprecated in Coder 8.3.30 and will be removed in Coder 9.0.0. Checking CSS
2222
* coding standards is not supported anymore, use Stylelint instead with the
@@ -27,16 +27,9 @@
2727
* @package PHP_CodeSniffer
2828
* @link http://pear.php.net/package/PHP_CodeSniffer
2929
*/
30-
class ColourDefinitionSniff implements Sniff, DeprecatedSniff
30+
class ColourDefinitionSniff implements Sniff
3131
{
3232

33-
/**
34-
* A list of tokenizers this sniff supports.
35-
*
36-
* @var array<string>
37-
*/
38-
public $supportedTokenizers = ['CSS'];
39-
4033

4134
/**
4235
* Returns the token types that this sniff is interested in.
@@ -45,7 +38,7 @@ class ColourDefinitionSniff implements Sniff, DeprecatedSniff
4538
*/
4639
public function register()
4740
{
48-
return [T_COLOUR];
41+
return [T_OPEN_TAG];
4942

5043
}//end register()
5144

@@ -61,21 +54,8 @@ public function register()
6154
*/
6255
public function process(File $phpcsFile, $stackPtr)
6356
{
64-
$tokens = $phpcsFile->getTokens();
65-
$color = $tokens[$stackPtr]['content'];
66-
67-
$expected = strtolower($color);
68-
if ($color !== $expected) {
69-
$error = 'CSS colors must be defined in lowercase; expected %s but found %s';
70-
$data = [
71-
$expected,
72-
$color,
73-
];
74-
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotLower', $data);
75-
if ($fix === true) {
76-
$phpcsFile->fixer->replaceToken($stackPtr, $expected);
77-
}
78-
}
57+
// This sniff is deprecated and disabled - do nothing.
58+
return ($phpcsFile->numTokens + 1);
7959

8060
}//end process()
8161

coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,53 @@
99

1010
namespace Drupal\Sniffs\Strings;
1111

12-
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
13-
use PHP_CodeSniffer\Standards\Generic\Sniffs\Strings\UnnecessaryStringConcatSniff as GenericUnnecessaryStringConcatSniff;
12+
use PHP_CodeSniffer\Files\File;
13+
use PHP_CodeSniffer\Sniffs\Sniff;
1414

1515
/**
1616
* Checks that two strings are not concatenated together; suggests using one string instead.
1717
*
18+
* We cannot implement DeprecatedSniff here because that would show deprecation
19+
* messages to Coder users although they cannot fix them.
20+
*
1821
* @deprecated in Coder 8.3.30 and will be removed in Coder 9.0.0. Use
1922
* Generic.Strings.UnnecessaryStringConcat instead.
2023
*
2124
* @category PHP
2225
* @package PHP_CodeSniffer
2326
* @link http://pear.php.net/package/PHP_CodeSniffer
2427
*/
25-
class UnnecessaryStringConcatSniff extends GenericUnnecessaryStringConcatSniff implements DeprecatedSniff
28+
class UnnecessaryStringConcatSniff implements Sniff
2629
{
2730

2831

32+
/**
33+
* Returns the token types that this sniff is interested in.
34+
*
35+
* @return array<int, int|string>
36+
*/
37+
public function register()
38+
{
39+
return [T_OPEN_TAG];
40+
41+
}//end register()
42+
43+
2944
/**
30-
* If true, strings concatenated over multiple lines are allowed.
45+
* Processes the tokens that this sniff is interested in.
3146
*
32-
* Useful if you break strings over multiple lines to work
33-
* within a max line length.
47+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
48+
* @param int $stackPtr The position in the stack where
49+
* the token was found.
3450
*
35-
* @var boolean
51+
* @return void
3652
*/
37-
public $allowMultiline = true;
53+
public function process(File $phpcsFile, $stackPtr)
54+
{
55+
// This sniff is deprecated and disabled - do nothing.
56+
return ($phpcsFile->numTokens + 1);
57+
58+
}//end process()
3859

3960

4061
/**

coder_sniffer/Drupal/ruleset.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,12 @@
2424
</rule>
2525

2626
<!-- Silence deprecated sniffs that will be removed in Coder 9.x. -->
27-
<rule ref="Drupal.CSS.ClassDefinitionNameSpacing">
28-
<severity>0</severity>
29-
</rule>
30-
<!-- cspell:ignore Colour -->
31-
<rule ref="Drupal.CSS.ColourDefinition">
32-
<severity>0</severity>
33-
</rule>
3427
<rule ref="Drupal.Functions.FunctionDeclaration.SpaceAfter">
3528
<severity>0</severity>
3629
</rule>
3730
<rule ref="Drupal.Functions.FunctionDeclaration.SpaceBeforeParenthesis">
3831
<severity>0</severity>
3932
</rule>
40-
<rule ref="Drupal.Strings.UnnecessaryStringConcat">
41-
<severity>0</severity>
42-
</rule>
4333

4434
<!-- Silence method name underscore warning which is covered already in
4535
Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps. -->

0 commit comments

Comments
 (0)