[PATCH, v2] checkpatch: Warn on code with 6+ tab indentation, remove 80col warning

Ingo Molnar
2012-02-04T13:04:15Z

* Joe Perches <joe@perches.com> wrote:

> Overly indented code should be refactored.

_AND_ the 80 cols warning should be removed. The overwhelming
majority of developers either ignore the 80 cols warning or make
the code worse as a result of the warning.

So something like the patch below.

Thanks,

Ingo

--------------------->
Subject: checkpatch: Warn on code with 6+ tab indentation, remove 80col warning

It's better to warn about too deeply indented code than about
too long lines, as the too long line tends to cause people to
think about *that line*, instead of the surrounding code, fixing
it by breaking the line unnecessarily, etc.

If we warn about too deep indentation then the fix will be a
natural one: people will reduce code complexity, which is an
almost black and white good thing.

The few false positives can be ignored.

Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e3bfcbe..5406011 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1726,17 +1726,6 @@ sub process {
# check we are in a valid source file if not then ignore this hunk
next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);

-#80 column limit
- if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
- $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
- !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ ||
- $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
- $length > 80)
- {
- WARN("LONG_LINE",
- "line over 80 characters\n" . $herecurr);
- }
-
# check for spaces before a quoted newline
if ($rawline =~ /^.*\".*\s\\n/) {
WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
@@ -1924,6 +1913,12 @@ sub process {
my $pre_ctx = "$1$2";

my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
+
+ if ($line =~ /^\+\t{6,}/) {
+ WARN("DEEP_INDENTATION",
+ "Too many leading tabs - code should probably be split up\n" . $herecurr);
+ }
+
my $ctx_cnt = $realcnt - $#ctx - 1;
my $ctx = join("\n", @ctx);