-
Notifications
You must be signed in to change notification settings - Fork 100
feat(cli): Allow validate from text #71
feat(cli): Allow validate from text #71
Conversation
With this approach makes easier validate commit messages through a text instead of only accepting validation through files.
Codecov Report
@@ Coverage Diff @@
## master #71 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 3 3
Lines 123 123
=====================================
Hits 123 123 Continue to review full report at Codecov.
|
There was a problem hiding this 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! Some comments from me.
lib/cli.js
Outdated
|
||
function getCommitMessage(buffer) { | ||
return hasToString(buffer) && buffer.toString(); | ||
fs.stat(commitMsgFileOrText, function(err, stat) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you use fs.stat
here to check existence of the file. This is not recommended by node docs. You could use fs.readFile
and if there is an ENOENT
error execute validate(commitMsgFileOrText, false);
. Would this work?
|
||
var commitMsgFile = process.argv[2] || getGitFolder() + '/COMMIT_EDITMSG'; | ||
var incorrectLogFile = commitMsgFile.replace('COMMIT_EDITMSG', 'logs/incorrect-commit-msgs'); | ||
var bufferToString = function (buffer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could turn these anonymous function expressions to named function expressions. Usually anonymous functions are annoying during debugging 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By setting a function to a variable it will be named after that variable. So doing something like this one below is redundant:
var bufferToString = function bufferToString(buffer) {
Since in case the file exists we will read it. Makes more sense use directly fs.readFile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool 🎉
Thanks! |
With this approach makes easier validate commit messages through a text instead of only accepting
validation through files.