Skip to content

Commit 67f5ace

Browse files
authored
Merge pull request #34 from rliebz/non-negative
Avoid returning negative positions
2 parents ed10182 + 230cc3b commit 67f5ace

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

handler.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ func (h *langHandler) lint(uri DocumentURI) ([]Diagnostic, error) {
9191

9292
d := Diagnostic{
9393
Range: Range{
94-
Start: Position{Line: issue.Pos.Line - 1, Character: issue.Pos.Column - 1},
95-
End: Position{Line: issue.Pos.Line - 1, Character: issue.Pos.Column - 1},
94+
Start: Position{
95+
Line: max(issue.Pos.Line-1, 0),
96+
Character: max(issue.Pos.Column-1, 0),
97+
},
98+
End: Position{
99+
Line: max(issue.Pos.Line-1, 0),
100+
Character: max(issue.Pos.Column-1, 0),
101+
},
96102
},
97103
Severity: issue.DiagSeverity(),
98104
Source: &issue.FromLinter,
@@ -104,6 +110,13 @@ func (h *langHandler) lint(uri DocumentURI) ([]Diagnostic, error) {
104110
return diagnostics, nil
105111
}
106112

113+
func max(a, b int) int {
114+
if a > b {
115+
return a
116+
}
117+
return b
118+
}
119+
107120
func (h *langHandler) diagnosticMessage(issue *Issue) string {
108121
if h.noLinterName {
109122
return issue.Text

0 commit comments

Comments
 (0)