8000 fixed 'base search dir' + fixed 'blank line inserted' when line befor… · 77web/symfony@3d5a96e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d5a96e

Browse files
committed
fixed 'base search dir' + fixed 'blank line inserted' when line before ends with colon
1 parent d528b74 commit 3d5a96e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

check_cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ $finder
2626
->name('*.xml')
2727
->name('*.xml.dist')
2828
->name('*.yml')
29-
->in(__DIR__.'/src', __DIR__.'/tests')
29+
->in(__DIR__)
3030
->notName(basename(__FILE__))
3131
->exclude('.git')
3232
->exclude('vendor')
3333
;
3434

3535
$exit = 0;
3636
foreach ($finder as $file) {
37+
38+
/* @var $file Symfony\Component\Finder\SplFileInfo */
39+
3740
// These files are skipped because tests would break
3841
if (in_array($file->getRelativePathname(), array(
3942
'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php',
@@ -68,19 +71,21 @@ foreach ($finder as $file) {
6871

6972
// [Structure] Add a blank line before return statements
7073
$new = preg_replace_callback('/(^.*$)\n(^ +return)/m', function ($match) {
71-
// don't add it if the previous line is
72-
// * {
73-
// * :
74-
// * already blank line
75-
if (preg_match('#(\{ *$|^$|^ *//|\:)#', $match[1])) {
74+
// don't add it if the previous line is ...
75+
if (
76+
preg_match('/\{$/m', $match[1]) || // ... ending with an opening brace
77+
preg_match('/\:$/m', $match[1]) || // ... ending with a colon (e.g. a case statement)
78+
preg_match('%^ *//%m', $match[1]) || // ... an inline comment
79+
preg_match('/^$/m', $match[1]) // ... already blank
80+
) {
7681
return $match[1]."\n".$match[2];
7782
}
7883

7984
return $match[1]."\n\n".$match[2];
8085
}, $new);
8186

8287
// [Structure] A file must always ends with a linefeed character
83-
if (strlen($new) && "\n" != $new[strlen($new) - 1]) {
88+
if (strlen($new) && "\n" != substr($new, -1)) {
8489
$new .= "\n";
8590
}
8691

0 commit comments

Comments
 (0)
0