-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Verify linter name in integration tests #1595
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ import ( | |
| "github.com/golangci/golangci-lint/test/testshared" | ||
| ) | ||
|
|
||
| func runGoErrchk(c *exec.Cmd, files []string, t *testing.T) { | ||
| func runGoErrchk(c *exec.Cmd, defaultExpectedLinter string, files []string, t *testing.T) { | ||
| output, err := c.CombinedOutput() | ||
| // The returned error will be nil if the test file does not have any issues | ||
| // and thus the linter exits with exit code 0. So perform the additional | ||
|
|
@@ -33,7 +33,7 @@ func runGoErrchk(c *exec.Cmd, files []string, t *testing.T) { | |
| fullshort = append(fullshort, f, filepath.Base(f)) | ||
| } | ||
|
|
||
| err = errorCheck(string(output), false, fullshort...) | ||
| err = errorCheck(string(output), false, defaultExpectedLinter, fullshort...) | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
|
|
@@ -124,7 +124,6 @@ func testOneSource(t *testing.T, sourcePath string) { | |
| "--allow-parallel-runners", | ||
| "--disable-all", | ||
| "--print-issued-lines=false", | ||
| "--print-linter-name=false", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need the linter name to verify it |
||
| "--out-format=line-number", | ||
| "--max-same-issues=100", | ||
| } | ||
|
|
@@ -156,14 +155,15 @@ func testOneSource(t *testing.T, sourcePath string) { | |
|
|
||
| cmd := exec.Command(binName, caseArgs...) | ||
| t.Log(caseArgs) | ||
| runGoErrchk(cmd, []string{sourcePath}, t) | ||
| runGoErrchk(cmd, rc.expectedLinter, []string{sourcePath}, t) | ||
| } | ||
| } | ||
|
|
||
| type runContext struct { | ||
| args []string | ||
| config map[string]interface{} | ||
| configPath string | ||
| args []string | ||
| config map[string]interface{} | ||
| configPath string | ||
| expectedLinter string | ||
| } | ||
|
|
||
| func buildConfigFromShortRepr(t *testing.T, repr string, config map[string]interface{}) { | ||
|
|
@@ -213,7 +213,7 @@ func extractRunContextFromComments(t *testing.T, sourcePath string) *runContext | |
| continue | ||
| } | ||
| if !strings.HasPrefix(line, "//") { | ||
| return rc | ||
| break | ||
| } | ||
|
|
||
| line = strings.TrimLeft(strings.TrimPrefix(line, "//"), " ") | ||
|
|
@@ -242,9 +242,29 @@ func extractRunContextFromComments(t *testing.T, sourcePath string) *runContext | |
| continue | ||
| } | ||
|
|
||
| if strings.HasPrefix(line, "expected_linter: ") { | ||
| expectedLinter := strings.TrimPrefix(line, "expected_linter: ") | ||
| assert.NotEmpty(t, expectedLinter) | ||
| rc.expectedLinter = expectedLinter | ||
| continue | ||
| } | ||
|
|
||
| assert.Fail(t, "invalid prefix of comment line %s", line) | ||
| } | ||
|
|
||
| // guess the expected linter if none is specified | ||
| if rc.expectedLinter == "" { | ||
| for _, arg := range rc.args { | ||
| if strings.HasPrefix(arg, "-E") && !strings.Contains(arg, ",") { | ||
| if rc.expectedLinter != "" { | ||
| assert.Fail(t, "could not infer expected linter for errors because multiple linters are enabled. Please use the `expected_linter: ` directive in your test to indicate the linter-under-test.") //nolint:lll | ||
| break | ||
| } | ||
| rc.expectedLinter = arg[2:] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return rc | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| //args: -Easciicheck | ||
| package testdata | ||
|
|
||
| type TеstStruct struct{} // ERROR `identifier "TеstStruct" contain non-ASCII character: U+0435 'е'` | ||
| type TеstStruct struct{} // ERROR `identifier "TеstStruct" contain non-ASCII character: U\+0435 'е'` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ..."` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explicitly indicating the expected linter here |
||
| // if include EXC0011, only the warning from golint will be ignored. | ||
| // And only the warning from stylecheck will start with "ST1020". | ||
| func ExportedFunc1() { | ||
| } | ||
|
|
||
| // InvalidFuncComment // ERROR `ST1020: comment on exported function ExportedFunc2 should be of the form "ExportedFunc2 ..."` | ||
| // InvalidFuncComment // ERROR stylecheck `ST1020: comment on exported function ExportedFunc2 should be of the form "ExportedFunc2 ..."` | ||
| // nolint:golint | ||
| func ExportedFunc2() { | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,11 @@ | |
| package testdata | ||
|
|
||
| func todoLeftInCode() { | ||
| // TODO implement me // ERROR godox.go:6: Line contains FIXME/TODO: "TODO implement me" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| //TODO no space // ERROR godox.go:7: Line contains FIXME/TODO: "TODO no space" | ||
| // TODO(author): 123 // ERROR godox.go:8: Line contains FIXME/TODO: "TODO\(author\): 123 // ERROR godox.go:8: L..." | ||
| //TODO(author): 123 // ERROR godox.go:9: Line contains FIXME/TODO: "TODO\(author\): 123 // ERROR godox.go:9: L..." | ||
| //TODO(author) 456 // ERROR godox.go:10: Line contains FIXME/TODO: "TODO\(author\) 456 // ERROR godox.go:10: L..." | ||
| // TODO: qwerty // ERROR godox.go:11: Line contains FIXME/TODO: "TODO: qwerty // ERROR godox.go:11: Line ..." | ||
| // todo 789 // ERROR godox.go:12: Line contains FIXME/TODO: "todo 789" | ||
| // TODO implement me // ERROR `Line contains FIXME/TODO: "TODO implement me` | ||
| //TODO no space // ERROR `Line contains FIXME/TODO: "TODO no space` | ||
| // TODO(author): 123 // ERROR `Line contains FIXME/TODO: "TODO\(author\): 123` | ||
| //TODO(author): 123 // ERROR `Line contains FIXME/TODO: "TODO\(author\): 123` | ||
| //TODO(author) 456 // ERROR `Line contains FIXME/TODO: "TODO\(author\) 456` | ||
| // TODO: qwerty // ERROR `Line contains FIXME/TODO: "TODO: qwerty` | ||
| // todo 789 // ERROR `Line contains FIXME/TODO: "todo 789` | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change makes this a valid regex in a go string |
||
| } | ||
|
|
||
| func SimpleNotEqual(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"` | ||
| } | ||
|
|
||
| func CheckGoerr13Import(e error) bool { | ||
| f, err := os.Create("f.txt") | ||
| if err != nil { | ||
| return err == e // ERROR `err113: do not compare errors directly, use errors.Is() instead: "err == e"` | ||
| return err == e // ERROR `err113: do not compare errors directly, use errors.Is\(\) instead: "err == e"` | ||
| } | ||
| f.Close() | ||
| return 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.
as far as I could tell, nothing was using this logic that appears to have to do with matching line numbers.