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.dist')
|
||||
->name('*.yml')
|
||||
->in(__DIR__.'/src', __DIR__.'/tests')
|
||||
->in(__DIR__)
|
||||
->notName(basename(__FILE__))
|
||||
->exclude('.git')
|
||||
->exclude('vendor')
|
||||
@ -34,6 +34,9 @@ $finder
|
||||
|
||||
$exit = 0;
|
||||
foreach ($finder as $file) {
|
||||
|
||||
/* @var $file Symfony\Component\Finder\SplFileInfo */
|
||||
|
||||
// These files are skipped because tests would break
|
||||
if (in_array($file->getRelativePathname(), array(
|
||||
'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php',
|
||||
@ -68,11 +71,13 @@ foreach ($finder as $file) {
|
||||
|
||||
// [Structure] Add a blank line before return statements
|
||||
$new = preg_replace_callback('/(^.*$)\n(^ +return)/m', function ($match) {
|
||||
// don't add it if the previous line is
|
||||
// * {
|
||||
// * :
|
||||
// * already blank line
|
||||
if (preg_match('#(\{ *$|^$|^ *//|\:)#', $match[1])) {
|
||||
// don't add it if the previous line is ...
|
||||
if (
|
||||
preg_match('/\{$/m', $match[1]) || // ... ending with an opening brace
|
||||
preg_match('/\:$/m', $match[1]) || // ... ending with a colon (e.g. a case statement)
|
||||
preg_match('%^ *//%m', $match[1]) || // ... an inline comment
|
||||
preg_match('/^$/m', $match[1]) // ... already blank
|
||||
) {
|
||||
return $match[1]."\n".$match[2];
|
||||
}
|
||||
|
||||
@ -80,7 +85,7 @@ foreach ($finder as $file) {
|
||||
}, $new);
|
||||
|
||||
// [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";
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user