Add line fixer: FixTraimTrailingWhitespaceRule.

This commit is contained in:
Amy Boyd
2016-12-22 13:53:37 +00:00
parent bbbff6689b
commit 948f51d2a7
2 changed files with 26 additions and 0 deletions

View File

@@ -53,3 +53,11 @@ func FixUndividableIndentationToNearestSpacesAmount(ruleValueNumberOfSpaces stri
return line
}
func FixTrimTrailingWhitespaceRule(ruleValue string, line string) string {
if strings.ToLower(ruleValue) != "true" {
return line
}
return endsWithTabsAndSpacesRegexp.ReplaceAllString(line, "")
}

View File

@@ -70,3 +70,21 @@ func TestFixUndividableIndentationToNearestSpacesAmount(t *testing.T) {
t.Error("Unexpected result: " + result)
}
}
func TestFixTrimTrailingWhitespaceRule(t *testing.T) {
if FixTrimTrailingWhitespaceRule("true", "") != "" {
t.Error()
}
if FixTrimTrailingWhitespaceRule("true", " a b c") != " a b c" {
t.Error()
}
if FixTrimTrailingWhitespaceRule("true", "abc \t\t \t \t \t ") != "abc" {
t.Error()
}
if FixTrimTrailingWhitespaceRule("false", "abc \t\t \t \t \t ") != "abc \t\t \t \t \t " {
t.Error()
}
}