git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Abhradeep Chakraborty via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason [ ]" <avarab@gmail.com>,
	"Johannes Schindelin [ ]" <Johannes.Schindelin@gmx.de>,
	"Junio C Hamano [ ]" <gitster@pobox.com>,
	"Abhradeep Chakraborty" <chakrabortyabhradeep79@gmail.com>,
	"Abhradeep Chakraborty" <chakrabortyabhradeep79@gmail.com>
Subject: [PATCH] add coccinelle script to check the option usage strings
Date: Fri, 15 Apr 2022 12:03:29 +0000	[thread overview]
Message-ID: <pull.1216.git.1650024209568.gitgitgadget@gmail.com> (raw)

From: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>

There is no check to see if usage strings for option flags are
following the style guide or not. Style convention says, usage
strings should not start with capital letter (unless needed) and
it should not end with `.`.

Add a coccinelle script to check the option strings against the
style convention.

Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
---
    add a coccinelle script to check the option usage strings
    
    Fixes #636 [1]
    
    There was a previous patch request
    [https://lore.kernel.org/git/pull.1147.git.1645030949730.gitgitgadget@gmail.com/]
    where I implemented it in different methods (first version was written
    in bash and the second version was to add some checks in the
    parse-options.c file). But dscho [https://github.com/dscho] was
    confident to use Coccinelle here. So, here is the Coccinelle version.
    
    Previous discussion link -
    https://lore.kernel.org/git/nycvar.QRO.7.76.6.2203071709540.11118@tvgsbejvaqbjf.bet/
    
    [1] https://github.com/gitgitgadget/git/issues/636

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1216%2FAbhra303%2Fadd_cocci_check-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1216/Abhra303/add_cocci_check-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1216

 contrib/coccinelle/usage_strings.cocci | 53 ++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 contrib/coccinelle/usage_strings.cocci

diff --git a/contrib/coccinelle/usage_strings.cocci b/contrib/coccinelle/usage_strings.cocci
new file mode 100644
index 00000000000..3fa34001a6b
--- /dev/null
+++ b/contrib/coccinelle/usage_strings.cocci
@@ -0,0 +1,53 @@
+@ usage_strings @
+identifier opts;
+constant opt_flag != OPT_GROUP;
+char[] e;
+@@
+
+
+
+struct option opts[] = {
+    ...,
+    opt_flag(...,<+... \(N_(e)\|e\) ...+>, ...),
+    ...,};
+
+
+@script:python string_checker depends on usage_strings@
+e << usage_strings.e;
+replacement;
+@@
+
+length = len(e)
+should_make_change = False
+if length > 2:
+    if e[length-2] == '.' and e[length-3] != '.':
+        coccinelle.replacement = e[:length-2] + '"'
+        should_make_change = True
+    else:
+        coccinelle.replacement = e
+    if e[1].isupper():
+        if not e[2].isupper():
+            coccinelle.replacement = coccinelle.replacement[0] + coccinelle.replacement[1].lower() + coccinelle.replacement[2:]
+            should_make_change = True
+if not should_make_change:
+    cocci.include_match(False)
+
+@ depends on string_checker@
+identifier usage_strings.opts;
+constant usage_strings.opt_flag;
+char[] usage_strings.e;
+identifier string_checker.replacement;
+@@
+
+struct option opts[] = {
+    ...,
+    opt_flag(...,
+    \(
+-    N_(e)
++    N_(replacement)
+    \|
+-    e
++    replacement
+    \)
+    , ...),
+    ...,};

base-commit: 4027e30c5395c9c1aeea85e99f51ac62f5148145
-- 
gitgitgadget

             reply	other threads:[~2022-04-15 12:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15 12:03 Abhradeep Chakraborty via GitGitGadget [this message]
2022-04-20  5:16 ` [PATCH] add coccinelle script to check the option usage strings Abhradeep Chakraborty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1216.git.1650024209568.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=chakrabortyabhradeep79@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).