From: Joe Perches <joe@perches.com>
To: David Miller <davem@davemloft.net>,
Andy Whitcroft <apw@shadowen.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: andrei.emeltchenko.news@gmail.com, linville@tuxdriver.com,
linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] checkpatch: Add some --strict coding style checks
Date: Tue, 21 Feb 2012 12:59:19 -0800 [thread overview]
Message-ID: <1329857959.5143.11.camel@joe2Laptop> (raw)
In-Reply-To: <20120221.154053.2103818562080068513.davem@davemloft.net>
Argument alignment across multiple lines should
match the open parenthesis.
Logical continuations should be at the end of
the previous line, not the start of a new line.
These are not required by CodingStyle so make the
tests active only when using --strict.
Tested with:
int foo(void)
{
if (foo &&
bar())
baz();
if (foo &&
bar())
baz();
foo_some_long_function(bar,
baz);
foo_some_long_function(bar,
baz);
return 0;
}
Signed-off-by: Joe Perches <joe@perches.com>
---
scripts/checkpatch.pl | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a3b9782..629944e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1783,6 +1783,28 @@ sub process {
"please, no space before tabs\n" . $herevet);
}
+# check for && or || at the start of a line
+ if ($rawline =~ /^\+\s*(&&|\|\|)/) {
+ CHK("LOGICAL_CONTINUATIONS",
+ "Logical continuations should be on the previous line\n" . $hereprev);
+ }
+
+# check multi-line statement indentation matches previous line
+ if ($prevline =~ /^\+(\t*)(if \(|$Ident\().*(\&\&|\|\||,)\s*$/ && $rawline =~ /^\+([ \t]*)/) {
+ $prevline =~ /^\+(\t*)(if \(|$Ident\().*(\&\&|\|\||,)\s*$/;
+ my $oldindent = $1;
+ my $if_or_func = $2;
+ $rawline =~ /^\+([ \t]*)/;
+ my $newindent = $1;
+ my $goodindent = $oldindent .
+ "\t" x (length($if_or_func) / 8) .
+ " " x (length($if_or_func) % 8);
+ if ($newindent ne "$goodindent") {
+ CHK("PARENTHESIS_ALIGNMENT",
+ "Alignment should match open parenthesis\n" . $hereprev);
+ }
+ }
+
# check for spaces at the beginning of a line.
# Exceptions:
# 1) within comments
next prev parent reply other threads:[~2012-02-21 20:59 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-20 20:37 pull request: wireless 2012-02-20 John W. Linville
2012-02-21 0:23 ` David Miller
2012-02-21 15:14 ` John W. Linville
2012-02-21 19:44 ` David Miller
2012-02-21 20:38 ` Andrei Emeltchenko
2012-02-21 20:40 ` David Miller
2012-02-21 20:59 ` Joe Perches [this message]
2012-02-21 21:09 ` [PATCH] checkpatch: Add some --strict coding style checks Andrew Morton
2012-02-21 21:11 ` Joe Perches
2012-02-21 22:09 ` Allan, Bruce W
2012-02-21 23:16 ` Joe Perches
2012-02-22 1:36 ` Joe Perches
2012-02-22 1:56 ` Allan, Bruce W
2012-02-22 1:58 ` Joe Perches
2012-02-22 2:17 ` Allan, Bruce W
2012-02-23 3:43 ` Joe Perches
2012-02-24 18:22 ` Allan, Bruce W
2012-02-24 18:37 ` [PATCH v2] " Joe Perches
2012-02-29 14:38 ` Kalle Valo
2012-02-22 9:35 ` [PATCH] " David Laight
2012-02-22 9:46 ` Johannes Berg
2012-02-22 10:07 ` pull request: wireless 2012-02-20 Zefir Kurtisi
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=1329857959.5143.11.camel@joe2Laptop \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=andrei.emeltchenko.news@gmail.com \
--cc=apw@shadowen.org \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=netdev@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;
as well as URLs for NNTP newsgroup(s).