Skip to content

Respect the severity reported in the issue, #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion golangci-lint.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package main

import "strings"

type Issue struct {
FromLinter string `json:"FromLinter"`
Text string `json:"Text"`
Severity string `json:"Severity"`
SourceLines []string `json:"SourceLines"`
Replacement interface{} `json:"Replacement"`
Pos struct {
Expand All @@ -11,12 +14,34 @@ type Issue struct {
Line int `json:"Line"`
Column int `json:"Column"`
} `json:"Pos"`
LineRange struct {
ExpectNoLint bool `json:"ExpectNoLint"`
ExpectedNoLintLinter string `json:"ExpectedNoLintLinter"`
LineRange struct {
From int `json:"From"`
To int `json:"To"`
} `json:"LineRange,omitempty"`
}

func (i Issue) DiagSeverity() DiagnosticSeverity {
if i.Severity == "" {
// TODO: How to get default-severity from .golangci.yml, if available?
i.Severity = defaultSeverity
}

switch strings.ToLower(i.Severity) {
case "err", "error":
return DSError
case "warn", "warning":
return DSWarning
case "info", "information":
return DSInformation
case "hint":
return DSHint
default:
return DSWarning
}
}

//nolint:unused,deadcode
type GolangCILintResult struct {
Issues []Issue `json:"Issues"`
Expand Down
3 changes: 1 addition & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ func (h *langHandler) lint(uri DocumentURI) ([]Diagnostic, error) {
continue
}

//nolint:gomnd
d := Diagnostic{
Range: Range{
Start: Position{Line: issue.Pos.Line - 1, Character: issue.Pos.Column - 1},
End: Position{Line: issue.Pos.Line - 1, Character: issue.Pos.Column - 1},
},
Severity: DSWarning,
Severity: issue.DiagSeverity(),
Source: &issue.FromLinter,
Message: h.diagnosticMessage(&issue),
}
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
"github.com/sourcegraph/jsonrpc2"
)

var defaultSeverity = "Warn"

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

flag.Parse()

Expand Down