Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Validate multi-line messages #68

Merged
merged 1 commit into from
Nov 17, 2023
Merged

Conversation

grahamhar
Copy link
Contributor

@grahamhar grahamhar commented Oct 31, 2023

The documented conventional commit specification states that on multi-line commit message there must be a blank line between the title and the body.

I was unsure on updating the error output or not. If it is updated I guess the error out put should guide towards which element failed the title line or the multi line issue. Let me know your thoughts.

fixes #67

@thekaveman
Copy link
Member

Thanks for working on this @grahamhar.

I have a few comments on the implementation having thought about this a little more:

  1. The is_conventional() function should do this validation (rather than having to call a separate function), since as you note, it is part of the spec
  2. To that end, I think we can probably do this by modifying the existing regex for r_subject(), perhaps splitting that into r_subject() and r_body()
  3. Finally (and this is a little trickier) -- making the blank line a requirement is technically a breaking change (while acknowledging again that yes, the spec does call for a blank line); so I'd like to start with this feature hidden behind our --strict flag (see feat: introduce "strict" mode #61) so we can release a 2.x update. In a future 3.x update, we can make it the default.

@grahamhar grahamhar force-pushed the issue-67 branch 2 times, most recently from b143dcf to 5d30aa0 Compare November 5, 2023 15:27
@grahamhar
Copy link
Contributor Author

grahamhar commented Nov 5, 2023

Thanks for working on this @grahamhar.

I have a few comments on the implementation having thought about this a little more:

  1. The is_conventional() function should do this validation (rather than having to call a separate function), since as you note, it is part of the spec
  2. To that end, I think we can probably do this by modifying the existing regex for r_subject(), perhaps splitting that into r_subject() and r_body()
  3. Finally (and this is a little trickier) -- making the blank line a requirement is technically a breaking change (while acknowledging again that yes, the spec does call for a blank line); so I'd like to start with this feature hidden behind our --strict flag (see feat: introduce "strict" mode #61) so we can release a 2.x update. In a future 3.x update, we can make it the default.

@thekaveman I think I have managed to implement this in the way you are asking, let me know if you have any other suggestions.

I do have one thought on how we should handle the following example (A subject followed by a blank line but no body) as I couldn't find an answer in the spec on this

feat: A valid

Also I am unsure if the use of \n in the regex is sufficient, How does git running on Windows based systems behave? The editor used might also use \r\n.

@thekaveman
Copy link
Member

@grahamhar:

I do have one thought on how we should handle the following example (A subject followed by a blank line but no body)

I'm OK to ignore this case -- you're right, I can't see anything in the spec on this either, and normally git will just delete those extra blank lines from the commit message in post.

Also I am unsure if the use of \n in the regex is sufficient, How does git running on Windows based systems behave?

Good point. I think a regex like \r?\n will work here, as that will catch both Windows and Unix-style line endings. Seems like Mac OS X and later also uses \n so that should cover our bases. https://stackoverflow.com/a/39022365/453168

The documented conventional commit specification states that on
multi-line commit message there must be a blank line between the title
and the body.

To avoid a breaking change this has been toggled using the strict
option, in the next major release this toggle will be removed.
@grahamhar
Copy link
Contributor Author

@thekaveman I think this should be good now.

Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this and going back and forth with me on some reviews @grahamhar!

@thekaveman thekaveman merged commit ad10cec into compilerla:main Nov 17, 2023
6 checks passed
@grahamhar grahamhar deleted the issue-67 branch November 17, 2023 17:56
@thekaveman
Copy link
Member

Thanks again @grahamhar!

I have released v3.0.0 which includes the change to enforce the blank line, but drops the effect of the --strict flag -- the blank line is always required now.

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.

Capture malformed multi-line commit messages
2 participants