Use exit code 1 when there's a style error.

This commit is contained in:
Amy Boyd
2016-12-22 14:22:00 +00:00
parent 6a2c768176
commit 167a87e60d

View File

@@ -3,6 +3,7 @@ package editorconfig
import ( import (
"fmt" "fmt"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"os"
"strconv" "strconv"
"strings" "strings"
) )
@@ -19,6 +20,8 @@ func CheckCommand(c *cli.Context) error {
configs := FindConfigFiles(files) configs := FindConfigFiles(files)
hasError := false
for _, f := range files { for _, f := range files {
rules := GetRulesToApplyToSourcePath(f, configs) rules := GetRulesToApplyToSourcePath(f, configs)
if len(rules) == 0 { if len(rules) == 0 {
@@ -32,6 +35,7 @@ func CheckCommand(c *cli.Context) error {
if fullFileChecker, ok := fullFileCheckers[ruleName]; ok { if fullFileChecker, ok := fullFileCheckers[ruleName]; ok {
result := fullFileChecker(ruleValue, fileContent) result := fullFileChecker(ruleValue, fileContent)
if !result.isOk { if !result.isOk {
hasError = true
fmt.Println(f + ": " + ruleName + ": " + result.messageIfNotOk) fmt.Println(f + ": " + ruleName + ": " + result.messageIfNotOk)
} }
} }
@@ -46,6 +50,7 @@ func CheckCommand(c *cli.Context) error {
result := lineChecker(ruleValue, line) result := lineChecker(ruleValue, line)
if !result.isOk { if !result.isOk {
fmt.Println(f + ": line " + strconv.Itoa(lineNo) + ": " + ruleName + ": " + result.messageIfNotOk) fmt.Println(f + ": line " + strconv.Itoa(lineNo) + ": " + ruleName + ": " + result.messageIfNotOk)
hasError = true
// Don't show more than 1 error per line. // Don't show more than 1 error per line.
break break
} }
@@ -55,5 +60,9 @@ func CheckCommand(c *cli.Context) error {
} }
} }
if hasError {
os.Exit(1)
}
return nil return nil
} }