fixed 'base search dir' + fixed 'blank line inserted' when line before ends with colon
This commit is contained in:
parent
d528b7481f
commit
3d5a96ef98
19
check_cs
19
check_cs
@ -26,7 +26,7 @@ $finder
|
|||||||
->name('*.xml')
|
->name('*.xml')
|
||||||
->name('*.xml.dist')
|
->name('*.xml.dist')
|
||||||
->name('*.yml')
|
->name('*.yml')
|
||||||
->in(__DIR__.'/src', __DIR__.'/tests')
|
->in(__DIR__)
|
||||||
->notName(basename(__FILE__))
|
->notName(basename(__FILE__))
|
||||||
->exclude('.git')
|
->exclude('.git')
|
||||||
->exclude('vendor')
|
->exclude('vendor')
|
||||||
@ -34,6 +34,9 @@ $finder
|
|||||||
|
|
||||||
$exit = 0;
|
$exit = 0;
|
||||||
foreach ($finder as $file) {
|
foreach ($finder as $file) {
|
||||||
|
|
||||||
|
/* @var $file Symfony\Component\Finder\SplFileInfo */
|
||||||
|
|
||||||
// These files are skipped because tests would break
|
// These files are skipped because tests would break
|
||||||
if (in_array($file->getRelativePathname(), array(
|
if (in_array($file->getRelativePathname(), array(
|
||||||
'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php',
|
'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php',
|
||||||
@ -68,11 +71,13 @@ foreach ($finder as $file) {
|
|||||||
|
|
||||||
// [Structure] Add a blank line before return statements
|
// [Structure] Add a blank line before return statements
|
||||||
$new = preg_replace_callback('/(^.*$)\n(^ +return)/m', function ($match) {
|
$new = preg_replace_callback('/(^.*$)\n(^ +return)/m', function ($match) {
|
||||||
// don't add it if the previous line is
|
// don't add it if the previous line is ...
|
||||||
// * {
|
if (
|
||||||
// * :
|
preg_match('/\{$/m', $match[1]) || // ... ending with an opening brace
|
||||||
// * already blank line
|
preg_match('/\:$/m', $match[1]) || // ... ending with a colon (e.g. a case statement)
|
||||||
if (preg_match('#(\{ *$|^$|^ *//|\:)#', $match[1])) {
|
preg_match('%^ *//%m', $match[1]) || // ... an inline comment
|
||||||
|
preg_match('/^$/m', $match[1]) // ... already blank
|
||||||
|
) {
|
||||||
return $match[1]."\n".$match[2];
|
return $match[1]."\n".$match[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +85,7 @@ foreach ($finder as $file) {
|
|||||||
}, $new);
|
}, $new);
|
||||||
|
|
||||||
// [Structure] A file must always ends with a linefeed character
|
// [Structure] A file must always ends with a linefeed character
|
||||||
if (strlen($new) && "\n" != $new[strlen($new) - 1]) {
|
if (strlen($new) && "\n" != substr($new, -1)) {
|
||||||
$new .= "\n";
|
$new .= "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user