2016-04-05 14:11:34 +00:00
|
|
|
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,
|
2017-10-09 19:49:59 +00:00
|
|
|
Default: true,
|
2016-04-05 14:11:34 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
validate.RegisterRule(DanglingWhitespace)
|
|
|
|
}
|
|
|
|
|
2017-04-27 17:37:17 +00:00
|
|
|
// ValidateDanglingWhitespace runs Git's check to look for whitespace errors.
|
2017-10-09 19:49:59 +00:00
|
|
|
func ValidateDanglingWhitespace(r validate.Rule, c git.CommitEntry) (vr validate.Result) {
|
2016-04-05 14:11:34 +00:00
|
|
|
vr.CommitEntry = c
|
2016-04-06 16:33:31 +00:00
|
|
|
vr.Msg = "commit does not have any whitespace errors"
|
2016-04-05 14:11:34 +00:00
|
|
|
vr.Pass = true
|
2016-04-06 16:33:31 +00:00
|
|
|
|
|
|
|
_, 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()
|
2016-04-05 14:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|