Skip to content

Commit 7dc64b5

Browse files
authored
Merge pull request #27 from alexaandru/respect-severity
Respect the severity reported in the issue,
2 parents 92f7002 + f7f29c7 commit 7dc64b5

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

golangci-lint.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package main
22

3+
import "strings"
4+
35
type Issue struct {
46
FromLinter string `json:"FromLinter"`
57
Text string `json:"Text"`
8+
Severity string `json:"Severity"`
69
SourceLines []string `json:"SourceLines"`
710
Replacement interface{} `json:"Replacement"`
811
Pos struct {
@@ -11,12 +14,34 @@ type Issue struct {
1114
Line int `json:"Line"`
1215
Column int `json:"Column"`
1316
} `json:"Pos"`
14-
LineRange struct {
17+
ExpectNoLint bool `json:"ExpectNoLint"`
18+
ExpectedNoLintLinter string `json:"ExpectedNoLintLinter"`
19+
LineRange struct {
1520
From int `json:"From"`
1621
To int `json:"To"`
1722
} `json:"LineRange,omitempty"`
1823
}
1924

25+
func (i Issue) DiagSeverity() DiagnosticSeverity {
26+
if i.Severity == "" {
27+
// TODO: How to get default-severity from .golangci.yml, if available?
28+
i.Severity = defaultSeverity
29+
}
30+
31+
switch strings.ToLower(i.Severity) {
32+
case "err", "error":
33+
return DSError
34+
case "warn", "warning":
35+
return DSWarning
36+
case "info", "information":
37+
return DSInformation
38+
case "hint":
39+
return DSHint
40+
default:
41+
return DSWarning
42+
}
43+
}
44+
2045
//nolint:unused,deadcode
2146
type GolangCILintResult struct {
2247
Issues []Issue `json:"Issues"`

handler.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ func (h *langHandler) lint(uri DocumentURI) ([]Diagnostic, error) {
6060
continue
6161
}
6262

63-
//nolint:gomnd
6463
d := Diagnostic{
6564
Range: Range{
6665
Start: Position{Line: issue.Pos.Line - 1, Character: issue.Pos.Column - 1},
6766
End: Position{Line: issue.Pos.Line - 1, Character: issue.Pos.Column - 1},
6867
},
69-
Severity: DSWarning,
68+
Severity: issue.DiagSeverity(),
7069
Source: &issue.FromLinter,
7170
Message: h.diagnosticMessage(&issue),
7271
}

main.go

+3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import (
88
"github.com/sourcegraph/jsonrpc2"
99
)
1010

11+
var defaultSeverity = "Warn"
12+
1113
func main() {
1214
debug := flag.Bool("debug", false, "output debug log")
1315
noLinterName := flag.Bool("nolintername", false, "don't show a linter name in message")
16+
flag.StringVar(&defaultSeverity, "severity", defaultSeverity, "Default severity to use. Choices are: Err(or), Warn(ing), Info(rmation) or Hint")
1417

1518
flag.Parse()
1619

0 commit comments

Comments
 (0)