Skip to content

Add newline check for mdox-exec output - #68

Merged
bwplotka merged 2 commits into
bwplotka:mainfrom
saswatamcode:check-newline
Aug 4, 2021
Merged

bwplotka merged 2 commits into
bwplotka:mainfrom
saswatamcode:check-newline

Conversation

@saswatamcode

Copy link
Copy Markdown
Collaborator

This PR adds a check to ensure mdgen output for a command always has a new line at the end so that there are no surprising formatting issues. Test case added. Fixes #67.

Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
@saswatamcode
saswatamcode requested a review from bwplotka August 1, 2021 06:18
@saswatamcode saswatamcode self-assigned this Aug 1, 2021

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread pkg/mdformatter/mdgen/mdgen.go Outdated
return b.Bytes(), nil
output := b.Bytes()
// Add newline to output if not present.
if !bytes.HasSuffix(output, []byte("\n")) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !bytes.HasSuffix(output, []byte("\n")) {
if !bytes.HasSuffix(output, newLineChar) {

.. to not creat slice every time? (micro-optimization, but also readability) and I think we already have newLineChar somewhere 🤔

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a blocker

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
@saswatamcode
saswatamcode requested a review from bwplotka August 4, 2021 04:18

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@bwplotka
bwplotka merged commit 13fc035 into bwplotka:main Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check newline in mdox-exec output

2 participants

⌂ 换网址