The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Gregory Fong <gregory.0xf0@gmail.com>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>
Cc: Brian Norris <computersforpeace@gmail.com>,
	linux-kernel@vger.kernel.org,
	Gregory Fong <gregory.0xf0@gmail.com>
Subject: [PATCH 1/1] checkpatch.pl: 1-tab relative indent for conditionals/blocks
Date: Fri, 18 Jul 2014 12:40:47 -0700	[thread overview]
Message-ID: <1405712447-18788-1-git-send-email-gregory.0xf0@gmail.com> (raw)

The following would incorrectly pass checkpatch:

void foo(void)
{
        if (a) {
                something;
                somethingelse;
        } else {
                        messed_up_indentation;
                }
}

Assume single-tab indentation of blocks to catch this.
Also add "else" to the list to check.

Signed-off-by: Gregory Fong <gregory.0xf0@gmail.com>
---
 scripts/checkpatch.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 182be0f..f94c364 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2523,7 +2523,8 @@ sub process {
 		}
 
 # Check relative indent for conditionals and blocks.
-		if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
+		if ($line =~ /\b(?:(?:if|while|for)\s*\(|do|else\b)/ &&
+		    $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
 			($stat, $cond, $line_nr_next, $remain_next, $off_next) =
 				ctx_statement_block($linenr, $realcnt, 0)
 					if (!defined $stat);
@@ -2606,6 +2607,7 @@ sub process {
 			#print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
 
 			if ($check && (($sindent % 8) != 0 ||
+			    ((($sindent - $indent) / 8) > 1) ||
 			    ($sindent <= $indent && $s ne ''))) {
 				WARN("SUSPECT_CODE_INDENT",
 				     "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
-- 
1.8.3.2


             reply	other threads:[~2014-07-18 19:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-18 19:40 Gregory Fong [this message]
2014-07-18 20:39 ` [PATCH 1/1] checkpatch.pl: 1-tab relative indent for conditionals/blocks Joe Perches

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=1405712447-18788-1-git-send-email-gregory.0xf0@gmail.com \
    --to=gregory.0xf0@gmail.com \
    --cc=apw@canonical.com \
    --cc=computersforpeace@gmail.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