History

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 8195b1396ec8 ("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 '+')

Aditya Srivastava committed 5 years ago

Commit da7355a1 parent 03f49351 file · +8 −2Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+8−2
@@ -3533,8 +3533,14 @@ sub process { · 3532 unmodified lines
3533 3533
3534# check for assignments on the start of a line3534# check for assignments on the start of a line
3535 if ($sline =~ /^\+\s+($Assignment)[^=]/) {3535 if ($sline =~ /^\+\s+($Assignment)[^=]/) {
3536 CHK("ASSIGNMENT_CONTINUATIONS",3536 my $operator = $1;
3537 "Assignment operator '$1' should be on the previous line\n" . $hereprev);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 }
3538 }3544 }
3539 3545
3540# check for && or || at the start of a line3546# check for && or || at the start of a line