Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

fix(scope): Allow no scope in the commit message when validate is set to true. #69

Merged

Conversation

yeelan0319
Copy link
Contributor

When validate: true, it should allow the user provided no scope. Commit message such as chore: Publish should pass.

However, the current setup tries to call multiple method on undefined in that situation. So I fixed that by adding scope.length > 0 before validate any individual message.

@codecov-io
Copy link

codecov-io commented Mar 6, 2017

Codecov Report

Merging #69 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master    #69   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           3      3           
  Lines         121    123    +2     
=====================================
+ Hits          121    123    +2
Impacted Files Coverage Δ
lib/validateMessage.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b737246...4abbb72. Read the comment docs.

Copy link
Collaborator

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Looks fine to me (just wrapping things in if (scopes.length > 0)). But I'm starting to not recognize the code in the codebase anymore. I'd like a review/merge from @spirosikmd and/or @Garbee

@spirosikmd spirosikmd self-requested a review March 6, 2017 19:53
Copy link
Collaborator

@spirosikmd spirosikmd left a comment

Choose a reason for hiding this comment

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

Thank you very much for your PR! One comment from me. What do you think?

if (scopes.length > 1) {
error('only one scope can be provided !');
isValid = false;
if (scopes.length > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe to avoid more if nesting at this point, we should inverse the check and return isValid? For example

if (!scopes) {
  return isValid;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 to the early return as @spirosikmd recommended here. It is currently at 3 levels of if nesting, this makes 4 levels which is quite difficult to follow through. Having the early return keeps the nesting at 3 levels which is basically as minimal as we can get.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great suggestion. Let me quickly update it.

Copy link
Collaborator

@Garbee Garbee left a comment

Choose a reason for hiding this comment

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

Nice catch on the bug. I would like to see the new if be an early return instead of encapsulating the existing code.

if (scopes.length > 1) {
error('only one scope can be provided !');
isValid = false;
if (scopes.length > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 to the early return as @spirosikmd recommended here. It is currently at 3 levels of if nesting, this makes 4 levels which is quite difficult to follow through. Having the early return keeps the nesting at 3 levels which is basically as minimal as we can get.

@yeelan0319
Copy link
Contributor Author

Please take a look again and see if this is good. Thanks! 😃

Copy link
Collaborator

@Garbee Garbee left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

LGTM!

@kentcdodds kentcdodds merged commit 7a580ce into conventional-changelog-archived-repos:master Mar 8, 2017
@kentcdodds
Copy link
Collaborator

Thanks @yeelan0319!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants