diff --git a/.cspell.json b/.cspell.json index c51e9f059a1ec466996354a4698c96dc35e62c14..48c70026495ed3cba88f8e09e10fa0784a77e26c 100644 --- a/.cspell.json +++ b/.cspell.json @@ -25,6 +25,7 @@ "CURLOPT_SSL_VERIFYPEER", "datestamp", "defgroup", + "drupalcode", "drush", "endcode", "endlink", diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php index b8cfdaabffd4d62c09a0ddcefe70f5976b9048b7..0211f81383dc46b514c5d6c6888118f18b67fbe5 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php @@ -208,19 +208,19 @@ class DeprecatedSniff implements Sniff } // Allow for the alternative 'node' or 'project/aaa/issues' format. - preg_match('[^http(s*)://www.drupal.org/(node|project/\w+/issues)/(\d+)([\.\?\;!]*)$]', $crLink, $matches); - if (isset($matches[4]) === true && empty($matches[4]) === false) { - // If matches[4] is not blank it means that the url is OK but it + preg_match('[^http(s*)://(www.drupal.org/(node|project/\w+/issues)|git.drupalcode.org/project/\w+/-/work_items)/(\d+)([\.\?\;!]*)$]', $crLink, $matches); + if (isset($matches[5]) === true && empty($matches[5]) === false) { + // If matches[5] is not blank it means that the url is OK but it // ends with punctuation. This is a common and fixable mistake. $error = "The @see url '%s' should not end with punctuation"; $fix = $phpcsFile->addFixableError($error, $string, 'DeprecatedPeriodAfterSeeUrl', [$crLink]); if ($fix === true) { // Remove all of the the trailing punctuation. - $content = substr($crLink, 0, -(strlen($matches[4]))); + $content = substr($crLink, 0, -(strlen($matches[5]))); $phpcsFile->fixer->replaceToken($string, $content); }//end if } elseif (empty($matches) === true) { - $error = "The @see url '%s' does not match the standard: http(s)://www.drupal.org/node/n or http(s)://www.drupal.org/project/aaa/issues/n"; + $error = "The @see url '%s' does not match the standard: http(s)://www.drupal.org/node/n or http(s)://www.drupal.org/project/aaa/issues/n or http(s)://git.drupalcode.org/project/aaa/-/work_items/n"; $phpcsFile->addWarning($error, $seeTag, 'DeprecatedWrongSeeUrlFormat', [$crLink]); } } diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTriggerErrorSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTriggerErrorSniff.php index d2e015014109d9ee4f91c75fa1156da6169e06ee..7002655ac55f3bd8e601ddbb3be32974f9d665c8 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTriggerErrorSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTriggerErrorSniff.php @@ -169,15 +169,15 @@ class FunctionTriggerErrorSniff extends FunctionCall // Check the 'See' link. $crLink = $matches[6]; // Allow for the alternative 'node' or 'project/aaa/issues' format. - preg_match('[^http(s*)://www.drupal.org/(node|project/\w+/issues)/(\d+)(\.*)$]', $crLink, $crMatches); + preg_match('[^http(s*)://(www.drupal.org/(node|project/\w+/issues)|git.drupalcode.org/project/\w+/-/work_items)/(\d+)([\.\?\;!]*)$]', $crLink, $crMatches); // If cr_matches[4] is not blank it means that the url is correct // but it ends with a period. As this can be a common mistake give a // specific message to assist in fixing. - if (isset($crMatches[4]) === true && empty($crMatches[4]) === false) { + if (isset($crMatches[5]) === true && empty($crMatches[5]) === false) { $error = "The url '%s' should not end with a period."; $phpcsFile->addWarning($error, $argument['start'], 'TriggerErrorPeriodAfterSeeUrl', [$crLink]); } elseif (empty($crMatches) === true) { - $error = "The url '%s' does not match the standard: http(s)://www.drupal.org/node/n or http(s)://www.drupal.org/project/aaa/issues/n"; + $error = "The url '%s' does not match the standard: http(s)://www.drupal.org/node/n or http(s)://www.drupal.org/project/aaa/issues/n or http(s)://git.drupalcode.org/project/aaa/-/work_items/n"; $phpcsFile->addWarning($error, $argument['start'], 'TriggerErrorSeeUrlFormat', [$crLink]); } }//end if diff --git a/tests/Drupal/Commenting/DeprecatedUnitTest.inc b/tests/Drupal/Commenting/DeprecatedUnitTest.inc index 43ce34533ec1832b4e39648afd9b468ad80665d9..009f156b8c9287f701ed3e4d37cb3680f0e09290 100644 --- a/tests/Drupal/Commenting/DeprecatedUnitTest.inc +++ b/tests/Drupal/Commenting/DeprecatedUnitTest.inc @@ -110,3 +110,13 @@ function w() { */ function meanwhile() { } + +/** + * Test deprecation in doc block with GitLab URL. + * + * @deprecated in my_project:1.7.0 and is removed from my_project:2.0.0. Use + * bar() instead. + * @see https://git.drupalcode.org/project/drupal/-/work_items/123 + */ +function meanwhile_gitlab() { +} diff --git a/tests/Drupal/Commenting/DeprecatedUnitTest.inc.fixed b/tests/Drupal/Commenting/DeprecatedUnitTest.inc.fixed index a1497f6c4708323412435ce9ec1115e8366f239d..ce6288ac827cd31c70bb40364338f52a1ce94f6f 100644 --- a/tests/Drupal/Commenting/DeprecatedUnitTest.inc.fixed +++ b/tests/Drupal/Commenting/DeprecatedUnitTest.inc.fixed @@ -110,3 +110,13 @@ function w() { */ function meanwhile() { } + +/** + * Test deprecation in doc block with GitLab URL. + * + * @deprecated in my_project:1.7.0 and is removed from my_project:2.0.0. Use + * bar() instead. + * @see https://git.drupalcode.org/project/drupal/-/work_items/123 + */ +function meanwhile_gitlab() { +} diff --git a/tests/Drupal/Semantics/FunctionTriggerErrorUnitTest.2.inc b/tests/Drupal/Semantics/FunctionTriggerErrorUnitTest.2.inc index 0230dbacbef6506b8bc88e5932535c1f884af2df..90000915e15a6fa6fdc29cc3d80f6ae022024c97 100644 --- a/tests/Drupal/Semantics/FunctionTriggerErrorUnitTest.2.inc +++ b/tests/Drupal/Semantics/FunctionTriggerErrorUnitTest.2.inc @@ -32,7 +32,7 @@ function foo2() { /** * Test function three. * - * @deprecated in my_projectl:1.7.0 and is removed from my_project:2.0.0. Use + * @deprecated in my_project:1.7.0 and is removed from my_project:2.0.0. Use * bar() instead. * @see https://www.drupal.org/node/123 */ @@ -48,3 +48,14 @@ function foo4() { // This passes the contrib semantic versioning, relaxed standard. @trigger_error('Function foo4() is deprecated in my_project:2.8.0 and will be gone by my_project:3.0.0. See https://www.drupal.org/node/123', E_USER_DEPRECATED); } + +/** + * Test function five with GitLab URL. + * + * @deprecated in my_project:1.7.0 and is removed from my_project:2.0.0. Use + * bar() instead. + * @see https://git.drupalcode.org/project/drupal/-/work_items/123 + */ +function foo5(): void { + @trigger_error('Function foo5() is deprecated in my_project:1.7.0 and is removed from my_project:2.0.0. Use bar() instead. See https://git.drupalcode.org/project/drupal/-/work_items/123', E_USER_DEPRECATED); +}