git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] add coccinelle script to check the option usage strings
@ 2022-04-15 12:03 Abhradeep Chakraborty via GitGitGadget
  2022-04-20  5:16 ` Abhradeep Chakraborty
  0 siblings, 1 reply; 2+ messages in thread
From: Abhradeep Chakraborty via GitGitGadget @ 2022-04-15 12:03 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason [ ],
	Johannes Schindelin [ ], Junio C Hamano [ ],
	Abhradeep Chakraborty, Abhradeep Chakraborty

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] add coccinelle script to check the option usage strings
  2022-04-15 12:03 [PATCH] add coccinelle script to check the option usage strings Abhradeep Chakraborty via GitGitGadget
@ 2022-04-20  5:16 ` Abhradeep Chakraborty
  0 siblings, 0 replies; 2+ messages in thread
From: Abhradeep Chakraborty @ 2022-04-20  5:16 UTC (permalink / raw)
  To: Git
  Cc: Abhradeep Chakraborty, Ævar Arnfjörð Bjarmason,
	Johannes Schindelin, Junio C Hamano


Hello community,

Looks like it is not reviewed yet. Could you please review it?

Thanks :)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-20  5:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-15 12:03 [PATCH] add coccinelle script to check the option usage strings Abhradeep Chakraborty via GitGitGadget
2022-04-20  5:16 ` Abhradeep Chakraborty

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).