Skip to content

Ruleset: remove support for standards called "Internal" #988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -892,11 +892,13 @@ private function expandSniffDirectory($directory, $depth=0)
*/
private function expandRulesetReference($ref, $rulesetDir, $depth=0)
{
// Naming an (external) standard "Internal" is deprecated.
// Naming an (external) standard "Internal" is not supported.
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);
$this->msgCache->add($message, MessageCollector::ERROR);

return [];
}

// Ignore internal sniffs codes as they are used to only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

<rule ref="Internal"/>

<!-- Prevent a "no sniffs were registered" error. -->
<rule ref="Generic.PHP.BacktickOperator"/>
</ruleset>
16 changes: 8 additions & 8 deletions tests/Core/Ruleset/ExpandRulesetReferenceInternalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,30 @@ public function testInternalRefDoesNotGetExpanded()


/**
* While definitely not recommended, including a standard named "Internal", _does_ allow for sniffs to be registered.
* As of PHPCS 4.0, a standard can no longer be named "Internal".
*
* Note: customizations (exclusions/property setting etc) for individual sniffs may not always be handled correctly,
* which is why naming a standard "Internal" is definitely not recommended.
* Standards with this name will be ignored.
*
* @return void
*/
public function testInternalStandardDoesGetExpanded()
public function testInternalStandardIsNotSupported()
{
$message = 'DEPRECATED: The name "Internal" is reserved for internal use. A PHP_CodeSniffer standard should not be called "Internal".'.PHP_EOL;
$message = 'ERROR: 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);
$this->expectRuntimeExceptionMessage($message);

// Set up the ruleset.
$standard = __DIR__.'/ExpandRulesetReferenceInternalStandardTest.xml';
$config = new ConfigDouble(["--standard=$standard"]);
$ruleset = new Ruleset($config);

$expected = ['Internal.Valid.Valid' => 'Fixtures\\Internal\\Sniffs\\Valid\\ValidSniff'];
$expected = ['Generic.PHP.BacktickOperator' => 'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\PHP\\BacktickOperatorSniff'];

// This assertion will only take effect for PHPUnit 10+.
$this->assertSame($expected, $ruleset->sniffCodes);

}//end testInternalStandardDoesGetExpanded()
}//end testInternalStandardIsNotSupported()


}//end class