1
0
Fork 0

Merge pull request #7019 from mhujer/mh-validate-script-descriptions

Validation warns if script description for nonexistent script is present
pull/7024/merge
Jordi Boggiano 2018-01-22 14:05:39 +01:00 committed by GitHub
commit 9f60e50401
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -118,6 +118,18 @@ class ConfigValidator
} }
} }
// report scripts-descriptions for non-existent scripts
$scriptsDescriptions = isset($manifest['scripts-descriptions']) ? $manifest['scripts-descriptions'] : array();
$scripts = isset($manifest['scripts']) ? $manifest['scripts'] : array();
foreach ($scriptsDescriptions as $scriptName => $scriptDescription) {
if (!array_key_exists($scriptName, $scripts)) {
$warnings[] = sprintf(
'Description for non-existent script "%s" found in "scripts-descriptions"',
$scriptName
);
}
}
// check for empty psr-0/psr-4 namespace prefixes // check for empty psr-0/psr-4 namespace prefixes
if (isset($manifest['autoload']['psr-0'][''])) { if (isset($manifest['autoload']['psr-0'][''])) {
$warnings[] = "Defining autoload.psr-0 with an empty namespace prefix is a bad idea for performance"; $warnings[] = "Defining autoload.psr-0 with an empty namespace prefix is a bad idea for performance";

View File

@ -34,4 +34,15 @@ class ConfigValidatorTest extends TestCase
$warnings $warnings
); );
} }
public function testConfigValidatorWarnsOnScriptDescriptionForNonexistentScript()
{
$configValidator = new ConfigValidator(new NullIO());
list(, , $warnings) = $configValidator->validate(__DIR__ . '/Fixtures/composer_scripts-descriptions.json');
$this->assertContains(
'Description for non-existent script "phpcsxxx" found in "scripts-descriptions"',
$warnings
);
}
} }

View File

@ -0,0 +1,10 @@
{
"scripts": {
"test": "phpunit",
"phpcs": "phpcs --standard=PSR2 src"
},
"scripts-descriptions": {
"test": "Launches the preconfigured PHPUnit",
"phpcsxxx": "Checks that the application code conforms to coding standard"
}
}