From fb5eaeb0cf56cb377b3d8efeccbce5d868e11aea Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 31 Jan 2025 00:00:11 +0100 Subject: [PATCH] Ruleset: hard deprecate support for standards called "Internal" Support for standards called `Internal` was soft deprecated in PHPCS 3.12.0 This PR adds a new Ruleset deprecation notice for when such a standard would be requested from a ruleset. Support for sniffs not following the naming conventions will be removed in PHPCS 4.0. Includes test. Related to 799 --- src/Ruleset.php | 7 +++++++ tests/Core/Ruleset/ExpandRulesetReferenceInternalTest.php | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/Ruleset.php b/src/Ruleset.php index b6279bf9f3..a78e2f9b3d 100644 --- a/src/Ruleset.php +++ b/src/Ruleset.php @@ -892,6 +892,13 @@ private function expandSniffDirectory($directory, $depth=0) */ private function expandRulesetReference($ref, $rulesetDir, $depth=0) { + // Naming an (external) standard "Internal" is deprecated. + if (strtolower($ref) === 'internal') { + $message = 'The name "Internal" is reserved for internal use. A PHP_CodeSniffer standard should not be called "Internal".'.PHP_EOL; + $message .= 'Contact the maintainer of the standard to fix this.'; + $this->msgCache->add($message, MessageCollector::DEPRECATED); + } + // Ignore internal sniffs codes as they are used to only // hide and change internal messages. if (substr($ref, 0, 9) === 'Internal.') { diff --git a/tests/Core/Ruleset/ExpandRulesetReferenceInternalTest.php b/tests/Core/Ruleset/ExpandRulesetReferenceInternalTest.php index edac7490d0..5f0180dacb 100644 --- a/tests/Core/Ruleset/ExpandRulesetReferenceInternalTest.php +++ b/tests/Core/Ruleset/ExpandRulesetReferenceInternalTest.php @@ -51,6 +51,11 @@ public function testInternalRefDoesNotGetExpanded() */ public function testInternalStandardDoesGetExpanded() { + $message = 'DEPRECATED: The name "Internal" is reserved for internal use. A PHP_CodeSniffer standard should not be called "Internal".'.PHP_EOL; + $message .= 'Contact the maintainer of the standard to fix this.'.PHP_EOL.PHP_EOL; + + $this->expectOutputString($message); + // Set up the ruleset. $standard = __DIR__.'/ExpandRulesetReferenceInternalStandardTest.xml'; $config = new ConfigDouble(["--standard=$standard"]);