cobra icon indicating copy to clipboard operation
cobra copied to clipboard

Move newline to inside the DisableAutoGenTag block

Open dramich opened this issue 1 year ago • 4 comments

Fixes https://github.com/spf13/cobra/issues/2029

dramich avatar Sep 20 '23 17:09 dramich

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 20 '23 17:09 CLAassistant

There are tools that care about whitespace regardless of the file type, as stated in the original issue pre-commit has a end-of-file-fixer which looks for things like double returns. https://github.com/pre-commit/pre-commit-hooks?tab=readme-ov-file#end-of-file-fixer

The fix ensures the generated files only have a single return at the end of the file, it does not remove all of them.

If this is deemed not needed feel free to close it or let me know and I can.

dramich avatar May 18 '24 15:05 dramich

It would be nice to add a little test to keep the output correct after this change.

nirs avatar May 18 '24 15:05 nirs

Added a new assertion to the tests Test fails before the change with:

go test github.com/spf13/cobra/doc
--- FAIL: TestGenMdNoTag (0.00s)
    cmd_test.go:110: Expected to not have suffix:
         "\n\n"
        Got: "## root\n\nRoot short description\n\n### Synopsis\n\nRoot long description\n\n```\nroot [flags]\n```\n\n### Options\n\n```\n  -h, --help              help for root\n  -r, --rootflag string    (default \"two\")\n  -t, --strtwo string     help message for parent flag strtwo (default \"two\")\n```\n\n### SEE ALSO\n\n* [root echo](root_echo.md)\t - Echo anything to the screen\n\n"

After fix the test passes. All other tests already pass as they don't have the double line break.

dramich avatar May 18 '24 21:05 dramich