Skip to content

Commit 7c268d0

Browse files
authored
refactor(VariableAnalysis): Replace sniff with upstream sniff (#3553265)
1 parent 2433a7b commit 7c268d0

File tree

9 files changed

+105
-259
lines changed

9 files changed

+105
-259
lines changed

.github/workflows/testing.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ jobs:
9292
find . -type f -exec sed -i '/\/\/ phpcs:ignore/ s/, /,/g' {} +
9393
find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreStart#// phpcs:disable#g' {} +
9494
find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreEnd#// phpcs:enable#g' {} +
95+
sed -i '/<rule ref="Drupal.Functions.FunctionDeclaration"\/>/d' phpcs.xml.dist
96+
sed -i 's/DrupalPractice.CodeAnalysis.VariableAnalysis/VariableAnalysis.CodeAnalysis.VariableAnalysis/g' phpcs.xml.dist
97+
find .. -type f -name "*.php" -exec sed -i 's#// phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis#// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis#g' {} +
9598
../../vendor/bin/phpcs -p -s --parallel=$(nproc) --ignore=lib/Drupal/Core/Command/GenerateTheme.php,modules/mysql/tests/src/Kernel/mysql/Console/DbDumpCommandTest.php

coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php

Lines changed: 0 additions & 70 deletions
This file was deleted.

coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php

Lines changed: 0 additions & 97 deletions
This file was deleted.

coder_sniffer/Drupal/ruleset.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@
2323
<exclude-pattern>*.tpl.php</exclude-pattern>
2424
</rule>
2525

26-
<!-- Silence deprecated sniffs that will be removed in Coder 9.x. -->
27-
<rule ref="Drupal.Functions.FunctionDeclaration.SpaceAfter">
28-
<severity>0</severity>
29-
</rule>
30-
<rule ref="Drupal.Functions.FunctionDeclaration.SpaceBeforeParenthesis">
31-
<severity>0</severity>
32-
</rule>
33-
3426
<!-- Silence method name underscore warning which is covered already in
3527
Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps. -->
3628
<rule ref="Drupal.Methods.MethodDeclaration.Underscore">

coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

coder_sniffer/DrupalPractice/ruleset.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
<exclude-pattern>*</exclude-pattern>
1111
</rule>
1212

13-
<rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis">
13+
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
1414
<!-- Do not run this sniff on template files. -->
1515
<exclude-pattern>*.tpl.php</exclude-pattern>
1616
<properties>
1717
<property name="allowUnusedFunctionParameters" value="true"/>
1818
</properties>
1919
</rule>
20-
<rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable">
20+
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable">
2121
<severity>0</severity>
2222
</rule>
2323

tests/DrupalPractice/CodeAnalysis/VariableAnalysisUnitTest.php

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Unit test class for all bad files.
4+
*/
5+
6+
namespace DrupalPractice\Test\bad;
7+
8+
use Drupal\Test\CoderSniffUnitTest;
9+
10+
/**
11+
* Unit test class for all bad files.
12+
*/
13+
class BadUnitTest extends CoderSniffUnitTest
14+
{
15+
16+
17+
/**
18+
* Returns the lines where errors should occur.
19+
*
20+
* The key of the array should represent the line number and the value
21+
* should represent the number of errors that should occur on that line.
22+
*
23+
* @param string $testFile The name of the file being tested.
24+
*
25+
* @return array<int, int>
26+
*/
27+
protected function getErrorList(string $testFile): array
28+
{
29+
return [];
30+
31+
}//end getErrorList()
32+
33+
34+
/**
35+
* Returns the lines where warnings should occur.
36+
*
37+
* The key of the array should represent the line number and the value
38+
* should represent the number of warnings that should occur on that line.
39+
*
40+
* @param string $testFile The name of the file being tested.
41+
*
42+
* @return array<int, int>
43+
*/
44+
protected function getWarningList(string $testFile): array
45+
{
46+
switch ($testFile) {
47+
case 'VariableAnalysisUnitTest.inc':
48+
return [
49+
4 => 1,
50+
8 => 1,
51+
17 => 1,
52+
61 => 1,
53+
];
54+
}
55+
56+
return [];
57+
58+
}//end getWarningList()
59+
60+
61+
/**
62+
* Returns a list of test files that should be checked.
63+
*
64+
* @param string $testFileBase The base path that the unit tests files will have.
65+
*
66+
* @return array<string>
67+
*/
68+
protected function getTestFiles($testFileBase): array
69+
{
70+
$di = new \DirectoryIterator(__DIR__);
71+
$testFiles = [];
72+
73+
foreach ($di as $file) {
74+
$path = $file->getPathname();
75+
if ($path !== __FILE__ && $file->isFile() === true && preg_match('/\.fixed$/', $path) !== 1) {
76+
$testFiles[] = $path;
77+
}
78+
}
79+
80+
// Get them in order.
81+
sort($testFiles);
82+
return $testFiles;
83+
84+
}//end getTestFiles()
85+
86+
87+
/**
88+
* False if just the current sniff should be checked, true if all sniffs should be checked.
89+
*
90+
* @return bool
91+
*/
92+
protected function checkAllSniffCodes()
93+
{
94+
// We want to test all sniffs defined in the standard.
95+
return true;
96+
97+
}//end checkAllSniffCodes()
98+
99+
100+
}//end class

0 commit comments

Comments
 (0)