* [PATCH] Add fix case for open braces
@ 2016-02-16 1:20 Jeffrey Merkey
0 siblings, 0 replies; only message in thread
From: Jeffrey Merkey @ 2016-02-16 1:20 UTC (permalink / raw)
To: linux-kernel; +Cc: apw, joe
Some quite excellent fixes from Joe Perches that belong
back in the original. Submitting to Joe for inclusion. Joe
was the original author of these fixes that save a lot of time
rewriting code. Thanks Joe.
Signed-off-by: Jeffrey Merkey <jeffmerkey@gmail.com>
---
scripts/checkpatch.pl | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 874132b..71f93e8 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3108,9 +3108,15 @@ sub process {
#print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
- ERROR("OPEN_BRACE",
- "that open brace { should be on the previous line\n" .
- "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
+ if (ERROR("OPEN_BRACE",
+ "that open brace { should be on the previous line\n" .
+ "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n") &&
+ $fix &&
+ $rawlines[$ctx_ln - 2] =~ /^\+/ &&
+ $rawlines[$ctx_ln - 1] =~ /^\+\s*{\s*$/) {
+ $fixed[$ctx_ln - 2] = rtrim($fixed[$ctx_ln - 2]) . ' {';
+ fix_delete_line($ctx_ln - 1, $rawlines[$ctx_ln - 1]);
+ }
}
if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
$ctx =~ /\)\s*\;\s*$/ &&
@@ -4807,8 +4813,15 @@ sub process {
$herectx .= raw_line($linenr, $n) . "\n";
}
- WARN("BRACES",
- "braces {} are not necessary for single statement blocks\n" . $herectx);
+ if (WARN("BRACES",
+ "braces {} are not necessary for single statement blocks\n" . $herectx) &&
+ $fix &&
+ $fixed[$fixlinenr] =~ /^\+.*\{\s*$/ &&
+ $fixed[$fixlinenr + 1] =~ /^\+.*;\s*$/ &&
+ $fixed[$fixlinenr + 2] =~ /^\+\s*\}\s*$/) {
+ $fixed[$fixlinenr] =~ s/\{\s*$//;
+ fix_delete_line($fixlinenr + 2, $rawlines[$fixlinenr + 2]);
+ }
}
}
--
1.8.3.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-02-16 1:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-16 1:20 [PATCH] Add fix case for open braces Jeffrey Merkey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®