Currently checkpatch warns for BAD_SIGN_OFF on non-standard signature styles. A large number of these warnings occur because of typo mistakes in signature tags. An evaluation over v4.13..v5.8 showed that out of 539 warnings due to non-standard signatures, 87 are due to typo mistakes. Following are the standard signature tags which are often incorrectly used, along with their individual counts of incorrect use (over v4.13..v5.8): Reviewed-by: 42 Signed-off-by: 25 Reported-by: 6 Acked-by: 4 Tested-by: 4 Suggested-by: 4 Provide a fix by calculating levenshtein distance for the signature tag with all the standard signatures and suggest a fix with a signature, whose edit distance is less than or equal to 2 with the misspelled signature. Out of the 86 mispelled signatures fixed with this approach, 85 were found to be good corrections and 1 was bad correction. Following was found to be a bad correction: Tweeted-by (count: 1) => Tested-by
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -506,6 +506,64 @@ our $signature_tags = qr{(?xi: · 505 unmodified lines | ||
| 506 | 506 | Cc: |
| 507 | 507 | )}; |
| 508 | 508 | |
| 509 | +sub edit_distance_min { | |
| 510 | + my (@arr) = @_; | |
| 511 | + my $len = scalar @arr; | |
| 512 | + if ((scalar @arr) < 1) { | |
| 513 | + # if underflow, return | |
| 514 | + return; | |
| 515 | + } | |
| 516 | + my $min = $arr[0]; | |
| 517 | + for my $i (0 .. ($len-1)) { | |
| 518 | + if ($arr[$i] < $min) { | |
| 519 | + $min = $arr[$i]; | |
| 520 | + } | |
| 521 | + } | |
| 522 | + return $min; | |
| 523 | +} | |
| 524 | + | |
| 525 | +sub get_edit_distance { | |
| 526 | + my ($str1, $str2) = @_; | |
| 527 | + $str1 = lc($str1); | |
| 528 | + $str2 = lc($str2); | |
| 529 | + $str1 =~ s/-//g; | |
| 530 | + $str2 =~ s/-//g; | |
| 531 | + my $len1 = length($str1); | |
| 532 | + my $len2 = length($str2); | |
| 533 | + # two dimensional array storing minimum edit distance | |
| 534 | + my @distance; | |
| 535 | + for my $i (0 .. $len1) { | |
| 536 | + for my $j (0 .. $len2) { | |
| 537 | + if ($i == 0) { | |
| 538 | + $distance[$i][$j] = $j; | |
| 539 | + } elsif ($j == 0) { | |
| 540 | + $distance[$i][$j] = $i; | |
| 541 | + } elsif (substr($str1, $i-1, 1) eq substr($str2, $j-1, 1)) { | |
| 542 | + $distance[$i][$j] = $distance[$i - 1][$j - 1]; | |
| 543 | + } else { | |
| 544 | + my $dist1 = $distance[$i][$j - 1]; #insert distance | |
| 545 | + my $dist2 = $distance[$i - 1][$j]; # remove | |
| 546 | + my $dist3 = $distance[$i - 1][$j - 1]; #replace | |
| 547 | + $distance[$i][$j] = 1 + edit_distance_min($dist1, $dist2, $dist3); | |
| 548 | + } | |
| 549 | + } | |
| 550 | + } | |
| 551 | + return $distance[$len1][$len2]; | |
| 552 | +} | |
| 553 | + | |
| 554 | +sub find_standard_signature { | |
| 555 | + my ($sign_off) = @_; | |
| 556 | + my @standard_signature_tags = ( | |
| 557 | + 'Signed-off-by:', 'Co-developed-by:', 'Acked-by:', 'Tested-by:', | |
| 558 | + 'Reviewed-by:', 'Reported-by:', 'Suggested-by:' | |
| 559 | + ); | |
| 560 | + foreach my $signature (@standard_signature_tags) { | |
| 561 | + return $signature if (get_edit_distance($sign_off, $signature) <= 2); | |
| 562 | + } | |
| 563 | + | |
| 564 | + return ""; | |
| 565 | +} | |
| 566 | + | |
| 509 | 567 | our @typeListMisordered = ( |
| 510 | 568 | qr{char\s+(?:un)?signed}, |
| 511 | 569 | qr{int\s+(?:(?:un)?signed\s+)?short\s}, |
| @@ -2773,8 +2831,17 @@ sub process { · 2261 unmodified lines | ||
| 2773 | 2831 | my $ucfirst_sign_off = ucfirst(lc($sign_off)); |
| 2774 | 2832 | |
| 2775 | 2833 | if ($sign_off !~ /$signature_tags/) { |
| 2776 | − WARN("BAD_SIGN_OFF", | |
| 2777 | − "Non-standard signature: $sign_off\n" . $herecurr); | |
| 2834 | + my $suggested_signature = find_standard_signature($sign_off); | |
| 2835 | + if ($suggested_signature eq "") { | |
| 2836 | + WARN("BAD_SIGN_OFF", | |
| 2837 | + "Non-standard signature: $sign_off\n" . $herecurr); | |
| 2838 | + } else { | |
| 2839 | + if (WARN("BAD_SIGN_OFF", | |
| 2840 | + "Non-standard signature: '$sign_off' - perhaps '$suggested_signature'?\n" . $herecurr) && | |
| 2841 | + $fix) { | |
| 2842 | + $fixed[$fixlinenr] =~ s/$sign_off/$suggested_signature/; | |
| 2843 | + } | |
| 2844 | + } | |
| 2778 | 2845 | } |
| 2779 | 2846 | if (defined $space_before && $space_before ne "") { |
| 2780 | 2847 | if (WARN("BAD_SIGN_OFF", |