Skip to content

Commit da7355a

Browse files
AdityaSrivasttorvalds
authored andcommitted
checkpatch: add fix option for ASSIGNMENT_CONTINUATIONS
Currently, checkpatch warns us if an assignment operator is placed at the start of a line and not at the end of previous line. E.g., running checkpatch on commit 8195b13 ("hv_netvsc: fix deadlock on hotplug") reports: CHECK: Assignment operator '=' should be on the previous line + struct netvsc_device *nvdev + = container_of(w, struct netvsc_device, subchan_work); Provide a simple fix by appending assignment operator to the previous line and removing from the current line, if both the lines are additions (ie start with '+') Link: https://lkml.kernel.org/r/20201121120407.22942-1-yashsri421@gmail.com Signed-off-by: Aditya Srivastava <yashsri421@gmail.com> Acked-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 03f4935 commit da7355a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,8 +3533,14 @@ sub process {
35333533

35343534
# check for assignments on the start of a line
35353535
if ($sline =~ /^\+\s+($Assignment)[^=]/) {
3536-
CHK("ASSIGNMENT_CONTINUATIONS",
3537-
"Assignment operator '$1' should be on the previous line\n" . $hereprev);
3536+
my $operator = $1;
3537+
if (CHK("ASSIGNMENT_CONTINUATIONS",
3538+
"Assignment operator '$1' should be on the previous line\n" . $hereprev) &&
3539+
$fix && $prevrawline =~ /^\+/) {
3540+
# add assignment operator to the previous line, remove from current line
3541+
$fixed[$fixlinenr - 1] .= " $operator";
3542+
$fixed[$fixlinenr] =~ s/\Q$operator\E\s*//;
3543+
}
35383544
}
35393545

35403546
# check for && or || at the start of a line

0 commit comments

Comments
 (0)