From 20014bdfa74ceef0e88faaa3bf06bef7a73122df Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 14 Sep 2023 04:46:51 +0200 Subject: [PATCH] Remove `NamespaceDeclaration` sniff in favour of similar from PHPCSExtra --- .../NamespaceDeclarationStandard.xml | 65 ----------- .../Namespaces/NamespaceDeclarationSniff.php | 110 ------------------ .../NamespaceDeclarationUnitTest.1.inc | 8 -- .../NamespaceDeclarationUnitTest.2.inc | 11 -- .../NamespaceDeclarationUnitTest.php | 49 -------- Yoast/ruleset.xml | 9 ++ 6 files changed, 9 insertions(+), 243 deletions(-) delete mode 100644 Yoast/Docs/Namespaces/NamespaceDeclarationStandard.xml delete mode 100644 Yoast/Sniffs/Namespaces/NamespaceDeclarationSniff.php delete mode 100644 Yoast/Tests/Namespaces/NamespaceDeclarationUnitTest.1.inc delete mode 100644 Yoast/Tests/Namespaces/NamespaceDeclarationUnitTest.2.inc delete mode 100644 Yoast/Tests/Namespaces/NamespaceDeclarationUnitTest.php diff --git a/Yoast/Docs/Namespaces/NamespaceDeclarationStandard.xml b/Yoast/Docs/Namespaces/NamespaceDeclarationStandard.xml deleted file mode 100644 index 2bd53679..00000000 --- a/Yoast/Docs/Namespaces/NamespaceDeclarationStandard.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - ; - ]]> - - - { - // Code. -} - ]]> - - - - - - - - - Yoast\Sub; - ]]> - - - ; - ]]> - - - - - - - - - - - - namespace Yoast\Sub\B { -} - ]]> - - - diff --git a/Yoast/Sniffs/Namespaces/NamespaceDeclarationSniff.php b/Yoast/Sniffs/Namespaces/NamespaceDeclarationSniff.php deleted file mode 100644 index 1d9179a3..00000000 --- a/Yoast/Sniffs/Namespaces/NamespaceDeclarationSniff.php +++ /dev/null @@ -1,110 +0,0 @@ -getTokens(); - - $statements = []; - - while ( ( $stackPtr = $phpcsFile->findNext( \T_NAMESPACE, ( $stackPtr + 1 ) ) ) !== false ) { - - $next_non_empty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); - if ( $next_non_empty === false ) { - // Live coding or parse error. - break; - } - - if ( $tokens[ $next_non_empty ]['code'] === \T_NS_SEPARATOR ) { - // Not a namespace declaration, but the use of the namespace keyword as operator. - continue; - } - - // OK, found a namespace declaration. - $statements[] = $stackPtr; - - if ( isset( $tokens[ $stackPtr ]['scope_condition'] ) - && $tokens[ $stackPtr ]['scope_condition'] === $stackPtr - ) { - // Scoped namespace declaration. - $phpcsFile->addError( - 'Scoped namespace declarations are not allowed.', - $stackPtr, - 'ScopedForbidden' - ); - } - - if ( $tokens[ $next_non_empty ]['code'] === \T_SEMICOLON - || $tokens[ $next_non_empty ]['code'] === \T_OPEN_CURLY_BRACKET - ) { - // Namespace declaration without namespace name (= global namespace). - $phpcsFile->addError( - 'Namespace declarations without a namespace name are not allowed.', - $stackPtr, - 'NoNameForbidden' - ); - } - } - - $count = \count( $statements ); - if ( $count > 1 ) { - $data = [ - $count, - $tokens[ $statements[0] ]['line'], - ]; - - for ( $i = 1; $i < $count; $i++ ) { - $phpcsFile->addError( - 'There should be only one namespace declaration per file. Found %d namespace declarations. The first declaration was found on line %d', - $statements[ $i ], - 'MultipleFound', - $data - ); - } - } - - return ( $phpcsFile->numTokens + 1 ); - } -} diff --git a/Yoast/Tests/Namespaces/NamespaceDeclarationUnitTest.1.inc b/Yoast/Tests/Namespaces/NamespaceDeclarationUnitTest.1.inc deleted file mode 100644 index 0127313d..00000000 --- a/Yoast/Tests/Namespaces/NamespaceDeclarationUnitTest.1.inc +++ /dev/null @@ -1,8 +0,0 @@ - => - */ - public function getErrorList( $testFile = '' ) { - switch ( $testFile ) { - case 'NamespaceDeclarationUnitTest.2.inc': - return [ - 3 => 1, - 5 => 3, - 7 => 2, - 9 => 3, - 11 => 2, - ]; - - default: - return []; - } - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return []; - } -} diff --git a/Yoast/ruleset.xml b/Yoast/ruleset.xml index 72acbfb9..82a53fc3 100644 --- a/Yoast/ruleset.xml +++ b/Yoast/ruleset.xml @@ -142,6 +142,15 @@ + + + + + + + + +