From: Jeffrey Merkey <jeffmerkey@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: apw@canonical.com, joe@perches.com
Subject: [PATCH] Add fix case for open braces
Date: Mon, 15 Feb 2016 18:20:06 -0700 [thread overview]
Message-ID: <1455585606-21054-1-git-send-email-jeffmerkey@gmail.com> (raw)
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
reply other threads:[~2016-02-16 1:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1455585606-21054-1-git-send-email-jeffmerkey@gmail.com \
--to=jeffmerkey@gmail.com \
--cc=apw@canonical.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®