From b5375222c647021ee60ffb3c3eab451a838d136a Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 3 Jul 2020 16:20:52 +0100 Subject: [PATCH] Switch to Generic.VersionControl.GitMergeConflict Removes WordPressVIPMinimum.VersionControl.MergeConflict sniff. The merge conflict boundary detection sniff in the built-in Generic standard is a more comprehensive sniff, and it means one less thing for VIP to maintain. Requires PHPCS 3.4+ (made a requirement in #484). Fixes #330. --- WordPress-VIP-Go/ruleset-test.inc | 14 +-- WordPress-VIP-Go/ruleset-test.php | 3 +- .../VersionControl/MergeConflictSniff.php | 98 ------------------- .../VersionControl/MergeConflictUnitTest.inc | 13 --- .../VersionControl/MergeConflictUnitTest.php | 41 -------- WordPressVIPMinimum/ruleset-test.inc | 15 ++- WordPressVIPMinimum/ruleset-test.php | 5 +- WordPressVIPMinimum/ruleset.xml | 1 + 8 files changed, 17 insertions(+), 173 deletions(-) delete mode 100644 WordPressVIPMinimum/Sniffs/VersionControl/MergeConflictSniff.php delete mode 100644 WordPressVIPMinimum/Tests/VersionControl/MergeConflictUnitTest.inc delete mode 100644 WordPressVIPMinimum/Tests/VersionControl/MergeConflictUnitTest.php diff --git a/WordPress-VIP-Go/ruleset-test.inc b/WordPress-VIP-Go/ruleset-test.inc index d6992fe9..11c2b764 100644 --- a/WordPress-VIP-Go/ruleset-test.inc +++ b/WordPress-VIP-Go/ruleset-test.inc @@ -567,12 +567,8 @@ $_SERVER['HTTP_X_FORWARDED_FOR']; // Error. $_SERVER["REMOTE_ADDR"]; // Error. // phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotValidated,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -// WordPressVIPMinimum.VersionControl.MergeConflict -function is_prime( $n ) { - if ( 2 === $n ) { - } -//phpcs:ignore Generic.PHP.Syntax.PHPSyntax -======= // Error. - if ( $n % 2 === 0 ) { - } -} +// Generic.VersionControl.GitMergeConflict +?> +<<<<<<< HEAD // Error. + +>>>>>>> // Error. diff --git a/WordPress-VIP-Go/ruleset-test.php b/WordPress-VIP-Go/ruleset-test.php index 28493bca..26be9a5a 100644 --- a/WordPress-VIP-Go/ruleset-test.php +++ b/WordPress-VIP-Go/ruleset-test.php @@ -115,7 +115,8 @@ 565 => 1, 566 => 1, 567 => 1, - 575 => 1, + 572 => 1, + 574 => 1, ], 'warnings' => [ 4 => 1, diff --git a/WordPressVIPMinimum/Sniffs/VersionControl/MergeConflictSniff.php b/WordPressVIPMinimum/Sniffs/VersionControl/MergeConflictSniff.php deleted file mode 100644 index a2922dac..00000000 --- a/WordPressVIPMinimum/Sniffs/VersionControl/MergeConflictSniff.php +++ /dev/null @@ -1,98 +0,0 @@ -tokens[ $stackPtr ]['code'] ) { - $nextToken = $this->phpcsFile->findNext( Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true ); - if ( T_SL !== $this->tokens[ $nextToken ]['code'] ) { - return; - } - $nextToken = $this->phpcsFile->findNext( Tokens::$emptyTokens, $nextToken + 1, null, true, null, true ); - if ( T_STRING !== $this->tokens[ $nextToken ]['code'] || 0 !== strpos( $this->tokens[ $nextToken ]['content'], '<<< HEAD' ) ) { - return; - } - - $message = 'Merge conflict detected. Found "<<<<<<< HEAD" string.'; - $this->phpcsFile->addError( $message, $stackPtr, 'Start' ); - - return; - } - - if ( T_ENCAPSED_AND_WHITESPACE === $this->tokens[ $stackPtr ]['code'] ) { - if ( 0 === strpos( $this->tokens[ $stackPtr ]['content'], '=======' ) ) { - $this->addSeparatorError( $stackPtr ); - - return; - } - - if ( 0 === strpos( $this->tokens[ $stackPtr ]['content'], '>>>>>>>' ) ) { - $message = 'Merge conflict detected. Found "%s" string.'; - $data = [ trim( $this->tokens[ $stackPtr ]['content'] ) ]; - $this->phpcsFile->addError( $message, $stackPtr, 'End', $data ); - - return; - } - } elseif ( T_IS_IDENTICAL === $this->tokens[ $stackPtr ]['code'] && T_IS_IDENTICAL === $this->tokens[ $stackPtr + 1 ]['code'] ) { - $this->addSeparatorError( $stackPtr ); - - return; - } - } - - /** - * Consolidated violation. - * - * @param int $stackPtr The position of the current token in the stack passed in $tokens. - */ - private function addSeparatorError( $stackPtr ) { - $message = 'Merge conflict detected. Found "=======" string.'; - $this->phpcsFile->addError( $message, $stackPtr, 'Separator' ); - } - -} diff --git a/WordPressVIPMinimum/Tests/VersionControl/MergeConflictUnitTest.inc b/WordPressVIPMinimum/Tests/VersionControl/MergeConflictUnitTest.inc deleted file mode 100644 index 31965cc3..00000000 --- a/WordPressVIPMinimum/Tests/VersionControl/MergeConflictUnitTest.inc +++ /dev/null @@ -1,13 +0,0 @@ ->>>>>> branch-a -} diff --git a/WordPressVIPMinimum/Tests/VersionControl/MergeConflictUnitTest.php b/WordPressVIPMinimum/Tests/VersionControl/MergeConflictUnitTest.php deleted file mode 100644 index f0e40e67..00000000 --- a/WordPressVIPMinimum/Tests/VersionControl/MergeConflictUnitTest.php +++ /dev/null @@ -1,41 +0,0 @@ - => - */ - public function getErrorList() { - return [ - 4 => 1, - 8 => 1, - 12 => 1, - ]; - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return []; - } - -} diff --git a/WordPressVIPMinimum/ruleset-test.inc b/WordPressVIPMinimum/ruleset-test.inc index 8d3641bc..e799c264 100644 --- a/WordPressVIPMinimum/ruleset-test.inc +++ b/WordPressVIPMinimum/ruleset-test.inc @@ -604,15 +604,12 @@ function foo() { $c = compact( $a, $b ); // Warning x 2. } -// WordPressVIPMinimum.VersionControl.MergeConflict -function is_prime( $n ) { - if ( 2 === $n ) { - } -//phpcs:ignore Generic.PHP.Syntax.PHPSyntax -======= // Error. - if ( $n % 2 === 0 ) { - } -} +// Generic.VersionControl.GitMergeConflict +?> +<<<<<<< HEAD // Error. + +>>>>>>> // Error. + diff --git a/WordPressVIPMinimum/ruleset-test.php b/WordPressVIPMinimum/ruleset-test.php index a4dd1efd..a901f9ce 100644 --- a/WordPressVIPMinimum/ruleset-test.php +++ b/WordPressVIPMinimum/ruleset-test.php @@ -206,8 +206,9 @@ 595 => 1, 596 => 1, 597 => 1, - 612 => 1, - 618 => 1, + 609 => 1, + 611 => 1, + 615 => 1, ], 'warnings' => [ 32 => 1, diff --git a/WordPressVIPMinimum/ruleset.xml b/WordPressVIPMinimum/ruleset.xml index 1ff8b2a0..7e0d0d68 100644 --- a/WordPressVIPMinimum/ruleset.xml +++ b/WordPressVIPMinimum/ruleset.xml @@ -42,6 +42,7 @@ +