diff options
author | Joe Perches <joe@perches.com> | 2014-11-27 11:09:47 +1100 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2014-11-27 11:09:47 +1100 |
commit | 4c0fa8937c926ef0de9ec66e26ac1b8c9c8056eb (patch) | |
tree | bbc4b28f199e75becfbac114ef207b25d935bf12 /scripts | |
parent | bc7ca5aec399454bdb92fd08279c2eff1617be11 (diff) |
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>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 374abf443636..696254eee78b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3563,14 +3563,33 @@ sub process { } } - # , must have a space on the right. + # , must not have a space before and must have a space on the right. } elsif ($op eq ',') { + my $rtrim_before = 0; + my $space_after = 0; + if ($ctx =~ /Wx./) { + if (ERROR("SPACING", + "space prohibited before that '$op' $at\n" . $hereptr)) { + $line_fixed = 1; + $rtrim_before = 1; + } + } if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { if (ERROR("SPACING", "space required after that '$op' $at\n" . $hereptr)) { - $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " "; $line_fixed = 1; $last_after = $n; + $space_after = 1; + } + } + if ($rtrim_before || $space_after) { + if ($rtrim_before) { + $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]); + } else { + $good = $fix_elements[$n] . trim($fix_elements[$n + 1]); + } + if ($space_after) { + $good .= " "; } } |