Skip to content
Snippets Groups Projects
Unverified Commit d51e0b8c authored by Mitch Portier's avatar Mitch Portier Committed by GitHub
Browse files

fix(CoreVersionRequirement): Ensure sniff is only run on project info.yml...

fix(CoreVersionRequirement): Ensure sniff is only run on project info.yml files (#3133361 by Arkener)
parent 5c7b3890
Branches
Tags
No related merge requests found
......@@ -49,11 +49,18 @@ class CoreVersionRequirementSniff implements Sniff
*/
public function process(File $phpcsFile, $stackPtr)
{
$fileExtension = strtolower(substr($phpcsFile->getFilename(), -9));
$filename = $phpcsFile->getFilename();
$fileExtension = strtolower(substr($filename, -9));
if ($fileExtension !== '.info.yml') {
return ($phpcsFile->numTokens + 1);
}
// Exclude config files which might contain the info.yml extension.
$filenameWithoutExtension = substr($filename, 0, -9);
if (strpos($filenameWithoutExtension, '.') !== false) {
return ($phpcsFile->numTokens + 1);
}
$contents = file_get_contents($phpcsFile->getFilename());
try {
$info = Yaml::parse($contents);
......@@ -62,6 +69,11 @@ class CoreVersionRequirementSniff implements Sniff
return ($phpcsFile->numTokens + 1);
}
// Check if the type key is set, to verify if we're inside a project info.yml file.
if (isset($info['type']) === false) {
return ($phpcsFile->numTokens + 1);
}
// Test modules can omit the core_version_requirement key.
if (isset($info['package']) === true && $info['package'] === 'Testing') {
return ($phpcsFile->numTokens + 1);
......
......@@ -61,6 +61,7 @@ class CoreVersionRequirementUnitTest extends CoderSniffUnitTest
return [
__DIR__.'/core_version.info.yml',
__DIR__.'/core_version_test.info.yml',
__DIR__.'/core_version.config.info.yml',
];
}//end getTestFiles()
......
type: coder
description: 'This is a configuration file.'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment