Fix wrongly reported errors when an unindented line is part of a comment.

This commit is contained in:
Amy Boyd
2016-06-24 22:05:39 +01:00
parent 014e48701c
commit 2af7d8d9c7
2 changed files with 4 additions and 2 deletions

View File

@@ -61,7 +61,7 @@ func CheckIndentStyleRule(ruleValue string, line string) *LineCheckResult {
}
if strings.ToLower(ruleValue) == "tab" {
if IsIndentedWithSpaces(line) {
if IsIndentedWithSpaces(line) && !strings.HasPrefix(line, " *") {
return &LineCheckResult{isOk: false, messageIfNotOk: "starts with space instead of tab"}
} else if IsIndentedWithMixedTabsAndSpaces(line) && !IsIndentedWithTabsThenCommentLine(line) {
return &LineCheckResult{isOk: false, messageIfNotOk: "indented with mix of tabs and spaces instead of just tabs"}

View File

@@ -46,7 +46,9 @@ func TestCheckIndentStyleRule(t *testing.T) {
ExpectFail("\t ", "tab", f, t, "indented with mix of tabs and spaces instead of just tabs")
// Allow comments like /**\n\t *\n\t */
ExpectPass("\t *line", "tab", f, t)
ExpectPass("\t * comment 1", "tab", f, t)
ExpectPass("\t\t * comment 2", "tab", f, t)
ExpectPass(" * comment 3", "tab", f, t)
ExpectFail(" line", "dinosaurs", f, t, "invalid value for indent_style: dinosaurs")
}