Skip to content

Commit d2e025f

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: add --strict test for spaces around arithmetic
Some prefer code to have spaces around arithmetic so instead of: a = b*c+d; suggest a = b * c + d; Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 101ee68 commit d2e025f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/checkpatch.pl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3689,7 +3689,22 @@ sub process {
36893689
$op eq '*' or $op eq '/' or
36903690
$op eq '%')
36913691
{
3692-
if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
3692+
if ($check) {
3693+
if (defined $fix_elements[$n + 2] && $ctx !~ /[EW]x[EW]/) {
3694+
if (CHK("SPACING",
3695+
"spaces preferred around that '$op' $at\n" . $hereptr)) {
3696+
$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
3697+
$fix_elements[$n + 2] =~ s/^\s+//;
3698+
$line_fixed = 1;
3699+
}
3700+
} elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) {
3701+
if (CHK("SPACING",
3702+
"space preferred before that '$op' $at\n" . $hereptr)) {
3703+
$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
3704+
$line_fixed = 1;
3705+
}
3706+
}
3707+
} elsif ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
36933708
if (ERROR("SPACING",
36943709
"need consistent spacing around '$op' $at\n" . $hereptr)) {
36953710
$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";

0 commit comments

Comments
 (0)