add coccinelle script to check the option usage strings
PATCH 1/1 add coccinelle script to check the option usage strings
From: Abhradeep Chakraborty <[email protected]>
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.
---
add a coccinelle script to check the option usage strings
Fixes #636 [1]
There was a previous patch request
[https://lore.kernel.org/git/[email protected]/]
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/[email protected]/
[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
contrib/coccinelle/usage_strings.cocci new file +53 -0
@@ -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
Signature · 1 line
gitgitgadget
Hello community,
Looks like it is not reviewed yet. Could you please review it?
Thanks :)