Fix wrongly reported errors when an unindented line is part of a comment.
This commit is contained in:
@@ -61,7 +61,7 @@ func CheckIndentStyleRule(ruleValue string, line string) *LineCheckResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.ToLower(ruleValue) == "tab" {
|
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"}
|
return &LineCheckResult{isOk: false, messageIfNotOk: "starts with space instead of tab"}
|
||||||
} else if IsIndentedWithMixedTabsAndSpaces(line) && !IsIndentedWithTabsThenCommentLine(line) {
|
} else if IsIndentedWithMixedTabsAndSpaces(line) && !IsIndentedWithTabsThenCommentLine(line) {
|
||||||
return &LineCheckResult{isOk: false, messageIfNotOk: "indented with mix of tabs and spaces instead of just tabs"}
|
return &LineCheckResult{isOk: false, messageIfNotOk: "indented with mix of tabs and spaces instead of just tabs"}
|
||||||
|
|||||||
@@ -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")
|
ExpectFail("\t ", "tab", f, t, "indented with mix of tabs and spaces instead of just tabs")
|
||||||
|
|
||||||
// Allow comments like /**\n\t *\n\t */
|
// 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")
|
ExpectFail(" line", "dinosaurs", f, t, "invalid value for indent_style: dinosaurs")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user