Fix #388: include staticcheck check name into a message

This commit is contained in:
Denis Isaev 2019-02-17 23:48:08 +03:00
parent ebadb7a679
commit 307c287356
3 changed files with 17 additions and 12 deletions

View File

@ -258,8 +258,9 @@ func (m megacheck) Run(ctx context.Context, lintCtx *linter.Context) ([]result.I
}
res = append(res, result.Issue{
Pos: i.Position,
Text: i.Text,
Pos: i.Position,
// TODO: use severity
Text: fmt.Sprintf("%s: %s", i.Check, i.Text),
FromLinter: i.Checker,
})
}

View File

@ -36,24 +36,26 @@ var replacePatterns = []replacePattern{
{`^TLS InsecureSkipVerify set true.$`, "TLS `InsecureSkipVerify` set true."},
// gosimple
{`^should replace loop with (.*)$`, "should replace loop with `${1}`"},
{`^should use a simple channel send/receive instead of select with a single case`,
{`should replace loop with (.*)$`, "should replace loop with `${1}`"},
{`should use a simple channel send/receive instead of select with a single case`,
"should use a simple channel send/receive instead of `select` with a single case"},
{`^should omit comparison to bool constant, can be simplified to (.+)$`,
{`should omit comparison to bool constant, can be simplified to (.+)$`,
"should omit comparison to bool constant, can be simplified to `${1}`"},
{`^should write (.+) instead of (.+)$`, "should write `${1}` instead of `${2}`"},
{`^redundant return statement$`, "redundant `return` statement"},
{`should write (.+) instead of (.+)$`, "should write `${1}` instead of `${2}`"},
{`redundant return statement$`, "redundant `return` statement"},
{`should replace this if statement with an unconditional strings.TrimPrefix`,
"should replace this `if` statement with an unconditional `strings.TrimPrefix`"},
// staticcheck
{`^this value of (\S+) is never used$`, "this value of `${1}` is never used"},
{`^should use time.Since instead of time.Now\(\).Sub$`,
{`this value of (\S+) is never used$`, "this value of `${1}` is never used"},
{`should use time.Since instead of time.Now\(\).Sub$`,
"should use `time.Since` instead of `time.Now().Sub`"},
{`^should check returned error before deferring response.Close\(\)$`,
{`should check returned error before deferring response.Close\(\)$`,
"should check returned error before deferring `response.Close()`"},
{`^no value of type uint is less than 0$`, "no value of type `uint` is less than `0`"},
{`no value of type uint is less than 0$`, "no value of type `uint` is less than `0`"},
// unused
{`^(func|const|field|type|var) (\S+) is unused$`, "${1} `${2}` is unused"},
{`(func|const|field|type|var) (\S+) is unused$`, "${1} `${2}` is unused"},
// typecheck
{`^unknown field (\S+) in struct literal$`, "unknown field `${1}` in struct literal"},

View File

@ -43,6 +43,8 @@ func TestIdentifierMarker(t *testing.T) {
"don't use underscores in Go names; var `Go_lint` should be `GoLint`"},
{"G501: Blacklisted import crypto/md5: weak cryptographic primitive",
"G501: Blacklisted import `crypto/md5`: weak cryptographic primitive"},
{"S1017: should replace this if statement with an unconditional strings.TrimPrefix",
"S1017: should replace this `if` statement with an unconditional `strings.TrimPrefix`"},
}
p := NewIdentifierMarker()