From: Abhradeep Chakraborty <chakrabortyabhradeep79@xxxxxxxxx> `parse-options.c` doesn't check if the 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 checks to the `parse_options_check()` function to check usage strings against the style convention. Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@xxxxxxxxx> --- parse-options.c | 11 +++++++++++ t/t1502-rev-parse-parseopt.sh | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/parse-options.c b/parse-options.c index 2437ad3bcdd..acd9ddbb372 100644 --- a/parse-options.c +++ b/parse-options.c @@ -492,6 +492,17 @@ static void parse_options_check(const struct option *opts) default: ; /* ok. (usually accepts an argument) */ } + + // OPTION_GROUP should be ignored + // if the first two characters of the help string are uppercase, then assume it is an + // acronym (i.e. "GPG") or special name (i.e. "HEAD"), thus allowed. + // else assume the usage string is violating the style convention and throw error. + if (opts->type != OPTION_GROUP && opts->help && + opts->help[0] && isupper(opts->help[0]) && + !(opts->help[1] && isupper(opts->help[1]))) + err |= optbug(opts, xstrfmt("help should not start with capital letter unless needed: %s", opts->help)); + if (opts->help && !ends_with(opts->help, "...") && ends_with(opts->help, ".")) + err |= optbug(opts, xstrfmt("help should not end with a dot: %s", opts->help)); if (opts->argh && strcspn(opts->argh, " _") != strlen(opts->argh)) err |= optbug(opts, "multi-word argh should use dash to separate words"); diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh index 284fe18e726..2a07e130b96 100755 --- a/t/t1502-rev-parse-parseopt.sh +++ b/t/t1502-rev-parse-parseopt.sh @@ -53,7 +53,7 @@ test_expect_success 'setup optionspec-only-hidden-switches' ' | |some-command does foo and bar! |-- -|hidden1* A hidden switch +|hidden1* a hidden switch EOF ' @@ -131,7 +131,7 @@ test_expect_success 'test --parseopt help-all output hidden switches' ' | | some-command does foo and bar! | -| --hidden1 A hidden switch +| --hidden1 a hidden switch | |EOF END_EXPECT -- gitgitgadget