-
Notifications
You must be signed in to change notification settings - Fork 5
/
error.go
60 lines (49 loc) · 1.19 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2013 Kamil Kisiel
// Modifications copyright 2016 Palantir Technologies, Inc.
// Licensed under the MIT License. See LICENSE in the project root
// for license information.
package outparamcheck
import (
"fmt"
"go/token"
"strings"
"github.com/dustin/go-humanize"
)
type OutParamError struct {
Pos token.Position
Line string
Method string
Argument int
}
func (err OutParamError) Error() string {
pos := err.Pos.String()
line := err.Line
comment := strings.Index(line, "//")
if comment != -1 {
line = line[:comment]
}
line = strings.TrimSpace(line)
ord := humanize.Ordinal(err.Argument + 1)
return fmt.Sprintf("%s\t%s // %s argument of '%s' requires '&'", pos, line, ord, err.Method)
}
type byLocation []OutParamError
func (errs byLocation) Len() int {
return len(errs)
}
func (errs byLocation) Swap(i, j int) {
errs[i], errs[j] = errs[j], errs[i]
}
func (errs byLocation) Less(i, j int) bool {
ei, ej := errs[i], errs[j]
pi, pj := ei.Pos, ej.Pos
if pi.Filename != pj.Filename {
return pi.Filename < pj.Filename
}
if pi.Line != pj.Line {
return pi.Line < pj.Line
}
if pi.Column < pj.Column {
return pi.Column < pj.Column
}
return ei.Line < ej.Line
}