Skip to content

Commit

Permalink
fix(output): compare line numbers while consolidating
Browse files Browse the repository at this point in the history
without comparing line numbers we do not detect two blocks of errors
with the same error message that are next to each other in output, but
their originating sections are separated by error-free lines

incorrect example:
    multiple-wrong-indentations.txt:
            2-7: Wrong amount of left-padding spaces(want multiple of 10)
    6 errors found
    1 files checked

correct example:
    multiple-wrong-indentations.txt:
            2-4: Wrong amount of left-padding spaces(want multiple of 10)
            8-9: Wrong amount of left-padding spaces(want multiple of 10)
    6 errors found
    1 files checked
  • Loading branch information
klaernie committed Aug 30, 2024
1 parent 08b86b1 commit 441e13b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/error/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func ConsolidateErrors(errors []ValidationError, config config.Config) []Validat
// scan through the errors after the current one
for j, nextError := range errorsWithLines[i+1:] {
config.Logger.Debug("comparing against error %d(%s)", j, nextError.Message)
if nextError.Message.Error() == thisError.Message.Error() {
if nextError.Message.Error() == thisError.Message.Error() && nextError.LineNumber == thisError.LineNumber+thisError.ConsecuitiveCount+1 {
thisError.ConsecuitiveCount++ // keep track of how many consecutive lines we've seen
i = i + j + 1 // make sure the outer loop jumps over the consecutive errors we just found
} else {
Expand Down

0 comments on commit 441e13b

Please sign in to comment.