Unverified Commit c39e5b9d authored by Jonathan Smith's avatar Jonathan Smith Committed by GitHub
Browse files

fix(Deprecated): Deprecation error messages don't allow module:n.n.n versions...

fix(Deprecated): Deprecation error messages don't allow module:n.n.n versions (#3192093 by jonathan1055, JohnAlbin)
parent cab1d0b1
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -169,12 +169,12 @@ class DeprecatedSniff implements Sniff
            }
        } else {
            // The text follows the basic layout. Now check that the versions
            // match drupal:n.n.n or project:n.x-n.n or project:n.x-n.n-version[n]
            // or project:n.n.n or project:n.n.n-version[n].
            // match drupal:n.n.n or project:n.x-n.n or project:n.x-n.n-label[n]
            // or project:n.n.n or project:n.n.n-label[n].
            // The text must be all lower case and numbers can be one or two digits.
            foreach (['deprecation-version' => $matches[1], 'removal-version' => $matches[2]] as $name => $version) {
                if (preg_match('/^[a-z\d_]+:(\d{1,2}\.\d{1,2}\.\d{1,2}|\d{1,2}\.x\-\d{1,2}\.\d{1,2})(-[a-z]{1,5}\d{1,2})?$/', $version) === 0) {
                    $error = "The %s '%s' does not match the lower-case machine-name standard: drupal:n.n.n or project:n.x-n.n or project:n.x-n.n-version[n] or project:n.n.n or project:n.n.n-version[n]";
                    $error = "The %s '%s' does not match the lower-case machine-name standard: drupal:n.n.n or project:n.x-n.n or project:n.x-n.n-label[n] or project:n.n.n or project:n.n.n-label[n]";
                    $phpcsFile->addWarning($error, $stackPtr, 'DeprecatedVersionFormat', [$name, $version]);
                }
            }
+4 −5
Original line number Diff line number Diff line
@@ -152,13 +152,12 @@ class FunctionTriggerErrorSniff extends FunctionCall
            $phpcsFile->addError($error, $argument['start'], $sniff, [$messageText]);
        } else {
            // The text follows the basic layout. Now check that the version
            // matches drupal:n.n.n or project:n.x-n.n. The text must be all
            // matches drupal:n.n.n or project:n.x-n.n or project:n.x-n.n-label[n]
            // or project:n.n.n or project:n.n.n-label[n]. The text must be all
            // lower case and numbers can be one or two digits.
            foreach (['deprecation-version' => $matches[2], 'removal-version' => $matches[4]] as $name => $version) {
                if (preg_match('/^drupal:\d{1,2}\.\d{1,2}\.\d{1,2}$/', $version) === 0
                    && preg_match('/^[a-z\d_]+:\d{1,2}\.x\-\d{1,2}\.\d{1,2}$/', $version) === 0
                ) {
                    $error = "The %s '%s' does not match the lower-case machine-name standard: drupal:n.n.n or project:n.x-n.n";
                if (preg_match('/^[a-z\d_]+:(\d{1,2}\.\d{1,2}\.\d{1,2}|\d{1,2}\.x\-\d{1,2}\.\d{1,2})(-[a-z]{1,5}\d{1,2})?$/', $version) === 0) {
                    $error = "The %s '%s' does not match the lower-case machine-name standard: drupal:n.n.n or project:n.x-n.n or project:n.x-n.n-label[n] or project:n.n.n or project:n.n.n-label[n]";
                    $phpcsFile->addWarning($error, $argument['start'], 'TriggerErrorVersion', [$name, $version]);
                }
            }
+8 −8
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

/**
 * @file
 * Example code lines for FunctionTriggerError sniff test.
 * Test data for the relaxed version of FunctionTriggerError coding standard.
 */

// Passes.
@@ -11,19 +11,19 @@
// Not E_USER_DEPRECATED, so cannot fail it.
@trigger_error('CommentTestBase is deprecated in drupal 8.4.0', E_USER_SOMETHING_ELSE);
// All correct.
@trigger_error('\Drupal\Some\Class\Foo is deprecated in drupal:8.5.0 and wont work in in drupal:9.0.0. Use \Drupal\Foo\Bar instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
@trigger_error('\Drupal\Some\Class\Foo is deprecated in drupal:8.5.0 and will not work in in drupal:9.0.0. Use \Drupal\Foo\Bar instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
// Alternative using __NAMESPACE__.
@trigger_error(__NAMESPACE__ . '\Foo is deprecated in drupal:8.5.12 and wont work in drupal:9.0.0. Use \Drupal\Foo\Bar instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
@trigger_error(__NAMESPACE__ . '\Foo is deprecated in drupal:8.5.12 and will not work in drupal:9.0.0. Use \Drupal\Foo\Bar instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
// Alternative https url and cater for E_User_Deprecated in non-upper case.
@trigger_error("\Drupal\Some\Class\Foo is deprecated in drupal:8.11.0 and wont work in drupal:9.0.0. Use \Drupal\Foo. See https://www.drupal.org/project/drupal/issues/2908490", E_User_Deprecated);
@trigger_error("\Drupal\Some\Class\Foo is deprecated in drupal:8.11.0 and will not work in drupal:9.0.0. Use \Drupal\Foo. See https://www.drupal.org/project/drupal/issues/2908490", E_User_Deprecated);
// Alternative syntax for contrib project and issue url.
@trigger_error('Function foo_bar() is deprecated in my_module:8.x-2.0 and wont work in my_module:9.x-1.0. Use bar_baz() instead. See https://www.drupal.org/project/my_module/issues/2908490', E_USER_DEPRECATED);
@trigger_error('Function foo_bar() is deprecated in my_module:8.x-2.0 and will not work in my_module:9.x-1.0. Use bar_baz() instead. See https://www.drupal.org/project/my_module/issues/2908490', E_USER_DEPRECATED);
// Cater for sprintf inside the message.
@trigger_error(sprintf('Function %s is deprecated in drupal:8.5.0 and wont work in drupal:9.0.0. Use foo() instead. See http://www.drupal.org/project/my_module/issues/123', $settings), E_USER_DEPRECATED);
@trigger_error(sprintf('Function %s is deprecated in drupal:8.5.0 and will not work in drupal:9.0.0. Use foo() instead. See http://www.drupal.org/project/my_module/issues/123', $settings), E_USER_DEPRECATED);
// Cater for concatenations in the message.
@trigger_error(__METHOD__ . ' method is deprecated in drupal:8.4.0 and wont work in drupal:9.0.0. Use ' . __CLASS__ . '::bundle() instead. See https://www.drupal.org/project/drupal/issues/12345', E_USER_DEPRECATED);
@trigger_error(__METHOD__ . ' method is deprecated in drupal:8.4.0 and will not work in drupal:9.0.0. Use ' . __CLASS__ . '::bundle() instead. See https://www.drupal.org/project/drupal/issues/12345', E_USER_DEPRECATED);
// Cater for concatenation with nothing else before 'is deprecated.
@trigger_error(__NAMESPACE__ . ' is deprecated in drupal:8.5.0 and wont work in drupal:9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
@trigger_error(__NAMESPACE__ . ' is deprecated in drupal:8.5.0 and will not work in drupal:9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
// Varibale interpolation, and no extra info (optional in relaxed standard).
@trigger_error("Thing::\${$name} is deprecated in drupal:9.1.0 and will error in drupal:10.0.0. See https://www.drupal.org/node/3177488", E_USER_DEPRECATED);

+19 −0
Original line number Diff line number Diff line
@@ -29,3 +29,22 @@ function foo2() {
  @trigger_error('Function foo2() is deprecated in drupal:8.5.0 but instead use bar() in drupal:9.0.0. See https://www.drupal.org/node/123', E_USER_DEPRECATED);
}

/**
 * Test function three.
 *
 * @deprecated in my_projectl:1.7.0 and is removed from my_project:2.0.0. Use
 *   bar() instead.
 * @see https://www.drupal.org/node/123
 */
function foo3() {
  // This passes the contrib semantic versioning, strict standard.
  @trigger_error('Function foo3() is 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', E_USER_DEPRECATED);
}

/**
 * Test function four.
 */
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);
}