From 9264a972f0cdd641697d0e3281d73e0aed22e57d Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 26 Oct 2025 16:47:06 +0100 Subject: [PATCH 1/8] refactor(ClassFileName): Use upstream Squiz ClassFileName sniff directly --- .../Sniffs/Classes/ClassFileNameSniff.php | 90 -- coder_sniffer/Drupal/ruleset.xml | 1 + .../Drupal/Classes/ClassFileNameUnitTest.php | 69 -- .../drupal7/class_file_name_test.module | 5 - tests/Drupal/Classes/drupal7/drupal7.info | 1 - .../Classes/drupal8/ClassFileNameUnitTest.php | 5 - .../Drupal/Classes/drupal8/drupal8.behat.inc | 10 - tests/Drupal/Classes/drupal8/drupal8.info.yml | 2 - tests/Drupal/Classes/drupal8/markdownFile.md | 11 - tests/Drupal/bad/BadUnitTest.php | 4 + .../bad/ClassCreateInstanceUnitTest.inc | 2 +- .../bad/ClassCreateInstanceUnitTest.inc.fixed | 2 +- .../Drupal/bad/UnusedUseStatementUnitTest.inc | 2 +- .../bad/UnusedUseStatementUnitTest.inc.fixed | 2 +- tests/Drupal/good/GoodAlignment.php | 24 + tests/Drupal/good/GoodAnnotation.php | 20 + tests/Drupal/good/GoodAttributeNamespace.php | 33 + tests/Drupal/good/GoodClass.php | 103 +++ tests/Drupal/good/GoodClassOperator.php | 23 + tests/Drupal/good/GoodClassProperty.php | 15 + tests/Drupal/good/GoodCoversTag.php | 16 + tests/Drupal/good/GoodDeprecation.php | 19 + tests/Drupal/good/GoodDocBlock.php | 236 +++++ tests/Drupal/good/GoodDocBlockIgnore.php | 78 ++ tests/Drupal/good/GoodEnum.php | 9 + tests/Drupal/good/GoodEnumNameIgnore.php | 10 + tests/Drupal/good/GoodException.php | 6 + tests/Drupal/good/GoodHookAttribute.php | 19 + tests/Drupal/good/GoodInterface.php | 6 + tests/Drupal/good/GoodLongAnnotation.php | 53 ++ tests/Drupal/good/GoodNestedArray.php | 31 + tests/Drupal/good/GoodPhpAttributes.php | 21 + tests/Drupal/good/GoodReferenceDocs.php | 50 ++ tests/Drupal/good/good.php | 818 +----------------- 34 files changed, 782 insertions(+), 1014 deletions(-) delete mode 100644 coder_sniffer/Drupal/Sniffs/Classes/ClassFileNameSniff.php delete mode 100644 tests/Drupal/Classes/ClassFileNameUnitTest.php delete mode 100644 tests/Drupal/Classes/drupal7/class_file_name_test.module delete mode 100644 tests/Drupal/Classes/drupal7/drupal7.info delete mode 100644 tests/Drupal/Classes/drupal8/ClassFileNameUnitTest.php delete mode 100644 tests/Drupal/Classes/drupal8/drupal8.behat.inc delete mode 100644 tests/Drupal/Classes/drupal8/drupal8.info.yml delete mode 100644 tests/Drupal/Classes/drupal8/markdownFile.md create mode 100644 tests/Drupal/good/GoodAlignment.php create mode 100644 tests/Drupal/good/GoodAnnotation.php create mode 100644 tests/Drupal/good/GoodAttributeNamespace.php create mode 100644 tests/Drupal/good/GoodClass.php create mode 100644 tests/Drupal/good/GoodClassOperator.php create mode 100644 tests/Drupal/good/GoodClassProperty.php create mode 100644 tests/Drupal/good/GoodCoversTag.php create mode 100644 tests/Drupal/good/GoodDeprecation.php create mode 100644 tests/Drupal/good/GoodDocBlock.php create mode 100644 tests/Drupal/good/GoodDocBlockIgnore.php create mode 100644 tests/Drupal/good/GoodEnum.php create mode 100644 tests/Drupal/good/GoodEnumNameIgnore.php create mode 100644 tests/Drupal/good/GoodException.php create mode 100644 tests/Drupal/good/GoodHookAttribute.php create mode 100644 tests/Drupal/good/GoodInterface.php create mode 100644 tests/Drupal/good/GoodLongAnnotation.php create mode 100644 tests/Drupal/good/GoodNestedArray.php create mode 100644 tests/Drupal/good/GoodPhpAttributes.php create mode 100644 tests/Drupal/good/GoodReferenceDocs.php diff --git a/coder_sniffer/Drupal/Sniffs/Classes/ClassFileNameSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/ClassFileNameSniff.php deleted file mode 100644 index 6610d43d..00000000 --- a/coder_sniffer/Drupal/Sniffs/Classes/ClassFileNameSniff.php +++ /dev/null @@ -1,90 +0,0 @@ - - */ - public function register() - { - return [ - T_CLASS, - T_INTERFACE, - T_TRAIT, - T_ENUM, - ]; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @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. - * - * @return int - */ - public function process(File $phpcsFile, $stackPtr) - { - // This check only applies to Drupal 8+, in Drupal 7 we can have classes - // in all kinds of files. - if (Project::getCoreVersion($phpcsFile) < 8) { - return ($phpcsFile->numTokens + 1); - } - - $fullPath = basename($phpcsFile->getFilename()); - $fileName = substr($fullPath, 0, strrpos($fullPath, '.')); - if ($fileName === '') { - // No filename probably means STDIN, so we can't do this check. - return ($phpcsFile->numTokens + 1); - } - - // If the file is not a php file, we do not care about how it looks, - // since we care about psr-4. - $extension = pathinfo($fullPath, PATHINFO_EXTENSION); - if ($extension !== 'php') { - return ($phpcsFile->numTokens + 1); - } - - $tokens = $phpcsFile->getTokens(); - $decName = $phpcsFile->findNext(Tokens::EMPTY_TOKENS, ($stackPtr + 1), null, true); - - if ($tokens[$decName]['code'] === T_STRING - && $tokens[$decName]['content'] !== $fileName - ) { - $error = '%s name doesn\'t match filename; expected "%s %s"'; - $data = [ - ucfirst($tokens[$stackPtr]['content']), - $tokens[$stackPtr]['content'], - $fileName, - ]; - $phpcsFile->addError($error, $stackPtr, 'NoMatch', $data); - } - - // Only check the first class in a file, we don't care about helper - // classes in tests for example. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/coder_sniffer/Drupal/ruleset.xml b/coder_sniffer/Drupal/ruleset.xml index 80b5f683..1330263f 100644 --- a/coder_sniffer/Drupal/ruleset.xml +++ b/coder_sniffer/Drupal/ruleset.xml @@ -186,6 +186,7 @@ + diff --git a/tests/Drupal/Classes/ClassFileNameUnitTest.php b/tests/Drupal/Classes/ClassFileNameUnitTest.php deleted file mode 100644 index c1fd3269..00000000 --- a/tests/Drupal/Classes/ClassFileNameUnitTest.php +++ /dev/null @@ -1,69 +0,0 @@ - - */ - protected function getErrorList(string $testFile): array - { - switch ($testFile) { - case 'ClassFileNameUnitTest.php': - return [3 => 1]; - } - - return []; - - }//end getErrorList() - - - /** - * Returns the lines where warnings should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - protected function getWarningList(string $testFile): array - { - return []; - - }//end getWarningList() - - - /** - * Returns a list of test files that should be checked. - * - * @param string $testFileBase The base path that the unit tests files will have. - * - * @return array - */ - protected function getTestFiles($testFileBase): array - { - return [ - __DIR__.'/drupal8/ClassFileNameUnitTest.php', - __DIR__.'/drupal8/drupal8.behat.inc', - __DIR__.'/drupal7/class_file_name_test.module', - __DIR__.'/drupal8/markdownFile.md', - ]; - - }//end getTestFiles() - - -}//end class diff --git a/tests/Drupal/Classes/drupal7/class_file_name_test.module b/tests/Drupal/Classes/drupal7/class_file_name_test.module deleted file mode 100644 index 1f142a1e..00000000 --- a/tests/Drupal/Classes/drupal7/class_file_name_test.module +++ /dev/null @@ -1,5 +0,0 @@ - 1, 98 => 1, ]; + case 'WrongClassName.php': + return [ + 6 => 1, + ]; }//end switch return []; diff --git a/tests/Drupal/bad/ClassCreateInstanceUnitTest.inc b/tests/Drupal/bad/ClassCreateInstanceUnitTest.inc index d6ba42e9..915f6b57 100644 --- a/tests/Drupal/bad/ClassCreateInstanceUnitTest.inc +++ b/tests/Drupal/bad/ClassCreateInstanceUnitTest.inc @@ -18,7 +18,7 @@ $bar = new $foo[$x + 1][$y + 1]; /** * Test class. */ -class Test2 { +class ClassCreateInstanceUnitTest { /** * Using PHP 7 return type hints is fine. diff --git a/tests/Drupal/bad/ClassCreateInstanceUnitTest.inc.fixed b/tests/Drupal/bad/ClassCreateInstanceUnitTest.inc.fixed index f0db1660..db58a59c 100644 --- a/tests/Drupal/bad/ClassCreateInstanceUnitTest.inc.fixed +++ b/tests/Drupal/bad/ClassCreateInstanceUnitTest.inc.fixed @@ -21,7 +21,7 @@ $bar = new $foo[$x + 1][$y + 1](); /** * Test class. */ -class Test2 { +class ClassCreateInstanceUnitTest { /** * Using PHP 7 return type hints is fine. diff --git a/tests/Drupal/bad/UnusedUseStatementUnitTest.inc b/tests/Drupal/bad/UnusedUseStatementUnitTest.inc index ec4124aa..e2252dbe 100644 --- a/tests/Drupal/bad/UnusedUseStatementUnitTest.inc +++ b/tests/Drupal/bad/UnusedUseStatementUnitTest.inc @@ -25,7 +25,7 @@ use Some\Data\Test10; /** * Bla. */ -class Pum { +class UnusedUseStatementUnitTest { use TraitTest; use Test\AnotherTrait; diff --git a/tests/Drupal/bad/UnusedUseStatementUnitTest.inc.fixed b/tests/Drupal/bad/UnusedUseStatementUnitTest.inc.fixed index 93b5fe68..8ec3a968 100644 --- a/tests/Drupal/bad/UnusedUseStatementUnitTest.inc.fixed +++ b/tests/Drupal/bad/UnusedUseStatementUnitTest.inc.fixed @@ -12,7 +12,7 @@ use MyNamespace\Depth\SomeClass as CoreSomeClass; /** * Bla. */ -class Pum { +class UnusedUseStatementUnitTest { use TraitTest; use Test\AnotherTrait; diff --git a/tests/Drupal/good/GoodAlignment.php b/tests/Drupal/good/GoodAlignment.php new file mode 100644 index 00000000..c9f9f242 --- /dev/null +++ b/tests/Drupal/good/GoodAlignment.php @@ -0,0 +1,24 @@ + 'change', + ] +)] +class GoodAttributeNamespace extends StateActionBase { + + /** + * Partial names are ok in attributes for now. + */ + #[Assert\NotBlank] + private bool $bar; + + /** + * Partially qualified names are ok in attributes for now. + */ + #[CLI\Command( + name: 'example', + aliases: ['example-foo'] + )] + #[CLI\Option(name: 'pretty_format', description: 'Display the count in pretty format.')] + public function test(array $options = ['pretty-format' => TRUE]): void { + } + +} diff --git a/tests/Drupal/good/GoodClass.php b/tests/Drupal/good/GoodClass.php new file mode 100644 index 00000000..b6022edb --- /dev/null +++ b/tests/Drupal/good/GoodClass.php @@ -0,0 +1,103 @@ +foo++; + $this->foo--; + --$this->foo; + ++$this->foo; + } + + /** + * It is allowed to leave out param docs on methods. + */ + public function noParamDocs($a, $b) { + + } + + /** + * Param comments with references are found correctly. + * + * @param string $a + * Parameter one. + * @param array $b + * Parameter two. + */ + public function test($a, array &$b) { + + } + +} diff --git a/tests/Drupal/good/GoodClassOperator.php b/tests/Drupal/good/GoodClassOperator.php new file mode 100644 index 00000000..2d47639a --- /dev/null +++ b/tests/Drupal/good/GoodClassOperator.php @@ -0,0 +1,23 @@ +entity; + /** @var \Drupal\node\NodeInterface[] $nodes */ + $nodes = foo(); + /** @var \Drupal\node\NodeInterface|\PHPUnit_Framework_MockObject_MockObject $node_mock */ + $node_mock = mock_node(); + /** @var \Drupal\SomeInterface4You $thing */ + $thing = thing(); + /** @var \Drupal\SomeInterface4You $test2 */ + $test2 = test2(); + return $node; + } + + /** + * {@inheritdoc} + * + * Some additional documentation here. + */ + public function test2() {} + + /** + * Return docs are allowed to use $this. + * + * @return $this + * This object for chaining method calls. + */ + public function test3() { + return $this; + } + + /** + * Returns the string representatuion of this object. + */ + public function __toString() { + return 'foo'; + } + + /** + * Omitting the comment when returning $this is allowed. + * + * @return $this + */ + public function test4() { + return $this; + } + + /** + * Omitting the comment when returning static is allowed. + * + * @return static + */ + public function test41() { + return new static(); + } + + /** + * Loads multiple string objects. + * + * @param array $conditions + * Any of the conditions used by dbStringSelect(). + * @param array $options + * Any of the options used by dbStringSelect(). + * @param string $class + * Class name to use for fetching returned objects. + * + * @return \Drupal\locale\StringInterface[] + * Array of objects of the class requested. + */ + protected function dbStringLoad(array $conditions, array $options, $class) { + $strings = []; + $result = $this->dbStringSelect($conditions, $options)->execute(); + foreach ($result as $item) { + /** @var \Drupal\locale\StringInterface $string */ + $string = new $class($item); + $string->setStorage($this); + $strings[] = $string; + } + return $strings; + } + + /** + * Short array syntax is allowed. + */ + public function getConfiguration() { + return [ + 'id' => $this->getPluginId(), + ] + $this->configuration; + } + + /** + * Not documenting a "throws" tag is allowed. + * + * This should not fail for errors with underscores in names as well. + * The second version of this test with error name with underscores + * is added below. + * + * @throws Exception + */ + public function test6() { + throw new Exception(); + } + + /** + * Repeat of above test with error name with underscores. + * + * @throws \Twig_Error_Syntax + */ + public function test7() { + throw new Exception(); + } + + /** + * {@inheritDoc} + */ + public function test8() {} + + /** + * Orders the result set by a given field. + * + * If called multiple times, the query will order by each specified field in + * the order this method is called. + * + * If the query uses DISTINCT or GROUP BY conditions, fields or expressions + * that are used for the order must be selected to be compatible with some + * databases like PostgreSQL. The PostgreSQL driver can handle simple cases + * automatically but it is suggested to explicitly specify them. Additionally, + * when ordering on an alias, the alias must be added before orderBy() is + * called. + * + * @param string $field + * The field on which to order. The field is escaped for security so only + * valid field and alias names are possible. To order by an expression, add + * the expression with addExpression() first and then use the alias to order + * on. + * + * Example: + * @code + * $query->addExpression('SUBSTRING(thread, 1, (LENGTH(thread) - 1))', 'order_field'); + * $query->orderBy('order_field', 'ASC'); + * @endcode + * @param string $direction + * The direction to sort. Legal values are "ASC" and "DESC". Any other value + * will be converted to "ASC". + * + * @return \Drupal\Core\Database\Query\SelectInterface + * The called object. + */ + public function orderBy($field, $direction = 'ASC') { + return $this; + } + + /** + * Example with multiple code blocks in param docs. + * + * @param string $param1 + * Just some Example param. + * @param ... + * Any additional arguments are passed on to the functions called by + * self::submitForm(), including the unique form constructor function. + * For example, the node_edit form requires that a node object be passed + * in here when it is called. Arguments that need to be passed by reference + * should not be included here, but rather placed directly in the + * $form_state build info array so that the reference can be preserved. For + * example, a form builder function with the following signature: + * @code + * function mymodule_form($form, FormStateInterface &$form_state, &$object) { + * } + * @endcode + * would be called via self::submitForm() as follows: + * @code + * $form_state->setValues($my_form_values); + * $form_state->addBuildInfo('args', [&$object]); + * \Drupal::formBuilder()->submitForm('mymodule_form', $form_state); + * @endcode + */ + public function test9($param1) {} + + /** + * This is an example of a doc block that is good. + * + * We want to show some example code: + * @code + * if ($something) { + * $x = $y; + * } + * @endcode + * Some more example code: + * @code + * if ($something) { + * $x = $y; + * } + * @endcode + * And one more piece of example code: + * @code + * if ($something) { + * $x = $y; + * } + * @endcode + * Followed by some summary text. + */ + public function test10() {} + + /** + * This is good. + * + * @return string + * Here is a comment, let's explain the return value with an example: + * @code + * if ($something) { + * $x = $y; + * } + * @endcode + * And then the comment goes on here. You want more code? Here you go: + * @code + * if ($something) { + * $x = $y; + * } + * @endcode + * And this is the end. + */ + public function test11() { + return 'foo'; + } + +} diff --git a/tests/Drupal/good/GoodDocBlockIgnore.php b/tests/Drupal/good/GoodDocBlockIgnore.php new file mode 100644 index 00000000..eb6ffa18 --- /dev/null +++ b/tests/Drupal/good/GoodDocBlockIgnore.php @@ -0,0 +1,78 @@ + 'checkboxes', + '#parents' => [$policyTypeKey, 'directives', $directiveName, 'flags', 'humans'], + '#options' => [ + 'unsafe-inline' => "'unsafe-inline'", + 'unsafe-eval' => "'unsafe-eval'", + 'unsafe-hashes' => "'unsafe-hashes'", + 'unsafe-allow-redirects' => "'unsafe-allow-redirects'", + 'strict-dynamic' => "'strict-dynamic'", + 'report-sample' => "'report-sample'", + ], + '#default_value' => $config->get($policyTypeKey . '.directives.' . $directiveName . '.flags') ?: [], + ]; + } + } + } + +} diff --git a/tests/Drupal/good/GoodPhpAttributes.php b/tests/Drupal/good/GoodPhpAttributes.php new file mode 100644 index 00000000..6e5684a9 --- /dev/null +++ b/tests/Drupal/good/GoodPhpAttributes.php @@ -0,0 +1,21 @@ +getTriggeringElement(); + $i = $trigger['#parents'][1]; + + $queues = $form_state->getValue('watch_queues', []); + $queues[$i]['to_remove'] = 1; + $form_state->setValue('watch_queues', $queues); + $this->rebuild($form_state, $form); + + drupal_set_message($this->t('Item will be removed permanently when configuration is saved.')); + return StatusMessages::renderMessages(NULL); + } + + /** + * Parameters described by reference are OK. + * + * @param Drupal\Core\Form\FormStateInterface $form_state + * The form state. + * @param array &$old_form + * The old form build. + * + * @return array + * The newly built form. + */ + protected function rebuild(FormStateInterface $form_state, array &$old_form) { + $form_state->setRebuild(); + $form = $this->formBuilder + ->rebuildForm($this->getFormId(), $form_state, $old_form); + return $form; + } + +} diff --git a/tests/Drupal/good/good.php b/tests/Drupal/good/good.php index 4e5d487d..1979f649 100644 --- a/tests/Drupal/good/good.php +++ b/tests/Drupal/good/good.php @@ -578,108 +578,6 @@ function foo_bar($field1, $field2, $field3 = NULL, &$field4 = NULL) { ] ); -/** - * Class declaration. - * - * Classes can have a multiline comment. - */ -class Bar { - - /** - * Private properties have no prefix. - * - * @var int - */ - private $secret = 1; - - /** - * Protected properties also don't have a prefix. - * - * @var int - */ - protected $foo = 1; - - /** - * Longer properties use camelCase naming. - * - * @var int - */ - public $barProperty = 1; - - /** - * Using property types is allowed. - * - * @var \Foo\Bar - */ - public ?Bar $bar; - - /** - * A typed property may omit @var. - */ - public Bar $baz; - - /** - * Public static variables use camelCase, too. - * - * @var string - */ - public static $basePath = NULL; - - /** - * {@inheritdoc} - */ - protected $modules = ['node', 'user']; - - /** - * {@inheritDoc} - */ - protected $allowedModules = ['node', 'user']; - - /** - * Enter description here ... - */ - public function foo() { - - } - - /** - * Enter description here ... - */ - protected function barMethod() { - - } - - /** - * Test the ++ and -- operator. - */ - public function incDecTest() { - $this->foo++; - $this->foo--; - --$this->foo; - ++$this->foo; - } - - /** - * It is allowed to leave out param docs on methods. - */ - public function noParamDocs($a, $b) { - - } - - /** - * Param comments with references are found correctly. - * - * @param string $a - * Parameter one. - * @param array $b - * Parameter two. - */ - public function test($a, array &$b) { - - } - -} - /** * Enter description here ... */ @@ -706,34 +604,6 @@ function _private_foo() { $i . $i; $i . NULL; -/** - * It is allowed to have the closing "}" on the same line if the class is empty. - */ -class MyException extends Exception {} - -/** - * Nice alignment is allowed for assignments. - */ -class MyExampleLog { - const INFO = 0; - const WARNING = 1; - const ERROR = 2; - const EMERGENCY = 3; - - /** - * Empty method implementation is allowed. - */ - public function emptyMethod() {} - - /** - * Protected functions are allowed. - */ - protected function protectedTest() { - - } - -} - /** * Nice allignment in functions. */ @@ -982,11 +852,6 @@ function mymodule_form_callback($form, &$form_state, Node $node) { preg_replace('@.+@i', 'replacement', 'subject'); preg_match("/test(\d+)/is", 'subject'); -/** - * Interfaces must have a comment block. - */ -interface MyWellNamedInterface {} - // Correctly formed try/catch block. try { do_something(); @@ -997,134 +862,7 @@ interface MyWellNamedInterface {} $result = $x ?: FALSE; -/** - * All classes need to have a docblock. - */ -class Foo implements FooInterface { - - /** - * {@inheritdoc} - */ - public function test() { - /** @var \Drupal\node\NodeInterface $node */ - $node = $this->entity; - /** @var \Drupal\node\NodeInterface[] $nodes */ - $nodes = foo(); - /** @var \Drupal\node\NodeInterface|\PHPUnit_Framework_MockObject_MockObject $node_mock */ - $node_mock = mock_node(); - /** @var \Drupal\SomeInterface4You $thing */ - $thing = thing(); - /** @var \Drupal\SomeInterface4You $test2 */ - $test2 = test2(); - return $node; - } - - /** - * {@inheritdoc} - * - * Some additional documentation here. - */ - public function test2() {} - - /** - * Return docs are allowed to use $this. - * - * @return $this - * This object for chaining method calls. - */ - public function test3() { - return $this; - } - - /** - * Returns the string representatuion of this object. - */ - public function __toString() { - return 'foo'; - } - - /** - * Omitting the comment when returning $this is allowed. - * - * @return $this - */ - public function test4() { - return $this; - } - - /** - * Omitting the comment when returning static is allowed. - * - * @return static - */ - public function test41() { - return new static(); - } - - /** - * Loads multiple string objects. - * - * @param array $conditions - * Any of the conditions used by dbStringSelect(). - * @param array $options - * Any of the options used by dbStringSelect(). - * @param string $class - * Class name to use for fetching returned objects. - * - * @return \Drupal\locale\StringInterface[] - * Array of objects of the class requested. - */ - protected function dbStringLoad(array $conditions, array $options, $class) { - $strings = []; - $result = $this->dbStringSelect($conditions, $options)->execute(); - foreach ($result as $item) { - /** @var \Drupal\locale\StringInterface $string */ - $string = new $class($item); - $string->setStorage($this); - $strings[] = $string; - } - return $strings; - } - - /** - * Short array syntax is allowed. - */ - public function getConfiguration() { - return [ - 'id' => $this->getPluginId(), - ] + $this->configuration; - } - - /** - * Not documenting a "throws" tag is allowed. - * - * This should not fail for errors with underscores in names as well. - * The second version of this test with error name with underscores - * is added below. - * - * @throws Exception - */ - public function test6() { - throw new Exception(); - } - - /** - * Repeat of above test with error name with underscores. - * - * @throws \Twig_Error_Syntax - */ - public function test7() { - throw new Exception(); - } - - /** - * {@inheritDoc} - */ - public function test8() {} - -} - -t('Some long mulit-line +t('Some long mulit-line text is weird, but allowed.'); // Anonymous functions should not throw indentation errors here. @@ -1199,33 +937,8 @@ function test7($x) { } -/** - * @coversDefaultClass \Drupal\rules\Plugin\Condition\ListContains - * @group rules_conditions - */ -class ListContainsTest extends RulesIntegrationTestBase {} - $x = 'Some markup text with allowed HTML5
tag'; -/** - * Provides a 'Delete any path alias' action. - * - * @todo Add access callback information from Drupal 7. - * @todo Add group information from Drupal 7. - * - * @Action( - * id = "rules_path_alias_delete", - * label = @Translation("Delete any path alias"), - * context = { - * "alias" = @ContextDefinition("string", - * label = @Translation("Existing system path alias"), - * description = @Translation("Specifies the existing path alias you wish to delete, for example 'about/team'. Use a relative path and do not add a trailing slash.") - * ) - * } - * ) - */ -class AliasDelete extends RulesActionBase implements ContainerFactoryPluginInterface {} - /** * Some comment with exclamation mark! * @@ -1310,93 +1023,6 @@ function test14(AliasedExampleClass $a) { } -/** - * Example annotation that exceeds 80 characters several times, but is valid. - * - * @ConfigEntityType( - * id = "rules_reaction_rule", - * label = @Translation("Reaction Rule"), - * handlers = { - * "storage" = "Drupal\rules\Entity\ReactionRuleStorage", - * "list_builder" = "Drupal\rules\Entity\Controller\RulesReactionListBuilder", - * "form" = { - * "add" = "\Drupal\rules\Entity\ReactionRuleAddForm", - * "edit" = "\Drupal\rules\Entity\ReactionRuleEditForm", - * "delete" = "\Drupal\Core\Entity\EntityDeleteForm" - * } - * }, - * admin_permission = "administer rules", - * config_prefix = "reaction", - * entity_keys = { - * "id" = "id", - * "label" = "label", - * "status" = "status" - * }, - * config_export = { - * "id", - * "label", - * "event", - * "module", - * "description", - * "tag", - * "core", - * "expression_id", - * "configuration", - * }, - * links = { - * "collection" = "/admin/config/workflow/rules", - * "edit-form" = "/admin/config/workflow/rules/reactions/edit/{rules_reaction_rule}", - * "delete-form" = "/admin/config/workflow/rules/reactions/delete/{rules_reaction_rule}" - * } - * ) - */ -class ReactionRule extends ConfigEntityBase { - - /** - * Config entities are allowed to have property names with underscores. - * - * @var string - */ - protected $expression_id; - -} - -/** - * Underscores are allowed in properties of config entity classes. - */ -class NodeType extends ConfigEntityBundleBase { - - /** - * Default value of the 'Create new revision' checkbox of this node type. - * - * @var bool - */ - protected $new_revision = TRUE; - -} - -/** - * Test class. - */ -class OperatorTest { - - /** - * Seen IDs. - * - * @var array - */ - protected static $seenIds; - - /** - * Test method. - */ - public function test() { - $id = $id . '--' . ++static::$seenIds[$id]; - return $id; - } - -} - // camelCase and snake_case variables are allowed. $snake_case = 1; $camelCase = 1; @@ -1538,20 +1164,6 @@ function mymodule_very_long_module_name_neverending_hook_name_that_is_a_long_cat } -/** - * @coversDefaultClass \Drupal\mymodule\Something - */ -class MyTest extends UnitTestBase { - - /** - * @covers ::foo - */ - public function testFoo() { - - } - -} - /** * Numbers in types are allowed. * @@ -1582,249 +1194,6 @@ function test24(Element ...$element) { } -/** - * Test class. - */ -class Test2 { - - /** - * Using PHP 7 return type hints is fine. - * - * @return ValidatorInterface[] - * The validators. - */ - public function getValidators(): array { - return [ - new PublishedNodesValidator(), - new MinimumNodesValidator($this->nrOfArticles), - new AccessibleOnCurrentDomainValidator($this->sectionService), - ]; - } - -} - -/** - * Another test. - */ -class Test3 { - - /** - * Parameters described by reference are OK. - * - * @param array &$form - * The form array. - * @param Drupal\Core\Form\FormStateInterface $form_state - * The form state. - * - * @return array - * A renderable array. - */ - public function removeQueueItem(array &$form, FormStateInterface $form_state) { - $trigger = $form_state->getTriggeringElement(); - $i = $trigger['#parents'][1]; - - $queues = $form_state->getValue('watch_queues', []); - $queues[$i]['to_remove'] = 1; - $form_state->setValue('watch_queues', $queues); - $this->rebuild($form_state, $form); - - drupal_set_message($this->t('Item will be removed permanently when configuration is saved.')); - return StatusMessages::renderMessages(NULL); - } - - /** - * Parameters described by reference are OK. - * - * @param Drupal\Core\Form\FormStateInterface $form_state - * The form state. - * @param array &$old_form - * The old form build. - * - * @return array - * The newly built form. - */ - protected function rebuild(FormStateInterface $form_state, array &$old_form) { - $form_state->setRebuild(); - $form = $this->formBuilder - ->rebuildForm($this->getFormId(), $form_state, $old_form); - return $form; - } - -} - -/** - * Long annotation lines over 80 characters are ok. - * - * @WebformHandler( - * id = "email", - * label = @Translation("Email"), - * category = @Translation("Notification"), - * description = @Translation("Sends a webform submission via an email."), - * cardinality = \Drupal\webform\WebformHandlerInterface::CARDINALITY_UNLIMITED, - * results = \Drupal\webform\WebformHandlerInterface::RESULTS_PROCESSED, - * ) - */ -class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMessageInterface { - -} - -/** - * Deprecation check. - * - * @deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. - * Switch off your television set and go and do something less boring instead. - * @see http://www.drupal.org/node/123 - */ -class Test4 { - - /** - * Check trigger_error format. - */ - public function testDeprecation() { - @trigger_error('Function testDeprecation() is deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Why Dont You. See http://www.drupal.org/node/123', E_USER_DEPRECATED); - } - -} - -/** - * Foo. - */ -interface Test5Interface { - - /** - * Orders the result set by a given field. - * - * If called multiple times, the query will order by each specified field in - * the order this method is called. - * - * If the query uses DISTINCT or GROUP BY conditions, fields or expressions - * that are used for the order must be selected to be compatible with some - * databases like PostgreSQL. The PostgreSQL driver can handle simple cases - * automatically but it is suggested to explicitly specify them. Additionally, - * when ordering on an alias, the alias must be added before orderBy() is - * called. - * - * @param string $field - * The field on which to order. The field is escaped for security so only - * valid field and alias names are possible. To order by an expression, add - * the expression with addExpression() first and then use the alias to order - * on. - * - * Example: - * @code - * $query->addExpression('SUBSTRING(thread, 1, (LENGTH(thread) - 1))', 'order_field'); - * $query->orderBy('order_field', 'ASC'); - * @endcode - * @param string $direction - * The direction to sort. Legal values are "ASC" and "DESC". Any other value - * will be converted to "ASC". - * - * @return \Drupal\Core\Database\Query\SelectInterface - * The called object. - */ - public function orderBy($field, $direction = 'ASC'); - - /** - * Example with multiple code blocks in param docs. - * - * @param string $param1 - * Just some Example param. - * @param ... - * Any additional arguments are passed on to the functions called by - * self::submitForm(), including the unique form constructor function. - * For example, the node_edit form requires that a node object be passed - * in here when it is called. Arguments that need to be passed by reference - * should not be included here, but rather placed directly in the - * $form_state build info array so that the reference can be preserved. For - * example, a form builder function with the following signature: - * @code - * function mymodule_form($form, FormStateInterface &$form_state, &$object) { - * } - * @endcode - * would be called via self::submitForm() as follows: - * @code - * $form_state->setValues($my_form_values); - * $form_state->addBuildInfo('args', [&$object]); - * \Drupal::formBuilder()->submitForm('mymodule_form', $form_state); - * @endcode - */ - public function test1($param1); - - /** - * This is an example of a doc block that is good. - * - * We want to show some example code: - * @code - * if ($something) { - * $x = $y; - * } - * @endcode - * Some more example code: - * @code - * if ($something) { - * $x = $y; - * } - * @endcode - * And one more piece of example code: - * @code - * if ($something) { - * $x = $y; - * } - * @endcode - * Followed by some summary text. - */ - public function test2(); - - /** - * This is good. - * - * @return string - * Here is a comment, let's explain the return value with an example: - * @code - * if ($something) { - * $x = $y; - * } - * @endcode - * And then the comment goes on here. You want more code? Here you go: - * @code - * if ($something) { - * $x = $y; - * } - * @endcode - * And this is the end. - */ - public function test3(); - -} - -/** - * Test PHP attributes. - */ -class TestPhpAttributes { - - /** - * Bar property. - */ - #[NotBlank] - private bool $bar; - - /** - * Tests method with PHP attribute and docblock. - */ - #[\ReturnTypeWillChange] - public function attributes(): void { - } - -} - -/** - * Enums must have a comment block. - */ -enum MyWellNamedEnum: int { - case One = 1; - case Two = 2; -} - // Allow longer than 80 character array definitions on one line (up to 120). if (!in_array($form_object->getOperation(), ['add', 'edit', 'delete', 'clone', 'default'], TRUE)) { return; @@ -1833,36 +1202,6 @@ enum MyWellNamedEnum: int { $foo->setContentTypeFacetValues($item, $entity_type, $content_type_facet_field); } -/** - * Testing nested array definitions going over 80 characters. - */ -class LongNestedArrayLine { - - /** - * Test method. - */ - public function foo() { - foreach ($x as $y) { - foreach ($a as $b) { - $form[$policyTypeKey]['directives'][$directiveName]['options']['flags_wrapper']['flags'] = [ - '#type' => 'checkboxes', - '#parents' => [$policyTypeKey, 'directives', $directiveName, 'flags', 'humans'], - '#options' => [ - 'unsafe-inline' => "'unsafe-inline'", - 'unsafe-eval' => "'unsafe-eval'", - 'unsafe-hashes' => "'unsafe-hashes'", - 'unsafe-allow-redirects' => "'unsafe-allow-redirects'", - 'strict-dynamic' => "'strict-dynamic'", - 'report-sample' => "'report-sample'", - ], - '#default_value' => $config->get($policyTypeKey . '.directives.' . $directiveName . '.flags') ?: [], - ]; - } - } - } - -} - // Allow array definition statements over 80 but under 120 characters. $form['strings'] = [ '#type' => 'table', @@ -1877,65 +1216,6 @@ public function foo() { '#attributes' => ['class' => ['locale-translate-edit-table']], ]; -/** - * Implements hook_cron(). - */ -#[Hook('cron')] -class CronHook { - - public function __construct( - private readonly EntityTypeManagerInterface $entityTypeManager, - private readonly StreamWrapperManagerInterface $streamWrapperManager, - private readonly ConfigFactoryInterface $configFactory, - private readonly FileUsageInterface $fileUsage, - private readonly TimeInterface $time, - #[Autowire('@logger.channel.file')] - private readonly LoggerInterface $logger, - ) {} - -} - -/** - * Doc block is here and an ignore directive is ok. - */ -// phpcs:ignore Drupal.NamingConventions.ValidClassName -enum PUROSELY_WRONG_BUT_OK: int { - case One = 1; - case Two = 2; -} - -/** - * Fully qualified class name is allowed in PHP attributes for now. - */ -#[\Drupal\action_link\Attribute\StateAction( - id: 'test_always', - label: new \Drupal\Core\StringTranslation\TranslatableMarkup('Test Always'), - description: new \Drupal\Core\StringTranslation\TranslatableMarkup('Test Always'), - directions: [ - 'change' => 'change', - ] -)] -class TestAlways extends StateActionBase { - - /** - * Partial names are ok in attributes for now. - */ - #[Assert\NotBlank] - private bool $bar; - - /** - * Partially qualified names are ok in attributes for now. - */ - #[CLI\Command( - name: 'example', - aliases: ['example-foo'] - )] - #[CLI\Option(name: 'pretty_format', description: 'Display the count in pretty format.')] - public function test(array $options = ['pretty-format' => TRUE]): void { - } - -} - /** * Doc block is here and an ignore directive is ok. */ @@ -1944,55 +1224,6 @@ function phpcs_ignore_comment() { } -/** - * Test class. - */ -class TestPlugin { - - /** - * Gets a fallback id for a missing plugin. - * - * This method should be implemented in extending classes that also implement - * FallbackPluginManagerInterface. It is called by - * PluginManagerBase::handlePluginNotFound on the abstract class, and - * therefore should be defined as well on the abstract class to prevent static - * analysis errors. - * - * @param string $plugin_id - * The ID of the missing requested plugin. - * @param array $configuration - * An array of configuration relevant to the plugin instance. - * - * phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn - * @return string - * The id of an existing plugin to use when the plugin does not exist. - * - * @throws \BadMethodCallException - * If the method is not implemented in the concrete plugin manager class. - */ - protected function getFallbackPluginId($plugin_id, array $configuration = []) { - throw new \BadMethodCallException(static::class . '::getFallbackPluginId() not implemented.'); - } - -} - -/** - * Provides a collection of condition plugins. - */ -class ConditionPluginCollection extends DefaultLazyPluginCollection { - - /** - * {@inheritdoc} - * - * phpcs:ignore Drupal.Commenting.FunctionComment.MissingReturnComment - * @return \Drupal\Core\Condition\ConditionInterface - */ - public function &get($instance_id) { - return 'x'; - } - -} - /** * Test for @phpstan-ignore-next-line. * @@ -2010,33 +1241,6 @@ public function ignore_phpstan_comment() { public function ignore_phpstan_comment_with_attribute_before() { } -/** - * Test PHPCS ignore comments between param docs. - */ -interface BreadcrumbBuilderInterface { - - /** - * Whether this breadcrumb builder should be used to build the breadcrumb. - * - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The current route match. - * phpcs:ignore Drupal.Commenting.FunctionComment.ParamNameNoMatch - * @param \Drupal\Core\Cache\CacheableMetadata $cacheable_metadata - * The cacheable metadata to add to if your check varies by or depends - * on something. Anything you specify here does not have to be repeated in - * the build() method as it will be merged in automatically. - * - * @return bool - * TRUE if this builder should be used or FALSE to let other builders - * decide. - * - * @todo Uncomment new method parameters before drupal:12.0.0, see - * https://www.drupal.org/project/drupal/issues/3459277. - */ - public function applies(RouteMatchInterface $route_match /* , CacheableMetadata $cacheable_metadata */); - -} - /** * Test that nested array types are ok. * @@ -2054,23 +1258,3 @@ function pdo_weird_return_type($param) { * Comments are allowed to end in 3 dots... */ function comment_test_dots() {} - -/** - * Executes the page caching before the main kernel takes over the request. - */ -class PageCache implements HttpKernelInterface { - - /** - * The wrapped HTTP kernel. - */ - protected \Closure $httpKernel; - - /** - * The entity for this result. - * - * @var \Drupal\Core\Entity\EntityInterface - */ - // phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName,PSR2.Classes.PropertyDeclaration.Underscore - public $_entity = NULL; - -} From 5c4657a2416983de71fcc4e0755b4ebd0176d4d1 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 26 Oct 2025 16:52:58 +0100 Subject: [PATCH 2/8] add errors detected now in bad files --- tests/Drupal/bad/BadUnitTest.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/Drupal/bad/BadUnitTest.php b/tests/Drupal/bad/BadUnitTest.php index dbf206df..ee457258 100644 --- a/tests/Drupal/bad/BadUnitTest.php +++ b/tests/Drupal/bad/BadUnitTest.php @@ -30,6 +30,7 @@ protected function getErrorList(string $testFile): array case 'bad_crlf.inc': return [ 1 => 1, + 7 => 1, 8 => 1, ]; case 'bad.info': @@ -245,7 +246,7 @@ protected function getErrorList(string $testFile): array 372 => 3, 375 => 1, 376 => 1, - 379 => 1, + 379 => 2, 383 => 1, 384 => 1, 385 => 1, @@ -265,15 +266,15 @@ protected function getErrorList(string $testFile): array 400 => 1, 401 => 1, 403 => 1, - 406 => 1, + 406 => 2, 407 => 3, 411 => 2, 417 => 1, 418 => 2, 421 => 1, 422 => 1, - 424 => 2, - 426 => 2, + 424 => 3, + 426 => 3, 428 => 1, 436 => 1, 438 => 1, @@ -341,7 +342,7 @@ protected function getErrorList(string $testFile): array 750 => 1, 756 => 1, 765 => 1, - 791 => 1, + 791 => 2, 795 => 4, 796 => 1, 799 => 1, @@ -352,13 +353,14 @@ protected function getErrorList(string $testFile): array 805 => 1, 806 => 1, 807 => 1, - 809 => 3, + 809 => 4, 815 => 1, 820 => 1, 827 => 1, 829 => 1, 836 => 1, - 838 => 3, + 838 => 4, + 844 => 1, 849 => 2, 860 => 2, 867 => 1, From 7b9bc1a47b697957bb22341877be2443f97e6468 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 26 Oct 2025 16:54:25 +0100 Subject: [PATCH 3/8] add test file --- tests/Drupal/bad/WrongClassName.php | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/Drupal/bad/WrongClassName.php diff --git a/tests/Drupal/bad/WrongClassName.php b/tests/Drupal/bad/WrongClassName.php new file mode 100644 index 00000000..c55627a5 --- /dev/null +++ b/tests/Drupal/bad/WrongClassName.php @@ -0,0 +1,6 @@ + Date: Sun, 26 Oct 2025 17:02:57 +0100 Subject: [PATCH 4/8] exclude test files --- phpcs.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 650e6c16..7a447046 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -7,7 +7,7 @@ tests/*\.(inc|api\.php|tpl\.php)$ - tests/*/(good|bad)\.php$ + tests/*/(good|bad)/*\.php$ tests/*/drupal(6|7|8)/*\.php$ From 7e0dcc088715eb510a9830abe42416c9b886eb97 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 26 Oct 2025 17:04:31 +0100 Subject: [PATCH 5/8] phpstan ignores --- phpstan.neon | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 1e13f20d..858fe568 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,8 +7,8 @@ parameters: # Test files that should not be checked. - 'tests/*/*.tpl.php' - 'tests/*/*.api.php' - - 'tests/*/good.php' - - 'tests/*/bad.php' + - 'tests/*/good/*.php' + - 'tests/*/bad/*.php' - 'tests/*/drupal[678]/*.php' bootstrapFiles: - tests/Drupal/phpunit-bootstrap.php From 50f92cded14454984b2408100e3ca1f534b65223 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 26 Oct 2025 17:08:00 +0100 Subject: [PATCH 6/8] fix core phpcs file --- .github/workflows/testing.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index a27c22b9..c971784a 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -86,6 +86,7 @@ jobs: sed -i 's/Drupal.Classes.ClassCreateInstance/SlevomatCodingStandard.ControlStructures.NewWithParentheses/g' phpcs.xml.dist sed -i 's/Drupal.Classes.UnusedUseStatement/SlevomatCodingStandard.Namespaces.UnusedUses/g' phpcs.xml.dist sed -i '//a \ ' phpcs.xml.dist + sed -i 's/Drupal.Classes.ClassFileName/Squiz.Classes.ClassFileName/g' phpcs.xml.dist find . -type f -name "*.php" -exec sed -i 's#// phpcs:ignore Drupal.Classes.PropertyDeclaration, Drupal.NamingConventions.ValidVariableName.LowerCamelName, Drupal.Commenting.VariableComment.Missing#// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName,PSR2.Classes.PropertyDeclaration.Underscore#g' {} + find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreLine#// phpcs:ignore#g' {} + find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreFile#// phpcs:ignoreFile#g' {} + From 0549a46e6cc4ca585cc991ba33df59f04ad73d1a Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 26 Oct 2025 17:46:07 +0100 Subject: [PATCH 7/8] change ignore to Test.hp classes --- .github/workflows/testing.yml | 2 +- coder_sniffer/Drupal/ruleset.xml | 5 ++++- tests/Drupal/good/GoodClassNameTest.php | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/Drupal/good/GoodClassNameTest.php diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index c971784a..78ca0b26 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -86,7 +86,7 @@ jobs: sed -i 's/Drupal.Classes.ClassCreateInstance/SlevomatCodingStandard.ControlStructures.NewWithParentheses/g' phpcs.xml.dist sed -i 's/Drupal.Classes.UnusedUseStatement/SlevomatCodingStandard.Namespaces.UnusedUses/g' phpcs.xml.dist sed -i '//a \ ' phpcs.xml.dist - sed -i 's/Drupal.Classes.ClassFileName/Squiz.Classes.ClassFileName/g' phpcs.xml.dist + sed -i 's||\n \n */tests/*/*Test.php\n |' phpcs.xml.dist find . -type f -name "*.php" -exec sed -i 's#// phpcs:ignore Drupal.Classes.PropertyDeclaration, Drupal.NamingConventions.ValidVariableName.LowerCamelName, Drupal.Commenting.VariableComment.Missing#// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName,PSR2.Classes.PropertyDeclaration.Underscore#g' {} + find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreLine#// phpcs:ignore#g' {} + find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreFile#// phpcs:ignoreFile#g' {} + diff --git a/coder_sniffer/Drupal/ruleset.xml b/coder_sniffer/Drupal/ruleset.xml index 1330263f..f18527ac 100644 --- a/coder_sniffer/Drupal/ruleset.xml +++ b/coder_sniffer/Drupal/ruleset.xml @@ -186,7 +186,10 @@ - + + + */tests/*/*Test.php + diff --git a/tests/Drupal/good/GoodClassNameTest.php b/tests/Drupal/good/GoodClassNameTest.php new file mode 100644 index 00000000..5cd2ffe3 --- /dev/null +++ b/tests/Drupal/good/GoodClassNameTest.php @@ -0,0 +1,6 @@ + Date: Sun, 26 Oct 2025 18:12:45 +0100 Subject: [PATCH 8/8] also ignore test base --- .github/workflows/testing.yml | 4 ++-- coder_sniffer/Drupal/ruleset.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 78ca0b26..cd81e041 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -86,7 +86,7 @@ jobs: sed -i 's/Drupal.Classes.ClassCreateInstance/SlevomatCodingStandard.ControlStructures.NewWithParentheses/g' phpcs.xml.dist sed -i 's/Drupal.Classes.UnusedUseStatement/SlevomatCodingStandard.Namespaces.UnusedUses/g' phpcs.xml.dist sed -i '//a \ ' phpcs.xml.dist - sed -i 's||\n \n */tests/*/*Test.php\n |' phpcs.xml.dist + sed -i 's@@\n \n */tests/*/*(Test|TestBase).php\n @' phpcs.xml.dist find . -type f -name "*.php" -exec sed -i 's#// phpcs:ignore Drupal.Classes.PropertyDeclaration, Drupal.NamingConventions.ValidVariableName.LowerCamelName, Drupal.Commenting.VariableComment.Missing#// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName,PSR2.Classes.PropertyDeclaration.Underscore#g' {} + find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreLine#// phpcs:ignore#g' {} + find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreFile#// phpcs:ignoreFile#g' {} + @@ -96,4 +96,4 @@ jobs: sed -i '//d' phpcs.xml.dist sed -i 's/DrupalPractice.CodeAnalysis.VariableAnalysis/VariableAnalysis.CodeAnalysis.VariableAnalysis/g' phpcs.xml.dist find .. -type f -name "*.php" -exec sed -i 's#// phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis#// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis#g' {} + - ../../vendor/bin/phpcs -p -s --parallel=$(nproc) --ignore=lib/Drupal/Core/Command/GenerateTheme.php,modules/mysql/tests/src/Kernel/mysql/Console/DbDumpCommandTest.php + ../../vendor/bin/phpcs -p -s --parallel=$(nproc) --ignore=lib/Drupal/Core/Command/GenerateTheme.php,modules/mysql/tests/src/Kernel/mysql/Console/DbDumpCommandTest.php,modules/big_pipe/tests/modules/big_pipe_test/src/BigPipePlaceholderTestCases.php,tests/fixtures/plugins/CustomPlugin.php,modules/package_manager/tests/modules/package_manager_test_api/src/ApiController.php diff --git a/coder_sniffer/Drupal/ruleset.xml b/coder_sniffer/Drupal/ruleset.xml index f18527ac..c2cc648d 100644 --- a/coder_sniffer/Drupal/ruleset.xml +++ b/coder_sniffer/Drupal/ruleset.xml @@ -188,7 +188,7 @@ - */tests/*/*Test.php + */tests/*/*(Test|TestBase).php