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

Add min-body-length option #135

Merged
merged 1 commit into from
May 26, 2024
Merged

Conversation

soulseekah
Copy link
Contributor

@soulseekah soulseekah commented May 23, 2024

When set an error will be emitted if the body does not contain enough characters. This is useful to require commit bodies with more information, like impact, motivation, approach, testing results, new behavior, etc.

Default: no minimum. Suggested: at least 150.

Fixes #136.

@mristin
Copy link
Owner

mristin commented May 23, 2024

Thanks a lot, @soulseekah ! I won't make it today to review -- hopefully tomorrow.

In the meantime, could you please have a look at the CI -- I think you need to fix the commit message to comply to 72 characters width?

@Fryuni would you mind reviewing as well, so that at least two pairs of eyes looked at the code?

@mristin mristin self-requested a review May 23, 2024 08:44
@soulseekah
Copy link
Contributor Author

Thank you @mristin. The commit validation issue is a false positive. My longest line is 69 characters :)

image

This is probably related to #111

@mristin
Copy link
Owner

mristin commented May 24, 2024

Thank you @mristin. The commit validation issue is a false positive. My longest line is 69 characters :)

This is probably related to #111

I fixed #111 -- would you mind rebasing your PR so that the tests can run again?

@Fryuni
Copy link
Contributor

Fryuni commented May 24, 2024

@Fryuni would you mind reviewing as well, so that at least two pairs of eyes looked at the code?

Sure, I'll take a look today.

Copy link
Contributor

@Fryuni Fryuni left a comment

Choose a reason for hiding this comment

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

I've got one point of preference in the implementation. Besides that, there are no tests for this.

@@ -228,6 +228,14 @@ function checkBody(
return errors;
}

// Minimum character body length
if (inputs.minBodyLength && bodyLines.join().length < inputs.minBodyLength) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it could newlines as characters?

The lines are split by \n, so they are not included in bodyLines. But calling join() without any arguments adds a , between each line, effectively counting what was originally the line breaks.

I'd prefer join('') to not count those, but it's definitely not blocking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the '', good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While writing tests the '' seems counterintuitive. If the message is laid out into one long string shouldn't there be a space when joining?

  const message =
    'Change SomeClass to OtherClass\n' +
    '\n' +
    'This replaces the SomeClass with OtherClass in all of the module\n' +
    'since Some class was deprecated.';

If we do '' we get 96 characters but the string would become "This replaces the SomeClass with OtherClass in all of the modulesince Some class was deprecated."

Instead of "module since". What would be more intuitive then?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think both counting and not counting the newlines are equally fine as those are mostly corner cases.
But given how unintuitive it might be then counting would be better. So count newlines the same as counting whitespaces

@soulseekah soulseekah force-pushed the min-body-length branch 2 times, most recently from 4d4e1dd to 2af2219 Compare May 24, 2024 19:28
@soulseekah
Copy link
Contributor Author

Thank you @mristin. The commit validation issue is a false positive. My longest line is 69 characters :)
This is probably related to #111

I fixed #111 -- would you mind rebasing your PR so that the tests can run again?

Rebased.

@soulseekah
Copy link
Contributor Author

I've added some tests assuming that we join with a space. Happy to agree on whatever you think is better for glueing lines together.

Quick question: should I be running npm run pack for PRs here or should I leave the dist/ directory alone and commit only the src/?

@mristin
Copy link
Owner

mristin commented May 24, 2024

@soulseekah

Quick question: should I be running npm run pack for PRs here or should I leave the dist/ directory alone and commit only the src/?

I think you need to include dist/ for the changes to take place.

When set an error will be emitted if the body does not contain enough
characters. This is useful to require commit bodies with more
information, like impact, motivation, approach, testing results, new
behavior, etc. Default: no minimum. Suggested: at least 150.
@soulseekah
Copy link
Contributor Author

soulseekah commented May 24, 2024

Added another test. So three tests in total:

  • fail on minimum body length
  • pass on exact minimum body length (and obviously over the minimum)
  • pass on default body length (no minimum)

These assume that the join is with spaces.

@mristin mristin merged commit 6e738f9 into mristin:master May 26, 2024
3 checks passed
@mristin
Copy link
Owner

mristin commented May 26, 2024

Thanks again a lot, @soulseekah for the contribution and @Fryuni for the review!

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.

Add min-body-length option
3 participants