Commit 2381097b6c9b8621797a717c0b199f780ecaa992

Authored by Joe Perches
Committed by Linus Torvalds
1 parent 69c953c85c

checkpatch: add an error test for no space before comma

Using code like:

    int foo , bar;

is not preferred to:

    int foo, bar;

so emit an error on this style.

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>

Showing 1 changed file with 21 additions and 2 deletions Side-by-side Diff

scripts/checkpatch.pl
... ... @@ -3563,14 +3563,33 @@
3563 3563 }
3564 3564 }
3565 3565  
3566   - # , must have a space on the right.
  3566 + # , must not have a space before and must have a space on the right.
3567 3567 } elsif ($op eq ',') {
  3568 + my $rtrim_before = 0;
  3569 + my $space_after = 0;
  3570 + if ($ctx =~ /Wx./) {
  3571 + if (ERROR("SPACING",
  3572 + "space prohibited before that '$op' $at\n" . $hereptr)) {
  3573 + $line_fixed = 1;
  3574 + $rtrim_before = 1;
  3575 + }
  3576 + }
3568 3577 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
3569 3578 if (ERROR("SPACING",
3570 3579 "space required after that '$op' $at\n" . $hereptr)) {
3571   - $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
3572 3580 $line_fixed = 1;
3573 3581 $last_after = $n;
  3582 + $space_after = 1;
  3583 + }
  3584 + }
  3585 + if ($rtrim_before || $space_after) {
  3586 + if ($rtrim_before) {
  3587 + $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
  3588 + } else {
  3589 + $good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
  3590 + }
  3591 + if ($space_after) {
  3592 + $good .= " ";
3574 3593 }
3575 3594 }
3576 3595