made some enhancement to check_cs
This commit is contained in:
parent
5f8a0f5d23
commit
8d262bf1c6
25
check_cs
25
check_cs
@ -52,22 +52,35 @@ foreach ($finder as $file) {
|
|||||||
|
|
||||||
$new = $old;
|
$new = $old;
|
||||||
|
|
||||||
// [Structure] Never use short tags (<?);
|
// [Structure] Never use short tags (<?)
|
||||||
$new = str_replace('<? ', '<?php ', $new);
|
$new = str_replace('<? ', '<?php ', $new);
|
||||||
|
|
||||||
// [Structure] Indentation is done by steps of four spaces (tabs are never allowed);
|
// [Structure] Indentation is done by steps of four spaces (tabs are never allowed)
|
||||||
$new = preg_replace_callback('/^( *)(\t+)/m', function ($matches) use ($new) {
|
$new = preg_replace_callback('/^( *)(\t+)/m', function ($matches) use ($new) {
|
||||||
return $matches[1].str_repeat(' ', strlen($matches[2]));
|
return $matches[1].str_repeat(' ', strlen($matches[2]));
|
||||||
}, $new);
|
}, $new);
|
||||||
|
|
||||||
// [Structure] Use the linefeed character (0x0A) to end lines;
|
// [Structure] Use the linefeed character (0x0A) to end lines
|
||||||
$new = str_replace("\r\n", "\n", $new);
|
$new = str_replace("\r\n", "\n", $new);
|
||||||
|
|
||||||
// [Structure] Don't add trailing spaces at the end of lines;
|
// [Structure] Don't add trailing spaces at the end of lines
|
||||||
$new = preg_replace('/[ \t]*$/m', '', $new);
|
$new = preg_replace('/[ \t]*$/m', '', $new);
|
||||||
|
|
||||||
// [Structure] Add a blank line before return statements;
|
// [Structure] Add a blank line before return statements
|
||||||
$new = preg_replace('/([^ {|\n]$)(\n return .+?$\n \}$)/m', '$1'."\n".'$2', $new);
|
$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])) {
|
||||||
|
return $match[1]."\n".$match[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $match[1]."\n\n".$match[2];
|
||||||
|
}, $new);
|
||||||
|
|
||||||
|
// [Structure] A file must always ends with a linefeed character
|
||||||
|
// FIXME
|
||||||
|
|
||||||
if ($new != $old) {
|
if ($new != $old) {
|
||||||
$exit = 1;
|
$exit = 1;
|
||||||
|
Reference in New Issue
Block a user