From 0eaab6a504f0b5d87672fdfe7efe232339c0187e Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Mon, 24 Jun 2024 15:01:08 +0200 Subject: [PATCH 1/5] - change the license to GPL-2.0-or-later; - remove third-party code from the SinceTagSniff::find_docblock() method; - remove third-party code from the SinceTagSniff::is_function_call() method; - remove the SinceTagSniff::find_hook_docblock() method and add the new find_previous_line_token() method (refactoring); - fix typo in the SinceTagSniff::process() method; - remove unused code from bootstrap.php and make variables use snake case; --- .../.phpcs.xml.dist | 9 +- .../ForbiddenFunctionsAndClassesSniff.php | 3 +- .../GuardedFunctionAndClassNamesSniff.php | 3 +- .../Sniffs/Commenting/SinceTagSniff.php | 116 +++++++----------- .../ValidBlockLibraryFunctionNameSniff.php | 3 +- .../Gutenberg/Tests/AbstractSniffUnitTest.php | 10 +- .../ForbiddenFunctionsAndClassesUnitTest.php | 3 +- .../GuardedFunctionAndClassNamesUnitTest.php | 3 +- .../Tests/Commenting/SinceTagUnitTest.php | 3 +- .../ValidBlockLibraryFunctionNameUnitTest.php | 3 +- .../Tests/bootstrap.php | 87 ++++--------- .../gutenberg-coding-standards/composer.json | 2 +- 12 files changed, 83 insertions(+), 162 deletions(-) diff --git a/test/php/gutenberg-coding-standards/.phpcs.xml.dist b/test/php/gutenberg-coding-standards/.phpcs.xml.dist index 7f717f65374d7..7ebe60e3d2856 100644 --- a/test/php/gutenberg-coding-standards/.phpcs.xml.dist +++ b/test/php/gutenberg-coding-standards/.phpcs.xml.dist @@ -1,15 +1,8 @@ - + The Coding standard for the Gutenberg Coding Standards itself. - - . diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/CodeAnalysis/ForbiddenFunctionsAndClassesSniff.php b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/CodeAnalysis/ForbiddenFunctionsAndClassesSniff.php index 87d966ecb5603..12d388cc37818 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/CodeAnalysis/ForbiddenFunctionsAndClassesSniff.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/CodeAnalysis/ForbiddenFunctionsAndClassesSniff.php @@ -3,8 +3,7 @@ * Gutenberg Coding Standards. * * @package gutenberg/gutenberg-coding-standards - * @link https://github.com/WordPress/gutenberg - * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/WordPress/gutenberg/tree/trunk/test/php/gutenberg-coding-standards */ namespace GutenbergCS\Gutenberg\Sniffs\CodeAnalysis; diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/CodeAnalysis/GuardedFunctionAndClassNamesSniff.php b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/CodeAnalysis/GuardedFunctionAndClassNamesSniff.php index c6e51119f1513..d947d6d9382b3 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/CodeAnalysis/GuardedFunctionAndClassNamesSniff.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/CodeAnalysis/GuardedFunctionAndClassNamesSniff.php @@ -3,8 +3,7 @@ * Gutenberg Coding Standards. * * @package gutenberg/gutenberg-coding-standards - * @link https://github.com/WordPress/gutenberg - * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/WordPress/gutenberg/tree/trunk/test/php/gutenberg-coding-standards */ namespace GutenbergCS\Gutenberg\Sniffs\CodeAnalysis; diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/Commenting/SinceTagSniff.php b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/Commenting/SinceTagSniff.php index f216f4f681f0e..3d6fd85faac62 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/Commenting/SinceTagSniff.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/Commenting/SinceTagSniff.php @@ -3,8 +3,7 @@ * Gutenberg Coding Standards. * * @package gutenberg/gutenberg-coding-standards - * @link https://github.com/WordPress/gutenberg - * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/WordPress/gutenberg/tree/trunk/test/php/gutenberg-coding-standards */ namespace GutenbergCS\Gutenberg\Sniffs\Commenting; @@ -22,7 +21,7 @@ /** * This sniff verifies the presence of valid `@since` tags in the docblocks of various PHP structures * and WordPress hooks. Supported structures include classes, interfaces, traits, enums, functions, methods and properties. - * Files located within the __experimental block of the block-library are excluded from checks. + * Files located within the __experimental blocks of the block-library folder are excluded from checks. */ class SinceTagSniff implements Sniff { @@ -147,7 +146,7 @@ protected function process_hook( File $phpcs_file, $stack_pointer ) { $violation_codes = static::get_violation_codes( 'Hook' ); - $docblock = static::find_hook_docblock( $phpcs_file, $stack_pointer ); + $docblock = static::find_docblock( $phpcs_file, $stack_pointer ); $version_tags = static::parse_since_tags( $phpcs_file, $docblock ); if ( empty( $version_tags ) ) { @@ -442,108 +441,77 @@ protected function check_below_minimum_visibility( $visibility ) { * * @param File $phpcs_file The file being scanned. * @param int $stack_pointer The position to start looking for the docblock. - * @return array|false An associative array containing the start and end tokens of the docblock, or false if not found. + * @return int|false The last token on the previous line. */ - protected static function find_hook_docblock( File $phpcs_file, $stack_pointer ) { + protected static function find_previous_line_token( File $phpcs_file, $stack_pointer ) { $tokens = $phpcs_file->getTokens(); $current_line = $tokens[ $stack_pointer ]['line']; - for ( $i = $stack_pointer; $i >= 0; $i-- ) { - if ( $tokens[ $i ]['line'] < $current_line ) { - // The previous token is on the previous line, so the current token is the first on the line. - return static::find_docblock( $phpcs_file, $i + 1 ); + for ( $token = $stack_pointer; $token >= 0; $token-- ) { + if ( $tokens[ $token ]['line'] < $current_line ) { + return $token; } } - return static::find_docblock( $phpcs_file, 0 ); + return false; } /** - * Determines if a T_STRING token represents a function call. - * The implementation was copied from PHPCompatibility\Sniffs\Extensions\RemovedExtensionsSniff::process(). + * Finds the docblock preceding a specified position (stack pointer) in a given PHP file. * * @param File $phpcs_file The file being scanned. - * @param int $stack_pointer The position of the T_STRING token in question. - * @return bool True if the token represents a function call, false otherwise. + * @param int $stack_pointer The position (stack pointer) in the token stack from which to start searching backwards. + * @return array|false An associative array containing the start and end tokens of the docblock, or false if not found. */ - protected static function is_function_call( File $phpcs_file, $stack_pointer ) { - $tokens = $phpcs_file->getTokens(); - - // Find the next non-empty token. - $open_bracket = $phpcs_file->findNext( Tokens::$emptyTokens, ( $stack_pointer + 1 ), null, true ); - - if ( T_OPEN_PARENTHESIS !== $tokens[ $open_bracket ]['code'] ) { - // Not a function call. + protected static function find_docblock( File $phpcs_file, $stack_pointer ) { + // It can be assumed that the DocBlock should end on the previous line, not the current one. + $previous_line_end_token = static::find_previous_line_token( $phpcs_file, $stack_pointer ); + if ( false === $previous_line_end_token ) { return false; } - if ( false === isset( $tokens[ $open_bracket ]['parenthesis_closer'] ) ) { - // Not a function call. + $docblock_end_token = $phpcs_file->findPrevious( array( T_WHITESPACE ), $previous_line_end_token, null, true ); + + $tokens = $phpcs_file->getTokens(); + if ( false === $docblock_end_token || T_DOC_COMMENT_CLOSE_TAG !== $tokens[ $docblock_end_token ]['code'] ) { + // Only "/**" style comments are supported. return false; } - // Find the previous non-empty token. - $search = Tokens::$emptyTokens; - $search[] = T_BITWISE_AND; - $previous = $phpcs_file->findPrevious( $search, ( $stack_pointer - 1 ), null, true ); - - $previous_tokens_to_ignore = array( - T_FUNCTION, // Function declaration. - T_NEW, // Creating an object. - T_OBJECT_OPERATOR, // Calling an object. + return array( + 'start_token' => $tokens[ $docblock_end_token ]['comment_opener'], + 'end_token' => $docblock_end_token, ); - - return ! in_array( $tokens[ $previous ]['code'], $previous_tokens_to_ignore, true ); } /** - * Finds the docblock preceding a specified position (stack pointer) in a given PHP file. - * The implementation was copied from PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FunctionCommentSniff::process(). + * Determines if a T_STRING token represents a function call. * * @param File $phpcs_file The file being scanned. - * @param int $stack_pointer The position (stack pointer) in the token stack from which to start searching backwards. - * @return array|false An associative array containing the start and end tokens of the docblock, or false if not found. + * @param int $stack_pointer The position of the T_STRING token in question. + * @return bool True if the token represents a function call, false otherwise. */ - protected static function find_docblock( File $phpcs_file, $stack_pointer ) { - $tokens = $phpcs_file->getTokens(); - $ignore = Tokens::$methodPrefixes; - $ignore[ T_WHITESPACE ] = T_WHITESPACE; - - for ( $comment_end = ( $stack_pointer - 1 ); $comment_end >= 0; $comment_end-- ) { - if ( isset( $ignore[ $tokens[ $comment_end ]['code'] ] ) ) { - continue; - } - - if ( T_ATTRIBUTE_END === $tokens[ $comment_end ]['code'] - && isset( $tokens[ $comment_end ]['attribute_opener'] ) - ) { - $comment_end = $tokens[ $comment_end ]['attribute_opener']; - continue; - } + protected static function is_function_call( File $phpcs_file, $stack_pointer ) { + $tokens = $phpcs_file->getTokens(); - break; - } + // Find the previous non-empty token. + $previous = $phpcs_file->findPrevious( Tokens::$emptyTokens, ( $stack_pointer - 1 ), null, true ); - if ( $tokens[ $comment_end ]['code'] === T_COMMENT ) { - // Inline comments might just be closing comments for - // control structures or functions instead of function comments - // using the wrong comment type. If there is other code on the line, - // assume they relate to that code. - $previous = $phpcs_file->findPrevious( $ignore, ( $comment_end - 1 ), null, true ); - if ( false !== $previous && $tokens[ $previous ]['line'] === $tokens[ $comment_end ]['line'] ) { - $comment_end = $previous; - } - } + $previous_tokens_to_ignore = array( + T_NEW, // Creating an object. + T_OBJECT_OPERATOR, // Calling an object. + T_FUNCTION, // Function declaration. + ); - if ( T_DOC_COMMENT_CLOSE_TAG !== $tokens[ $comment_end ]['code'] ) { - // Only "/**" style comments are supported. + if ( in_array( $tokens[ $previous ]['code'], $previous_tokens_to_ignore, true ) ) { + // This is an object or function declaration. return false; } - return array( - 'start_token' => $tokens[ $comment_end ]['comment_opener'], - 'end_token' => $comment_end, - ); + // Find the next non-empty token. + $open_bracket = $phpcs_file->findNext( Tokens::$emptyTokens, ( $stack_pointer + 1 ), null, true ); + + return ( false !== $open_bracket ) && ( T_OPEN_PARENTHESIS === $tokens[ $open_bracket ]['code'] ); } /** diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/NamingConventions/ValidBlockLibraryFunctionNameSniff.php b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/NamingConventions/ValidBlockLibraryFunctionNameSniff.php index 74608921c32d8..bf7dbc2fd85d3 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/NamingConventions/ValidBlockLibraryFunctionNameSniff.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/NamingConventions/ValidBlockLibraryFunctionNameSniff.php @@ -3,8 +3,7 @@ * Gutenberg Coding Standards. * * @package gutenberg/gutenberg-coding-standards - * @link https://github.com/WordPress/gutenberg - * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/WordPress/gutenberg/tree/trunk/test/php/gutenberg-coding-standards */ namespace GutenbergCS\Gutenberg\Sniffs\NamingConventions; diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Tests/AbstractSniffUnitTest.php b/test/php/gutenberg-coding-standards/Gutenberg/Tests/AbstractSniffUnitTest.php index 08838ce412fc3..c5c58fd412121 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Tests/AbstractSniffUnitTest.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Tests/AbstractSniffUnitTest.php @@ -3,8 +3,7 @@ * An abstract class that all sniff unit tests must extend. * * @package gutenberg-coding-standards/gbc - * @link https://github.com/WordPress/gutenberg - * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/WordPress/gutenberg/tree/trunk/test/php/gutenberg-coding-standards */ namespace GutenbergCS\Gutenberg\Tests; @@ -14,6 +13,9 @@ use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Sniffs\Sniff; +/** + * An abstract test class that contains common methods for all sniff unit tests. + */ abstract class AbstractSniffUnitTest extends BaseAbstractSniffUnitTest { /** @@ -65,7 +67,7 @@ public function setCliValues( $filename, $config ) { if ( ! isset( $GLOBALS['PHP_CODESNIFFER_RULESETS']['Gutenberg'] ) || ( ! $GLOBALS['PHP_CODESNIFFER_RULESETS']['Gutenberg'] instanceof Ruleset ) ) { - throw new \RuntimeException( $error_message ); + throw new \RuntimeException( $error_message ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- this is non-production code. } // Backup the original Ruleset instance. @@ -76,7 +78,7 @@ public function setCliValues( $filename, $config ) { $sniff_fqcn = $this->get_sniff_fqcn(); if ( ! isset( $current_ruleset->sniffs[ $sniff_fqcn ] ) ) { - throw new \RuntimeException( $error_message ); + throw new \RuntimeException( $error_message ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- this is non-production code. } $sniff = $current_ruleset->sniffs[ $sniff_fqcn ]; diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Tests/CodeAnalysis/ForbiddenFunctionsAndClassesUnitTest.php b/test/php/gutenberg-coding-standards/Gutenberg/Tests/CodeAnalysis/ForbiddenFunctionsAndClassesUnitTest.php index 8026e88f1d945..79719fba6039d 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Tests/CodeAnalysis/ForbiddenFunctionsAndClassesUnitTest.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Tests/CodeAnalysis/ForbiddenFunctionsAndClassesUnitTest.php @@ -3,8 +3,7 @@ * Unit test class for Gutenberg Coding Standard. * * @package gutenberg-coding-standards/gbc - * @link https://github.com/WordPress/gutenberg - * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/WordPress/gutenberg/tree/trunk/test/php/gutenberg-coding-standards */ namespace GutenbergCS\Gutenberg\Tests\CodeAnalysis; diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Tests/CodeAnalysis/GuardedFunctionAndClassNamesUnitTest.php b/test/php/gutenberg-coding-standards/Gutenberg/Tests/CodeAnalysis/GuardedFunctionAndClassNamesUnitTest.php index 652f6b735378c..b4e26fd2e69c4 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Tests/CodeAnalysis/GuardedFunctionAndClassNamesUnitTest.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Tests/CodeAnalysis/GuardedFunctionAndClassNamesUnitTest.php @@ -3,8 +3,7 @@ * Unit test class for Gutenberg Coding Standard. * * @package gutenberg-coding-standards/gbc - * @link https://github.com/WordPress/gutenberg - * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/WordPress/gutenberg/tree/trunk/test/php/gutenberg-coding-standards */ namespace GutenbergCS\Gutenberg\Tests\CodeAnalysis; diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Tests/Commenting/SinceTagUnitTest.php b/test/php/gutenberg-coding-standards/Gutenberg/Tests/Commenting/SinceTagUnitTest.php index bc7ca28c263ff..1318687768c9d 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Tests/Commenting/SinceTagUnitTest.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Tests/Commenting/SinceTagUnitTest.php @@ -3,8 +3,7 @@ * Unit test class for Gutenberg Coding Standard. * * @package gutenberg-coding-standards/gbc - * @link https://github.com/WordPress/gutenberg - * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/WordPress/gutenberg/tree/trunk/test/php/gutenberg-coding-standards */ namespace GutenbergCS\Gutenberg\Tests\Commenting; diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Tests/NamingConventions/ValidBlockLibraryFunctionNameUnitTest.php b/test/php/gutenberg-coding-standards/Gutenberg/Tests/NamingConventions/ValidBlockLibraryFunctionNameUnitTest.php index 51174dd769d0a..14a2cb1a97dd7 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Tests/NamingConventions/ValidBlockLibraryFunctionNameUnitTest.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Tests/NamingConventions/ValidBlockLibraryFunctionNameUnitTest.php @@ -3,8 +3,7 @@ * Unit test class for Gutenberg Coding Standard. * * @package gutenberg-coding-standards/gbc - * @link https://github.com/WordPress/gutenberg - * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/WordPress/gutenberg/tree/trunk/test/php/gutenberg-coding-standards */ namespace GutenbergCS\Gutenberg\Tests\NamingConventions; diff --git a/test/php/gutenberg-coding-standards/Tests/bootstrap.php b/test/php/gutenberg-coding-standards/Tests/bootstrap.php index f28528bc1b972..0f4a73e0d364e 100644 --- a/test/php/gutenberg-coding-standards/Tests/bootstrap.php +++ b/test/php/gutenberg-coding-standards/Tests/bootstrap.php @@ -1,86 +1,51 @@ true, -); - -$allStandards = PHP_CodeSniffer\Util\Standards::getInstalledStandards(); -$allStandards[] = 'Generic'; +$available_standards = PHP_CodeSniffer\Util\Standards::getInstalledStandards(); +$ignored_standards = array( 'Generic' ); -$standardsToIgnore = array(); -foreach ( $allStandards as $standard ) { - if ( isset( $gbcsStandards[ $standard ] ) === true ) { +foreach ( $available_standards as $available_standard ) { + if ( 'Gutenberg' === $available_standard ) { continue; } - $standardsToIgnore[] = $standard; + $ignored_standards[] = $available_standard; } -$standardsToIgnoreString = implode( ',', $standardsToIgnore ); +$ignore_standards_string = implode( ',', $ignored_standards ); -// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv -- This is not production, but test code. -putenv( "PHPCS_IGNORE_TESTS={$standardsToIgnoreString}" ); +// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv -- This is non-production code. +putenv( "PHPCS_IGNORE_TESTS={$ignore_standards_string}" ); -// Clean up. -unset( $ds, $phpcsDir, $composerPHPCSPath, $allStandards, $standardsToIgnore, $standard, $standardsToIgnoreString ); +// Cleanup. +unset( $dir_separator, $phpcs_path, $available_standards, $ignored_standards, $available_standard, $ignore_standards_string ); diff --git a/test/php/gutenberg-coding-standards/composer.json b/test/php/gutenberg-coding-standards/composer.json index c1c27f81818aa..2d79dc906a8d9 100644 --- a/test/php/gutenberg-coding-standards/composer.json +++ b/test/php/gutenberg-coding-standards/composer.json @@ -8,7 +8,7 @@ "static analysis", "Gutenberg" ], - "license": "MIT", + "license": "GPL-2.0-or-later", "authors": [ { "name": "Contributors", From 49becaf6bfd61a76b490df3d2b5db0741061178e Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 19 Jul 2024 19:33:40 +0200 Subject: [PATCH 2/5] Update DocBlock to reflect changes to the find_previous_line_token method. --- .../Gutenberg/Sniffs/Commenting/SinceTagSniff.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/Commenting/SinceTagSniff.php b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/Commenting/SinceTagSniff.php index 3d6fd85faac62..20f698954cb26 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/Commenting/SinceTagSniff.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/Commenting/SinceTagSniff.php @@ -435,13 +435,11 @@ protected function check_below_minimum_visibility( $visibility ) { } /** - * Finds the docblock associated with a hook, starting from a specified position in the token stack. - * Since a line containing a hook can include any type of tokens, this method backtracks through the tokens - * to locate the first token on the current line. This token is then used as the starting point for searching the docblock. + * Finds the first token on the previous line relative to the stack pointer passed to the method. * * @param File $phpcs_file The file being scanned. - * @param int $stack_pointer The position to start looking for the docblock. - * @return int|false The last token on the previous line. + * @param int $stack_pointer The position to find the previous line token from. + * @return int|false The last token on the previous line, or false if not found. */ protected static function find_previous_line_token( File $phpcs_file, $stack_pointer ) { $tokens = $phpcs_file->getTokens(); From 43dd7d21a7bfcffbcd2695da2145c8cb82ce42e0 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 19 Jul 2024 20:13:01 +0200 Subject: [PATCH 3/5] Update the inline comment as bootstrap.php doesn't need the PHPCS_DIR environment variable in the context of Gutenberg. --- test/php/gutenberg-coding-standards/Tests/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/php/gutenberg-coding-standards/Tests/bootstrap.php b/test/php/gutenberg-coding-standards/Tests/bootstrap.php index 0f4a73e0d364e..547a1ce303835 100644 --- a/test/php/gutenberg-coding-standards/Tests/bootstrap.php +++ b/test/php/gutenberg-coding-standards/Tests/bootstrap.php @@ -14,7 +14,7 @@ $dir_separator = DIRECTORY_SEPARATOR; -// Define the path to the PHPCS directory from an environment variable. +// Define the path to the PHPCS directory. $phpcs_path = dirname( __DIR__ ) . $dir_separator . 'vendor' . $dir_separator . 'squizlabs' . $dir_separator . 'php_codesniffer'; $autoload_script_path = $phpcs_path . $dir_separator . 'autoload.php'; $bootstrap_script_path = $phpcs_path . $dir_separator . 'tests' . $dir_separator . 'bootstrap.php'; From 2fb65f9e1a8c637bc735c18a8f3bde067173f8d0 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Mon, 5 Aug 2024 18:33:53 +0200 Subject: [PATCH 4/5] Add space per https://github.com/WordPress/gutenberg/pull/61913/files#r1704157375. --- .../Gutenberg/Tests/AbstractSniffUnitTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Tests/AbstractSniffUnitTest.php b/test/php/gutenberg-coding-standards/Gutenberg/Tests/AbstractSniffUnitTest.php index c5c58fd412121..f1be5ab00b075 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Tests/AbstractSniffUnitTest.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Tests/AbstractSniffUnitTest.php @@ -67,7 +67,7 @@ public function setCliValues( $filename, $config ) { if ( ! isset( $GLOBALS['PHP_CODESNIFFER_RULESETS']['Gutenberg'] ) || ( ! $GLOBALS['PHP_CODESNIFFER_RULESETS']['Gutenberg'] instanceof Ruleset ) ) { - throw new \RuntimeException( $error_message ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- this is non-production code. + throw new \RuntimeException( $error_message ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- this is non-production code. } // Backup the original Ruleset instance. @@ -78,7 +78,7 @@ public function setCliValues( $filename, $config ) { $sniff_fqcn = $this->get_sniff_fqcn(); if ( ! isset( $current_ruleset->sniffs[ $sniff_fqcn ] ) ) { - throw new \RuntimeException( $error_message ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- this is non-production code. + throw new \RuntimeException( $error_message ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- this is non-production code. } $sniff = $current_ruleset->sniffs[ $sniff_fqcn ]; From ded90f025e048490c408b13b7fe7249b4dd987bd Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 9 Aug 2024 22:12:08 +0200 Subject: [PATCH 5/5] Add the #license section to the README.md (props to @azaozz). --- test/php/gutenberg-coding-standards/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/php/gutenberg-coding-standards/README.md b/test/php/gutenberg-coding-standards/README.md index 51f6574fa2053..500abe2e5b481 100644 --- a/test/php/gutenberg-coding-standards/README.md +++ b/test/php/gutenberg-coding-standards/README.md @@ -1,3 +1,9 @@ # Gutenberg Coding Standards for Gutenberg -This project is a collection of [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) rules (sniffs) to validate code developed for Gutenberg. It ensures code quality and adherence to coding conventions. \ No newline at end of file +This project is a collection of [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) rules (sniffs) to validate code developed for Gutenberg. It ensures code quality and adherence to coding conventions. + +## License + +This project is licensed under the same terms as the Gutenberg project. + +Please refer to this [LICENSE.md](../../../LICENSE.md) file for detailed license information.