mirror of
https://github.com/vbatts/git-validation.git
synced 2024-12-28 16:26:31 +00:00
37 lines
926 B
Go
37 lines
926 B
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,
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
validate.RegisterRule(DanglingWhitespace)
|
|
}
|
|
|
|
func ValidateDanglingWhitespace(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
|
|
}
|