1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2024-11-23 00:25:41 +00:00
git-validation/rules/danglingwhitespace/rule.go
Vincent Batts 00823a324b
message_regexp: regular expression rule for messages
Fixes: #30

now you can add a regular expression to the rules to be run
i.e. `git-validation -run "dco,message_regexp='^JIRA-[0-9]+ [A-Z].*$'"`

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-10-09 16:07:40 -04:00

39 lines
1 KiB
Go

package danglingwhitespace
import (
"github.com/vbatts/git-validation/git"
"github.com/vbatts/git-validation/validate"
)
var (
// DanglingWhitespace is the rule for checking the presence of dangling
// whitespaces on line endings.
DanglingWhitespace = validate.Rule{
Name: "dangling-whitespace",
Description: "checking the presence of dangling whitespaces on line endings",
Run: ValidateDanglingWhitespace,
Default: true,
}
)
func init() {
validate.RegisterRule(DanglingWhitespace)
}
// ValidateDanglingWhitespace runs Git's check to look for whitespace errors.
func ValidateDanglingWhitespace(r validate.Rule, c git.CommitEntry) (vr validate.Result) {
vr.CommitEntry = c
vr.Msg = "commit does not have any whitespace errors"
vr.Pass = true
_, err := git.Check(c["commit"])
if err != nil {
vr.Pass = false
if err.Error() == "exit status 2" {
vr.Msg = "has whitespace errors. See `git show --check " + c["commit"] + "`."
} else {
vr.Msg = "errored with: " + err.Error()
}
}
return
}