Skip to content

Commit 8eef05d

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: Warn on code with 6+ tab indentation
Overly indented code should be refactored. Suggest refactoring excessive indentation of of if/else/for/do/while/switch statements. For example: $ cat t.c #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if (1) if (2) if (3) if (4) if (5) if (6) if (7) if (8) ; return 0; } $ ./scripts/checkpatch.pl -f t.c WARNING: Too many leading tabs - consider code refactoring #12: FILE: t.c:12: + if (6) WARNING: Too many leading tabs - consider code refactoring #13: FILE: t.c:13: + if (7) WARNING: Too many leading tabs - consider code refactoring #14: FILE: t.c:14: + if (8) total: 0 errors, 3 warnings, 17 lines checked t.c has style problems, please review. If any of these errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. Signed-off-by: Joe Perches <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6bd113f commit 8eef05d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

scripts/checkpatch.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,12 @@ sub process {
19241924
my $pre_ctx = "$1$2";
19251925

19261926
my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
1927+
1928+
if ($line =~ /^\+\t{6,}/) {
1929+
WARN("DEEP_INDENTATION",
1930+
"Too many leading tabs - consider code refactoring\n" . $herecurr);
1931+
}
1932+
19271933
my $ctx_cnt = $realcnt - $#ctx - 1;
19281934
my $ctx = join("\n", @ctx);
19291935

0 commit comments

Comments
 (0)