aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-07-18 23:16:52 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-07-19 00:53:11 +0900
commit2aaa272ea1e6261a298024cc5c490878984ba07e (patch)
tree116fa09ceb91ae9e929081cb24813fed1e3b8528
parentDetect multiple semantic errors in a single parse (diff)
downloadcotia-2aaa272ea1e6261a298024cc5c490878984ba07e.tar.gz
cotia-2aaa272ea1e6261a298024cc5c490878984ba07e.tar.xz
Sort error messages before printing them
-rw-r--r--error/error.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/error/error.go b/error/error.go
index f953e3b..1781f2a 100644
--- a/error/error.go
+++ b/error/error.go
@@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"os"
+ "sort"
"strings"
)
@@ -14,9 +15,18 @@ func (e SpecErrors) Error() string {
return ""
}
+ sorted := make([]*SpecError, len(e))
+ copy(sorted, e)
+ sort.SliceStable(sorted, func(i, j int) bool {
+ return sorted[i].Row < sorted[j].Row
+ })
+ sort.SliceStable(sorted, func(i, j int) bool {
+ return sorted[i].FilePath < sorted[j].FilePath
+ })
+
var b strings.Builder
- fmt.Fprintf(&b, "%v", e[0])
- for _, err := range e[1:] {
+ fmt.Fprintf(&b, "%v", sorted[0])
+ for _, err := range sorted[1:] {
fmt.Fprintf(&b, "\n%v", err)
}