From 3d5a96ef9846abfaffb3a5d9cc6e73e949effe48 Mon Sep 17 00:00:00 2001 From: Brikou CARRE Date: Wed, 8 Jun 2011 16:21:52 +0200 Subject: [PATCH] fixed 'base search dir' + fixed 'blank line inserted' when line before ends with colon --- check_cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/check_cs b/check_cs index 23bd0b8332..87618dd613 100755 --- a/check_cs +++ b/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"; }