From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.3 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 268C3C4741F for ; Thu, 5 Nov 2020 12:00:28 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 673D52078E for ; Thu, 5 Nov 2020 12:00:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="glh87jI7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 673D52078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-kernel-mentees-bounces@lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id C5CFD86457; Thu, 5 Nov 2020 12:00:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kzrIgdcnUASG; Thu, 5 Nov 2020 12:00:25 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 83C2D85F9B; Thu, 5 Nov 2020 12:00:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 72612C088B; Thu, 5 Nov 2020 12:00:25 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 106F8C0889 for ; Thu, 5 Nov 2020 12:00:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 0A40387144 for ; Thu, 5 Nov 2020 12:00:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id D5MbuQtGgTDo for ; Thu, 5 Nov 2020 12:00:23 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by hemlock.osuosl.org (Postfix) with ESMTPS id 2BF4E87141 for ; Thu, 5 Nov 2020 12:00:23 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id z24so1303979pgk.3 for ; Thu, 05 Nov 2020 04:00:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DQk5IDsyENH45uUiFTC8E+OCQhtMayPZ2ZBICZ3zfiQ=; b=glh87jI7JEK8SbroZkpgj9MLIxH7Hhf2ORAL82JO/VmmDR+eOEwOFVlpv0ry2RZamh 7IJMRIZGy1W7aJP+4IICzL4uan0CPPEINGWYV68o6ofDfCmyqerZ5P5ouJGVHPhqX/zX ZktsOM+Fm0dUL/DamBK3kT4ode0c+1wLAu0w1O8fSMu/zHGx/KvTHQ6onIttovrBAnMa 0eIRrJQQsIjOb11zQZN8jW9hp0gCSvB8TvhLfVf8EG4sb1qULZ0RiNRM1HYJxBFmzhzL Kg5SjoXaOS3u4Wj9Y0xHcXY4rYxSVVlDj2+1/750M24F1qHEnq2LSxgrT2egfgladDsd JSIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DQk5IDsyENH45uUiFTC8E+OCQhtMayPZ2ZBICZ3zfiQ=; b=PnraPXbstjinBnnGo8aZmmk0ZMdHfxqwQ7du4y/t9T9McaBXh2ng51jaTP1QbmFBnf nAerinxsLJmGXxJZYoJii8f1MFps7oG2qUGK/En+JwKX5Jggat5kZsLuFCWQDXPtFjlZ qaWm/2hfKHtnFj77GHGWhwlS0Yt3bc837v7Xj8Ps4AD+KLrmHpI3AD3sJv6w2D7W3S6r uCMgMAFLiZejaK09dHcBrcLDVLA/SfLb0TeHyntNSJN+QqTp3dKQQzfTyg0lDDWwIYg2 qNA+ACvRa3c3rbEt0iSLxZTDFGonUOPiUDL7g4IOWloKF0vtToDj0GJwmsbIJ2bQBMUe YqDw== X-Gm-Message-State: AOAM532i5euw1M/nqltA2urdUJws9jwapo9mzygXq0AtqA7pvofMKfaw CPOBlyIrSQzjpwT3vfexasL2GyNOaWmom2yw X-Google-Smtp-Source: ABdhPJwq6e/UuOZ7WnMVHfJsilv7l3DPaK1ZkYyhQ7AU+wVTcBIgFoM+3YZXsCKqHyhEvYhkr37Hng== X-Received: by 2002:a17:90a:d590:: with SMTP id v16mr2133405pju.88.1604577622527; Thu, 05 Nov 2020 04:00:22 -0800 (PST) Received: from localhost.localdomain ([2405:201:9004:60c1:275b:c814:aca3:d7c6]) by smtp.gmail.com with ESMTPSA id k5sm2198768pjs.14.2020.11.05.04.00.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 04:00:20 -0800 (PST) From: Dwaipayan Ray To: joe@perches.com Date: Thu, 5 Nov 2020 17:29:49 +0530 Message-Id: <20201105115949.39474-1-dwaipayanray1@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Cc: dwaipayanray1@gmail.com, yashsri421@gmail.com, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [Linux-kernel-mentees] [PATCH v3] checkpatch: improve email parsing X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" checkpatch doesn't report warnings for many common mistakes in emails. Some of which are trailing commas and incorrect use of email comments. At the same time several false positives are reported due to incorrect handling of mail comments. The most common of which is due to the pattern: # X.X Improve email parsing in checkpatch. Some general comment rules are defined: - Multiple name comments should not be allowed. - Comments inside address should not be allowed. - In general comments should be enclosed within parentheses. Exception for stable@vger.kernel.org # X.X Improvements to parsing: - Detect and report unexpected content after email. - Quoted names are excluded from comment parsing. - Trailing dots or commas in email are removed during formatting. Correspondingly a BAD_SIGN_OFF warning is emitted. - Improperly quoted email like '"name
"' are now warned about. In addition, added fixes for all the possible rules. Signed-off-by: Dwaipayan Ray --- scripts/checkpatch.pl | 88 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 17 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index fab38b493cef..dc8b664b7de1 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1152,6 +1152,7 @@ sub parse_email { my ($formatted_email) = @_; my $name = ""; + my $quoted = ""; my $name_comment = ""; my $address = ""; my $comment = ""; @@ -1183,14 +1184,20 @@ sub parse_email { } } - $comment = trim($comment); - $name = trim($name); - $name =~ s/^\"|\"$//g; - if ($name =~ s/(\s*\([^\)]+\))\s*//) { - $name_comment = trim($1); + # Extract comments from names excluding quoted parts + # "John A. (Kennedy)" - Do not extract + if ($name =~ s/\"(.+)\"//) { + $quoted = $1; + } + while ($name =~ s/\s*($balanced_parens)\s*/ /) { + $name_comment .= trim($1); } + $name =~ s/^[ \"]+|[ \"]+$//g; + $name = trim("$quoted $name"); + $address = trim($address); $address =~ s/^\<|\>$//g; + $comment = trim($comment); if ($name =~ /[^\w \-]/i) { ##has "must quote" chars $name =~ s/(? 0; + $comment = trim($comment); + $comment = " $comment" if length($comment) > 0; + if ("$name" eq "") { $formatted_email = "$address"; } else { @@ -1233,15 +1243,11 @@ sub reformat_email { } sub same_email_addresses { - my ($email1, $email2, $match_comment) = @_; + my ($email1, $email2) = @_; my ($email1_name, $name1_comment, $email1_address, $comment1) = parse_email($email1); my ($email2_name, $name2_comment, $email2_address, $comment2) = parse_email($email2); - if ($match_comment != 1) { - return $email1_name eq $email2_name && - $email1_address eq $email2_address; - } return $email1_name eq $email2_name && $email1_address eq $email2_address && $name1_comment eq $name2_comment && @@ -2704,7 +2710,7 @@ sub process { $signoff++; $in_commit_log = 0; if ($author ne '' && $authorsignoff != 1) { - if (same_email_addresses($1, $author, 1)) { + if (same_email_addresses($1, $author)) { $authorsignoff = 1; } else { my $ctx = $1; @@ -2800,9 +2806,57 @@ sub process { $dequoted =~ s/" 1) { WARN("BAD_SIGN_OFF", - "email address '$email' might be better as '$suggested_email'\n" . $herecurr); + "Use a single name comment in email: '$email'\n" . $herecurr); + } + + # Comments must begin only with ( + # or # in case of stable@vger.kernel.org + if ($email =~ /^.*stable\@vger/) { + if ($comment ne "" && $comment !~ /^#.+/) { + if (WARN("BAD_SIGN_OFF", + "Invalid comment format for stable: '$email', prefer parentheses\n" . $herecurr) && + $fix) { + my $new_comment = $comment; + $new_comment =~ s/^[ \(\[]+|[ \)\]]+$//g; + $new_comment = " # $new_comment" if length($new_comment) > 0; + $fixed[$fixlinenr] =~ s/\s*\Q$comment\E$/$new_comment/; + } + } + } else { + if ($comment ne "" && $comment !~ /^\(.+\)$/) { + if (WARN("BAD_SIGN_OFF", + "Unexpected content after email: '$email'\n" . $herecurr) && + $fix) { + my $new_comment = $comment; + $new_comment =~ s/^(?:\#|\/\*|\.|\,)//g; + $new_comment =~ s/^[ \{\[]+|[ \}\]]+$//g; + $new_comment = " ($new_comment)" if length($new_comment) > 0; + $fixed[$fixlinenr] =~ s/\s*\Q$comment\E$/$new_comment/; + } + } } } -- 2.27.0 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees