{"thread":{"id":"57739","subject":"[PATCH] add coccinelle script to check the option usage strings","startedAt":"2022-04-15T12:03:43Z","lastAt":"2022-04-20T05:16:46Z","messageCount":2,"participants":["Abhradeep Chakraborty via GitGitGadget","Abhradeep Chakraborty"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"453694","messageId":"pull.1216.git.1650024209568.gitgitgadget@gmail.com","threadId":"57739","inReplyTo":null,"subject":"[PATCH] add coccinelle script to check the option usage strings","fromName":"Abhradeep Chakraborty via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-04-15T12:03:29Z","receivedAt":"2022-04-15T12:03:43Z","isPatch":true,"sender":{"key":"chakrabortyabhradeep79@gmail.com","avatar":"https://avatars.githubusercontent.com/u/75240995?v=4"},"body":"From: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>\n\nThere is no check to see if usage strings for option flags are\nfollowing the style guide or not. Style convention says, usage\nstrings should not start with capital letter (unless needed) and\nit should not end with `.`.\n\nAdd a coccinelle script to check the option strings against the\nstyle convention.\n\nSigned-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>\n---\n    add a coccinelle script to check the option usage strings\n    \n    Fixes #636 [1]\n    \n    There was a previous patch request\n    [https://lore.kernel.org/git/pull.1147.git.1645030949730.gitgitgadget@gmail.com/]\n    where I implemented it in different methods (first version was written\n    in bash and the second version was to add some checks in the\n    parse-options.c file). But dscho [https://github.com/dscho] was\n    confident to use Coccinelle here. So, here is the Coccinelle version.\n    \n    Previous discussion link -\n    https://lore.kernel.org/git/nycvar.QRO.7.76.6.2203071709540.11118@tvgsbejvaqbjf.bet/\n    \n    [1] https://github.com/gitgitgadget/git/issues/636\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1216%2FAbhra303%2Fadd_cocci_check-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1216/Abhra303/add_cocci_check-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1216\n\n contrib/coccinelle/usage_strings.cocci | 53 ++++++++++++++++++++++++++\n 1 file changed, 53 insertions(+)\n create mode 100644 contrib/coccinelle/usage_strings.cocci\n\ndiff --git a/contrib/coccinelle/usage_strings.cocci b/contrib/coccinelle/usage_strings.cocci\nnew file mode 100644\nindex 00000000000..3fa34001a6b\n--- /dev/null\n+++ b/contrib/coccinelle/usage_strings.cocci\n@@ -0,0 +1,53 @@\n+@ usage_strings @\n+identifier opts;\n+constant opt_flag != OPT_GROUP;\n+char[] e;\n+@@\n+\n+\n+\n+struct option opts[] = {\n+    ...,\n+    opt_flag(...,<+... \\(N_(e)\\|e\\) ...+>, ...),\n+    ...,};\n+\n+\n+@script:python string_checker depends on usage_strings@\n+e << usage_strings.e;\n+replacement;\n+@@\n+\n+length = len(e)\n+should_make_change = False\n+if length > 2:\n+    if e[length-2] == '.' and e[length-3] != '.':\n+        coccinelle.replacement = e[:length-2] + '\"'\n+        should_make_change = True\n+    else:\n+        coccinelle.replacement = e\n+    if e[1].isupper():\n+        if not e[2].isupper():\n+            coccinelle.replacement = coccinelle.replacement[0] + coccinelle.replacement[1].lower() + coccinelle.replacement[2:]\n+            should_make_change = True\n+if not should_make_change:\n+    cocci.include_match(False)\n+\n+@ depends on string_checker@\n+identifier usage_strings.opts;\n+constant usage_strings.opt_flag;\n+char[] usage_strings.e;\n+identifier string_checker.replacement;\n+@@\n+\n+struct option opts[] = {\n+    ...,\n+    opt_flag(...,\n+    \\(\n+-    N_(e)\n++    N_(replacement)\n+    \\|\n+-    e\n++    replacement\n+    \\)\n+    , ...),\n+    ...,};\n\nbase-commit: 4027e30c5395c9c1aeea85e99f51ac62f5148145\n-- \ngitgitgadget\n"},{"id":"453950","messageId":"20220420051626.1216-1-chakrabortyabhradeep79@gmail.com","threadId":"57739","inReplyTo":"pull.1216.git.1650024209568.gitgitgadget@gmail.com","subject":"Re: [PATCH] add coccinelle script to check the option usage strings","fromName":"Abhradeep Chakraborty","fromEmail":"chakrabortyabhradeep79@gmail.com","sentAt":"2022-04-20T05:16:26Z","receivedAt":"2022-04-20T05:16:46Z","isPatch":true,"sender":{"key":"chakrabortyabhradeep79@gmail.com","avatar":"https://avatars.githubusercontent.com/u/75240995?v=4"},"body":"\nHello community,\n\nLooks like it is not reviewed yet. Could you please review it?\n\nThanks :)\n"}]}