-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Verify linter name in integration tests #1595
Verify linter name in integration tests #1595
Conversation
pkg/printers/text.go
Outdated
@@ -52,7 +53,7 @@ func (p *Text) Print(ctx context.Context, issues []result.Issue) error { | |||
} | |||
|
|||
func (p Text) printIssue(i *result.Issue) { | |||
text := p.SprintfColored(color.FgRed, "%s", i.Text) | |||
text := p.SprintfColored(color.FgRed, "%s", strings.TrimSpace(i.Text)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is actually because paralleltest
returns issues with newlines at the end, causing us to not have the linter name at the end. paralleltest
does not have a customer issue reporter step, so I'm not sure it's wrong to make this adjustment generally.
} | ||
replacedOnce = true | ||
n := lineNum | ||
if strings.HasPrefix(m, "LINE+") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I could tell, nothing was using this logic that appears to have to do with matching line numbers.
@@ -18,3 +18,9 @@ func StaticcheckNolintMegacheckInMegacheck() { | |||
var x int | |||
x = x //nolint:megacheck | |||
} | |||
|
|||
func Staticcheck2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved this from stylecheck_in_megacheck since it appeared to be misplaced.
@@ -124,7 +124,6 @@ func testOneSource(t *testing.T, sourcePath string) { | |||
"--allow-parallel-runners", | |||
"--disable-all", | |||
"--print-issued-lines=false", | |||
"--print-linter-name=false", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the linter name to verify it
@@ -4,13 +4,13 @@ | |||
/*Package testdata ...*/ | |||
package testdata | |||
|
|||
// InvalidFuncComment, both golint and stylecheck will complain about this, // ERROR `ST1020: comment on exported function ExportedFunc1 should be of the form "ExportedFunc1 ..."` | |||
// InvalidFuncComment, both golint and stylecheck will complain about this, // ERROR stylecheck `ST1020: comment on exported function ExportedFunc1 should be of the form "ExportedFunc1 ..."` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicitly indicating the expected linter here
@@ -3,11 +3,11 @@ | |||
package testdata | |||
|
|||
func todoLeftInCode() { | |||
// TODO implement me // ERROR godox.go:6: Line contains FIXME/TODO: "TODO implement me" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the only thing being matched here was the stuff between double-quotes.
@@ -4,17 +4,17 @@ package testdata | |||
import "os" | |||
|
|||
func SimpleEqual(e1, e2 error) bool { | |||
return e1 == e2 // ERROR `err113: do not compare errors directly, use errors.Is() instead: "e1 == e2"` | |||
return e1 == e2 // ERROR `err113: do not compare errors directly, use errors.Is\(\) instead: "e1 == e2"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes this a valid regex in a go string
32f6694
to
12dce4b
Compare
12dce4b
to
1f5492b
Compare
I wanted to merge the PR so I rebased it, but now the CI is failing on a problem that I don't reproduce...
The CI is going to drive me crazy. |
Enforce a strict syntax for error matches in tests (although we still don't verify line number). Also fix some incorrect matches in tests
1f5492b
to
4184b87
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @ldez! |
This PR ensures that the expected linter is triggered in the integration tests (after a case where returned the wrong linter name for a linter -- see #1589).
The PR infers the name of the linter if it is the only explicitly listed linter (enabled with
-E<linter>
). It can also be specified by adding the argumentexpected_linter:
to the test header or by adding the linter name:This PR also enforces a strict syntax for error matches in tests by requiring that a string be Go-syntax string. Note that we still don't verify line number, although we could do that in a later test.
This PR also fixes some incorrect matches in tests where we were just matching a double-quoted subsection of an expected name.