From 2b4c9ab4fc5758d41886125ce2854c7abf91006b Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sat, 20 Aug 2022 18:53:45 +0200 Subject: [PATCH] dev: follow standards by using 'want' instead of 'ERROR' for tests (#3104) --- Makefile | 2 +- test/data.go | 18 -- test/errchk.go | 240 ------------------ test/fix_test.go | 41 ++- test/linters_test.go | 212 ++-------------- test/output_test.go | 82 ++++++ test/run_test.go | 132 +++++----- test/testdata/asasalint.go | 4 +- test/testdata/asciicheck.go | 8 +- test/testdata/bidichk.go | 2 +- test/testdata/bodyclose.go | 2 +- .../{goimports.yml => goimports_local.yml} | 0 test/testdata/containedctx.go | 2 +- test/testdata/contextcheck.go | 6 +- test/testdata/cyclop.go | 2 +- test/testdata/deadcode.go | 4 +- test/testdata/decorder.go | 6 +- test/testdata/decorder_default.go | 1 + test/testdata/default_exclude.go | 4 +- test/testdata/depguard.go | 4 +- test/testdata/depguard_additional_guards.go | 8 +- test/testdata/depguard_ignore_file_rules.go | 1 + test/testdata/dogsled.go | 4 +- test/testdata/dupl.go | 4 +- test/testdata/durationcheck.go | 6 +- test/testdata/errcheck.go | 2 +- test/testdata/errcheck_exclude.go | 2 +- test/testdata/errcheck_exclude_functions.go | 2 +- test/testdata/errcheck_ignore.go | 2 +- test/testdata/errcheck_ignore_default.go | 2 +- test/testdata/errcheck_type_assertions.go | 1 + test/testdata/errchkjson.go | 190 +++++++------- .../errchkjson_check_error_free_encoding.go | 184 +++++++------- test/testdata/errchkjson_no_exported.go | 2 +- test/testdata/errname.go | 22 +- test/testdata/errorlint.go | 6 +- test/testdata/errorlint_asserts.go | 10 +- test/testdata/errorlint_comparison.go | 12 +- test/testdata/errorlint_errorf.go | 8 +- test/testdata/execinquery.go | 8 +- test/testdata/exhaustive.go | 2 +- test/testdata/exhaustive_default.go | 1 + test/testdata/exhaustive_generated.go | 1 + .../exhaustive_ignore_enum_members.go | 2 +- test/testdata/exhaustivestruct.go | 6 +- test/testdata/exhaustivestruct_custom.go | 12 +- test/testdata/exhaustruct.go | 6 +- test/testdata/exhaustruct_custom.go | 6 +- test/testdata/exportloopref.go | 8 +- test/testdata/fix/in/gci.go | 1 + test/testdata/fix/in/gocritic.go | 1 + test/testdata/fix/in/godot.go | 1 + test/testdata/fix/in/gofmt.go | 1 + test/testdata/fix/in/gofumpt.go | 1 + test/testdata/fix/in/goimports.go | 1 + test/testdata/fix/in/misspell.go | 1 + test/testdata/fix/in/whitespace.go | 1 + test/testdata/fix/out/gci.go | 1 + test/testdata/fix/out/gocritic.go | 1 + test/testdata/fix/out/godot.go | 1 + test/testdata/fix/out/gofmt.go | 1 + test/testdata/fix/out/gofumpt.go | 1 + test/testdata/fix/out/goimports.go | 1 + test/testdata/fix/out/misspell.go | 1 + test/testdata/fix/out/whitespace.go | 1 + test/testdata/forbidigo_example.go | 4 +- test/testdata/forbidigo_example_test.go | 1 + .../forbidigo_include_godoc_examples_test.go | 2 +- test/testdata/forcetypeassert.go | 4 +- test/testdata/funlen.go | 4 +- test/testdata/gci.go | 4 +- test/testdata/gci/gci.go | 16 -- test/testdata/go-header_bad.go | 2 +- test/testdata/go-header_good.go | 1 + test/testdata/gochecknoglobals.go | 4 +- test/testdata/gochecknoinits.go | 2 +- test/testdata/gocognit.go | 6 +- test/testdata/goconst.go | 4 +- test/testdata/goconst_calls_enabled.go | 2 +- test/testdata/goconst_dont_ignore_test.go | 4 +- test/testdata/goconst_ignore_test.go | 1 + test/testdata/gocritic.go | 10 +- test/testdata/gocyclo.go | 2 +- test/testdata/godot.go | 2 +- test/testdata/godox.go | 14 +- test/testdata/goerr113.go | 6 +- test/testdata/gofmt.go | 2 +- test/testdata/gofmt_no_simplify.go | 2 +- test/testdata/gofumpt.go | 2 +- test/testdata/gofumpt_with_extra.go | 2 +- test/testdata/goimports.go | 2 +- test/testdata/goimports/goimports.go | 16 -- test/testdata/goimports_local.go | 16 ++ test/testdata/golint.go | 4 +- test/testdata/gomnd.go | 4 +- test/testdata/gomodguard.go | 2 +- test/testdata/goprintffuncname.go | 2 +- test/testdata/gosec.go | 6 +- test/testdata/gosec_rules_config.go | 4 +- test/testdata/gosec_severity_confidence.go | 2 +- test/testdata/gosimple.go | 2 +- test/testdata/govet.go | 8 +- test/testdata/govet_fieldalignment.go | 8 +- test/testdata/govet_ifaceassert.go | 2 +- test/testdata/ifshort.go | 2 +- test/testdata/importas.go | 6 +- test/testdata/importas_noalias.go | 1 + test/testdata/importas_strict.go | 8 +- test/testdata/ineffassign.go | 2 +- test/testdata/interfacer.go | 2 +- test/testdata/ireturn_allow.go | 1 + test/testdata/ireturn_default.go | 2 +- test/testdata/ireturn_reject_stdlib.go | 2 +- test/testdata/lll.go | 2 +- test/testdata/maintidx.go | 2 +- test/testdata/maintidx_under_100.go | 4 +- test/testdata/makezero.go | 6 +- test/testdata/makezero_always.go | 2 +- test/testdata/maligned.go | 2 +- test/testdata/misspell.go | 2 +- test/testdata/nakedret.go | 2 +- test/testdata/nestif.go | 10 +- test/testdata/nilerr.go | 6 +- test/testdata/nilnil.go | 52 ++-- test/testdata/nlreturn-block-size.go | 2 +- test/testdata/nlreturn.go | 22 +- test/testdata/noctx.go | 48 ++-- test/testdata/nolintlint.go | 6 +- test/testdata/nolintlint_unused.go | 4 +- test/testdata/nonamedreturns.go | 26 +- test/testdata/nonamedreturns_custom.go | 18 +- test/testdata/nosnakecase.go | 80 +++--- test/testdata/nosprintfhostport.go | 16 +- test/testdata/notcompiles/typecheck.go | 2 +- .../notcompiles/typecheck_many_issues.go | 8 +- test/testdata/paralleltest.go | 2 +- test/testdata/prealloc.go | 2 +- test/testdata/predeclared.go | 6 +- test/testdata/predeclared_custom.go | 4 +- test/testdata/promlinter.go | 8 +- test/testdata/revive.go | 2 +- test/testdata/revive_default.go | 2 +- test/testdata/rowserrcheck.go | 2 +- test/testdata/scopelint.go | 2 +- test/testdata/sqlclosecheck.go | 8 +- test/testdata/staticcheck.go | 4 +- test/testdata/staticcheck_in_megacheck.go | 4 +- test/testdata/structcheck.go | 2 +- test/testdata/stylecheck.go | 4 +- test/testdata/stylecheck_not_in_megacheck.go | 1 + test/testdata/tagliatelle.go | 8 +- test/testdata/tenv.go | 18 +- test/testdata/tenv_all.go | 18 +- test/testdata/tenv_all_test.go | 24 +- test/testdata/tenv_go118.go | 6 +- test/testdata/tenv_test.go | 18 +- test/testdata/testpackage_test.go | 2 +- test/testdata/thelper.go | 18 +- test/testdata/thelper_go118.go | 6 +- test/testdata/thelper_with_options.go | 4 +- .../tparallel/missing_subtest_test.go | 12 - .../tparallel/missing_toplevel_test.go | 11 - ...h_test.go => tparallel_happy_path_test.go} | 2 + .../tparallel_missing_subtest_test.go | 13 + .../tparallel_missing_toplevel_test.go | 12 + test/testdata/unconvert.go | 2 +- test/testdata/unparam.go | 2 +- test/testdata/unused.go | 12 +- test/testdata/usestdlibvars.go | 2 +- test/testdata/varcheck.go | 2 +- test/testdata/varnamelen.go | 2 +- test/testdata/wastedassign.go | 28 +- test/testdata/wrapcheck.go | 2 +- test/testdata/wsl.go | 28 +- test/testshared/analysis.go | 200 +++++++++++++++ test/testshared/analysis_test.go | 138 ++++++++++ test/testshared/directives.go | 18 +- test/testshared/directives_test.go | 3 + test/testshared/runner.go | 17 +- test/testshared/runner_test.go | 2 +- test/testshared/testdata/all.go | 1 + 181 files changed, 1275 insertions(+), 1246 deletions(-) delete mode 100644 test/data.go delete mode 100644 test/errchk.go create mode 100644 test/output_test.go rename test/testdata/configs/{goimports.yml => goimports_local.yml} (100%) delete mode 100644 test/testdata/gci/gci.go delete mode 100644 test/testdata/goimports/goimports.go create mode 100644 test/testdata/goimports_local.go delete mode 100644 test/testdata/tparallel/missing_subtest_test.go delete mode 100644 test/testdata/tparallel/missing_toplevel_test.go rename test/testdata/{tparallel/happy_path_test.go => tparallel_happy_path_test.go} (75%) create mode 100644 test/testdata/tparallel_missing_subtest_test.go create mode 100644 test/testdata/tparallel_missing_toplevel_test.go create mode 100644 test/testshared/analysis.go create mode 100644 test/testshared/analysis_test.go diff --git a/Makefile b/Makefile index 1ba54cb2..0933674f 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ test_race: build_race .PHONY: test_race test_linters: - GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdataWithIssuesDir/$T + GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdata/$T .PHONY: test_linters # Maintenance diff --git a/test/data.go b/test/data.go deleted file mode 100644 index 217be64c..00000000 --- a/test/data.go +++ /dev/null @@ -1,18 +0,0 @@ -package test - -import ( - "path/filepath" -) - -const testdataDir = "testdata" - -var minimalPkg = getTestDataDir("minimalpkg") - -func getProjectRoot() string { - return filepath.Join("..", "...") -} - -func getTestDataDir(names ...string) string { - parts := append([]string{testdataDir}, names...) - return filepath.Join(parts...) -} diff --git a/test/errchk.go b/test/errchk.go deleted file mode 100644 index 4285e21a..00000000 --- a/test/errchk.go +++ /dev/null @@ -1,240 +0,0 @@ -package test - -import ( - "bytes" - "errors" - "fmt" - "log" - "os" - "regexp" - "strconv" - "strings" -) - -var errorLineRx = regexp.MustCompile(`^\S+?: (.*)\((\S+?)\)$`) - -// errorCheck matches errors in outStr against comments in source files. -// For each line of the source files which should generate an error, -// there should be a comment of the form // ERROR "regexp". -// If outStr has an error for a line which has no such comment, -// this function will report an error. -// Likewise if outStr does not have an error for a line which has a comment, -// or if the error message does not match the . -// The syntax is Perl but it's best to stick to egrep. -// -// Sources files are supplied as fullshort slice. -// It consists of pairs: full path to source file and its base name. -// -//nolint:gocyclo,funlen -func errorCheck(outStr string, wantAuto bool, defaultWantedLinter string, fullshort ...string) (err error) { - var errs []error - out := splitOutput(outStr, wantAuto) - // Cut directory name. - for i := range out { - for j := 0; j < len(fullshort); j += 2 { - full, short := fullshort[j], fullshort[j+1] - out[i] = strings.ReplaceAll(out[i], full, short) - } - } - - var want []wantedError - for j := 0; j < len(fullshort); j += 2 { - full, short := fullshort[j], fullshort[j+1] - want = append(want, wantedErrors(full, short, defaultWantedLinter)...) - } - for _, we := range want { - if we.linter == "" { - err := fmt.Errorf("%s:%d: no expected linter indicated for test", - we.file, we.lineNum) - errs = append(errs, err) - continue - } - - var errmsgs []string - if we.auto { - errmsgs, out = partitionStrings("", out) - } else { - errmsgs, out = partitionStrings(we.prefix, out) - } - if len(errmsgs) == 0 { - errs = append(errs, fmt.Errorf("%s:%d: missing error %q", we.file, we.lineNum, we.reStr)) - continue - } - matched := false - var textsToMatch []string - for _, errmsg := range errmsgs { - // Assume errmsg says "file:line: foo ()". - matches := errorLineRx.FindStringSubmatch(errmsg) - if len(matches) == 0 { - err := fmt.Errorf("%s:%d: unexpected error line: %s", - we.file, we.lineNum, errmsg) - errs = append(errs, err) - continue - } - - text, actualLinter := matches[1], matches[2] - - if we.re.MatchString(text) { - matched = true - } else { - out = append(out, errmsg) - textsToMatch = append(textsToMatch, text) - } - - if actualLinter != we.linter { - err := fmt.Errorf("%s:%d: expected error from %q but got error from %q in:\n\t%s", - we.file, we.lineNum, we.linter, actualLinter, strings.Join(out, "\n\t")) - errs = append(errs, err) - } - } - if !matched { - err := fmt.Errorf("%s:%d: no match for %#q vs %q in:\n\t%s", - we.file, we.lineNum, we.reStr, textsToMatch, strings.Join(out, "\n\t")) - errs = append(errs, err) - continue - } - } - - if len(out) > 0 { - errs = append(errs, errors.New("unmatched errors")) - for _, errLine := range out { - errs = append(errs, fmt.Errorf("%s", errLine)) - } - } - - if len(errs) == 0 { - return nil - } - if len(errs) == 1 { - return errs[0] - } - var buf bytes.Buffer - fmt.Fprintf(&buf, "\n") - for _, err := range errs { - fmt.Fprintf(&buf, "%s\n", err.Error()) - } - return errors.New(buf.String()) -} - -func splitOutput(out string, wantAuto bool) []string { - // gc error messages continue onto additional lines with leading tabs. - // Split the output at the beginning of each line that doesn't begin with a tab. - // lines are impossible to match so those are filtered out. - var res []string - for _, line := range strings.Split(out, "\n") { - line = strings.TrimSuffix(line, "\r") // normalize Windows output - if strings.HasPrefix(line, "\t") { - res[len(res)-1] += "\n" + line - } else if strings.HasPrefix(line, "go tool") || strings.HasPrefix(line, "#") || !wantAuto && strings.HasPrefix(line, "") { - continue - } else if strings.TrimSpace(line) != "" { - res = append(res, line) - } - } - return res -} - -// matchPrefix reports whether s starts with file name prefix followed by a :, -// and possibly preceded by a directory name. -func matchPrefix(s, prefix string) bool { - i := strings.Index(s, ":") - if i < 0 { - return false - } - j := strings.LastIndex(s[:i], "/") - s = s[j+1:] - if len(s) <= len(prefix) || s[:len(prefix)] != prefix { - return false - } - if s[len(prefix)] == ':' { - return true - } - return false -} - -func partitionStrings(prefix string, strs []string) (matched, unmatched []string) { - for _, s := range strs { - if matchPrefix(s, prefix) { - matched = append(matched, s) - } else { - unmatched = append(unmatched, s) - } - } - return -} - -type wantedError struct { - reStr string - re *regexp.Regexp - lineNum int - auto bool // match line - file string - prefix string - linter string -} - -var ( - errRx = regexp.MustCompile(`// (?:GC_)?ERROR (.*)`) - errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO (.*)`) - linterPrefixRx = regexp.MustCompile("^\\s*([^\\s\"`]+)") -) - -// wantedErrors parses expected errors from comments in a file. -// -//nolint:nakedret -func wantedErrors(file, short, defaultLinter string) (errs []wantedError) { - cache := make(map[string]*regexp.Regexp) - - src, err := os.ReadFile(file) - if err != nil { - log.Fatal(err) - } - for i, line := range strings.Split(string(src), "\n") { - lineNum := i + 1 - if strings.Contains(line, "////") { - // double comment disables ERROR - continue - } - var auto bool - m := errAutoRx.FindStringSubmatch(line) - if m != nil { - auto = true - } else { - m = errRx.FindStringSubmatch(line) - } - if m == nil { - continue - } - rest := m[1] - linter := defaultLinter - if lm := linterPrefixRx.FindStringSubmatch(rest); lm != nil { - linter = lm[1] - rest = rest[len(lm[0]):] - } - rx, err := strconv.Unquote(strings.TrimSpace(rest)) - if err != nil { - log.Fatalf("%s:%d: invalid errchk line: %s, %v", file, lineNum, line, err) - } - re := cache[rx] - if re == nil { - var err error - re, err = regexp.Compile(rx) - if err != nil { - log.Fatalf("%s:%d: invalid regexp \"%#q\" in ERROR line: %v", file, lineNum, rx, err) - } - cache[rx] = re - } - prefix := fmt.Sprintf("%s:%d", short, lineNum) - errs = append(errs, wantedError{ - reStr: rx, - re: re, - prefix: prefix, - auto: auto, - lineNum: lineNum, - file: short, - linter: linter, - }) - } - - return -} diff --git a/test/fix_test.go b/test/fix_test.go index f39a9689..85653ddf 100644 --- a/test/fix_test.go +++ b/test/fix_test.go @@ -8,37 +8,29 @@ import ( "github.com/stretchr/testify/require" - "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/test/testshared" ) func TestFix(t *testing.T) { - findSources := func(pathPatterns ...string) []string { - sources, err := filepath.Glob(filepath.Join(pathPatterns...)) - require.NoError(t, err) - require.NotEmpty(t, sources) - return sources - } - tmpDir := filepath.Join(testdataDir, "fix.tmp") - os.RemoveAll(tmpDir) // cleanup after previous runs + _ = os.RemoveAll(tmpDir) // cleanup previous runs if os.Getenv("GL_KEEP_TEMP_FILES") == "1" { t.Logf("Temp dir for fix test: %s", tmpDir) } else { - t.Cleanup(func() { - os.RemoveAll(tmpDir) - }) + t.Cleanup(func() { _ = os.RemoveAll(tmpDir) }) } - fixDir := filepath.Join(testdataDir, "fix") - err := exec.Command("cp", "-R", fixDir, tmpDir).Run() + sourcesDir := filepath.Join(testdataDir, "fix") + + err := exec.Command("cp", "-R", sourcesDir, tmpDir).Run() require.NoError(t, err) testshared.InstallGolangciLint(t) - inputs := findSources(tmpDir, "in", "*.go") - for _, input := range inputs { + sources := findSources(t, tmpDir, "in", "*.go") + + for _, input := range sources { input := input t.Run(filepath.Base(input), func(t *testing.T) { t.Parallel() @@ -49,22 +41,19 @@ func TestFix(t *testing.T) { return } - runResult := testshared.NewRunnerBuilder(t). - WithRunContext(rc). - WithTargetPath(input). + testshared.NewRunnerBuilder(t). WithArgs( "--disable-all", "--print-issued-lines=false", "--print-linter-name=false", "--out-format=line-number", - "--fix"). + "--fix", + ). + WithRunContext(rc). + WithTargetPath(input). Runner(). - Run() - - // nolintlint test uses non existing linters (bob, alice) - if rc.ExpectedLinter != "nolintlint" { - runResult.ExpectExitCode(exitcodes.Success) - } + Run(). + ExpectExitCode(rc.ExitCode) output, err := os.ReadFile(input) require.NoError(t, err) diff --git a/test/linters_test.go b/test/linters_test.go index c1e49ccf..3d8ca694 100644 --- a/test/linters_test.go +++ b/test/linters_test.go @@ -1,20 +1,19 @@ package test import ( - "fmt" - "os" "os/exec" - "path" "path/filepath" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/test/testshared" ) -func TestSourcesFromTestdataWithIssuesDir(t *testing.T) { +const testdataDir = "testdata" + +func TestSourcesFromTestdata(t *testing.T) { testSourcesFromDir(t, testdataDir) } @@ -27,13 +26,7 @@ func testSourcesFromDir(t *testing.T, dir string) { t.Log(filepath.Join(dir, "*.go")) - findSources := func(pathPatterns ...string) []string { - sources, err := filepath.Glob(filepath.Join(pathPatterns...)) - require.NoError(t, err) - require.NotEmpty(t, sources) - return sources - } - sources := findSources(dir, "*.go") + sources := findSources(t, dir, "*.go") testshared.InstallGolangciLint(t) @@ -49,19 +42,18 @@ func testSourcesFromDir(t *testing.T, dir string) { func testOneSource(t *testing.T, sourcePath string) { t.Helper() - args := []string{ - "--allow-parallel-runners", - "--disable-all", - "--print-issued-lines=false", - "--out-format=line-number", - "--max-same-issues=100", - } - rc := testshared.ParseTestDirectives(t, sourcePath) if rc == nil { t.Skipf("Skipped: %s", sourcePath) } + args := []string{ + "--allow-parallel-runners", + "--disable-all", + "--out-format=json", + "--max-same-issues=100", + } + for _, addArg := range []string{"", "-Etypecheck"} { caseArgs := append([]string{}, args...) @@ -69,190 +61,36 @@ func testOneSource(t *testing.T, sourcePath string) { caseArgs = append(caseArgs, addArg) } - files := []string{sourcePath} - - runner := testshared.NewRunnerBuilder(t). + cmd := testshared.NewRunnerBuilder(t). WithNoParallelRunners(). WithArgs(caseArgs...). WithRunContext(rc). WithTargetPath(sourcePath). - Runner() + Runner(). + Command() + + output, err := cmd.CombinedOutput() - output, err := runner.RawRun() // 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 assertions only if the error is non-nil. if err != nil { var exitErr *exec.ExitError require.ErrorAs(t, err, &exitErr) - require.Equal(t, exitcodes.IssuesFound, exitErr.ExitCode(), "Unexpected exit code: %s", string(output)) } - fullshort := make([]string, 0, len(files)*2) - for _, f := range files { - fullshort = append(fullshort, f, filepath.Base(f)) - } + assert.Equal(t, rc.ExitCode, cmd.ProcessState.ExitCode(), "Unexpected exit code: %s", string(output)) - err = errorCheck(string(output), false, rc.ExpectedLinter, fullshort...) - require.NoError(t, err) + testshared.Analyze(t, sourcePath, output) } } -func TestMultipleOutputs(t *testing.T) { - sourcePath := filepath.Join(testdataDir, "gci", "gci.go") +func findSources(t *testing.T, pathPatterns ...string) []string { + t.Helper() - testshared.NewRunnerBuilder(t). - WithArgs( - "--disable-all", - "--print-issued-lines=false", - "--print-linter-name=false", - "--out-format=line-number,json:stdout", - ). - WithDirectives(sourcePath). - WithTargetPath(sourcePath). - Runner(). - Install(). - Run(). - ExpectHasIssue("testdata/gci/gci.go:8: File is not `gci`-ed"). - ExpectOutputContains(`"Issues":[`) -} - -func TestStderrOutput(t *testing.T) { - sourcePath := filepath.Join(testdataDir, "gci", "gci.go") - - testshared.NewRunnerBuilder(t). - WithArgs( - "--disable-all", - "--print-issued-lines=false", - "--print-linter-name=false", - "--out-format=line-number,json:stderr", - ). - WithDirectives(sourcePath). - WithTargetPath(sourcePath). - Runner(). - Install(). - Run(). - ExpectHasIssue("testdata/gci/gci.go:8: File is not `gci`-ed"). - ExpectOutputContains(`"Issues":[`) -} - -func TestFileOutput(t *testing.T) { - resultPath := path.Join(t.TempDir(), "golangci_lint_test_result") - - sourcePath := filepath.Join(testdataDir, "gci", "gci.go") - - testshared.NewRunnerBuilder(t). - WithArgs( - "--disable-all", - "--print-issued-lines=false", - "--print-linter-name=false", - fmt.Sprintf("--out-format=json:%s,line-number", resultPath), - ). - WithDirectives(sourcePath). - WithTargetPath(sourcePath). - Runner(). - Install(). - Run(). - ExpectHasIssue("testdata/gci/gci.go:8: File is not `gci`-ed"). - ExpectOutputNotContains(`"Issues":[`) - - b, err := os.ReadFile(resultPath) + sources, err := filepath.Glob(filepath.Join(pathPatterns...)) require.NoError(t, err) - require.Contains(t, string(b), `"Issues":[`) -} - -func TestLinter_goimports_local(t *testing.T) { - sourcePath := filepath.Join(testdataDir, "goimports", "goimports.go") - - testshared.NewRunnerBuilder(t). - WithArgs( - "--disable-all", - "--print-issued-lines=false", - "--print-linter-name=false", - "--out-format=line-number", - ). - WithDirectives(sourcePath). - WithTargetPath(sourcePath). - Runner(). - Install(). - Run(). - ExpectHasIssue("testdata/goimports/goimports.go:8: File is not `goimports`-ed") -} - -func TestLinter_gci_Local(t *testing.T) { - sourcePath := filepath.Join(testdataDir, "gci", "gci.go") - - testshared.NewRunnerBuilder(t). - WithArgs( - "--disable-all", - "--print-issued-lines=false", - "--print-linter-name=false", - "--out-format=line-number", - ). - WithDirectives(sourcePath). - WithTargetPath(sourcePath). - Runner(). - Install(). - Run(). - ExpectHasIssue("testdata/gci/gci.go:8: File is not `gci`-ed") -} - -// TODO(ldez) need to be converted to a classic linter test. -func TestLinter_tparallel(t *testing.T) { - testCases := []struct { - desc string - sourcePath string - expected func(result *testshared.RunnerResult) - }{ - { - desc: "should fail on missing top-level Parallel()", - sourcePath: filepath.Join(testdataDir, "tparallel", "missing_toplevel_test.go"), - expected: func(result *testshared.RunnerResult) { - result.ExpectHasIssue( - "testdata/tparallel/missing_toplevel_test.go:7:6: TestTopLevel should call t.Parallel on the top level as well as its subtests\n", - ) - }, - }, - { - desc: "should fail on missing subtest Parallel()", - sourcePath: filepath.Join(testdataDir, "tparallel", "missing_subtest_test.go"), - expected: func(result *testshared.RunnerResult) { - result.ExpectHasIssue( - "testdata/tparallel/missing_subtest_test.go:7:6: TestSubtests's subtests should call t.Parallel\n", - ) - }, - }, - { - desc: "should pass on parallel test with no subtests", - sourcePath: filepath.Join(testdataDir, "tparallel", "happy_path_test.go"), - expected: func(result *testshared.RunnerResult) { - result.ExpectNoIssues() - }, - }, - } - - testshared.InstallGolangciLint(t) - - for _, test := range testCases { - test := test - t.Run(test.desc, func(t *testing.T) { - t.Parallel() - - result := testshared.NewRunnerBuilder(t). - WithDirectives(test.sourcePath). - WithArgs( - "--disable-all", - "--enable", - "tparallel", - "--print-issued-lines=false", - "--print-linter-name=false", - "--out-format=line-number", - ). - WithTargetPath(test.sourcePath). - Runner(). - Run() - - test.expected(result) - }) - } + require.NotEmpty(t, sources) + + return sources } diff --git a/test/output_test.go b/test/output_test.go new file mode 100644 index 00000000..75f8469e --- /dev/null +++ b/test/output_test.go @@ -0,0 +1,82 @@ +package test + +import ( + "fmt" + "os" + "path" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/golangci/golangci-lint/test/testshared" +) + +//nolint:misspell,lll +const expectedJSONOutput = `{"Issues":[{"FromLinter":"misspell","Text":"` + "`" + `occured` + "`" + ` is a misspelling of ` + "`" + `occurred` + "`" + `","Severity":"","SourceLines":["\t// comment with incorrect spelling: occured // want \"` + "`" + `occured` + "`" + ` is a misspelling of ` + "`" + `occurred` + "`" + `\""],"Replacement":{"NeedOnlyDelete":false,"NewLines":null,"Inline":{"StartCol":37,"Length":7,"NewString":"occurred"}},"Pos":{"Filename":"testdata/misspell.go","Offset":0,"Line":6,"Column":38},"ExpectNoLint":false,"ExpectedNoLintLinter":""}],"Report":{"Linters":[{"Name":"asasalint"},{"Name":"asciicheck"},{"Name":"bidichk"},{"Name":"bodyclose"},{"Name":"containedctx"},{"Name":"contextcheck"},{"Name":"cyclop"},{"Name":"decorder"},{"Name":"deadcode","EnabledByDefault":true},{"Name":"depguard"},{"Name":"dogsled"},{"Name":"dupl"},{"Name":"durationcheck"},{"Name":"errcheck","EnabledByDefault":true},{"Name":"errchkjson"},{"Name":"errname"},{"Name":"errorlint"},{"Name":"execinquery"},{"Name":"exhaustive"},{"Name":"exhaustivestruct"},{"Name":"exhaustruct"},{"Name":"exportloopref"},{"Name":"forbidigo"},{"Name":"forcetypeassert"},{"Name":"funlen"},{"Name":"gci"},{"Name":"gochecknoglobals"},{"Name":"gochecknoinits"},{"Name":"gocognit"},{"Name":"goconst"},{"Name":"gocritic"},{"Name":"gocyclo"},{"Name":"godot"},{"Name":"godox"},{"Name":"goerr113"},{"Name":"gofmt"},{"Name":"gofumpt"},{"Name":"goheader"},{"Name":"goimports"},{"Name":"golint"},{"Name":"gomnd"},{"Name":"gomoddirectives"},{"Name":"gomodguard"},{"Name":"goprintffuncname"},{"Name":"gosec"},{"Name":"gosimple","EnabledByDefault":true},{"Name":"govet","EnabledByDefault":true},{"Name":"grouper"},{"Name":"ifshort"},{"Name":"importas"},{"Name":"ineffassign","EnabledByDefault":true},{"Name":"interfacer"},{"Name":"ireturn"},{"Name":"lll"},{"Name":"maintidx"},{"Name":"makezero"},{"Name":"maligned"},{"Name":"misspell","Enabled":true},{"Name":"nakedret"},{"Name":"nestif"},{"Name":"nilerr"},{"Name":"nilnil"},{"Name":"nlreturn"},{"Name":"noctx"},{"Name":"nonamedreturns"},{"Name":"nosnakecase"},{"Name":"nosprintfhostport"},{"Name":"paralleltest"},{"Name":"prealloc"},{"Name":"predeclared"},{"Name":"promlinter"},{"Name":"revive"},{"Name":"rowserrcheck"},{"Name":"scopelint"},{"Name":"sqlclosecheck"},{"Name":"staticcheck","EnabledByDefault":true},{"Name":"structcheck"},{"Name":"stylecheck"},{"Name":"tagliatelle"},{"Name":"tenv"},{"Name":"testpackage"},{"Name":"thelper"},{"Name":"tparallel"},{"Name":"typecheck","EnabledByDefault":true},{"Name":"unconvert"},{"Name":"unparam"},{"Name":"unused","EnabledByDefault":true},{"Name":"usestdlibvars"},{"Name":"varcheck","EnabledByDefault":true},{"Name":"varnamelen"},{"Name":"wastedassign"},{"Name":"whitespace"},{"Name":"wrapcheck"},{"Name":"wsl"},{"Name":"nolintlint"}]}}` + +func TestOutput_Stderr(t *testing.T) { + sourcePath := filepath.Join(testdataDir, "misspell.go") + fmt.Println(filepath.Abs(sourcePath)) + + testshared.NewRunnerBuilder(t). + WithArgs( + "--disable-all", + "--print-issued-lines=false", + "--print-linter-name=false", + "--out-format=line-number,json:stderr", + ). + WithDirectives(sourcePath). + WithTargetPath(sourcePath). + Runner(). + Install(). + Run(). + //nolint:misspell + ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`"). + ExpectOutputContains(expectedJSONOutput) +} + +func TestOutput_File(t *testing.T) { + resultPath := path.Join(t.TempDir(), "golangci_lint_test_result") + + sourcePath := filepath.Join(testdataDir, "misspell.go") + + testshared.NewRunnerBuilder(t). + WithArgs( + "--disable-all", + "--print-issued-lines=false", + "--print-linter-name=false", + fmt.Sprintf("--out-format=json:%s,line-number", resultPath), + ). + WithDirectives(sourcePath). + WithTargetPath(sourcePath). + Runner(). + Install(). + Run(). + //nolint:misspell + ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`") + + b, err := os.ReadFile(resultPath) + require.NoError(t, err) + require.Contains(t, string(b), expectedJSONOutput) +} + +func TestOutput_Multiple(t *testing.T) { + sourcePath := filepath.Join(testdataDir, "misspell.go") + + testshared.NewRunnerBuilder(t). + WithArgs( + "--disable-all", + "--print-issued-lines=false", + "--print-linter-name=false", + "--out-format=line-number,json:stdout", + ). + WithDirectives(sourcePath). + WithTargetPath(sourcePath). + Runner(). + Install(). + Run(). + //nolint:misspell + ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`"). + ExpectOutputContains(expectedJSONOutput) +} diff --git a/test/run_test.go b/test/run_test.go index da938540..bde6f434 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -12,13 +12,13 @@ import ( "github.com/golangci/golangci-lint/test/testshared" ) -func getCommonRunArgs() []string { - return []string{"--skip-dirs", "testdata_etc/,pkg/golinters/goanalysis/(checker|passes)"} -} +const minimalPkg = "minimalpkg" + +const skipDirsCommand = "testdata_etc/,pkg/golinters/goanalysis/(checker|passes)" func TestAutogeneratedNoIssues(t *testing.T) { testshared.NewRunnerBuilder(t). - WithTargetPath(getTestDataDir("autogenerated")). + WithTargetPath(testdataDir, "autogenerated"). Runner(). Install(). Run(). @@ -28,7 +28,7 @@ func TestAutogeneratedNoIssues(t *testing.T) { func TestEmptyDirRun(t *testing.T) { testshared.NewRunnerBuilder(t). WithEnviron("GO111MODULE=off"). - WithTargetPath(getTestDataDir("nogofiles")). + WithTargetPath(testdataDir, "nogofiles"). Runner(). Install(). Run(). @@ -39,7 +39,7 @@ func TestEmptyDirRun(t *testing.T) { func TestNotExistingDirRun(t *testing.T) { testshared.NewRunnerBuilder(t). WithEnviron("GO111MODULE=off"). - WithTargetPath(getTestDataDir("no_such_dir")). + WithTargetPath(testdataDir, "no_such_dir"). Runner(). Install(). Run(). @@ -50,7 +50,7 @@ func TestNotExistingDirRun(t *testing.T) { func TestSymlinkLoop(t *testing.T) { testshared.NewRunnerBuilder(t). - WithTargetPath(getTestDataDir("symlink_loop", "...")). + WithTargetPath(testdataDir, "symlink_loop", "..."). Runner(). Install(). Run(). @@ -59,9 +59,11 @@ func TestSymlinkLoop(t *testing.T) { // TODO(ldez): remove this in v2. func TestDeadline(t *testing.T) { + projectRoot := filepath.Join("..", "...") + testshared.NewRunnerBuilder(t). WithArgs("--deadline=1ms"). - WithTargetPath(getProjectRoot()). + WithTargetPath(projectRoot). Runner(). Install(). Run(). @@ -70,9 +72,11 @@ func TestDeadline(t *testing.T) { } func TestTimeout(t *testing.T) { + projectRoot := filepath.Join("..", "...") + testshared.NewRunnerBuilder(t). WithArgs("--timeout=1ms"). - WithTargetPath(getProjectRoot()). + WithTargetPath(projectRoot). Runner(). Install(). Run(). @@ -114,8 +118,8 @@ func TestTimeoutInConfig(t *testing.T) { // Run with disallowed option set only in config testshared.NewRunnerBuilder(t). WithConfig(c.cfg). - WithArgs(getCommonRunArgs()...). - WithTargetPath(minimalPkg). + WithArgs("--skip-dirs", skipDirsCommand). + WithTargetPath(testdataDir, minimalPkg). Runner(). Run(). ExpectExitCode(exitcodes.Timeout). @@ -125,7 +129,7 @@ func TestTimeoutInConfig(t *testing.T) { func TestTestsAreLintedByDefault(t *testing.T) { testshared.NewRunnerBuilder(t). - WithTargetPath(getTestDataDir("withtests")). + WithTargetPath(testdataDir, "withtests"). Runner(). Install(). Run(). @@ -141,7 +145,7 @@ func TestCgoOk(t *testing.T) { "-D", "nosnakecase,gci", ). - WithTargetPath(getTestDataDir("cgo")). + WithTargetPath(testdataDir, "cgo"). Runner(). Install(). Run(). @@ -152,34 +156,34 @@ func TestCgoWithIssues(t *testing.T) { testshared.InstallGolangciLint(t) testCases := []struct { - desc string - args []string - targetPath string - expected string + desc string + args []string + dir string + expected string }{ { - desc: "govet", - args: []string{"--no-config", "--disable-all", "-Egovet"}, - targetPath: getTestDataDir("cgo_with_issues"), - expected: "Printf format %t has arg cs of wrong type", + desc: "govet", + args: []string{"--no-config", "--disable-all", "-Egovet"}, + dir: "cgo_with_issues", + expected: "Printf format %t has arg cs of wrong type", }, { - desc: "staticcheck", - args: []string{"--no-config", "--disable-all", "-Estaticcheck"}, - targetPath: getTestDataDir("cgo_with_issues"), - expected: "SA5009: Printf format %t has arg #1 of wrong type", + desc: "staticcheck", + args: []string{"--no-config", "--disable-all", "-Estaticcheck"}, + dir: "cgo_with_issues", + expected: "SA5009: Printf format %t has arg #1 of wrong type", }, { - desc: "gofmt", - args: []string{"--no-config", "--disable-all", "-Egofmt"}, - targetPath: getTestDataDir("cgo_with_issues"), - expected: "File is not `gofmt`-ed with `-s` (gofmt)", + desc: "gofmt", + args: []string{"--no-config", "--disable-all", "-Egofmt"}, + dir: "cgo_with_issues", + expected: "File is not `gofmt`-ed with `-s` (gofmt)", }, { - desc: "revive", - args: []string{"--no-config", "--disable-all", "-Erevive"}, - targetPath: getTestDataDir("cgo_with_issues"), - expected: "indent-error-flow: if block ends with a return statement", + desc: "revive", + args: []string{"--no-config", "--disable-all", "-Erevive"}, + dir: "cgo_with_issues", + expected: "indent-error-flow: if block ends with a return statement", }, } @@ -190,7 +194,7 @@ func TestCgoWithIssues(t *testing.T) { testshared.NewRunnerBuilder(t). WithArgs(test.args...). - WithTargetPath(test.targetPath). + WithTargetPath(testdataDir, test.dir). Runner(). Run(). ExpectHasIssue(test.expected) @@ -202,7 +206,7 @@ func TestUnsafeOk(t *testing.T) { testshared.NewRunnerBuilder(t). WithNoConfig(). WithArgs("--enable-all"). - WithTargetPath(getTestDataDir("unsafe")). + WithTargetPath(testdataDir, "unsafe"). Runner(). Install(). Run(). @@ -211,7 +215,7 @@ func TestUnsafeOk(t *testing.T) { func TestGovetCustomFormatter(t *testing.T) { testshared.NewRunnerBuilder(t). - WithTargetPath(getTestDataDir("govet_custom_formatter")). + WithTargetPath(testdataDir, "govet_custom_formatter"). Runner(). Install(). Run(). @@ -232,7 +236,7 @@ func TestLineDirectiveProcessedFilesLiteLoading(t *testing.T) { "--exclude-use-default=false", "-Egolint", ). - WithTargetPath(getTestDataDir("quicktemplate")). + WithTargetPath(testdataDir, "quicktemplate"). Runner(). Install(). Run(). @@ -262,8 +266,6 @@ func TestSortedResults(t *testing.T) { }, } - dir := getTestDataDir("sort_results") - testshared.InstallGolangciLint(t) for _, test := range testCases { @@ -274,7 +276,7 @@ func TestSortedResults(t *testing.T) { testshared.NewRunnerBuilder(t). WithNoConfig(). WithArgs("--print-issued-lines=false", test.opt). - WithTargetPath(dir). + WithTargetPath(testdataDir, "sort_results"). Runner(). Run(). ExpectExitCode(exitcodes.IssuesFound).ExpectOutputEq(test.want + "\n") @@ -296,7 +298,7 @@ func TestLineDirectiveProcessedFilesFullLoading(t *testing.T) { "--exclude-use-default=false", "-Egolint,govet", ). - WithTargetPath(getTestDataDir("quicktemplate")). + WithTargetPath(testdataDir, "quicktemplate"). Runner(). Install(). Run(). @@ -320,7 +322,7 @@ func TestLintFilesWithLineDirective(t *testing.T) { "--disable-all", }, configPath: "testdata/linedirective/dupl.yml", - targetPath: getTestDataDir("linedirective"), + targetPath: "linedirective", expected: "21-23 lines are duplicate of `testdata/linedirective/hello.go:25-27` (dupl)", }, { @@ -329,7 +331,7 @@ func TestLintFilesWithLineDirective(t *testing.T) { "-Egofmt", "--disable-all", }, - targetPath: getTestDataDir("linedirective"), + targetPath: "linedirective", expected: "File is not `gofmt`-ed with `-s` (gofmt)", }, { @@ -338,7 +340,7 @@ func TestLintFilesWithLineDirective(t *testing.T) { "-Egoimports", "--disable-all", }, - targetPath: getTestDataDir("linedirective"), + targetPath: "linedirective", expected: "File is not `goimports`-ed (goimports)", }, { @@ -348,7 +350,7 @@ func TestLintFilesWithLineDirective(t *testing.T) { "--disable-all", }, configPath: "testdata/linedirective/gomodguard.yml", - targetPath: getTestDataDir("linedirective"), + targetPath: "linedirective", expected: "import of package `github.com/ryancurrah/gomodguard` is blocked because the module is not " + "in the allowed modules list. (gomodguard)", }, @@ -359,7 +361,7 @@ func TestLintFilesWithLineDirective(t *testing.T) { "--disable-all", }, configPath: "testdata/linedirective/lll.yml", - targetPath: getTestDataDir("linedirective"), + targetPath: "linedirective", expected: "line is 57 characters (lll)", }, { @@ -369,7 +371,7 @@ func TestLintFilesWithLineDirective(t *testing.T) { "--disable-all", }, configPath: "", - targetPath: getTestDataDir("linedirective"), + targetPath: "linedirective", expected: "is a misspelling of `language` (misspell)", }, { @@ -379,7 +381,7 @@ func TestLintFilesWithLineDirective(t *testing.T) { "--disable-all", }, configPath: "", - targetPath: getTestDataDir("linedirective"), + targetPath: "linedirective", expected: "block should not start with a whitespace (wsl)", }, } @@ -391,7 +393,7 @@ func TestLintFilesWithLineDirective(t *testing.T) { testshared.NewRunnerBuilder(t). WithArgs(test.args...). - WithTargetPath(test.targetPath). + WithTargetPath(testdataDir, test.targetPath). WithConfigFile(test.configPath). Runner(). Run(). @@ -401,7 +403,7 @@ func TestLintFilesWithLineDirective(t *testing.T) { } func TestSkippedDirsNoMatchArg(t *testing.T) { - dir := getTestDataDir("skipdirs", "skip_me", "nested") + dir := filepath.Join(testdataDir, "skipdirs", "skip_me", "nested") testshared.NewRunnerBuilder(t). WithNoConfig(). @@ -426,7 +428,7 @@ func TestSkippedDirsTestdata(t *testing.T) { "--print-issued-lines=false", "-Egolint", ). - WithTargetPath(getTestDataDir("skipdirs", "...")). + WithTargetPath(testdataDir, "skipdirs", "..."). Runner(). Install(). Run(). @@ -437,7 +439,7 @@ func TestDeadcodeNoFalsePositivesInMainPkg(t *testing.T) { testshared.NewRunnerBuilder(t). WithNoConfig(). WithArgs("--disable-all", "-Edeadcode"). - WithTargetPath(getTestDataDir("deadcode_main_pkg")). + WithTargetPath(testdataDir, "deadcode_main_pkg"). Runner(). Install(). Run(). @@ -448,7 +450,7 @@ func TestIdentifierUsedOnlyInTests(t *testing.T) { testshared.NewRunnerBuilder(t). WithNoConfig(). WithArgs("--disable-all", "-Eunused"). - WithTargetPath(getTestDataDir("used_only_in_tests")). + WithTargetPath(testdataDir, "used_only_in_tests"). Runner(). Install(). Run(). @@ -474,11 +476,11 @@ func TestConfigFileIsDetected(t *testing.T) { }{ { desc: "explicit", - targetPath: getTestDataDir("withconfig", "pkg"), + targetPath: filepath.Join(testdataDir, "withconfig", "pkg"), }, { desc: "recursive", - targetPath: getTestDataDir("withconfig", "..."), + targetPath: filepath.Join(testdataDir, "withconfig", "..."), }, } @@ -526,9 +528,9 @@ func TestEnableAllFastAndEnableCanCoexist(t *testing.T) { testshared.NewRunnerBuilder(t). WithNoConfig(). - WithArgs(getCommonRunArgs()...). + WithArgs("--skip-dirs", skipDirsCommand). WithArgs(test.args...). - WithTargetPath(minimalPkg). + WithTargetPath(testdataDir, minimalPkg). Runner(). Run(). ExpectExitCode(test.expected...) @@ -540,7 +542,7 @@ func TestEnabledPresetsAreNotDuplicated(t *testing.T) { testshared.NewRunnerBuilder(t). WithNoConfig(). WithArgs("-v", "-p", "style,bugs"). - WithTargetPath(minimalPkg). + WithTargetPath(testdataDir, minimalPkg). Runner(). Install(). Run(). @@ -633,8 +635,8 @@ func TestDisallowedOptionsInConfig(t *testing.T) { // Run with disallowed option set only in config testshared.NewRunnerBuilder(t). WithConfig(c.cfg). - WithArgs(getCommonRunArgs()...). - WithTargetPath(minimalPkg). + WithArgs("--skip-dirs", skipDirsCommand). + WithTargetPath(testdataDir, minimalPkg). Runner(). Run(). ExpectExitCode(exitcodes.Failure) @@ -648,9 +650,9 @@ func TestDisallowedOptionsInConfig(t *testing.T) { // Run with disallowed option set only in command-line testshared.NewRunnerBuilder(t). WithNoConfig(). - WithArgs(getCommonRunArgs()...). + WithArgs("--skip-dirs", skipDirsCommand). WithArgs(args...). - WithTargetPath(minimalPkg). + WithTargetPath(testdataDir, minimalPkg). Runner(). Run(). ExpectExitCode(exitcodes.Success) @@ -659,9 +661,9 @@ func TestDisallowedOptionsInConfig(t *testing.T) { testshared.NewRunnerBuilder(t). WithConfig(c.cfg). - WithArgs(getCommonRunArgs()...). + WithArgs("--skip-dirs", skipDirsCommand). WithArgs(args...). - WithTargetPath(minimalPkg). + WithTargetPath(testdataDir, minimalPkg). Runner(). Run(). ExpectExitCode(exitcodes.Failure) @@ -692,7 +694,7 @@ func TestPathPrefix(t *testing.T) { t.Run(test.desc, func(t *testing.T) { testshared.NewRunnerBuilder(t). WithArgs(test.args...). - WithTargetPath(getTestDataDir("withtests")). + WithTargetPath(testdataDir, "withtests"). Runner(). Run(). ExpectOutputRegexp(test.pattern) diff --git a/test/testdata/asasalint.go b/test/testdata/asasalint.go index 7dcc6839..ae37bc12 100644 --- a/test/testdata/asasalint.go +++ b/test/testdata/asasalint.go @@ -10,11 +10,11 @@ func getArgsLength(args ...interface{}) int { } func checkArgsLength(args ...interface{}) int { - return getArgsLength(args) // ERROR `pass \[\]any as any to func getArgsLength func\(args \.\.\.interface\{\}\)` + return getArgsLength(args) // want `pass \[\]any as any to func getArgsLength func\(args \.\.\.interface\{\}\)` } func someCall() { var a = []interface{}{1, 2, 3} - fmt.Println(checkArgsLength(a...) == getArgsLength(a)) // ERROR `pass \[\]any as any to func getArgsLength func\(args \.\.\.interface\{\}\)` + fmt.Println(checkArgsLength(a...) == getArgsLength(a)) // want `pass \[\]any as any to func getArgsLength func\(args \.\.\.interface\{\}\)` fmt.Println(checkArgsLength(a...) == getArgsLength(a...)) } diff --git a/test/testdata/asciicheck.go b/test/testdata/asciicheck.go index 772cc9d6..5da99c30 100644 --- a/test/testdata/asciicheck.go +++ b/test/testdata/asciicheck.go @@ -6,18 +6,18 @@ import ( "time" ) -type AsciicheckTеstStruct struct { // ERROR `identifier "AsciicheckTеstStruct" contain non-ASCII character: U\+0435 'е'` +type AsciicheckTеstStruct struct { // want `identifier "AsciicheckTеstStruct" contain non-ASCII character: U\+0435 'е'` Date time.Time } type AsciicheckField struct{} type AsciicheckJustStruct struct { - Tеst AsciicheckField // ERROR `identifier "Tеst" contain non-ASCII character: U\+0435 'е'` + Tеst AsciicheckField // want `identifier "Tеst" contain non-ASCII character: U\+0435 'е'` } -func AsciicheckTеstFunc() { // ERROR `identifier "AsciicheckTеstFunc" contain non-ASCII character: U\+0435 'е'` - var tеstVar int // ERROR `identifier "tеstVar" contain non-ASCII character: U\+0435 'е'` +func AsciicheckTеstFunc() { // want `identifier "AsciicheckTеstFunc" contain non-ASCII character: U\+0435 'е'` + var tеstVar int // want `identifier "tеstVar" contain non-ASCII character: U\+0435 'е'` tеstVar = 0 fmt.Println(tеstVar) } diff --git a/test/testdata/bidichk.go b/test/testdata/bidichk.go index 05e971a0..fbed2c69 100644 --- a/test/testdata/bidichk.go +++ b/test/testdata/bidichk.go @@ -4,5 +4,5 @@ package testdata import "fmt" func main() { - fmt.Println("LEFT-TO-RIGHT-OVERRIDE: '‭', it is between the single quotes, but it is not visible with a regular editor") // ERROR "found dangerous unicode character sequence LEFT-TO-RIGHT-OVERRIDE" + fmt.Println("LEFT-TO-RIGHT-OVERRIDE: '‭', it is between the single quotes, but it is not visible with a regular editor") // want "found dangerous unicode character sequence LEFT-TO-RIGHT-OVERRIDE" } diff --git a/test/testdata/bodyclose.go b/test/testdata/bodyclose.go index ca12d777..e48a045b 100644 --- a/test/testdata/bodyclose.go +++ b/test/testdata/bodyclose.go @@ -7,6 +7,6 @@ import ( ) func BodycloseNotClosed() { - resp, _ := http.Get("https://google.com") // ERROR "response body must be closed" + resp, _ := http.Get("https://google.com") // want "response body must be closed" _, _ = ioutil.ReadAll(resp.Body) } diff --git a/test/testdata/configs/goimports.yml b/test/testdata/configs/goimports_local.yml similarity index 100% rename from test/testdata/configs/goimports.yml rename to test/testdata/configs/goimports_local.yml diff --git a/test/testdata/containedctx.go b/test/testdata/containedctx.go index c68aed5f..c785f5c2 100644 --- a/test/testdata/containedctx.go +++ b/test/testdata/containedctx.go @@ -9,7 +9,7 @@ type ok struct { } type ng struct { - ctx context.Context // ERROR "found a struct that contains a context.Context field" + ctx context.Context // want "found a struct that contains a context.Context field" } type empty struct{} diff --git a/test/testdata/contextcheck.go b/test/testdata/contextcheck.go index c153b771..84635c33 100644 --- a/test/testdata/contextcheck.go +++ b/test/testdata/contextcheck.go @@ -6,7 +6,7 @@ import "context" type MyString string func contextcheckCase1(ctx context.Context) { - funcWithoutCtx() // ERROR "Function `funcWithoutCtx` should pass the context parameter" + funcWithoutCtx() // want "Function `funcWithoutCtx` should pass the context parameter" } func contextcheckCase2(ctx context.Context) { @@ -21,7 +21,7 @@ func contextcheckCase2(ctx context.Context) { funcWithCtx(ctx) }(ctx) - funcWithCtx(context.Background()) // ERROR "Non-inherited new context, use function like `context.WithXXX` instead" + funcWithCtx(context.Background()) // want "Non-inherited new context, use function like `context.WithXXX` instead" } func contextcheckCase3(ctx context.Context) { @@ -29,7 +29,7 @@ func contextcheckCase3(ctx context.Context) { funcWithCtx(ctx) }() - ctx = context.Background() // ERROR "Non-inherited new context, use function like `context.WithXXX` instead" + ctx = context.Background() // want "Non-inherited new context, use function like `context.WithXXX` instead" funcWithCtx(ctx) } diff --git a/test/testdata/cyclop.go b/test/testdata/cyclop.go index de93a9da..e954d3fc 100644 --- a/test/testdata/cyclop.go +++ b/test/testdata/cyclop.go @@ -2,7 +2,7 @@ //golangcitest:config_path testdata/configs/cyclop.yml package testdata -func cyclopComplexFunc(s string) { // ERROR "calculated cyclomatic complexity for function cyclopComplexFunc is 22, max is 15" +func cyclopComplexFunc(s string) { // want "calculated cyclomatic complexity for function cyclopComplexFunc is 22, max is 15" if s == "1" || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" { return } diff --git a/test/testdata/deadcode.go b/test/testdata/deadcode.go index 1d2cdd9d..e2c55580 100644 --- a/test/testdata/deadcode.go +++ b/test/testdata/deadcode.go @@ -3,12 +3,12 @@ package testdata var y int -var unused int // ERROR "`unused` is unused" +var unused int // want "`unused` is unused" func f(x int) { } -func g(x int) { // ERROR "`g` is unused" +func g(x int) { // want "`g` is unused" } func H(x int) { diff --git a/test/testdata/decorder.go b/test/testdata/decorder.go index 4f409db4..5936289d 100644 --- a/test/testdata/decorder.go +++ b/test/testdata/decorder.go @@ -10,12 +10,12 @@ const ( ) var decoa = 1 -var decob = 1 // ERROR "multiple \"var\" declarations are not allowed; use parentheses instead" +var decob = 1 // want "multiple \"var\" declarations are not allowed; use parentheses instead" -type decoe int // ERROR "type must not be placed after const" +type decoe int // want "type must not be placed after const" func decof() { const decog = 1 } -func init() {} // ERROR "init func must be the first function in file" +func init() {} // want "init func must be the first function in file" diff --git a/test/testdata/decorder_default.go b/test/testdata/decorder_default.go index a568cf4c..04736ec3 100644 --- a/test/testdata/decorder_default.go +++ b/test/testdata/decorder_default.go @@ -1,4 +1,5 @@ //golangcitest:args -Edecorder +//golangcitest:expected_exitcode 0 package testdata import "math" diff --git a/test/testdata/default_exclude.go b/test/testdata/default_exclude.go index be4547f5..7c9d0060 100644 --- a/test/testdata/default_exclude.go +++ b/test/testdata/default_exclude.go @@ -4,13 +4,13 @@ /*Package testdata ...*/ package testdata -// InvalidFuncComment, both golint and stylecheck will complain about this, // ERROR stylecheck `ST1020: comment on exported function ExportedFunc1 should be of the form "ExportedFunc1 ..."` +// InvalidFuncComment, both golint and stylecheck will complain about this, // want stylecheck:`ST1020: comment on exported function ExportedFunc1 should be of the form "ExportedFunc1 ..."` // 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 stylecheck `ST1020: comment on exported function ExportedFunc2 should be of the form "ExportedFunc2 ..."` +// InvalidFuncComment // want stylecheck:`ST1020: comment on exported function ExportedFunc2 should be of the form "ExportedFunc2 ..."` // //nolint:golint func ExportedFunc2() { diff --git a/test/testdata/depguard.go b/test/testdata/depguard.go index b5c2ec26..b1b1946b 100644 --- a/test/testdata/depguard.go +++ b/test/testdata/depguard.go @@ -3,8 +3,8 @@ package testdata import ( - "compress/gzip" // ERROR "`compress/gzip` is in the denylist" - "log" // ERROR "`log` is in the denylist: don't use log" + "compress/gzip" // want "`compress/gzip` is in the denylist" + "log" // want "`log` is in the denylist: don't use log" ) func SpewDebugInfo() { diff --git a/test/testdata/depguard_additional_guards.go b/test/testdata/depguard_additional_guards.go index 337b1bf2..46f2f43e 100644 --- a/test/testdata/depguard_additional_guards.go +++ b/test/testdata/depguard_additional_guards.go @@ -3,10 +3,10 @@ package testdata import ( - "compress/gzip" // ERROR "`compress/gzip` is in the denylist" - "fmt" // ERROR "`fmt` is in the denylist" - "log" // ERROR "`log` is in the denylist: don't use log" - "strings" // ERROR "`strings` is in the denylist: disallowed in additional guard" + "compress/gzip" // want "`compress/gzip` is in the denylist" + "fmt" // want "`fmt` is in the denylist" + "log" // want "`log` is in the denylist: don't use log" + "strings" // want "`strings` is in the denylist: disallowed in additional guard" ) func SpewDebugInfo() { diff --git a/test/testdata/depguard_ignore_file_rules.go b/test/testdata/depguard_ignore_file_rules.go index cb3cdc43..c1073767 100644 --- a/test/testdata/depguard_ignore_file_rules.go +++ b/test/testdata/depguard_ignore_file_rules.go @@ -1,5 +1,6 @@ //golangcitest:args -Edepguard //golangcitest:config_path testdata/configs/depguard_ignore_file_rules.yml +//golangcitest:expected_exitcode 0 package testdata // NOTE - No lint errors becuase this file is ignored diff --git a/test/testdata/dogsled.go b/test/testdata/dogsled.go index 1d1ade71..125210b1 100644 --- a/test/testdata/dogsled.go +++ b/test/testdata/dogsled.go @@ -4,8 +4,8 @@ package testdata func Dogsled() { _ = ret1() _, _ = ret2() - _, _, _ = ret3() // ERROR "declaration has 3 blank identifiers" - _, _, _, _ = ret4() // ERROR "declaration has 4 blank identifiers" + _, _, _ = ret3() // want "declaration has 3 blank identifiers" + _, _, _, _ = ret4() // want "declaration has 4 blank identifiers" } func ret1() (a int) { diff --git a/test/testdata/dupl.go b/test/testdata/dupl.go index 863c334c..31a9cdd6 100644 --- a/test/testdata/dupl.go +++ b/test/testdata/dupl.go @@ -11,7 +11,7 @@ func (DuplLogger) level() int { func (DuplLogger) Debug(args ...interface{}) {} func (DuplLogger) Info(args ...interface{}) {} -func (logger *DuplLogger) First(args ...interface{}) { // ERROR "14-23 lines are duplicate of `.*dupl.go:25-34`" +func (logger *DuplLogger) First(args ...interface{}) { // want "14-23 lines are duplicate of `.*dupl.go:25-34`" if logger.level() >= 0 { logger.Debug(args...) logger.Debug(args...) @@ -22,7 +22,7 @@ func (logger *DuplLogger) First(args ...interface{}) { // ERROR "14-23 lines are } } -func (logger *DuplLogger) Second(args ...interface{}) { // ERROR "25-34 lines are duplicate of `.*dupl.go:14-23`" +func (logger *DuplLogger) Second(args ...interface{}) { // want "25-34 lines are duplicate of `.*dupl.go:14-23`" if logger.level() >= 1 { logger.Info(args...) logger.Info(args...) diff --git a/test/testdata/durationcheck.go b/test/testdata/durationcheck.go index b7cd6816..ac526467 100644 --- a/test/testdata/durationcheck.go +++ b/test/testdata/durationcheck.go @@ -18,7 +18,7 @@ func durationcheckCase01() { func durationcheckCase02() { dcd := durationCheckData{d: 10 * time.Second} - _ = dcd.d * time.Second // ERROR "Multiplication of durations: `dcd.d \\* time.Second`" + _ = dcd.d * time.Second // want "Multiplication of durations: `dcd.d \\* time.Second`" } func durationcheckCase03() { @@ -27,12 +27,12 @@ func durationcheckCase03() { } func durationcheckCase04(someDuration time.Duration) { - timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second`" + timeToWait := someDuration * time.Second // want "Multiplication of durations: `someDuration \\* time.Second`" time.Sleep(timeToWait) } func durationcheckCase05() { someDuration := 2 * time.Second - timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second`" + timeToWait := someDuration * time.Second // want "Multiplication of durations: `someDuration \\* time.Second`" time.Sleep(timeToWait) } diff --git a/test/testdata/errcheck.go b/test/testdata/errcheck.go index a894ea3e..3227cac2 100644 --- a/test/testdata/errcheck.go +++ b/test/testdata/errcheck.go @@ -12,7 +12,7 @@ func RetErr() error { } func MissedErrorCheck() { - RetErr() // ERROR "Error return value is not checked" + RetErr() // want "Error return value is not checked" } func IgnoreCloseMissingErrHandling() error { diff --git a/test/testdata/errcheck_exclude.go b/test/testdata/errcheck_exclude.go index b6ddd987..9b9907c2 100644 --- a/test/testdata/errcheck_exclude.go +++ b/test/testdata/errcheck_exclude.go @@ -12,6 +12,6 @@ func TestErrcheckExclude() []byte { } func TestErrcheckNoExclude() []byte { - ret, _ := ioutil.ReadAll(nil) // ERROR "Error return value of `ioutil.ReadAll` is not checked" + ret, _ := ioutil.ReadAll(nil) // want "Error return value of `ioutil.ReadAll` is not checked" return ret } diff --git a/test/testdata/errcheck_exclude_functions.go b/test/testdata/errcheck_exclude_functions.go index ff17ab9a..f8010f5f 100644 --- a/test/testdata/errcheck_exclude_functions.go +++ b/test/testdata/errcheck_exclude_functions.go @@ -13,6 +13,6 @@ func TestErrcheckExcludeFunctions() []byte { } func TestErrcheckNoExcludeFunctions() []byte { - ret, _ := ioutil.ReadAll(nil) // ERROR "Error return value of `ioutil.ReadAll` is not checked" + ret, _ := ioutil.ReadAll(nil) // want "Error return value of `ioutil.ReadAll` is not checked" return ret } diff --git a/test/testdata/errcheck_ignore.go b/test/testdata/errcheck_ignore.go index 508101e8..667a5138 100644 --- a/test/testdata/errcheck_ignore.go +++ b/test/testdata/errcheck_ignore.go @@ -23,6 +23,6 @@ func TestErrcheckIgnoreIoutil() []byte { } func TestErrcheckNoIgnoreIoutil() []byte { - ret, _ := ioutil.ReadAll(nil) // ERROR "Error return value of `ioutil.ReadAll` is not checked" + ret, _ := ioutil.ReadAll(nil) // want "Error return value of `ioutil.ReadAll` is not checked" return ret } diff --git a/test/testdata/errcheck_ignore_default.go b/test/testdata/errcheck_ignore_default.go index e7a1466e..6052433c 100644 --- a/test/testdata/errcheck_ignore_default.go +++ b/test/testdata/errcheck_ignore_default.go @@ -20,5 +20,5 @@ func TestErrcheckIgnoreFmtByDefault(s string) int { } func TestErrcheckNoIgnoreOs() { - _, _ = os.Open("f.txt") // ERROR "Error return value of `os.Open` is not checked" + _, _ = os.Open("f.txt") // want "Error return value of `os.Open` is not checked" } diff --git a/test/testdata/errcheck_type_assertions.go b/test/testdata/errcheck_type_assertions.go index 94a192ef..e3c19441 100644 --- a/test/testdata/errcheck_type_assertions.go +++ b/test/testdata/errcheck_type_assertions.go @@ -1,5 +1,6 @@ //golangcitest:args -Eerrcheck //golangcitest:config_path testdata/configs/errcheck_type_assertions.yml +//golangcitest:expected_exitcode 0 package testdata func ErrorTypeAssertion(filter map[string]interface{}) bool { diff --git a/test/testdata/errchkjson.go b/test/testdata/errchkjson.go index b74411a7..f641597b 100644 --- a/test/testdata/errchkjson.go +++ b/test/testdata/errchkjson.go @@ -23,114 +23,114 @@ var _ encoding.TextMarshaler = marshalText(struct{}{}) func JSONMarshalSafeTypesWithNoSafe() { var err error - _, _ = json.Marshal(nil) // ERROR "Error return value of `encoding/json.Marshal` is not checked" - json.Marshal(nil) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(nil) // want "Error return value of `encoding/json.Marshal` is not checked" + json.Marshal(nil) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(nil) // nil is safe and check-error-free-encoding is false _ = err - _, _ = json.MarshalIndent(nil, "", " ") // ERROR "Error return value of `encoding/json.MarshalIndent` is not checked" - json.MarshalIndent(nil, "", " ") // ERROR "Error return value of `encoding/json.MarshalIndent` is not checked" + _, _ = json.MarshalIndent(nil, "", " ") // want "Error return value of `encoding/json.MarshalIndent` is not checked" + json.MarshalIndent(nil, "", " ") // want "Error return value of `encoding/json.MarshalIndent` is not checked" _, err = json.MarshalIndent(nil, "", " ") // nil is safe and check-error-free-encoding is false _ = err enc := json.NewEncoder(ioutil.Discard) - _ = enc.Encode(nil) // ERROR "Error return value of `\\([*]encoding/json.Encoder\\).Encode` is not checked" - enc.Encode(nil) // ERROR "Error return value of `\\([*]encoding/json.Encoder\\).Encode` is not checked" + _ = enc.Encode(nil) // want "Error return value of `\\([*]encoding/json.Encoder\\).Encode` is not checked" + enc.Encode(nil) // want "Error return value of `\\([*]encoding/json.Encoder\\).Encode` is not checked" err = enc.Encode(nil) // nil is safe and check-error-free-encoding is false _ = err var b bool - _, _ = json.Marshal(b) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(b) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(b) // bool is safe and check-error-free-encoding is false _ = err var i int - _, _ = json.Marshal(i) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(i) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(i) // int is safe and check-error-free-encoding is false _ = err var i8 int8 - _, _ = json.Marshal(i8) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(i8) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(i8) // int8 is safe and check-error-free-encoding is false _ = err var i16 int16 - _, _ = json.Marshal(i16) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(i16) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(i16) // int16 is safe and check-error-free-encoding is false _ = err var i32 int32 - _, _ = json.Marshal(i32) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(i32) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(i32) // int32 / rune is safe and check-error-free-encoding is false _ = err var i64 int64 - _, _ = json.Marshal(i64) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(i64) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(i64) // int64 is safe and check-error-free-encoding is false _ = err var ui uint - _, _ = json.Marshal(ui) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(ui) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(ui) // uint is safe and check-error-free-encoding is false _ = err var ui8 uint8 - _, _ = json.Marshal(ui8) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(ui8) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(ui8) // uint8 is safe and check-error-free-encoding is false _ = err var ui16 uint16 - _, _ = json.Marshal(ui16) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(ui16) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(ui16) // uint16 is safe and check-error-free-encoding is false _ = err var ui32 uint32 - _, _ = json.Marshal(ui32) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(ui32) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(ui32) // uint32 is safe and check-error-free-encoding is false _ = err var ui64 uint64 - _, _ = json.Marshal(ui64) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(ui64) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(ui64) // uint64 is safe and check-error-free-encoding is false _ = err var uiptr uintptr - _, _ = json.Marshal(uiptr) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(uiptr) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(uiptr) // uintptr is safe and check-error-free-encoding is false _ = err var str string - _, _ = json.Marshal(str) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(str) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(str) // string is safe and check-error-free-encoding is false _ = err var strSlice []string - _, _ = json.Marshal(strSlice) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(strSlice) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(strSlice) // []string is safe and check-error-free-encoding is false _ = err var intSlice []int - _, _ = json.Marshal(intSlice) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(intSlice) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(intSlice) // []int is safe and check-error-free-encoding is false _ = err var boolSlice []bool - _, _ = json.Marshal(boolSlice) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(boolSlice) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(boolSlice) // []bool is safe and check-error-free-encoding is false _ = err var strArray [10]string - _, _ = json.Marshal(strArray) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(strArray) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(strArray) // [10]string is safe and check-error-free-encoding is false _ = err var intArray [10]int - _, _ = json.Marshal(intArray) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(intArray) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(intArray) // [10]int is safe and check-error-free-encoding is false _ = err var boolArray [10]bool - _, _ = json.Marshal(boolArray) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(boolArray) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(boolArray) // [10]bool is safe and check-error-free-encoding is false _ = err @@ -149,7 +149,7 @@ func JSONMarshalSafeTypesWithNoSafe() { Uintptr uintptr String string } - _, _ = json.Marshal(basicStruct) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(basicStruct) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(basicStruct) // struct containing only safe basic types is safe and check-error-free-encoding is false _ = err @@ -168,37 +168,37 @@ func JSONMarshalSafeTypesWithNoSafe() { Uintptr *uintptr String *string } - _, _ = json.Marshal(ptrStruct) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(ptrStruct) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(ptrStruct) // struct containing pointer to only safe basic types is safe and check-error-free-encoding is false _ = err var mapStrStr map[string]string - _, _ = json.Marshal(mapStrStr) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(mapStrStr) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(mapStrStr) // map[string]string is safe and check-error-free-encoding is false _ = err var mapStrInt map[string]int - _, _ = json.Marshal(mapStrInt) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(mapStrInt) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(mapStrInt) // map[string]int is safe and check-error-free-encoding is false _ = err var mapStrBool map[string]bool - _, _ = json.Marshal(mapStrBool) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(mapStrBool) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(mapStrBool) // map[string]bool is safe and check-error-free-encoding is false _ = err var mapIntStr map[int]string - _, _ = json.Marshal(mapIntStr) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(mapIntStr) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(mapIntStr) // map[int]string is safe and check-error-free-encoding is false _ = err var mapIntInt map[int]int - _, _ = json.Marshal(mapIntInt) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(mapIntInt) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(mapIntInt) // map[int]int is safe and check-error-free-encoding is false _ = err var mapIntBool map[int]bool - _, _ = json.Marshal(mapIntBool) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(mapIntBool) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(mapIntBool) // map[int]bool is safe and check-error-free-encoding is false _ = err @@ -246,7 +246,7 @@ func JSONMarshalSafeTypesWithNoSafe() { InnerStruct innerStruct } - _, _ = json.Marshal(outerStruct) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(outerStruct) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(outerStruct) // struct with only safe types is safe and check-error-free-encoding is false _ = err } @@ -342,7 +342,7 @@ func JSONMarshalSaveStructWithUnexportedFieldsWithNoSafe() { _ = unexportedInStruct.ch _ = unexportedInStruct.unsafePtr _ = unexportedInStruct.mapStructStr[structKey{1}] - _, _ = json.Marshal(unexportedInStruct) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(unexportedInStruct) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(unexportedInStruct) // struct containing unsafe but unexported fields is safe _ = err } @@ -382,7 +382,7 @@ func JSONMarshalSaveStructWithOmittedFieldsWithNoSafe() { MapStructStr map[structKey]string `json:"-"` // invalid exported but omitted } _ = omitInStruct.MapStructStr[structKey{1}] - _, _ = json.Marshal(omitInStruct) // ERROR "Error return value of `encoding/json.Marshal` is not checked" + _, _ = json.Marshal(omitInStruct) // want "Error return value of `encoding/json.Marshal` is not checked" _, err = json.Marshal(omitInStruct) // struct containing unsafe but omitted, exported fields is safe and check-error-free-encoding is false _ = err } @@ -393,119 +393,119 @@ func JSONMarshalUnsafeTypes() { var err error var f32 float32 - json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" - _, _ = json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + json.Marshal(f32) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + _, _ = json.Marshal(f32) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" _, err = json.Marshal(f32) // err is checked _ = err var f64 float64 - _, _ = json.Marshal(f64) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" + _, _ = json.Marshal(f64) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" _, err = json.Marshal(f64) // err is checked _ = err var f32Slice []float32 - _, _ = json.Marshal(f32Slice) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + _, _ = json.Marshal(f32Slice) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" _, err = json.Marshal(f32Slice) // err is checked _ = err var f64Slice []float64 - _, _ = json.Marshal(f64Slice) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" + _, _ = json.Marshal(f64Slice) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" _, err = json.Marshal(f64Slice) // err is checked _ = err var f32Array [10]float32 - _, _ = json.Marshal(f32Array) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + _, _ = json.Marshal(f32Array) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" _, err = json.Marshal(f32Array) // err is checked _ = err var f64Array [10]float64 - _, _ = json.Marshal(f64Array) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" + _, _ = json.Marshal(f64Array) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" _, err = json.Marshal(f64Array) // err is checked _ = err var structPtrF32 struct { F32 *float32 } - _, _ = json.Marshal(structPtrF32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + _, _ = json.Marshal(structPtrF32) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" _, err = json.Marshal(structPtrF32) // err is checked _ = err var structPtrF64 struct { F64 *float64 } - _, _ = json.Marshal(structPtrF64) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" + _, _ = json.Marshal(structPtrF64) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" _, err = json.Marshal(structPtrF64) // err is checked _ = err var mapStrF32 map[string]float32 - _, _ = json.Marshal(mapStrF32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + _, _ = json.Marshal(mapStrF32) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" _, err = json.Marshal(mapStrF32) // err is checked _ = err var mapStrF64 map[string]float64 - _, _ = json.Marshal(mapStrF64) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" + _, _ = json.Marshal(mapStrF64) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" _, err = json.Marshal(mapStrF64) // err is checked _ = err var mapEIStr map[interface{}]string - _, _ = json.Marshal(mapEIStr) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` as map key found" + _, _ = json.Marshal(mapEIStr) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` as map key found" _, err = json.Marshal(mapEIStr) // err is checked _ = err var mapStringerStr map[fmt.Stringer]string - _, _ = json.Marshal(mapStringerStr) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `fmt.Stringer` as map key found" + _, _ = json.Marshal(mapStringerStr) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `fmt.Stringer` as map key found" _, err = json.Marshal(mapStringerStr) // err is checked _ = err var number json.Number - _, _ = json.Marshal(number) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" + _, _ = json.Marshal(number) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" _, err = json.Marshal(number) // err is checked _ = err var numberSlice []json.Number - _, _ = json.Marshal(numberSlice) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" + _, _ = json.Marshal(numberSlice) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" _, err = json.Marshal(numberSlice) // err is checked _ = err var mapNumberStr map[json.Number]string - _, _ = json.Marshal(mapNumberStr) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` as map key found" + _, _ = json.Marshal(mapNumberStr) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` as map key found" _, err = json.Marshal(mapNumberStr) // err is checked _ = err var mapStrNumber map[string]json.Number - _, _ = json.Marshal(mapStrNumber) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" + _, _ = json.Marshal(mapStrNumber) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" _, err = json.Marshal(mapStrNumber) // err is checked _ = err var ei interface{} - _, _ = json.Marshal(ei) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found" + _, _ = json.Marshal(ei) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found" _, err = json.Marshal(ei) // err is checked _ = err var eiptr *interface{} - _, _ = json.Marshal(eiptr) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `*interface{}` found" + _, _ = json.Marshal(eiptr) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `*interface{}` found" _, err = json.Marshal(eiptr) // err is checked _ = err var stringer fmt.Stringer - _, _ = json.Marshal(stringer) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `fmt.Stringer` found" + _, _ = json.Marshal(stringer) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `fmt.Stringer` found" _, err = json.Marshal(stringer) // err is checked _ = err var structWithEmptyInterface struct { EmptyInterface interface{} } - _, _ = json.Marshal(structWithEmptyInterface) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found" + _, _ = json.Marshal(structWithEmptyInterface) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found" _, err = json.Marshal(structWithEmptyInterface) // err is checked _ = err var mt marshalText - _, _ = json.Marshal(mt) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `[a-z-]+.marshalText` found" + _, _ = json.Marshal(mt) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `[a-z-]+.marshalText` found" _, err = json.Marshal(mt) // err is checked _ = err var mapMarshalTextString map[marshalText]string - _, _ = json.Marshal(mapMarshalTextString) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `[a-z-]+.marshalText` as map key found" + _, _ = json.Marshal(mapMarshalTextString) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `[a-z-]+.marshalText` as map key found" _, err = json.Marshal(mapMarshalTextString) // err is checked _ = err } @@ -517,93 +517,93 @@ func JSONMarshalInvalidTypes() { var err error var c64 complex64 - json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" - _, _ = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" - _, err = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" + json.Marshal(c64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" + _, _ = json.Marshal(c64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" + _, err = json.Marshal(c64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" _ = err var c128 complex128 - _, _ = json.Marshal(c128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" - _, err = json.Marshal(c128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" + _, _ = json.Marshal(c128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" + _, err = json.Marshal(c128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" _ = err var sliceC64 []complex64 - _, _ = json.Marshal(sliceC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" - _, err = json.Marshal(sliceC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" + _, _ = json.Marshal(sliceC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" + _, err = json.Marshal(sliceC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" _ = err var sliceC128 []complex128 - _, _ = json.Marshal(sliceC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" - _, err = json.Marshal(sliceC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" + _, _ = json.Marshal(sliceC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" + _, err = json.Marshal(sliceC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" _ = err var arrayC64 []complex64 - _, _ = json.Marshal(arrayC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" - _, err = json.Marshal(arrayC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" + _, _ = json.Marshal(arrayC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" + _, err = json.Marshal(arrayC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" _ = err var arrayC128 []complex128 - _, _ = json.Marshal(arrayC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" - _, err = json.Marshal(arrayC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" + _, _ = json.Marshal(arrayC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" + _, err = json.Marshal(arrayC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" _ = err var structPtrC64 struct { C64 *complex64 } - _, _ = json.Marshal(structPtrC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" - _, err = json.Marshal(structPtrC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" + _, _ = json.Marshal(structPtrC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" + _, err = json.Marshal(structPtrC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" _ = err var structPtrC128 struct { C128 *complex128 } - _, _ = json.Marshal(structPtrC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" - _, err = json.Marshal(structPtrC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" + _, _ = json.Marshal(structPtrC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" + _, err = json.Marshal(structPtrC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" _ = err var mapBoolStr map[bool]string - _, _ = json.Marshal(mapBoolStr) // ERROR "`encoding/json.Marshal` for unsupported type `bool` as map key found" - _, err = json.Marshal(mapBoolStr) // ERROR "`encoding/json.Marshal` for unsupported type `bool` as map key found" + _, _ = json.Marshal(mapBoolStr) // want "`encoding/json.Marshal` for unsupported type `bool` as map key found" + _, err = json.Marshal(mapBoolStr) // want "`encoding/json.Marshal` for unsupported type `bool` as map key found" _ = err var mapF32Str map[float32]string - _, _ = json.Marshal(mapF32Str) // ERROR "`encoding/json.Marshal` for unsupported type `float32` as map key found" - _, err = json.Marshal(mapF32Str) // ERROR "`encoding/json.Marshal` for unsupported type `float32` as map key found" + _, _ = json.Marshal(mapF32Str) // want "`encoding/json.Marshal` for unsupported type `float32` as map key found" + _, err = json.Marshal(mapF32Str) // want "`encoding/json.Marshal` for unsupported type `float32` as map key found" _ = err var mapF64Str map[float64]string - _, _ = json.Marshal(mapF64Str) // ERROR "`encoding/json.Marshal` for unsupported type `float64` as map key found" - _, err = json.Marshal(mapF64Str) // ERROR "`encoding/json.Marshal` for unsupported type `float64` as map key found" + _, _ = json.Marshal(mapF64Str) // want "`encoding/json.Marshal` for unsupported type `float64` as map key found" + _, err = json.Marshal(mapF64Str) // want "`encoding/json.Marshal` for unsupported type `float64` as map key found" _ = err var mapC64Str map[complex64]string - _, _ = json.Marshal(mapC64Str) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` as map key found" - _, err = json.Marshal(mapC64Str) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` as map key found" + _, _ = json.Marshal(mapC64Str) // want "`encoding/json.Marshal` for unsupported type `complex64` as map key found" + _, err = json.Marshal(mapC64Str) // want "`encoding/json.Marshal` for unsupported type `complex64` as map key found" _ = err var mapC128Str map[complex128]string - _, _ = json.Marshal(mapC128Str) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` as map key found" - _, err = json.Marshal(mapC128Str) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` as map key found" + _, _ = json.Marshal(mapC128Str) // want "`encoding/json.Marshal` for unsupported type `complex128` as map key found" + _, err = json.Marshal(mapC128Str) // want "`encoding/json.Marshal` for unsupported type `complex128` as map key found" _ = err mapStructStr := map[structKey]string{structKey{1}: "str"} - _, _ = json.Marshal(mapStructStr) // ERROR "`encoding/json.Marshal` for unsupported type `[a-z-]+.structKey` as map key found" - _, err = json.Marshal(mapStructStr) // ERROR "`encoding/json.Marshal` for unsupported type `[a-z-]+.structKey` as map key found" + _, _ = json.Marshal(mapStructStr) // want "`encoding/json.Marshal` for unsupported type `[a-z-]+.structKey` as map key found" + _, err = json.Marshal(mapStructStr) // want "`encoding/json.Marshal` for unsupported type `[a-z-]+.structKey` as map key found" _ = err f := func() {} - _, _ = json.Marshal(f) // ERROR "`encoding/json.Marshal` for unsupported type `func\\(\\)` found" - _, err = json.Marshal(f) // ERROR "`encoding/json.Marshal` for unsupported type `func\\(\\)` found" + _, _ = json.Marshal(f) // want "`encoding/json.Marshal` for unsupported type `func\\(\\)` found" + _, err = json.Marshal(f) // want "`encoding/json.Marshal` for unsupported type `func\\(\\)` found" _ = err var ch chan struct{} = make(chan struct{}) - _, _ = json.Marshal(ch) // ERROR "`encoding/json.Marshal` for unsupported type `chan struct{}` found" - _, err = json.Marshal(ch) // ERROR "`encoding/json.Marshal` for unsupported type `chan struct{}` found" + _, _ = json.Marshal(ch) // want "`encoding/json.Marshal` for unsupported type `chan struct{}` found" + _, err = json.Marshal(ch) // want "`encoding/json.Marshal` for unsupported type `chan struct{}` found" _ = err var unsafePtr unsafe.Pointer - _, _ = json.Marshal(unsafePtr) // ERROR "`encoding/json.Marshal` for unsupported type `unsafe.Pointer` found" - _, err = json.Marshal(unsafePtr) // ERROR "`encoding/json.Marshal` for unsupported type `unsafe.Pointer` found" + _, _ = json.Marshal(unsafePtr) // want "`encoding/json.Marshal` for unsupported type `unsafe.Pointer` found" + _, err = json.Marshal(unsafePtr) // want "`encoding/json.Marshal` for unsupported type `unsafe.Pointer` found" _ = err } @@ -623,7 +623,7 @@ func JSONMarshalStructWithoutExportedFields() { privateField bool ExportedButOmittedField bool `json:"-"` } - _, err = json.Marshal(withoutExportedFields) // want "Error argument passed to `encoding/json.Marshal` does not contain any exported field" + _, err = json.Marshal(withoutExportedFields) _ = err } diff --git a/test/testdata/errchkjson_check_error_free_encoding.go b/test/testdata/errchkjson_check_error_free_encoding.go index fde6deee..c14521c7 100644 --- a/test/testdata/errchkjson_check_error_free_encoding.go +++ b/test/testdata/errchkjson_check_error_free_encoding.go @@ -25,113 +25,113 @@ func JSONMarshalSafeTypes() { _, _ = json.Marshal(nil) // nil is safe json.Marshal(nil) // nil is safe - _, err = json.Marshal(nil) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(nil) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err _, _ = json.MarshalIndent(nil, "", " ") // nil is safe json.MarshalIndent(nil, "", " ") // nil is safe - _, err = json.MarshalIndent(nil, "", " ") // ERROR "Error return value of `encoding/json.MarshalIndent` is checked but passed argument is safe" + _, err = json.MarshalIndent(nil, "", " ") // want "Error return value of `encoding/json.MarshalIndent` is checked but passed argument is safe" _ = err enc := json.NewEncoder(ioutil.Discard) - _ = enc.Encode(nil) // ERROR "Error return value of `\\([*]encoding/json.Encoder\\).Encode` is not checked" - enc.Encode(nil) // ERROR "Error return value of `\\([*]encoding/json.Encoder\\).Encode` is not checked" + _ = enc.Encode(nil) // want "Error return value of `\\([*]encoding/json.Encoder\\).Encode` is not checked" + enc.Encode(nil) // want "Error return value of `\\([*]encoding/json.Encoder\\).Encode` is not checked" err = enc.Encode(nil) _ = err var b bool _, _ = json.Marshal(b) // bool is safe - _, err = json.Marshal(b) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(b) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var i int _, _ = json.Marshal(i) // int is safe - _, err = json.Marshal(i) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(i) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var i8 int8 _, _ = json.Marshal(i8) // int8 is safe - _, err = json.Marshal(i8) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(i8) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var i16 int16 _, _ = json.Marshal(i16) // int16 is safe - _, err = json.Marshal(i16) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(i16) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var i32 int32 _, _ = json.Marshal(i32) // int32 / rune is safe - _, err = json.Marshal(i32) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(i32) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var i64 int64 _, _ = json.Marshal(i64) // int64 is safe - _, err = json.Marshal(i64) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(i64) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var ui uint _, _ = json.Marshal(ui) // uint is safe - _, err = json.Marshal(ui) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(ui) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var ui8 uint8 _, _ = json.Marshal(ui8) // uint8 / byte is safe - _, err = json.Marshal(ui8) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(ui8) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var ui16 uint16 _, _ = json.Marshal(ui16) // uint16 is safe - _, err = json.Marshal(ui16) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(ui16) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var ui32 uint32 _, _ = json.Marshal(ui32) // uint32 / rune is safe - _, err = json.Marshal(ui32) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(ui32) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var ui64 uint64 _, _ = json.Marshal(ui64) // uint64 is safe - _, err = json.Marshal(ui64) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(ui64) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var uiptr uintptr _, _ = json.Marshal(uiptr) // uintptr is safe - _, err = json.Marshal(uiptr) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(uiptr) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var str string _, _ = json.Marshal(str) // string is safe - _, err = json.Marshal(str) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(str) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var strSlice []string _, _ = json.Marshal(strSlice) // []string is safe - _, err = json.Marshal(strSlice) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(strSlice) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var intSlice []int _, _ = json.Marshal(intSlice) // []int is safe - _, err = json.Marshal(intSlice) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(intSlice) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var boolSlice []bool _, _ = json.Marshal(boolSlice) // []bool is safe - _, err = json.Marshal(boolSlice) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(boolSlice) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var strArray [10]string _, _ = json.Marshal(strArray) // [10]string is safe - _, err = json.Marshal(strArray) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(strArray) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var intArray [10]int _, _ = json.Marshal(intArray) // [10]int is safe - _, err = json.Marshal(intArray) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(intArray) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var boolArray [10]bool _, _ = json.Marshal(boolArray) // [10]bool is safe - _, err = json.Marshal(boolArray) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(boolArray) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var basicStruct struct { @@ -150,7 +150,7 @@ func JSONMarshalSafeTypes() { String string } _, _ = json.Marshal(basicStruct) // struct containing only safe basic types is safe - _, err = json.Marshal(basicStruct) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(basicStruct) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var ptrStruct struct { @@ -169,37 +169,37 @@ func JSONMarshalSafeTypes() { String *string } _, _ = json.Marshal(ptrStruct) // struct containing pointer to only safe basic types is safe - _, err = json.Marshal(ptrStruct) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(ptrStruct) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var mapStrStr map[string]string _, _ = json.Marshal(mapStrStr) // map[string]string is safe - _, err = json.Marshal(mapStrStr) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(mapStrStr) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var mapStrInt map[string]int _, _ = json.Marshal(mapStrInt) // map[string]int is safe - _, err = json.Marshal(mapStrInt) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(mapStrInt) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var mapStrBool map[string]bool _, _ = json.Marshal(mapStrBool) // map[string]bool is safe - _, err = json.Marshal(mapStrBool) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(mapStrBool) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var mapIntStr map[int]string _, _ = json.Marshal(mapIntStr) // map[int]string is safe - _, err = json.Marshal(mapIntStr) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(mapIntStr) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var mapIntInt map[int]int _, _ = json.Marshal(mapIntInt) // map[int]int is safe - _, err = json.Marshal(mapIntInt) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(mapIntInt) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err var mapIntBool map[int]bool _, _ = json.Marshal(mapIntBool) // map[int]bool is safe - _, err = json.Marshal(mapIntBool) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(mapIntBool) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err type innerStruct struct { @@ -247,7 +247,7 @@ func JSONMarshalSafeTypes() { InnerStruct innerStruct } _, _ = json.Marshal(outerStruct) // struct with only safe types - _, err = json.Marshal(outerStruct) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(outerStruct) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err } @@ -343,7 +343,7 @@ func JSONMarshalSaveStructWithUnexportedFields() { _ = unexportedInStruct.unsafePtr _ = unexportedInStruct.mapStructStr[structKey{1}] _, _ = json.Marshal(unexportedInStruct) // struct containing unsafe but unexported fields is safe - _, err = json.Marshal(unexportedInStruct) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(unexportedInStruct) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err } @@ -383,7 +383,7 @@ func JSONMarshalSaveStructWithOmittedFields() { } _ = omitInStruct.MapStructStr[structKey{1}] _, _ = json.Marshal(omitInStruct) // struct containing unsafe but omitted, exported fields is safe - _, err = json.Marshal(omitInStruct) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" + _, err = json.Marshal(omitInStruct) // want "Error return value of `encoding/json.Marshal` is checked but passed argument is safe" _ = err } @@ -393,119 +393,119 @@ func JSONMarshalUnsafeTypes() { var err error var f32 float32 - json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" - _, _ = json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + json.Marshal(f32) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + _, _ = json.Marshal(f32) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" _, err = json.Marshal(f32) // err is checked _ = err var f64 float64 - _, _ = json.Marshal(f64) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" + _, _ = json.Marshal(f64) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" _, err = json.Marshal(f64) // err is checked _ = err var f32Slice []float32 - _, _ = json.Marshal(f32Slice) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + _, _ = json.Marshal(f32Slice) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" _, err = json.Marshal(f32Slice) // err is checked _ = err var f64Slice []float64 - _, _ = json.Marshal(f64Slice) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" + _, _ = json.Marshal(f64Slice) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" _, err = json.Marshal(f64Slice) // err is checked _ = err var f32Array [10]float32 - _, _ = json.Marshal(f32Array) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + _, _ = json.Marshal(f32Array) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" _, err = json.Marshal(f32Array) // err is checked _ = err var f64Array [10]float64 - _, _ = json.Marshal(f64Array) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" + _, _ = json.Marshal(f64Array) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" _, err = json.Marshal(f64Array) // err is checked _ = err var structPtrF32 struct { F32 *float32 } - _, _ = json.Marshal(structPtrF32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + _, _ = json.Marshal(structPtrF32) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" _, err = json.Marshal(structPtrF32) // err is checked _ = err var structPtrF64 struct { F64 *float64 } - _, _ = json.Marshal(structPtrF64) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" + _, _ = json.Marshal(structPtrF64) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" _, err = json.Marshal(structPtrF64) // err is checked _ = err var mapStrF32 map[string]float32 - _, _ = json.Marshal(mapStrF32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" + _, _ = json.Marshal(mapStrF32) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found" _, err = json.Marshal(mapStrF32) // err is checked _ = err var mapStrF64 map[string]float64 - _, _ = json.Marshal(mapStrF64) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" + _, _ = json.Marshal(mapStrF64) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float64` found" _, err = json.Marshal(mapStrF64) // err is checked _ = err var mapEIStr map[interface{}]string - _, _ = json.Marshal(mapEIStr) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` as map key found" + _, _ = json.Marshal(mapEIStr) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` as map key found" _, err = json.Marshal(mapEIStr) // err is checked _ = err var mapStringerStr map[fmt.Stringer]string - _, _ = json.Marshal(mapStringerStr) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `fmt.Stringer` as map key found" + _, _ = json.Marshal(mapStringerStr) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `fmt.Stringer` as map key found" _, err = json.Marshal(mapStringerStr) // err is checked _ = err var number json.Number - _, _ = json.Marshal(number) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" + _, _ = json.Marshal(number) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" _, err = json.Marshal(number) // err is checked _ = err var numberSlice []json.Number - _, _ = json.Marshal(numberSlice) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" + _, _ = json.Marshal(numberSlice) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" _, err = json.Marshal(numberSlice) // err is checked _ = err var mapNumberStr map[json.Number]string - _, _ = json.Marshal(mapNumberStr) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` as map key found" + _, _ = json.Marshal(mapNumberStr) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` as map key found" _, err = json.Marshal(mapNumberStr) // err is checked _ = err var mapStrNumber map[string]json.Number - _, _ = json.Marshal(mapStrNumber) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" + _, _ = json.Marshal(mapStrNumber) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `encoding/json.Number` found" _, err = json.Marshal(mapStrNumber) // err is checked _ = err var ei interface{} - _, _ = json.Marshal(ei) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found" + _, _ = json.Marshal(ei) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found" _, err = json.Marshal(ei) // err is checked _ = err var eiptr *interface{} - _, _ = json.Marshal(eiptr) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `*interface{}` found" + _, _ = json.Marshal(eiptr) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `*interface{}` found" _, err = json.Marshal(eiptr) // err is checked _ = err var stringer fmt.Stringer - _, _ = json.Marshal(stringer) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `fmt.Stringer` found" + _, _ = json.Marshal(stringer) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `fmt.Stringer` found" _, err = json.Marshal(stringer) // err is checked _ = err var structWithEmptyInterface struct { EmptyInterface interface{} } - _, _ = json.Marshal(structWithEmptyInterface) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found" + _, _ = json.Marshal(structWithEmptyInterface) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found" _, err = json.Marshal(structWithEmptyInterface) // err is checked _ = err var mt marshalText - _, _ = json.Marshal(mt) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `[a-z-]+.marshalText` found" + _, _ = json.Marshal(mt) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `[a-z-]+.marshalText` found" _, err = json.Marshal(mt) // err is checked _ = err var mapMarshalTextString map[marshalText]string - _, _ = json.Marshal(mapMarshalTextString) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `[a-z-]+.marshalText` as map key found" + _, _ = json.Marshal(mapMarshalTextString) // want "Error return value of `encoding/json.Marshal` is not checked: unsafe type `[a-z-]+.marshalText` as map key found" _, err = json.Marshal(mapMarshalTextString) // err is checked _ = err } @@ -517,93 +517,93 @@ func JSONMarshalInvalidTypes() { var err error var c64 complex64 - json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" - _, _ = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" - _, err = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" + json.Marshal(c64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" + _, _ = json.Marshal(c64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" + _, err = json.Marshal(c64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" _ = err var c128 complex128 - _, _ = json.Marshal(c128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" - _, err = json.Marshal(c128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" + _, _ = json.Marshal(c128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" + _, err = json.Marshal(c128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" _ = err var sliceC64 []complex64 - _, _ = json.Marshal(sliceC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" - _, err = json.Marshal(sliceC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" + _, _ = json.Marshal(sliceC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" + _, err = json.Marshal(sliceC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" _ = err var sliceC128 []complex128 - _, _ = json.Marshal(sliceC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" - _, err = json.Marshal(sliceC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" + _, _ = json.Marshal(sliceC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" + _, err = json.Marshal(sliceC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" _ = err var arrayC64 []complex64 - _, _ = json.Marshal(arrayC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" - _, err = json.Marshal(arrayC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" + _, _ = json.Marshal(arrayC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" + _, err = json.Marshal(arrayC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" _ = err var arrayC128 []complex128 - _, _ = json.Marshal(arrayC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" - _, err = json.Marshal(arrayC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" + _, _ = json.Marshal(arrayC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" + _, err = json.Marshal(arrayC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" _ = err var structPtrC64 struct { C64 *complex64 } - _, _ = json.Marshal(structPtrC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" - _, err = json.Marshal(structPtrC64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found" + _, _ = json.Marshal(structPtrC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" + _, err = json.Marshal(structPtrC64) // want "`encoding/json.Marshal` for unsupported type `complex64` found" _ = err var structPtrC128 struct { C128 *complex128 } - _, _ = json.Marshal(structPtrC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" - _, err = json.Marshal(structPtrC128) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` found" + _, _ = json.Marshal(structPtrC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" + _, err = json.Marshal(structPtrC128) // want "`encoding/json.Marshal` for unsupported type `complex128` found" _ = err var mapBoolStr map[bool]string - _, _ = json.Marshal(mapBoolStr) // ERROR "`encoding/json.Marshal` for unsupported type `bool` as map key found" - _, err = json.Marshal(mapBoolStr) // ERROR "`encoding/json.Marshal` for unsupported type `bool` as map key found" + _, _ = json.Marshal(mapBoolStr) // want "`encoding/json.Marshal` for unsupported type `bool` as map key found" + _, err = json.Marshal(mapBoolStr) // want "`encoding/json.Marshal` for unsupported type `bool` as map key found" _ = err var mapF32Str map[float32]string - _, _ = json.Marshal(mapF32Str) // ERROR "`encoding/json.Marshal` for unsupported type `float32` as map key found" - _, err = json.Marshal(mapF32Str) // ERROR "`encoding/json.Marshal` for unsupported type `float32` as map key found" + _, _ = json.Marshal(mapF32Str) // want "`encoding/json.Marshal` for unsupported type `float32` as map key found" + _, err = json.Marshal(mapF32Str) // want "`encoding/json.Marshal` for unsupported type `float32` as map key found" _ = err var mapF64Str map[float64]string - _, _ = json.Marshal(mapF64Str) // ERROR "`encoding/json.Marshal` for unsupported type `float64` as map key found" - _, err = json.Marshal(mapF64Str) // ERROR "`encoding/json.Marshal` for unsupported type `float64` as map key found" + _, _ = json.Marshal(mapF64Str) // want "`encoding/json.Marshal` for unsupported type `float64` as map key found" + _, err = json.Marshal(mapF64Str) // want "`encoding/json.Marshal` for unsupported type `float64` as map key found" _ = err var mapC64Str map[complex64]string - _, _ = json.Marshal(mapC64Str) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` as map key found" - _, err = json.Marshal(mapC64Str) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` as map key found" + _, _ = json.Marshal(mapC64Str) // want "`encoding/json.Marshal` for unsupported type `complex64` as map key found" + _, err = json.Marshal(mapC64Str) // want "`encoding/json.Marshal` for unsupported type `complex64` as map key found" _ = err var mapC128Str map[complex128]string - _, _ = json.Marshal(mapC128Str) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` as map key found" - _, err = json.Marshal(mapC128Str) // ERROR "`encoding/json.Marshal` for unsupported type `complex128` as map key found" + _, _ = json.Marshal(mapC128Str) // want "`encoding/json.Marshal` for unsupported type `complex128` as map key found" + _, err = json.Marshal(mapC128Str) // want "`encoding/json.Marshal` for unsupported type `complex128` as map key found" _ = err mapStructStr := map[structKey]string{structKey{1}: "str"} - _, _ = json.Marshal(mapStructStr) // ERROR "`encoding/json.Marshal` for unsupported type `[a-z-]+.structKey` as map key found" - _, err = json.Marshal(mapStructStr) // ERROR "`encoding/json.Marshal` for unsupported type `[a-z-]+.structKey` as map key found" + _, _ = json.Marshal(mapStructStr) // want "`encoding/json.Marshal` for unsupported type `[a-z-]+.structKey` as map key found" + _, err = json.Marshal(mapStructStr) // want "`encoding/json.Marshal` for unsupported type `[a-z-]+.structKey` as map key found" _ = err f := func() {} - _, _ = json.Marshal(f) // ERROR "`encoding/json.Marshal` for unsupported type `func\\(\\)` found" - _, err = json.Marshal(f) // ERROR "`encoding/json.Marshal` for unsupported type `func\\(\\)` found" + _, _ = json.Marshal(f) // want "`encoding/json.Marshal` for unsupported type `func\\(\\)` found" + _, err = json.Marshal(f) // want "`encoding/json.Marshal` for unsupported type `func\\(\\)` found" _ = err var ch chan struct{} = make(chan struct{}) - _, _ = json.Marshal(ch) // ERROR "`encoding/json.Marshal` for unsupported type `chan struct{}` found" - _, err = json.Marshal(ch) // ERROR "`encoding/json.Marshal` for unsupported type `chan struct{}` found" + _, _ = json.Marshal(ch) // want "`encoding/json.Marshal` for unsupported type `chan struct{}` found" + _, err = json.Marshal(ch) // want "`encoding/json.Marshal` for unsupported type `chan struct{}` found" _ = err var unsafePtr unsafe.Pointer - _, _ = json.Marshal(unsafePtr) // ERROR "`encoding/json.Marshal` for unsupported type `unsafe.Pointer` found" - _, err = json.Marshal(unsafePtr) // ERROR "`encoding/json.Marshal` for unsupported type `unsafe.Pointer` found" + _, _ = json.Marshal(unsafePtr) // want "`encoding/json.Marshal` for unsupported type `unsafe.Pointer` found" + _, err = json.Marshal(unsafePtr) // want "`encoding/json.Marshal` for unsupported type `unsafe.Pointer` found" _ = err } diff --git a/test/testdata/errchkjson_no_exported.go b/test/testdata/errchkjson_no_exported.go index ef5cc42d..e609de0d 100644 --- a/test/testdata/errchkjson_no_exported.go +++ b/test/testdata/errchkjson_no_exported.go @@ -12,7 +12,7 @@ func JSONMarshalStructWithoutExportedFields() { privateField bool ExportedButOmittedField bool `json:"-"` } - _, err := json.Marshal(withoutExportedFields) // ERROR "Error argument passed to `encoding/json.Marshal` does not contain any exported field" + _, err := json.Marshal(withoutExportedFields) // want "Error argument passed to `encoding/json.Marshal` does not contain any exported field" _ = err } diff --git a/test/testdata/errname.go b/test/testdata/errname.go index a5ccd436..d206ffc4 100644 --- a/test/testdata/errname.go +++ b/test/testdata/errname.go @@ -11,11 +11,11 @@ var ( ErrEndOfFile = errors.New("end of file") errEndOfFile = errors.New("end of file") - EndOfFileError = errors.New("end of file") // ERROR "the variable name `EndOfFileError` should conform to the `ErrXxx` format" - ErrorEndOfFile = errors.New("end of file") // ERROR "the variable name `ErrorEndOfFile` should conform to the `ErrXxx` format" - EndOfFileErr = errors.New("end of file") // ERROR "the variable name `EndOfFileErr` should conform to the `ErrXxx` format" - endOfFileError = errors.New("end of file") // ERROR "the variable name `endOfFileError` should conform to the `errXxx` format" - errorEndOfFile = errors.New("end of file") // ERROR "the variable name `errorEndOfFile` should conform to the `errXxx` format" + EndOfFileError = errors.New("end of file") // want "the variable name `EndOfFileError` should conform to the `ErrXxx` format" + ErrorEndOfFile = errors.New("end of file") // want "the variable name `ErrorEndOfFile` should conform to the `ErrXxx` format" + EndOfFileErr = errors.New("end of file") // want "the variable name `EndOfFileErr` should conform to the `ErrXxx` format" + endOfFileError = errors.New("end of file") // want "the variable name `endOfFileError` should conform to the `errXxx` format" + errorEndOfFile = errors.New("end of file") // want "the variable name `errorEndOfFile` should conform to the `errXxx` format" ) const maxSize = 256 @@ -24,8 +24,8 @@ var ( ErrOutOfSize = fmt.Errorf("out of size (max %d)", maxSize) errOutOfSize = fmt.Errorf("out of size (max %d)", maxSize) - OutOfSizeError = fmt.Errorf("out of size (max %d)", maxSize) // ERROR "the variable name `OutOfSizeError` should conform to the `ErrXxx` format" - outOfSizeError = fmt.Errorf("out of size (max %d)", maxSize) // ERROR "the variable name `outOfSizeError` should conform to the `errXxx` format" + OutOfSizeError = fmt.Errorf("out of size (max %d)", maxSize) // want "the variable name `OutOfSizeError` should conform to the `ErrXxx` format" + outOfSizeError = fmt.Errorf("out of size (max %d)", maxSize) // want "the variable name `outOfSizeError` should conform to the `errXxx` format" ) func errInsideFuncIsNotSentinel() error { @@ -42,14 +42,14 @@ type DNSConfigError struct{} func (D DNSConfigError) Error() string { return "DNS config error" } -type someTypeWithoutPtr struct{} // ERROR "the type name `someTypeWithoutPtr` should conform to the `xxxError` format" +type someTypeWithoutPtr struct{} // want "the type name `someTypeWithoutPtr` should conform to the `xxxError` format" func (s someTypeWithoutPtr) Error() string { return "someTypeWithoutPtr" } -type SomeTypeWithoutPtr struct{} // ERROR "the type name `SomeTypeWithoutPtr` should conform to the `XxxError` format" +type SomeTypeWithoutPtr struct{} // want "the type name `SomeTypeWithoutPtr` should conform to the `XxxError` format" func (s SomeTypeWithoutPtr) Error() string { return "SomeTypeWithoutPtr" } -type someTypeWithPtr struct{} // ERROR "the type name `someTypeWithPtr` should conform to the `xxxError` format" +type someTypeWithPtr struct{} // want "the type name `someTypeWithPtr` should conform to the `xxxError` format" func (s *someTypeWithPtr) Error() string { return "someTypeWithPtr" } -type SomeTypeWithPtr struct{} // ERROR "the type name `SomeTypeWithPtr` should conform to the `XxxError` format" +type SomeTypeWithPtr struct{} // want "the type name `SomeTypeWithPtr` should conform to the `XxxError` format" func (s *SomeTypeWithPtr) Error() string { return "SomeTypeWithPtr" } diff --git a/test/testdata/errorlint.go b/test/testdata/errorlint.go index 5dda3c86..7164b1fe 100644 --- a/test/testdata/errorlint.go +++ b/test/testdata/errorlint.go @@ -17,14 +17,14 @@ func (*errLintBar) Error() string { func errorLintAll() { err := func() error { return nil }() - if err == errLintFoo { // ERROR "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error" + if err == errLintFoo { // want "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error" log.Println("errCompare") } err = errors.New("oops") - fmt.Errorf("error: %v", err) // ERROR "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" + fmt.Errorf("error: %v", err) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" - switch err.(type) { // ERROR "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" + switch err.(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" case *errLintBar: log.Println("errLintBar") } diff --git a/test/testdata/errorlint_asserts.go b/test/testdata/errorlint_asserts.go index a38a58f4..f3357eb3 100644 --- a/test/testdata/errorlint_asserts.go +++ b/test/testdata/errorlint_asserts.go @@ -23,23 +23,23 @@ func errorLintAsserts() { if errors.As(err, &me) { log.Println("myError") } - _, ok := err.(*myError) // ERROR "type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors" + _, ok := err.(*myError) // want "type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors" if ok { log.Println("myError") } - switch err.(type) { // ERROR "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" + switch err.(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" case *myError: log.Println("myError") } - switch errorLintDoAnotherThing().(type) { // ERROR "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" + switch errorLintDoAnotherThing().(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" case *myError: log.Println("myError") } - switch t := err.(type) { // ERROR "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" + switch t := err.(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" case *myError: log.Println("myError", t) } - switch t := errorLintDoAnotherThing().(type) { // ERROR "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" + switch t := errorLintDoAnotherThing().(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" case *myError: log.Println("myError", t) } diff --git a/test/testdata/errorlint_comparison.go b/test/testdata/errorlint_comparison.go index 0b37f988..41ef591d 100644 --- a/test/testdata/errorlint_comparison.go +++ b/test/testdata/errorlint_comparison.go @@ -30,23 +30,23 @@ func errorLintComparison() { if nil != err { log.Println("nil") } - if err == errCompare { // ERROR "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error" + if err == errCompare { // want "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error" log.Println("errCompare") } - if err != errCompare { // ERROR "comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error" + if err != errCompare { // want "comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error" log.Println("not errCompare") } - if errCompare == err { // ERROR "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error" + if errCompare == err { // want "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error" log.Println("errCompare") } - if errCompare != err { // ERROR "comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error" + if errCompare != err { // want "comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error" log.Println("not errCompare") } - switch err { // ERROR "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors" + switch err { // want "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors" case errCompare: log.Println("errCompare") } - switch errorLintDoThing() { // ERROR "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors" + switch errorLintDoThing() { // want "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors" case errCompare: log.Println("errCompare") } diff --git a/test/testdata/errorlint_errorf.go b/test/testdata/errorlint_errorf.go index 52ed9feb..e6fc58ce 100644 --- a/test/testdata/errorlint_errorf.go +++ b/test/testdata/errorlint_errorf.go @@ -16,11 +16,11 @@ func (customError) Error() string { func errorLintErrorf() { err := errors.New("oops") fmt.Errorf("error: %w", err) - fmt.Errorf("error: %v", err) // ERROR "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" - fmt.Errorf("%v %v", err, err) // ERROR "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" - fmt.Errorf("error: %s", err.Error()) // ERROR "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" + fmt.Errorf("error: %v", err) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" + fmt.Errorf("%v %v", err, err) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" + fmt.Errorf("error: %s", err.Error()) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" customError := customError{} - fmt.Errorf("error: %s", customError.Error()) // ERROR "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" + fmt.Errorf("error: %s", customError.Error()) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" strErr := "oops" fmt.Errorf("%v", strErr) } diff --git a/test/testdata/execinquery.go b/test/testdata/execinquery.go index bcf3ba83..36db0af8 100644 --- a/test/testdata/execinquery.go +++ b/test/testdata/execinquery.go @@ -9,22 +9,22 @@ import ( func execInQuery(db *sql.DB) { test := "a" - _, err := db.Query("Update * FROM hoge where id = ?", test) // ERROR "Use Exec instead of Query to execute `UPDATE` query" + _, err := db.Query("Update * FROM hoge where id = ?", test) // want "Use Exec instead of Query to execute `UPDATE` query" if err != nil { return } - db.QueryRow("Update * FROM hoge where id = ?", test) // ERROR "Use Exec instead of QueryRow to execute `UPDATE` query" + db.QueryRow("Update * FROM hoge where id = ?", test) // want "Use Exec instead of QueryRow to execute `UPDATE` query" if err != nil { return } ctx := context.Background() - _, err = db.QueryContext(ctx, "Update * FROM hoge where id = ?", test) // ERROR "Use ExecContext instead of QueryContext to execute `UPDATE` query" + _, err = db.QueryContext(ctx, "Update * FROM hoge where id = ?", test) // want "Use ExecContext instead of QueryContext to execute `UPDATE` query" if err != nil { return } - db.QueryRowContext(ctx, "Update * FROM hoge where id = ?", test) // ERROR "Use ExecContext instead of QueryRowContext to execute `UPDATE` query" + db.QueryRowContext(ctx, "Update * FROM hoge where id = ?", test) // want "Use ExecContext instead of QueryRowContext to execute `UPDATE` query" } diff --git a/test/testdata/exhaustive.go b/test/testdata/exhaustive.go index 18b8a35b..ace3f81d 100644 --- a/test/testdata/exhaustive.go +++ b/test/testdata/exhaustive.go @@ -11,7 +11,7 @@ const ( ) func processDirection(d Direction) { - switch d { // ERROR "missing cases in switch of type Direction: East, West" + switch d { // want "missing cases in switch of type Direction: East, West" case North, South: } } diff --git a/test/testdata/exhaustive_default.go b/test/testdata/exhaustive_default.go index ff2fcf57..6732f3da 100644 --- a/test/testdata/exhaustive_default.go +++ b/test/testdata/exhaustive_default.go @@ -1,5 +1,6 @@ //golangcitest:args -Eexhaustive //golangcitest:config_path testdata/configs/exhaustive_default.yml +//golangcitest:expected_exitcode 0 package testdata type Direction int diff --git a/test/testdata/exhaustive_generated.go b/test/testdata/exhaustive_generated.go index 82618d38..fcc94697 100644 --- a/test/testdata/exhaustive_generated.go +++ b/test/testdata/exhaustive_generated.go @@ -1,4 +1,5 @@ //golangcitest:args -Eexhaustive +//golangcitest:expected_exitcode 0 package testdata // Code generated by some program. DO NOT EDIT. diff --git a/test/testdata/exhaustive_ignore_enum_members.go b/test/testdata/exhaustive_ignore_enum_members.go index da7a5b43..e1a810ee 100644 --- a/test/testdata/exhaustive_ignore_enum_members.go +++ b/test/testdata/exhaustive_ignore_enum_members.go @@ -15,7 +15,7 @@ const ( // using the ignore-enum-members setting. func processDirectionIgnoreEnumMembers(d Direction) { - switch d { // ERROR "missing cases in switch of type Direction: East" + switch d { // want "missing cases in switch of type Direction: East" case North, South: } } diff --git a/test/testdata/exhaustivestruct.go b/test/testdata/exhaustivestruct.go index 000a8f49..50476ceb 100644 --- a/test/testdata/exhaustivestruct.go +++ b/test/testdata/exhaustivestruct.go @@ -22,7 +22,7 @@ func exhaustiveStruct() { } // failPrivate - _ = ExhaustiveStruct{ // ERROR "c is missing in ExhaustiveStruct" + _ = ExhaustiveStruct{ // want "c is missing in ExhaustiveStruct" A: "a", B: 0, D: 1.0, @@ -30,7 +30,7 @@ func exhaustiveStruct() { } // fail - _ = ExhaustiveStruct{ // ERROR "B is missing in ExhaustiveStruct" + _ = ExhaustiveStruct{ // want "B is missing in ExhaustiveStruct" A: "a", c: false, D: 1.0, @@ -38,7 +38,7 @@ func exhaustiveStruct() { } // failMultiple - _ = ExhaustiveStruct{ // ERROR "B, D are missing in ExhaustiveStruct" + _ = ExhaustiveStruct{ // want "B, D are missing in ExhaustiveStruct" A: "a", c: false, E: time.Now(), diff --git a/test/testdata/exhaustivestruct_custom.go b/test/testdata/exhaustivestruct_custom.go index 55a9127c..08fde43f 100644 --- a/test/testdata/exhaustivestruct_custom.go +++ b/test/testdata/exhaustivestruct_custom.go @@ -23,7 +23,7 @@ func exhaustiveStructCustom() { } // fail - _ = ExhaustiveStructCustom{ // ERROR "B is missing in ExhaustiveStructCustom" + _ = ExhaustiveStructCustom{ // want "B is missing in ExhaustiveStructCustom" A: "a", c: false, D: 1.0, @@ -31,14 +31,14 @@ func exhaustiveStructCustom() { } // failMultiple - _ = ExhaustiveStructCustom{ // ERROR "B, D are missing in ExhaustiveStructCustom" + _ = ExhaustiveStructCustom{ // want "B, D are missing in ExhaustiveStructCustom" A: "a", c: false, E: time.Now(), } // failPrivate - _ = ExhaustiveStructCustom{ // ERROR "c is missing in ExhaustiveStructCustom" + _ = ExhaustiveStructCustom{ // want "c is missing in ExhaustiveStructCustom" A: "a", B: 0, D: 1.0, @@ -104,7 +104,7 @@ func exhaustiveStructCustom2() { } // fail - _ = ExhaustiveStructCustom2{ // ERROR "B is missing in ExhaustiveStructCustom2" + _ = ExhaustiveStructCustom2{ // want "B is missing in ExhaustiveStructCustom2" A: "a", c: false, D: 1.0, @@ -112,14 +112,14 @@ func exhaustiveStructCustom2() { } // failMultiple - _ = ExhaustiveStructCustom2{ // ERROR "B, D are missing in ExhaustiveStructCustom2" + _ = ExhaustiveStructCustom2{ // want "B, D are missing in ExhaustiveStructCustom2" A: "a", c: false, E: time.Now(), } // failPrivate - _ = ExhaustiveStructCustom2{ // ERROR "c is missing in ExhaustiveStructCustom2" + _ = ExhaustiveStructCustom2{ // want "c is missing in ExhaustiveStructCustom2" A: "a", B: 0, D: 1.0, diff --git a/test/testdata/exhaustruct.go b/test/testdata/exhaustruct.go index 6da51f4f..35675a5e 100644 --- a/test/testdata/exhaustruct.go +++ b/test/testdata/exhaustruct.go @@ -22,7 +22,7 @@ func exhaustruct() { } // failPrivate - _ = Exhaustruct{ // ERROR "c is missing in Exhaustruct" + _ = Exhaustruct{ // want "c is missing in Exhaustruct" A: "a", B: 0, D: 1.0, @@ -30,7 +30,7 @@ func exhaustruct() { } // fail - _ = Exhaustruct{ // ERROR "B is missing in Exhaustruct" + _ = Exhaustruct{ // want "B is missing in Exhaustruct" A: "a", c: false, D: 1.0, @@ -38,7 +38,7 @@ func exhaustruct() { } // failMultiple - _ = Exhaustruct{ // ERROR "B, D are missing in Exhaustruct" + _ = Exhaustruct{ // want "B, D are missing in Exhaustruct" A: "a", c: false, E: time.Now(), diff --git a/test/testdata/exhaustruct_custom.go b/test/testdata/exhaustruct_custom.go index 352ea911..60d00a5c 100644 --- a/test/testdata/exhaustruct_custom.go +++ b/test/testdata/exhaustruct_custom.go @@ -23,7 +23,7 @@ func exhaustructCustom() { } // fail - _ = ExhaustructCustom{ // ERROR "B is missing in ExhaustructCustom" + _ = ExhaustructCustom{ // want "B is missing in ExhaustructCustom" A: "a", c: false, D: 1.0, @@ -31,14 +31,14 @@ func exhaustructCustom() { } // failMultiple - _ = ExhaustructCustom{ // ERROR "B, D are missing in ExhaustructCustom" + _ = ExhaustructCustom{ // want "B, D are missing in ExhaustructCustom" A: "a", c: false, E: time.Now(), } // failPrivate - _ = ExhaustructCustom{ // ERROR "c is missing in ExhaustructCustom" + _ = ExhaustructCustom{ // want "c is missing in ExhaustructCustom" A: "a", B: 0, D: 1.0, diff --git a/test/testdata/exportloopref.go b/test/testdata/exportloopref.go index 0fe98b1a..2d6b6aa3 100644 --- a/test/testdata/exportloopref.go +++ b/test/testdata/exportloopref.go @@ -12,11 +12,11 @@ func dummyFunction() { fmt.Println("loop expecting 10, 11, 12, 13") for i, p := range []int{10, 11, 12, 13} { printp(&p) - slice = append(slice, &p) // ERROR "exporting a pointer for the loop variable p" - array[i] = &p // ERROR "exporting a pointer for the loop variable p" + slice = append(slice, &p) // want "exporting a pointer for the loop variable p" + array[i] = &p // want "exporting a pointer for the loop variable p" if i%2 == 0 { - ref = &p // ERROR "exporting a pointer for the loop variable p" - str.x = &p // ERROR "exporting a pointer for the loop variable p" + ref = &p // want "exporting a pointer for the loop variable p" + str.x = &p // want "exporting a pointer for the loop variable p" } var vStr struct{ x *int } var vArray [4]*int diff --git a/test/testdata/fix/in/gci.go b/test/testdata/fix/in/gci.go index 9a2be3fa..2449e8bf 100644 --- a/test/testdata/fix/in/gci.go +++ b/test/testdata/fix/in/gci.go @@ -1,5 +1,6 @@ //golangcitest:args -Egci //golangcitest:config_path testdata/configs/gci.yml +//golangcitest:expected_exitcode 0 package gci import ( diff --git a/test/testdata/fix/in/gocritic.go b/test/testdata/fix/in/gocritic.go index a3cecf04..a4a4fcfd 100644 --- a/test/testdata/fix/in/gocritic.go +++ b/test/testdata/fix/in/gocritic.go @@ -1,5 +1,6 @@ //golangcitest:args -Egocritic //golangcitest:config_path testdata/configs/gocritic-fix.yml +//golangcitest:expected_exitcode 0 package p import ( diff --git a/test/testdata/fix/in/godot.go b/test/testdata/fix/in/godot.go index 806978fb..13b8da1c 100644 --- a/test/testdata/fix/in/godot.go +++ b/test/testdata/fix/in/godot.go @@ -1,4 +1,5 @@ //golangcitest:args -Egodot +//golangcitest:expected_exitcode 0 package p /* diff --git a/test/testdata/fix/in/gofmt.go b/test/testdata/fix/in/gofmt.go index 9c35dc47..46dc6c81 100644 --- a/test/testdata/fix/in/gofmt.go +++ b/test/testdata/fix/in/gofmt.go @@ -1,4 +1,5 @@ //golangcitest:args -Egofmt +//golangcitest:expected_exitcode 0 package p func gofmt(a, b int) int { diff --git a/test/testdata/fix/in/gofumpt.go b/test/testdata/fix/in/gofumpt.go index 83b6c978..b8e0bcbc 100644 --- a/test/testdata/fix/in/gofumpt.go +++ b/test/testdata/fix/in/gofumpt.go @@ -1,5 +1,6 @@ //golangcitest:args -Egofumpt //golangcitest:config_path testdata/configs/gofumpt-fix.yml +//golangcitest:expected_exitcode 0 package p import "fmt" diff --git a/test/testdata/fix/in/goimports.go b/test/testdata/fix/in/goimports.go index 8e2248c5..1808bf18 100644 --- a/test/testdata/fix/in/goimports.go +++ b/test/testdata/fix/in/goimports.go @@ -1,4 +1,5 @@ //golangcitest:args -Egofmt,goimports +//golangcitest:expected_exitcode 0 package p import ( diff --git a/test/testdata/fix/in/misspell.go b/test/testdata/fix/in/misspell.go index ac2ef6c1..07d0ae5b 100644 --- a/test/testdata/fix/in/misspell.go +++ b/test/testdata/fix/in/misspell.go @@ -1,4 +1,5 @@ //golangcitest:args -Emisspell +//golangcitest:expected_exitcode 0 package p import "log" diff --git a/test/testdata/fix/in/whitespace.go b/test/testdata/fix/in/whitespace.go index be8050e2..20c20315 100644 --- a/test/testdata/fix/in/whitespace.go +++ b/test/testdata/fix/in/whitespace.go @@ -1,5 +1,6 @@ //golangcitest:args -Ewhitespace //golangcitest:config_path testdata/configs/whitespace-fix.yml +//golangcitest:expected_exitcode 0 package p import "fmt" diff --git a/test/testdata/fix/out/gci.go b/test/testdata/fix/out/gci.go index af4e2e80..489adb52 100644 --- a/test/testdata/fix/out/gci.go +++ b/test/testdata/fix/out/gci.go @@ -1,5 +1,6 @@ //golangcitest:args -Egci //golangcitest:config_path testdata/configs/gci.yml +//golangcitest:expected_exitcode 0 package gci import ( diff --git a/test/testdata/fix/out/gocritic.go b/test/testdata/fix/out/gocritic.go index 943e8142..93005ab4 100644 --- a/test/testdata/fix/out/gocritic.go +++ b/test/testdata/fix/out/gocritic.go @@ -1,5 +1,6 @@ //golangcitest:args -Egocritic //golangcitest:config_path testdata/configs/gocritic-fix.yml +//golangcitest:expected_exitcode 0 package p import ( diff --git a/test/testdata/fix/out/godot.go b/test/testdata/fix/out/godot.go index 7c29db76..6960f06c 100644 --- a/test/testdata/fix/out/godot.go +++ b/test/testdata/fix/out/godot.go @@ -1,4 +1,5 @@ //golangcitest:args -Egodot +//golangcitest:expected_exitcode 0 package p /* diff --git a/test/testdata/fix/out/gofmt.go b/test/testdata/fix/out/gofmt.go index 724fb76e..967f35ac 100644 --- a/test/testdata/fix/out/gofmt.go +++ b/test/testdata/fix/out/gofmt.go @@ -1,4 +1,5 @@ //golangcitest:args -Egofmt +//golangcitest:expected_exitcode 0 package p func gofmt(a, b int) int { diff --git a/test/testdata/fix/out/gofumpt.go b/test/testdata/fix/out/gofumpt.go index dd366b7c..5fc02f67 100644 --- a/test/testdata/fix/out/gofumpt.go +++ b/test/testdata/fix/out/gofumpt.go @@ -1,5 +1,6 @@ //golangcitest:args -Egofumpt //golangcitest:config_path testdata/configs/gofumpt-fix.yml +//golangcitest:expected_exitcode 0 package p import "fmt" diff --git a/test/testdata/fix/out/goimports.go b/test/testdata/fix/out/goimports.go index 21c25a69..8e28c8ee 100644 --- a/test/testdata/fix/out/goimports.go +++ b/test/testdata/fix/out/goimports.go @@ -1,4 +1,5 @@ //golangcitest:args -Egofmt,goimports +//golangcitest:expected_exitcode 0 package p func goimports(a, b int) int { diff --git a/test/testdata/fix/out/misspell.go b/test/testdata/fix/out/misspell.go index 7f364941..474dd3e0 100644 --- a/test/testdata/fix/out/misspell.go +++ b/test/testdata/fix/out/misspell.go @@ -1,4 +1,5 @@ //golangcitest:args -Emisspell +//golangcitest:expected_exitcode 0 package p import "log" diff --git a/test/testdata/fix/out/whitespace.go b/test/testdata/fix/out/whitespace.go index 653a7343..16be0dcd 100644 --- a/test/testdata/fix/out/whitespace.go +++ b/test/testdata/fix/out/whitespace.go @@ -1,5 +1,6 @@ //golangcitest:args -Ewhitespace //golangcitest:config_path testdata/configs/whitespace-fix.yml +//golangcitest:expected_exitcode 0 package p import "fmt" diff --git a/test/testdata/forbidigo_example.go b/test/testdata/forbidigo_example.go index ef5de706..0a289788 100644 --- a/test/testdata/forbidigo_example.go +++ b/test/testdata/forbidigo_example.go @@ -8,6 +8,6 @@ import ( ) func Forbidigo() { - fmt.Printf("too noisy!!!") // ERROR "use of `fmt\\.Printf` forbidden by pattern `fmt\\\\.Print\\.\\*`" - time.Sleep(time.Nanosecond) // ERROR "no sleeping!" + fmt.Printf("too noisy!!!") // want "use of `fmt\\.Printf` forbidden by pattern `fmt\\\\.Print\\.\\*`" + time.Sleep(time.Nanosecond) // want "no sleeping!" } diff --git a/test/testdata/forbidigo_example_test.go b/test/testdata/forbidigo_example_test.go index 8582c8d5..18abb36d 100644 --- a/test/testdata/forbidigo_example_test.go +++ b/test/testdata/forbidigo_example_test.go @@ -1,5 +1,6 @@ //golangcitest:args -Eforbidigo //golangcitest:config_path testdata/configs/forbidigo.yml +//golangcitest:expected_exitcode 0 package testdata import "fmt" diff --git a/test/testdata/forbidigo_include_godoc_examples_test.go b/test/testdata/forbidigo_include_godoc_examples_test.go index ea6fc3e0..e44fa3fe 100644 --- a/test/testdata/forbidigo_include_godoc_examples_test.go +++ b/test/testdata/forbidigo_include_godoc_examples_test.go @@ -5,5 +5,5 @@ package testdata import "fmt" func ExampleForbidigoNoGodoc() { - fmt.Printf("too noisy!!!") // ERROR "use of `fmt.Printf` forbidden by pattern.*" + fmt.Printf("too noisy!!!") // want "use of `fmt.Printf` forbidden by pattern.*" } diff --git a/test/testdata/forcetypeassert.go b/test/testdata/forcetypeassert.go index 7f415b22..846a806b 100644 --- a/test/testdata/forcetypeassert.go +++ b/test/testdata/forcetypeassert.go @@ -5,10 +5,10 @@ import "fmt" func forcetypeassertInvalid() { var a interface{} - _ = a.(int) // ERROR "type assertion must be checked" + _ = a.(int) // want "type assertion must be checked" var b interface{} - bi := b.(int) // ERROR "type assertion must be checked" + bi := b.(int) // want "type assertion must be checked" fmt.Println(bi) } diff --git a/test/testdata/funlen.go b/test/testdata/funlen.go index f8059dbc..4dd92c80 100644 --- a/test/testdata/funlen.go +++ b/test/testdata/funlen.go @@ -2,7 +2,7 @@ //golangcitest:config_path testdata/configs/funlen.yml package testdata -func TooManyLines() { // ERROR `Function 'TooManyLines' is too long \(22 > 20\)` +func TooManyLines() { // want `Function 'TooManyLines' is too long \(22 > 20\)` t := struct { A string B string @@ -27,7 +27,7 @@ func TooManyLines() { // ERROR `Function 'TooManyLines' is too long \(22 > 20\)` _ = t } -func TooManyStatements() { // ERROR `Function 'TooManyStatements' has too many statements \(11 > 10\)` +func TooManyStatements() { // want `Function 'TooManyStatements' has too many statements \(11 > 10\)` a := 1 b := a c := b diff --git a/test/testdata/gci.go b/test/testdata/gci.go index d29e85b0..ef2e1954 100644 --- a/test/testdata/gci.go +++ b/test/testdata/gci.go @@ -5,9 +5,9 @@ package testdata import ( "fmt" - "github.com/golangci/golangci-lint/pkg/config" // ERROR "File is not \\`gci\\`-ed with --skip-generated -s standard,prefix\\(github.com/golangci/golangci-lint\\),default" + "github.com/golangci/golangci-lint/pkg/config" // want "File is not \\`gci\\`-ed with --skip-generated -s standard,prefix\\(github.com/golangci/golangci-lint\\),default" - "github.com/pkg/errors" // ERROR "File is not \\`gci\\`-ed with --skip-generated -s standard,prefix\\(github.com/golangci/golangci-lint\\),default" + "github.com/pkg/errors" // want "File is not \\`gci\\`-ed with --skip-generated -s standard,prefix\\(github.com/golangci/golangci-lint\\),default" ) func GoimportsLocalTest() { diff --git a/test/testdata/gci/gci.go b/test/testdata/gci/gci.go deleted file mode 100644 index 8f83dc21..00000000 --- a/test/testdata/gci/gci.go +++ /dev/null @@ -1,16 +0,0 @@ -//golangcitest:args -Egci -//golangcitest:config_path testdata/configs/gci.yml -package gci - -import ( - "fmt" - - "github.com/golangci/golangci-lint/pkg/config" - "github.com/pkg/errors" -) - -func GoimportsLocalTest() { - fmt.Print("x") - _ = config.Config{} - _ = errors.New("") -} diff --git a/test/testdata/go-header_bad.go b/test/testdata/go-header_bad.go index 9c9de0b6..fbcf828e 100644 --- a/test/testdata/go-header_bad.go +++ b/test/testdata/go-header_bad.go @@ -1,4 +1,4 @@ -/*MY TITLE!*/ // ERROR `Expected:TITLE\., Actual: TITLE!` +/*MY TITLE!*/ // want `Expected:TITLE\., Actual: TITLE!` //golangcitest:args -Egoheader //golangcitest:config_path testdata/configs/go-header.yml diff --git a/test/testdata/go-header_good.go b/test/testdata/go-header_good.go index 74469811..4bc199d0 100644 --- a/test/testdata/go-header_good.go +++ b/test/testdata/go-header_good.go @@ -2,4 +2,5 @@ //golangcitest:args -Egoheader //golangcitest:config_path testdata/configs/go-header.yml +//golangcitest:expected_exitcode 0 package testdata diff --git a/test/testdata/gochecknoglobals.go b/test/testdata/gochecknoglobals.go index a2c1f82c..3da3a2a3 100644 --- a/test/testdata/gochecknoglobals.go +++ b/test/testdata/gochecknoglobals.go @@ -7,12 +7,12 @@ import ( "regexp" ) -var noGlobalsVar int // ERROR "noGlobalsVar is a global variable" +var noGlobalsVar int // want "noGlobalsVar is a global variable" var ErrSomeType = errors.New("test that global erorrs aren't warned") var ( OnlyDigites = regexp.MustCompile(`^\d+$`) - BadNamedErr = errors.New("this is bad") // ERROR "BadNamedErr is a global variable" + BadNamedErr = errors.New("this is bad") // want "BadNamedErr is a global variable" ) func NoGlobals() { diff --git a/test/testdata/gochecknoinits.go b/test/testdata/gochecknoinits.go index 5ea8060d..f3e574df 100644 --- a/test/testdata/gochecknoinits.go +++ b/test/testdata/gochecknoinits.go @@ -3,7 +3,7 @@ package testdata import "fmt" -func init() { // ERROR "don't use `init` function" +func init() { // want "don't use `init` function" fmt.Println() } diff --git a/test/testdata/gocognit.go b/test/testdata/gocognit.go index ffd582a3..454c39d9 100644 --- a/test/testdata/gocognit.go +++ b/test/testdata/gocognit.go @@ -2,7 +2,7 @@ //golangcitest:config_path testdata/configs/gocognit.yml package testdata -func GoCognit_CC4_GetWords(number int) string { // ERROR "cognitive complexity 4 of func .* is high .*" +func GoCognit_CC4_GetWords(number int) string { // want "cognitive complexity 4 of func .* is high .*" if number == 1 { // +1 return "one" } else if number == 2 { // +1 @@ -27,7 +27,7 @@ func GoCognit_CC1_GetWords(number int) string { } } // Cognitive complexity = 1 -func GoCognit_CC3_Fact(n int) int { // ERROR "cognitive complexity 3 of func .* is high .*" +func GoCognit_CC3_Fact(n int) int { // want "cognitive complexity 3 of func .* is high .*" if n <= 1 { // +1 return 1 } else { // +1 @@ -35,7 +35,7 @@ func GoCognit_CC3_Fact(n int) int { // ERROR "cognitive complexity 3 of func .* } } // total complexity = 3 -func GoCognit_CC7_SumOfPrimes(max int) int { // ERROR "cognitive complexity 7 of func .* is high .*" +func GoCognit_CC7_SumOfPrimes(max int) int { // want "cognitive complexity 7 of func .* is high .*" var total int OUT: diff --git a/test/testdata/goconst.go b/test/testdata/goconst.go index 6996acb8..f2f5314d 100644 --- a/test/testdata/goconst.go +++ b/test/testdata/goconst.go @@ -4,7 +4,7 @@ package testdata import "fmt" func GoconstA() { - a := "needconst" // ERROR "string `needconst` has 5 occurrences, make it a constant" + a := "needconst" // want "string `needconst` has 5 occurrences, make it a constant" fmt.Print(a) b := "needconst" fmt.Print(b) @@ -22,7 +22,7 @@ func GoconstB() { const AlreadyHasConst = "alreadyhasconst" func GoconstC() { - a := "alreadyhasconst" // ERROR "string `alreadyhasconst` has 3 occurrences, but such constant `AlreadyHasConst` already exists" + a := "alreadyhasconst" // want "string `alreadyhasconst` has 3 occurrences, but such constant `AlreadyHasConst` already exists" fmt.Print(a) b := "alreadyhasconst" fmt.Print(b) diff --git a/test/testdata/goconst_calls_enabled.go b/test/testdata/goconst_calls_enabled.go index 83df4e78..ea2a85f3 100644 --- a/test/testdata/goconst_calls_enabled.go +++ b/test/testdata/goconst_calls_enabled.go @@ -7,7 +7,7 @@ import "fmt" const FooBar = "foobar" func Baz() { - a := "foobar" // ERROR "string `foobar` has 4 occurrences, but such constant `FooBar` already exists" + a := "foobar" // want "string `foobar` has 4 occurrences, but such constant `FooBar` already exists" fmt.Print(a) b := "foobar" fmt.Print(b) diff --git a/test/testdata/goconst_dont_ignore_test.go b/test/testdata/goconst_dont_ignore_test.go index 72828270..333e67fe 100644 --- a/test/testdata/goconst_dont_ignore_test.go +++ b/test/testdata/goconst_dont_ignore_test.go @@ -8,7 +8,7 @@ import ( ) func TestGoConstA(t *testing.T) { - a := "needconst" // ERROR "string `needconst` has 5 occurrences, make it a constant" + a := "needconst" // want "string `needconst` has 5 occurrences, make it a constant" fmt.Print(a) b := "needconst" fmt.Print(b) @@ -26,7 +26,7 @@ func TestGoConstB(t *testing.T) { const AlreadyHasConst = "alreadyhasconst" func TestGoConstC(t *testing.T) { - a := "alreadyhasconst" // ERROR "string `alreadyhasconst` has 3 occurrences, but such constant `AlreadyHasConst` already exists" + a := "alreadyhasconst" // want "string `alreadyhasconst` has 3 occurrences, but such constant `AlreadyHasConst` already exists" fmt.Print(a) b := "alreadyhasconst" fmt.Print(b) diff --git a/test/testdata/goconst_ignore_test.go b/test/testdata/goconst_ignore_test.go index 5180b62a..bc538bf1 100644 --- a/test/testdata/goconst_ignore_test.go +++ b/test/testdata/goconst_ignore_test.go @@ -1,5 +1,6 @@ //golangcitest:args -Egoconst //golangcitest:config_path testdata/configs/goconst_ignore.yml +//golangcitest:expected_exitcode 0 package testdata import ( diff --git a/test/testdata/gocritic.go b/test/testdata/gocritic.go index d59bc48e..afca6f3c 100644 --- a/test/testdata/gocritic.go +++ b/test/testdata/gocritic.go @@ -8,7 +8,7 @@ import ( "strings" ) -var _ = *flag.Bool("global1", false, "") // ERROR `flagDeref: immediate deref in \*flag.Bool\(.global1., false, ..\) is most likely an error; consider using flag\.BoolVar` +var _ = *flag.Bool("global1", false, "") // want `flagDeref: immediate deref in \*flag.Bool\(.global1., false, ..\) is most likely an error; consider using flag\.BoolVar` type size1 struct { a bool @@ -26,23 +26,23 @@ func gocriticRangeValCopySize1(ss []size1) { } func gocriticRangeValCopySize2(ss []size2) { - for _, s := range ss { // ERROR "rangeValCopy: each iteration copies 2 bytes.*" + for _, s := range ss { // want "rangeValCopy: each iteration copies 2 bytes.*" log.Print(s) } } func gocriticStringSimplify() { s := "Most of the time, travellers worry about their luggage." - s = strings.Replace(s, ",", "", -1) // ERROR "ruleguard: this Replace call can be simplified.*" + s = strings.Replace(s, ",", "", -1) // want "ruleguard: this Replace call can be simplified.*" log.Print(s) } func gocriticDup(x bool) { - if x && x { // ERROR "ruleguard: suspicious identical LHS and RHS.*" + if x && x { // want "ruleguard: suspicious identical LHS and RHS.*" log.Print("x is true") } } func gocriticRuleWrapperFunc() { - strings.Replace("abcabc", "a", "d", -1) // ERROR "ruleguard: this Replace call can be simplified.*" + strings.Replace("abcabc", "a", "d", -1) // want "ruleguard: this Replace call can be simplified.*" } diff --git a/test/testdata/gocyclo.go b/test/testdata/gocyclo.go index 3fd1040e..b37c8f89 100644 --- a/test/testdata/gocyclo.go +++ b/test/testdata/gocyclo.go @@ -4,7 +4,7 @@ package testdata import "net/http" -func GocycloBigComplexity(s string) { // ERROR "cyclomatic complexity .* of func .* is high .*" +func GocycloBigComplexity(s string) { // want "cyclomatic complexity .* of func .* is high .*" if s == http.MethodGet || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" { return } diff --git a/test/testdata/godot.go b/test/testdata/godot.go index ece6e3d2..2cfc41b5 100644 --- a/test/testdata/godot.go +++ b/test/testdata/godot.go @@ -1,7 +1,7 @@ //golangcitest:args -Egodot package testdata -// Godot checks top-level comments // ERROR "Comment should end in a period" +// Godot checks top-level comments // want "Comment should end in a period" func Godot() { // nothing to do here } diff --git a/test/testdata/godox.go b/test/testdata/godox.go index e6f2364d..05dc554b 100644 --- a/test/testdata/godox.go +++ b/test/testdata/godox.go @@ -3,11 +3,11 @@ package testdata func todoLeftInCode() { - // 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` + // TODO implement me // want `Line contains FIXME/TODO: "TODO implement me` + //TODO no space // want `Line contains FIXME/TODO: "TODO no space` + // TODO(author): 123 // want `Line contains FIXME/TODO: "TODO\(author\): 123` + //TODO(author): 123 // want `Line contains FIXME/TODO: "TODO\(author\): 123` + //TODO(author) 456 // want `Line contains FIXME/TODO: "TODO\(author\) 456` + // TODO: qwerty // want `Line contains FIXME/TODO: "TODO: qwerty` + // todo 789 // want `Line contains FIXME/TODO: "todo 789` } diff --git a/test/testdata/goerr113.go b/test/testdata/goerr113.go index 28c13990..12124512 100644 --- a/test/testdata/goerr113.go +++ b/test/testdata/goerr113.go @@ -4,17 +4,17 @@ package testdata import "os" func SimpleEqual(e1, e2 error) bool { - return e1 == e2 // ERROR `err113: do not compare errors directly "e1 == e2", use "errors.Is\(e1, e2\)" instead` + return e1 == e2 // want `err113: do not compare errors directly "e1 == e2", use "errors.Is\(e1, e2\)" instead` } func SimpleNotEqual(e1, e2 error) bool { - return e1 != e2 // ERROR `err113: do not compare errors directly "e1 != e2", use "!errors.Is\(e1, e2\)" instead` + return e1 != e2 // want `err113: do not compare errors directly "e1 != e2", use "!errors.Is\(e1, e2\)" instead` } func CheckGoerr13Import(e error) bool { f, err := os.Create("f.txt") if err != nil { - return err == e // ERROR `err113: do not compare errors directly "err == e", use "errors.Is\(err, e\)" instead` + return err == e // want `err113: do not compare errors directly "err == e", use "errors.Is\(err, e\)" instead` } f.Close() return false diff --git a/test/testdata/gofmt.go b/test/testdata/gofmt.go index cf4bef61..877d9017 100644 --- a/test/testdata/gofmt.go +++ b/test/testdata/gofmt.go @@ -5,5 +5,5 @@ import "fmt" func GofmtNotSimplified() { var x []string - fmt.Print(x[1:len(x)]) // ERROR "File is not `gofmt`-ed with `-s`" + fmt.Print(x[1:len(x)]) // want "File is not `gofmt`-ed with `-s`" } diff --git a/test/testdata/gofmt_no_simplify.go b/test/testdata/gofmt_no_simplify.go index 423e6048..0d68bf18 100644 --- a/test/testdata/gofmt_no_simplify.go +++ b/test/testdata/gofmt_no_simplify.go @@ -9,5 +9,5 @@ func GofmtNotSimplifiedOk() { fmt.Print(x[1:len(x)]) } -func GofmtBadFormat(){ // ERROR "^File is not `gofmt`-ed" +func GofmtBadFormat(){ // want "^File is not `gofmt`-ed" } diff --git a/test/testdata/gofumpt.go b/test/testdata/gofumpt.go index 4570a2bc..73528d21 100644 --- a/test/testdata/gofumpt.go +++ b/test/testdata/gofumpt.go @@ -4,5 +4,5 @@ package testdata import "fmt" func GofumptNewLine() { - fmt.Println( "foo" ) // ERROR "File is not `gofumpt`-ed" + fmt.Println( "foo" ) // want "File is not `gofumpt`-ed" } diff --git a/test/testdata/gofumpt_with_extra.go b/test/testdata/gofumpt_with_extra.go index 9fdab582..4671f41e 100644 --- a/test/testdata/gofumpt_with_extra.go +++ b/test/testdata/gofumpt_with_extra.go @@ -4,6 +4,6 @@ package testdata import "fmt" -func GofmtNotExtra(bar string, baz string) { // ERROR "File is not `gofumpt`-ed with `-extra`" +func GofmtNotExtra(bar string, baz string) { // want "File is not `gofumpt`-ed with `-extra`" fmt.Print("foo") } diff --git a/test/testdata/goimports.go b/test/testdata/goimports.go index 39eb0f6c..63f657c0 100644 --- a/test/testdata/goimports.go +++ b/test/testdata/goimports.go @@ -2,7 +2,7 @@ package testdata import ( - "fmt" // ERROR "File is not `goimports`-ed" + "fmt" // want "File is not `goimports`-ed" "github.com/golangci/golangci-lint/pkg/config" ) diff --git a/test/testdata/goimports/goimports.go b/test/testdata/goimports/goimports.go deleted file mode 100644 index a94b76c2..00000000 --- a/test/testdata/goimports/goimports.go +++ /dev/null @@ -1,16 +0,0 @@ -//golangcitest:args -Egoimports -//golangcitest:config_path testdata/configs/goimports.yml -package goimports - -import ( - "fmt" - - "github.com/golangci/golangci-lint/pkg/config" - "github.com/pkg/errors" -) - -func GoimportsLocalTest() { - fmt.Print("x") - _ = config.Config{} - _ = errors.New("") -} diff --git a/test/testdata/goimports_local.go b/test/testdata/goimports_local.go new file mode 100644 index 00000000..8d9bd41b --- /dev/null +++ b/test/testdata/goimports_local.go @@ -0,0 +1,16 @@ +//golangcitest:args -Egoimports +//golangcitest:config_path testdata/configs/goimports_local.yml +package testdata + +import ( + "fmt" + + "github.com/golangci/golangci-lint/pkg/config" // want "File is not `goimports`-ed with -local github.com/golangci/golangci-lint" + "github.com/pkg/errors" +) + +func GoimportsLocalPrefixTest() { + fmt.Print("x") + _ = config.Config{} + _ = errors.New("") +} diff --git a/test/testdata/golint.go b/test/testdata/golint.go index 2671f2e8..feb52f00 100644 --- a/test/testdata/golint.go +++ b/test/testdata/golint.go @@ -1,7 +1,7 @@ //golangcitest:args -Egolint --internal-cmd-test package testdata -var Go_lint string // ERROR "don't use underscores in Go names; var `Go_lint` should be `GoLint`" +var Go_lint string // want "don't use underscores in Go names; var `Go_lint` should be `GoLint`" func ExportedFuncWithNoComment() { } @@ -19,4 +19,4 @@ type GolintTest struct{} func (receiver1 GolintTest) A() {} -func (receiver2 GolintTest) B() {} // ERROR "receiver name receiver2 should be consistent with previous receiver name receiver1 for GolintTest" +func (receiver2 GolintTest) B() {} // want "receiver name receiver2 should be consistent with previous receiver name receiver1 for GolintTest" diff --git a/test/testdata/gomnd.go b/test/testdata/gomnd.go index 26e53f29..589c53bb 100644 --- a/test/testdata/gomnd.go +++ b/test/testdata/gomnd.go @@ -9,14 +9,14 @@ import ( func UseMagicNumber() { c := &http.Client{ - Timeout: 2 * time.Second, // ERROR "Magic number: 2, in detected" + Timeout: 2 * time.Second, // want "Magic number: 2, in detected" } res, err := c.Get("http://www.google.com") if err != nil { log.Fatal(err) } - if res.StatusCode != 200 { // ERROR "Magic number: 200, in detected" + if res.StatusCode != 200 { // want "Magic number: 200, in detected" log.Println("Something went wrong") } } diff --git a/test/testdata/gomodguard.go b/test/testdata/gomodguard.go index 64bfdc02..a4c18c4c 100644 --- a/test/testdata/gomodguard.go +++ b/test/testdata/gomodguard.go @@ -6,7 +6,7 @@ import ( "log" "golang.org/x/mod/modfile" - "gopkg.in/yaml.v3" // ERROR "import of package `gopkg.in/yaml.v3` is blocked because the module is in the blocked modules list. `github.com/kylelemons/go-gypsy` is a recommended module. This is an example of recommendations." + "gopkg.in/yaml.v3" // want "import of package `gopkg.in/yaml.v3` is blocked because the module is in the blocked modules list. `github.com/kylelemons/go-gypsy` is a recommended module. This is an example of recommendations." ) // Something just some struct diff --git a/test/testdata/goprintffuncname.go b/test/testdata/goprintffuncname.go index 4a80ba06..221e7319 100644 --- a/test/testdata/goprintffuncname.go +++ b/test/testdata/goprintffuncname.go @@ -1,5 +1,5 @@ //golangcitest:args -Egoprintffuncname package testdata -func PrintfLikeFuncWithBadName(format string, args ...interface{}) { // ERROR "printf-like formatting function 'PrintfLikeFuncWithBadName' should be named 'PrintfLikeFuncWithBadNamef'" +func PrintfLikeFuncWithBadName(format string, args ...interface{}) { // want "printf-like formatting function 'PrintfLikeFuncWithBadName' should be named 'PrintfLikeFuncWithBadNamef'" } diff --git a/test/testdata/gosec.go b/test/testdata/gosec.go index f8282cfb..7e660728 100644 --- a/test/testdata/gosec.go +++ b/test/testdata/gosec.go @@ -2,7 +2,7 @@ package testdata import ( - "crypto/md5" // ERROR "G501: Blocklisted import crypto/md5: weak cryptographic primitive" + "crypto/md5" // want "G501: Blocklisted import crypto/md5: weak cryptographic primitive" "fmt" "log" "os" @@ -10,7 +10,7 @@ import ( ) func Gosec() { - h := md5.New() // ERROR "G401: Use of weak cryptographic primitive" + h := md5.New() // want "G401: Use of weak cryptographic primitive" log.Print(h) } @@ -34,5 +34,5 @@ func GosecG204SubprocWithFunc() { return "/tmp/dummy" } - exec.Command("ls", arg()).Run() // ERROR "G204: Subprocess launched with a potential tainted input or cmd arguments" + exec.Command("ls", arg()).Run() // want "G204: Subprocess launched with a potential tainted input or cmd arguments" } diff --git a/test/testdata/gosec_rules_config.go b/test/testdata/gosec_rules_config.go index 3eea8114..75845b6d 100644 --- a/test/testdata/gosec_rules_config.go +++ b/test/testdata/gosec_rules_config.go @@ -5,8 +5,8 @@ package testdata import "io/ioutil" const gosecToken = "62ebc7a03d6ca24dca1258fd4b48462f6fed1545" -const gosecSimple = "62ebc7a03d6ca24dca1258fd4b48462f6fed1545" // ERROR "G101: Potential hardcoded credentials" +const gosecSimple = "62ebc7a03d6ca24dca1258fd4b48462f6fed1545" // want "G101: Potential hardcoded credentials" func gosecCustom() { - ioutil.WriteFile("filename", []byte("test"), 0755) // ERROR "G306: Expect WriteFile permissions to be 0666 or less" + ioutil.WriteFile("filename", []byte("test"), 0755) // want "G306: Expect WriteFile permissions to be 0666 or less" } diff --git a/test/testdata/gosec_severity_confidence.go b/test/testdata/gosec_severity_confidence.go index 1b72dcea..ee1ed957 100644 --- a/test/testdata/gosec_severity_confidence.go +++ b/test/testdata/gosec_severity_confidence.go @@ -11,7 +11,7 @@ import ( var url string = "https://www.abcdefghijk.com" func gosecVariableURL() { - resp, err := http.Get(url) // ERROR "G107: Potential HTTP request made with variable url" + resp, err := http.Get(url) // want "G107: Potential HTTP request made with variable url" if err != nil { panic(err) } diff --git a/test/testdata/gosimple.go b/test/testdata/gosimple.go index 51ebf15d..970b1fdc 100644 --- a/test/testdata/gosimple.go +++ b/test/testdata/gosimple.go @@ -6,7 +6,7 @@ import ( ) func Gosimple(ss []string) { - if ss != nil { // ERROR "S1031: unnecessary nil check around range" + if ss != nil { // want "S1031: unnecessary nil check around range" for _, s := range ss { log.Printf(s) } diff --git a/test/testdata/govet.go b/test/testdata/govet.go index 53c0e35d..c09fd42f 100644 --- a/test/testdata/govet.go +++ b/test/testdata/govet.go @@ -9,12 +9,12 @@ import ( ) func GovetComposites() error { - return &os.PathError{"first", "path", os.ErrNotExist} // ERROR "composites: io/fs\\.PathError struct literal uses unkeyed fields" + return &os.PathError{"first", "path", os.ErrNotExist} // want "composites: io/fs\\.PathError struct literal uses unkeyed fields" } func GovetShadow(f io.Reader, buf []byte) (err error) { if f != nil { - _, err := f.Read(buf) // ERROR `shadow: declaration of .err. shadows declaration at line \d+` + _, err := f.Read(buf) // want `shadow: declaration of .err. shadows declaration at line \d+` if err != nil { return err } @@ -34,10 +34,10 @@ func GovetNolintVetShadow() error { func GovetPrintf() { x := "dummy" - fmt.Printf("%d", x) // ERROR "printf: fmt.Printf format %d has arg x of wrong type string" + fmt.Printf("%d", x) // want "printf: fmt.Printf format %d has arg x of wrong type string" } func GovetStringIntConv() { i := 42 - fmt.Println("i = " + string(i)) // ERROR "stringintconv: conversion from int to string yields a string of one rune, not a string of digits \\(did you mean fmt.Sprint\\(x\\)\\?\\)" + fmt.Println("i = " + string(i)) // want "stringintconv: conversion from int to string yields a string of one rune, not a string of digits \\(did you mean fmt.Sprint\\(x\\)\\?\\)" } diff --git a/test/testdata/govet_fieldalignment.go b/test/testdata/govet_fieldalignment.go index e7d6ffce..cb7f2af2 100644 --- a/test/testdata/govet_fieldalignment.go +++ b/test/testdata/govet_fieldalignment.go @@ -8,7 +8,7 @@ type gvfaGood struct { z byte } -type gvfaBad struct { // ERROR "struct of size 12 could be 8" +type gvfaBad struct { // want "struct of size 12 could be 8" x byte y int32 z byte @@ -19,7 +19,7 @@ type gvfaPointerGood struct { buf [1000]uintptr } -type gvfaPointerBad struct { // ERROR "struct with 8008 pointer bytes could be 8" +type gvfaPointerBad struct { // want "struct with 8008 pointer bytes could be 8" buf [1000]uintptr P *int } @@ -35,7 +35,7 @@ type gvfaPointerSorta struct { } } -type gvfaPointerSortaBad struct { // ERROR "struct with 32 pointer bytes could be 24" +type gvfaPointerSortaBad struct { // want "struct with 32 pointer bytes could be 24" a struct { p *int q [2]uintptr @@ -51,7 +51,7 @@ type gvfaZeroGood struct { b uint32 } -type gvfaZeroBad struct { // ERROR "struct of size 8 could be 4" +type gvfaZeroBad struct { // want "struct of size 8 could be 4" a uint32 b [0]byte } diff --git a/test/testdata/govet_ifaceassert.go b/test/testdata/govet_ifaceassert.go index fc8910e3..f495719c 100644 --- a/test/testdata/govet_ifaceassert.go +++ b/test/testdata/govet_ifaceassert.go @@ -10,5 +10,5 @@ func GovetIfaceAssert() { var v interface { Read() } - _ = v.(io.Reader) // ERROR "impossible type assertion: no type can implement both interface\\{Read\\(\\)\\} and io\\.Reader \\(conflicting types for Read method\\)" + _ = v.(io.Reader) // want "impossible type assertion: no type can implement both interface\\{Read\\(\\)\\} and io\\.Reader \\(conflicting types for Read method\\)" } diff --git a/test/testdata/ifshort.go b/test/testdata/ifshort.go index edff1bbe..20d79759 100644 --- a/test/testdata/ifshort.go +++ b/test/testdata/ifshort.go @@ -4,7 +4,7 @@ package testdata func DontUseShortSyntaxWhenPossible() { getValue := func() interface{} { return nil } - v := getValue() // ERROR "variable 'v' is only used in the if-statement .*" + v := getValue() // want "variable 'v' is only used in the if-statement .*" if v != nil { return } diff --git a/test/testdata/importas.go b/test/testdata/importas.go index 259d8226..20dfe1bc 100644 --- a/test/testdata/importas.go +++ b/test/testdata/importas.go @@ -3,11 +3,11 @@ package testdata import ( - wrong_alias "fmt" // ERROR `import "fmt" imported as "wrong_alias" but must be "fff" according to config` + wrong_alias "fmt" // want `import "fmt" imported as "wrong_alias" but must be "fff" according to config` "os" - wrong_alias_again "os" // ERROR `import "os" imported as "wrong_alias_again" but must be "std_os" according to config` + wrong_alias_again "os" // want `import "os" imported as "wrong_alias_again" but must be "std_os" according to config` - wrong "github.com/pkg/errors" // ERROR `import "github.com/pkg/errors" imported as "wrong" but must be "pkgerr" according to config` + wrong "github.com/pkg/errors" // want `import "github.com/pkg/errors" imported as "wrong" but must be "pkgerr" according to config` ) func ImportAsWrongAlias() { diff --git a/test/testdata/importas_noalias.go b/test/testdata/importas_noalias.go index 29554fce..a40fc1b9 100644 --- a/test/testdata/importas_noalias.go +++ b/test/testdata/importas_noalias.go @@ -1,5 +1,6 @@ //golangcitest:args -Eimportas //golangcitest:config_path testdata/configs/importas_noalias.yml +//golangcitest:expected_exitcode 0 package testdata import ( diff --git a/test/testdata/importas_strict.go b/test/testdata/importas_strict.go index ce801870..b381837c 100644 --- a/test/testdata/importas_strict.go +++ b/test/testdata/importas_strict.go @@ -3,11 +3,11 @@ package testdata import ( - wrong_alias "fmt" // ERROR `import "fmt" imported as "wrong_alias" but must be "fff" according to config` - "os" // ERROR `import "os" imported without alias but must be with alias "std_os" according to config` - wrong_alias_again "os" // ERROR `import "os" imported as "wrong_alias_again" but must be "std_os" according to config` + wrong_alias "fmt" // want `import "fmt" imported as "wrong_alias" but must be "fff" according to config` + "os" // want `import "os" imported without alias but must be with alias "std_os" according to config` + wrong_alias_again "os" // want `import "os" imported as "wrong_alias_again" but must be "std_os" according to config` - wrong "github.com/pkg/errors" // ERROR `import "github.com/pkg/errors" imported as "wrong" but must be "pkgerr" according to config` + wrong "github.com/pkg/errors" // want `import "github.com/pkg/errors" imported as "wrong" but must be "pkgerr" according to config` ) func ImportAsStrictWrongAlias() { diff --git a/test/testdata/ineffassign.go b/test/testdata/ineffassign.go index 96f7c949..7d4d6bd8 100644 --- a/test/testdata/ineffassign.go +++ b/test/testdata/ineffassign.go @@ -7,7 +7,7 @@ func _() { x := math.MinInt8 for { _ = x - x = 0 // ERROR "ineffectual assignment to x" + x = 0 // want "ineffectual assignment to x" x = 0 } } diff --git a/test/testdata/interfacer.go b/test/testdata/interfacer.go index c53b84a5..59e64e35 100644 --- a/test/testdata/interfacer.go +++ b/test/testdata/interfacer.go @@ -3,6 +3,6 @@ package testdata import "io" -func InterfacerCheck(f io.ReadCloser) { // ERROR "`f` can be `io.Closer`" +func InterfacerCheck(f io.ReadCloser) { // want "`f` can be `io.Closer`" f.Close() } diff --git a/test/testdata/ireturn_allow.go b/test/testdata/ireturn_allow.go index 3667f1c9..0ffc4d75 100644 --- a/test/testdata/ireturn_allow.go +++ b/test/testdata/ireturn_allow.go @@ -1,5 +1,6 @@ //golangcitest:args -Eireturn //golangcitest:config_path testdata/configs/ireturn.yml +//golangcitest:expected_exitcode 0 package testdata type ( diff --git a/test/testdata/ireturn_default.go b/test/testdata/ireturn_default.go index 0b6fb80d..e2b4c436 100644 --- a/test/testdata/ireturn_default.go +++ b/test/testdata/ireturn_default.go @@ -6,7 +6,7 @@ type ( ireturnDoer struct{} ) -func New() IreturnDoer { return new(ireturnDoer) } // ERROR `New returns interface \(command-line-arguments.IreturnDoer\)` +func New() IreturnDoer { return new(ireturnDoer) } // want `New returns interface \(command-line-arguments.IreturnDoer\)` func (d *ireturnDoer) Do() { /*...*/ } func Newer() *ireturnDoer { return new(ireturnDoer) } diff --git a/test/testdata/ireturn_reject_stdlib.go b/test/testdata/ireturn_reject_stdlib.go index 3bda7feb..8f09e785 100644 --- a/test/testdata/ireturn_reject_stdlib.go +++ b/test/testdata/ireturn_reject_stdlib.go @@ -7,7 +7,7 @@ import ( "io" ) -func NewWriter() io.Writer { // ERROR `NewWriter returns interface \(io.Writer\)` +func NewWriter() io.Writer { // want `NewWriter returns interface \(io.Writer\)` var buf bytes.Buffer return &buf } diff --git a/test/testdata/lll.go b/test/testdata/lll.go index 331e78d5..001da2e3 100644 --- a/test/testdata/lll.go +++ b/test/testdata/lll.go @@ -3,5 +3,5 @@ package testdata func Lll() { - // In my experience, long lines are the lines with comments, not the code. So this is a long comment // ERROR "line is 138 characters" + // In my experience, long lines are the lines with comments, not the code. So this is a long comment // want "line is 137 characters" } diff --git a/test/testdata/maintidx.go b/test/testdata/maintidx.go index 68106aa0..ce26ab21 100644 --- a/test/testdata/maintidx.go +++ b/test/testdata/maintidx.go @@ -4,7 +4,7 @@ package testdata func over20() { } -func under20() { // ERROR "Function name: under20, Cyclomatic Complexity: 76, Halstead Volume: 1636.00, Maintainability Index: 17" +func under20() { // want "Function name: under20, Cyclomatic Complexity: 76, Halstead Volume: 1636.00, Maintainability Index: 17" for true { if false { if false { diff --git a/test/testdata/maintidx_under_100.go b/test/testdata/maintidx_under_100.go index d8fe4486..72af2e39 100644 --- a/test/testdata/maintidx_under_100.go +++ b/test/testdata/maintidx_under_100.go @@ -2,10 +2,10 @@ //golangcitest:config_path testdata/configs/maintidx_under_100.yml package testdata -func over20() { // ERROR "Function name: over20, Cyclomatic Complexity: 1, Halstead Volume: 8.00, Maintainability Index: 86" +func over20() { // want "Function name: over20, Cyclomatic Complexity: 1, Halstead Volume: 8.00, Maintainability Index: 86" } -func under20() { // ERROR "Function name: under20, Cyclomatic Complexity: 76, Halstead Volume: 1636.00, Maintainability Index: 17" +func under20() { // want "Function name: under20, Cyclomatic Complexity: 76, Halstead Volume: 1636.00, Maintainability Index: 17" for true { if false { if false { diff --git a/test/testdata/makezero.go b/test/testdata/makezero.go index 12560359..a654b94a 100644 --- a/test/testdata/makezero.go +++ b/test/testdata/makezero.go @@ -5,13 +5,13 @@ import "math" func Makezero() []int { x := make([]int, math.MaxInt8) - return append(x, 1) // ERROR "append to slice `x` with non-zero initialized length" + return append(x, 1) // want "append to slice `x` with non-zero initialized length" } func MakezeroMultiple() []int { x, y := make([]int, math.MaxInt8), make([]int, math.MaxInt8) - return append(x, // ERROR "append to slice `x` with non-zero initialized length" - append(y, 1)...) // ERROR "append to slice `y` with non-zero initialized length" + return append(x, // want "append to slice `x` with non-zero initialized length" + append(y, 1)...) // want "append to slice `y` with non-zero initialized length" } func MakezeroNolint() []int { diff --git a/test/testdata/makezero_always.go b/test/testdata/makezero_always.go index 89093e0f..80396b44 100644 --- a/test/testdata/makezero_always.go +++ b/test/testdata/makezero_always.go @@ -5,7 +5,7 @@ package testdata import "math" func MakezeroAlways() []int { - x := make([]int, math.MaxInt8) // ERROR "slice `x` does not have non-zero initial length" + x := make([]int, math.MaxInt8) // want "slice `x` does not have non-zero initial length" return x } diff --git a/test/testdata/maligned.go b/test/testdata/maligned.go index 74586588..553fd53a 100644 --- a/test/testdata/maligned.go +++ b/test/testdata/maligned.go @@ -1,7 +1,7 @@ //golangcitest:args -Emaligned --internal-cmd-test package testdata -type BadAlignedStruct struct { // ERROR "struct of size 24 bytes could be of size 16 bytes" +type BadAlignedStruct struct { // want "struct of size 24 bytes could be of size 16 bytes" B bool I int B2 bool diff --git a/test/testdata/misspell.go b/test/testdata/misspell.go index 3e9f43d1..a866f117 100644 --- a/test/testdata/misspell.go +++ b/test/testdata/misspell.go @@ -3,7 +3,7 @@ package testdata func Misspell() { - // comment with incorrect spelling: occured // ERROR "`occured` is a misspelling of `occurred`" + // comment with incorrect spelling: occured // want "`occured` is a misspelling of `occurred`" } // the word langauge should be ignored here: it's set in config diff --git a/test/testdata/nakedret.go b/test/testdata/nakedret.go index eac9ff53..fc9e9043 100644 --- a/test/testdata/nakedret.go +++ b/test/testdata/nakedret.go @@ -31,7 +31,7 @@ func NakedretIssue() (a int, b string) { // ... // len of this function is 31 - return // ERROR "naked return in func `NakedretIssue` with 31 lines of code" + return // want "naked return in func `NakedretIssue` with 31 lines of code" } func NoNakedretIssue() (a int, b string) { diff --git a/test/testdata/nestif.go b/test/testdata/nestif.go index 5dc7da32..e930f13c 100644 --- a/test/testdata/nestif.go +++ b/test/testdata/nestif.go @@ -5,19 +5,19 @@ package testdata func _() { var b1, b2, b3, b4 bool - if b1 { // ERROR "`if b1` has complex nested blocks \\(complexity: 1\\)" + if b1 { // want "`if b1` has complex nested blocks \\(complexity: 1\\)" if b2 { // +1 } } - if b1 { // ERROR "`if b1` has complex nested blocks \\(complexity: 3\\)" + if b1 { // want "`if b1` has complex nested blocks \\(complexity: 3\\)" if b2 { // +1 if b3 { // +2 } } } - if b1 { // ERROR "`if b1` has complex nested blocks \\(complexity: 5\\)" + if b1 { // want "`if b1` has complex nested blocks \\(complexity: 5\\)" if b2 { // +1 } else if b3 { // +1 if b4 { // +2 @@ -26,7 +26,7 @@ func _() { } } - if b1 { // ERROR "`if b1` has complex nested blocks \\(complexity: 9\\)" + if b1 { // want "`if b1` has complex nested blocks \\(complexity: 9\\)" if b2 { // +1 if b3 { // +2 } @@ -40,7 +40,7 @@ func _() { } } - if b1 == b2 == b3 { // ERROR "`if b1 == b2 == b3` has complex nested blocks \\(complexity: 1\\)" + if b1 == b2 == b3 { // want "`if b1 == b2 == b3` has complex nested blocks \\(complexity: 1\\)" if b4 { // +1 } } diff --git a/test/testdata/nilerr.go b/test/testdata/nilerr.go index 1b71ce19..98597c9a 100644 --- a/test/testdata/nilerr.go +++ b/test/testdata/nilerr.go @@ -6,7 +6,7 @@ import "os" func nilErr1() error { err := nilErrDo() if err == nil { - return err // ERROR `error is nil \(line 7\) but it returns error` + return err // want `error is nil \(line 7\) but it returns error` } return nil @@ -15,7 +15,7 @@ func nilErr1() error { func nilErr2() error { err := nilErrDo() if err == nil { - return err // ERROR `error is nil \(line 16\) but it returns error` + return err // want `error is nil \(line 16\) but it returns error` } return nil @@ -24,7 +24,7 @@ func nilErr2() error { func nilErr3() error { err := nilErrDo() if err != nil { - return nil // ERROR `error is not nil \(line 25\) but it returns nil` + return nil // want `error is not nil \(line 25\) but it returns nil` } return nil diff --git a/test/testdata/nilnil.go b/test/testdata/nilnil.go index 0a174d5b..fd62faf5 100644 --- a/test/testdata/nilnil.go +++ b/test/testdata/nilnil.go @@ -9,70 +9,70 @@ import ( type User struct{} func primitivePtr() (*int, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func structPtr() (*User, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func emptyStructPtr() (*struct{}, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func anonymousStructPtr() (*struct{ ID string }, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func chBi() (chan int, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func chIn() (chan<- int, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func chOut() (<-chan int, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func fun() (func(), error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func funWithArgsAndResults() (func(a, b, c int) (int, int), error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func iface() (interface{}, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func m1() (map[int]int, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func m2() (map[int]*User, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } type Storage struct{} func (s *Storage) GetUser() (*User, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func ifReturn() (*User, error) { var s Storage if _, err := s.GetUser(); err != nil { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } return new(User), nil } func forReturn() (*User, error) { for { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } } @@ -80,15 +80,15 @@ func multipleReturn() (*User, error) { var s Storage if _, err := s.GetUser(); err != nil { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } if _, err := s.GetUser(); err != nil { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } if _, err := s.GetUser(); err != nil { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } return new(User), nil @@ -96,11 +96,11 @@ func multipleReturn() (*User, error) { func nested() { _ = func() (*User, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } _, _ = func() (*User, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" }() } @@ -111,7 +111,7 @@ func deeplyNested() { _ = func() (*User, error) { _ = func() {} _ = func() int { return 0 } - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } } return 0 @@ -128,23 +128,23 @@ type ( ) func structPtrType() (StructPtrType, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func primitivePtrType() (PrimitivePtrType, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func channelType() (ChannelType, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func funcType() (FuncType, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func ifaceType() (Checker, error) { - return nil, nil // ERROR "return both the `nil` error and invalid value: use a sentinel error instead" + return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead" } func withoutArgs() {} diff --git a/test/testdata/nlreturn-block-size.go b/test/testdata/nlreturn-block-size.go index 1321ab63..85cac539 100644 --- a/test/testdata/nlreturn-block-size.go +++ b/test/testdata/nlreturn-block-size.go @@ -15,7 +15,7 @@ func foo1(n int) int { if n == 1 { n2 := n * n n3 := n2 * n - return n3 // ERROR "return with no blank line before" + return n3 // want "return with no blank line before" } return 1 diff --git a/test/testdata/nlreturn.go b/test/testdata/nlreturn.go index 884ef775..7580062e 100644 --- a/test/testdata/nlreturn.go +++ b/test/testdata/nlreturn.go @@ -17,7 +17,7 @@ func cha() { { a := 1 _ = a - return // ERROR "return with no blank line before" + return // want "return with no blank line before" } return @@ -29,9 +29,9 @@ func cha() { { a := 1 _ = a - return // ERROR "return with no blank line before" + return // want "return with no blank line before" } - return // ERROR "return with no blank line before" + return // want "return with no blank line before" } } @@ -40,11 +40,11 @@ func baz() { case 0: a := 1 _ = a - fallthrough // ERROR "fallthrough with no blank line before" + fallthrough // want "fallthrough with no blank line before" case 1: a := 1 _ = a - break // ERROR "break with no blank line before" + break // want "break with no blank line before" case 2: break } @@ -60,7 +60,7 @@ func foo() int { for range v { return 0 } - return 0 // ERROR "return with no blank line before" + return 0 // want "return with no blank line before" } o := []int{ @@ -76,7 +76,7 @@ func bar() int { if o == 0 { return 1 } - return 0 // ERROR "return with no blank line before" + return 0 // want "return with no blank line before" } return o @@ -94,7 +94,7 @@ func bugNoAssignSmthHandling() string { }{ "foo", } - return o.foo // ERROR "return with no blank line before" + return o.foo // want "return with no blank line before" case 1: o := struct { @@ -115,7 +115,7 @@ func bugNoExprSmthHandling(string) { bugNoExprSmthHandling( "", ) - return // ERROR "return with no blank line before" + return // want "return with no blank line before" case 1: bugNoExprSmthHandling( @@ -132,7 +132,7 @@ func bugNoDeferSmthHandling(string) { defer bugNoDeferSmthHandling( "", ) - return // ERROR "return with no blank line before" + return // want "return with no blank line before" case 1: defer bugNoDeferSmthHandling( @@ -149,7 +149,7 @@ func bugNoGoSmthHandling(string) { go bugNoGoSmthHandling( "", ) - return // ERROR "return with no blank line before" + return // want "return with no blank line before" case 1: go bugNoGoSmthHandling( diff --git a/test/testdata/noctx.go b/test/testdata/noctx.go index 70323c4f..8b077a56 100644 --- a/test/testdata/noctx.go +++ b/test/testdata/noctx.go @@ -13,25 +13,25 @@ func Noctx() { cli := &http.Client{} ctx := context.Background() - http.Get(url) // ERROR `net/http\.Get must not be called` + http.Get(url) // want `net/http\.Get must not be called` _ = http.Get // OK f := http.Get // OK - f(url) // ERROR `net/http\.Get must not be called` + f(url) // want `net/http\.Get must not be called` - http.Head(url) // ERROR `net/http\.Head must not be called` - http.Post(url, "", nil) // ERROR `net/http\.Post must not be called` - http.PostForm(url, nil) // ERROR `net/http\.PostForm must not be called` + http.Head(url) // want `net/http\.Head must not be called` + http.Post(url, "", nil) // want `net/http\.Post must not be called` + http.PostForm(url, nil) // want `net/http\.PostForm must not be called` - cli.Get(url) // ERROR `\(\*net/http\.Client\)\.Get must not be called` + cli.Get(url) // want `\(\*net/http\.Client\)\.Get must not be called` _ = cli.Get // OK m := cli.Get // OK - m(url) // ERROR `\(\*net/http\.Client\)\.Get must not be called` + m(url) // want `\(\*net/http\.Client\)\.Get must not be called` - cli.Head(url) // ERROR `\(\*net/http\.Client\)\.Head must not be called` - cli.Post(url, "", nil) // ERROR `\(\*net/http\.Client\)\.Post must not be called` - cli.PostForm(url, nil) // ERROR `\(\*net/http\.Client\)\.PostForm must not be called` + cli.Head(url) // want `\(\*net/http\.Client\)\.Head must not be called` + cli.Post(url, "", nil) // want `\(\*net/http\.Client\)\.Post must not be called` + cli.PostForm(url, nil) // want `\(\*net/http\.Client\)\.PostForm must not be called` - req, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` cli.Do(req) req2, _ := http.NewRequestWithContext(ctx, http.MethodPost, url, nil) // OK @@ -44,7 +44,7 @@ func Noctx() { f2 := func(req *http.Request, ctx context.Context) *http.Request { return req } - req4, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req4, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` req4 = f2(req4, ctx) req41, _ := http.NewRequest(http.MethodPost, url, nil) // OK @@ -52,21 +52,21 @@ func Noctx() { req41 = f2(req41, ctx) newRequest := http.NewRequest - req5, _ := newRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req5, _ := newRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` cli.Do(req5) req51, _ := newRequest(http.MethodPost, url, nil) // OK req51 = req51.WithContext(ctx) cli.Do(req51) - req52, _ := newRequestPkg(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req52, _ := newRequestPkg(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` cli.Do(req52) type MyRequest = http.Request f3 := func(req *MyRequest, ctx context.Context) *MyRequest { return req } - req6, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req6, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` req6 = f3(req6, ctx) req61, _ := http.NewRequest(http.MethodPost, url, nil) // OK @@ -77,7 +77,7 @@ func Noctx() { f4 := func(req *MyRequest2, ctx context.Context) *MyRequest2 { return req } - req7, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req7, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` req71 := MyRequest2(*req7) f4(&req71, ctx) @@ -87,7 +87,7 @@ func Noctx() { f4(&req73, ctx) req8, _ := func() (*http.Request, error) { - return http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + return http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` }() cli.Do(req8) @@ -101,30 +101,30 @@ func Noctx() { f5 := func(req, req2 *http.Request, ctx context.Context) (*http.Request, *http.Request) { return req, req2 } - req9, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req9, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` req9, _ = f5(req9, req9, ctx) req91, _ := http.NewRequest(http.MethodPost, url, nil) // OK req91 = req91.WithContext(ctx) req9, _ = f5(req91, req91, ctx) - req10, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` - req11, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req10, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req11, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` req10, req11 = f5(req10, req11, ctx) - req101, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req101, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` req111, _ := http.NewRequest(http.MethodPost, url, nil) // OK req111 = req111.WithContext(ctx) req101, req111 = f5(req101, req111, ctx) func() (*http.Request, *http.Request) { - req12, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` - req13, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req12, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req13, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` return req12, req13 }() func() (*http.Request, *http.Request) { - req14, _ := http.NewRequest(http.MethodPost, url, nil) // ERROR `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req14, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` req15, _ := http.NewRequest(http.MethodPost, url, nil) // OK req15 = req15.WithContext(ctx) diff --git a/test/testdata/nolintlint.go b/test/testdata/nolintlint.go index da5537f0..719576b7 100644 --- a/test/testdata/nolintlint.go +++ b/test/testdata/nolintlint.go @@ -6,9 +6,9 @@ package testdata import "fmt" func Foo() { - fmt.Println("not specific") //nolint // ERROR "directive `.*` should mention specific linter such as `//nolint:my-linter`" - fmt.Println("not machine readable") // nolint // ERROR "directive `.*` should be written as `//nolint`" - fmt.Println("extra spaces") // nolint:deadcode // because // ERROR "directive `.*` should not have more than one leading space" + fmt.Println("not specific") //nolint // want "directive `.*` should mention specific linter such as `//nolint:my-linter`" + fmt.Println("not machine readable") // nolint // want "directive `.*` should be written as `//nolint`" + fmt.Println("extra spaces") // nolint:deadcode // because // want "directive `.*` should not have more than one leading space" // test expanded range //nolint:misspell // deliberate misspelling to trigger nolintlint diff --git a/test/testdata/nolintlint_unused.go b/test/testdata/nolintlint_unused.go index 34c32ae9..285d341e 100644 --- a/test/testdata/nolintlint_unused.go +++ b/test/testdata/nolintlint_unused.go @@ -6,7 +6,7 @@ package testdata import "fmt" func Foo() { - fmt.Println("unused") //nolint:all // ERROR "directive `//nolint .*` is unused" - fmt.Println("unused,specific") //nolint:varcheck // ERROR "directive `//nolint:varcheck .*` is unused for linter varcheck" + fmt.Println("unused") //nolint:all // want "directive `//nolint .*` is unused" + fmt.Println("unused,specific") //nolint:varcheck // want "directive `//nolint:varcheck .*` is unused for linter varcheck" fmt.Println("not run") //nolint:unparam // unparam is not run so this is ok } diff --git a/test/testdata/nonamedreturns.go b/test/testdata/nonamedreturns.go index 8de01ae1..21666400 100644 --- a/test/testdata/nonamedreturns.go +++ b/test/testdata/nonamedreturns.go @@ -10,7 +10,7 @@ func simple() (err error) { return } -func twoReturnParams() (i int, err error) { // ERROR `named return "i" with type "int" found` +func twoReturnParams() (i int, err error) { // want `named return "i" with type "int" found` defer func() { i = 0 err = nil @@ -32,7 +32,7 @@ func customName() (myName error) { return } -func errorIsNoAssigned() (err error) { // ERROR `named return "err" with type "error" found` +func errorIsNoAssigned() (err error) { // want `named return "err" with type "error" found` defer func() { _ = err processError(err) @@ -46,7 +46,7 @@ func errorIsNoAssigned() (err error) { // ERROR `named return "err" with type "e return } -func shadowVariable() (err error) { // ERROR `named return "err" with type "error" found` +func shadowVariable() (err error) { // want `named return "err" with type "error" found` defer func() { err := errors.New("xxx") _ = err @@ -65,7 +65,7 @@ func shadowVariableButAssign() (err error) { return } -func shadowVariable2() (err error) { // ERROR `named return "err" with type "error" found` +func shadowVariable2() (err error) { // want `named return "err" with type "error" found` defer func() { a, err := doSomething() _ = a @@ -85,7 +85,7 @@ func errorAliasIsTheSame() (err errorAlias) { type myError error // linter doesn't check underlying type (yet?) -func customTypeWithErrorUnderline() (err myError) { // ERROR `named return "err" with type "myError" found` +func customTypeWithErrorUnderline() (err myError) { // want `named return "err" with type "myError" found` defer func() { err = nil }() @@ -94,7 +94,7 @@ func customTypeWithErrorUnderline() (err myError) { // ERROR `named return "err" type myError2 interface{ error } // linter doesn't check interfaces -func customTypeWithTheSameInterface() (err myError2) { // ERROR `named return "err" with type "myError2" found` +func customTypeWithTheSameInterface() (err myError2) { // want `named return "err" with type "myError2" found` defer func() { err = nil }() @@ -107,7 +107,7 @@ type myError3 struct{} // linter doesn't check interfaces func (m myError3) Error() string { return "" } -func customTypeImplementingErrorInterface() (err myError3) { // ERROR `named return "err" with type "myError3" found` +func customTypeImplementingErrorInterface() (err myError3) { // want `named return "err" with type "myError3" found` defer func() { err = struct{}{} }() @@ -118,7 +118,7 @@ func shadowErrorType() { type error interface { // linter understands that this is not built-in error, even if it has the same name Error() string } - do := func() (err error) { // ERROR `named return "err" with type "error" found` + do := func() (err error) { // want `named return "err" with type "error" found` defer func() { err = nil }() @@ -150,14 +150,14 @@ func twoErrorsSeparated() (err1 error, err2 error) { return } -func errorSlice() (err []error) { // ERROR `named return "err" with type "\[\]error" found` +func errorSlice() (err []error) { // want `named return "err" with type "\[\]error" found` defer func() { err = nil }() return } -func deferWithVariable() (err error) { // ERROR `named return "err" with type "error" found` +func deferWithVariable() (err error) { // want `named return "err" with type "error" found` f := func() { err = nil } @@ -165,7 +165,7 @@ func deferWithVariable() (err error) { // ERROR `named return "err" with type "e return } -func uberMultierr() (err error) { // ERROR `named return "err" with type "error" found` +func uberMultierr() (err error) { // want `named return "err" with type "error" found` defer func() { multierrAppendInto(&err, nil) // linter doesn't allow it (yet?) }() @@ -243,7 +243,7 @@ var goodFuncLiteral = func() (err error) { return } -var badFuncLiteral = func() (err error) { // ERROR `named return "err" with type "error" found` +var badFuncLiteral = func() (err error) { // want `named return "err" with type "error" found` defer func() { _ = err }() @@ -269,7 +269,7 @@ func (x) goodMethod() (err error) { return } -func (x) badMethod() (err error) { // ERROR `named return "err" with type "error" found` +func (x) badMethod() (err error) { // want `named return "err" with type "error" found` defer func() { _ = err }() diff --git a/test/testdata/nonamedreturns_custom.go b/test/testdata/nonamedreturns_custom.go index c4bb4f6f..9040e313 100644 --- a/test/testdata/nonamedreturns_custom.go +++ b/test/testdata/nonamedreturns_custom.go @@ -20,7 +20,7 @@ var d = func() error { return nil } -var e = func() (err error) { // ERROR `named return "err" with type "error" found` +var e = func() (err error) { // want `named return "err" with type "error" found` err = nil return } @@ -29,7 +29,7 @@ var e2 = func() (_ error) { return } -func deferWithError() (err error) { // ERROR `named return "err" with type "error" found` +func deferWithError() (err error) { // want `named return "err" with type "error" found` defer func() { err = nil // use flag to allow this }() @@ -45,7 +45,7 @@ var ( return nil } - h = func() (err error) { // ERROR `named return "err" with type "error" found` + h = func() (err error) { // want `named return "err" with type "error" found` err = nil return } @@ -62,11 +62,11 @@ func funcDefintionImpl(arg1, arg2 interface{}) (int, error) { return 0, nil } -func funcDefintionImpl2(arg1, arg2 interface{}) (num int, err error) { // ERROR `named return "num" with type "int" found` +func funcDefintionImpl2(arg1, arg2 interface{}) (num int, err error) { // want `named return "num" with type "int" found` return 0, nil } -func funcDefintionImpl3(arg1, arg2 interface{}) (num int, _ error) { // ERROR `named return "num" with type "int" found` +func funcDefintionImpl3(arg1, arg2 interface{}) (num int, _ error) { // want `named return "num" with type "int" found` return 0, nil } @@ -74,7 +74,7 @@ func funcDefintionImpl4(arg1, arg2 interface{}) (_ int, _ error) { return 0, nil } -var funcVar = func() (msg string) { // ERROR `named return "msg" with type "string" found` +var funcVar = func() (msg string) { // want `named return "msg" with type "string" found` msg = "c" return msg } @@ -103,12 +103,12 @@ func good(i string) string { return i } -func bad(i string, a, b int) (ret1 string, ret2 interface{}, ret3, ret4 int, ret5 asdf) { // ERROR `named return "ret1" with type "string" found` +func bad(i string, a, b int) (ret1 string, ret2 interface{}, ret3, ret4 int, ret5 asdf) { // want `named return "ret1" with type "string" found` x := "dummy" return fmt.Sprintf("%s", x), nil, 1, 2, asdf{} } -func bad2() (msg string, err error) { // ERROR `named return "msg" with type "string" found` +func bad2() (msg string, err error) { // want `named return "msg" with type "string" found` msg = "" err = nil return @@ -120,6 +120,6 @@ func myLog(format string, args ...interface{}) { type obj struct{} -func (o *obj) func1() (err error) { return nil } // ERROR `named return "err" with type "error" found` +func (o *obj) func1() (err error) { return nil } // want `named return "err" with type "error" found` func (o *obj) func2() (_ error) { return nil } diff --git a/test/testdata/nosnakecase.go b/test/testdata/nosnakecase.go index d74e20b5..5a0d2073 100644 --- a/test/testdata/nosnakecase.go +++ b/test/testdata/nosnakecase.go @@ -3,147 +3,147 @@ package testdata import ( _ "fmt" - f_m_t "fmt" // ERROR "f_m_t contains underscore. You should use mixedCap or MixedCap." + f_m_t "fmt" // want "f_m_t contains underscore. You should use mixedCap or MixedCap." ) // global variable name with underscore. -var v_v = 0 // ERROR "v_v contains underscore. You should use mixedCap or MixedCap." +var v_v = 0 // want "v_v contains underscore. You should use mixedCap or MixedCap." // global constant name with underscore. -const c_c = 0 // ERROR "c_c contains underscore. You should use mixedCap or MixedCap." +const c_c = 0 // want "c_c contains underscore. You should use mixedCap or MixedCap." // struct name with underscore. -type S_a struct { // ERROR "S_a contains underscore. You should use mixedCap or MixedCap." +type S_a struct { // want "S_a contains underscore. You should use mixedCap or MixedCap." fi int } // non-exported struct field name with underscore. type Sa struct { - fi_a int // // ERROR "fi_a contains underscore. You should use mixedCap or MixedCap." + fi_a int // // want "fi_a contains underscore. You should use mixedCap or MixedCap." } // function as struct field, with parameter name with underscore. type Sb struct { - fib func(p_a int) // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." + fib func(p_a int) // want "p_a contains underscore. You should use mixedCap or MixedCap." } // exported struct field with underscore. type Sc struct { - Fi_A int // ERROR "Fi_A contains underscore. You should use mixedCap or MixedCap." + Fi_A int // want "Fi_A contains underscore. You should use mixedCap or MixedCap." } // function as struct field, with return name with underscore. type Sd struct { - fib func(p int) (r_a int) // ERROR "r_a contains underscore. You should use mixedCap or MixedCap." + fib func(p int) (r_a int) // want "r_a contains underscore. You should use mixedCap or MixedCap." } // interface name with underscore. -type I_a interface { // ERROR "I_a contains underscore. You should use mixedCap or MixedCap." +type I_a interface { // want "I_a contains underscore. You should use mixedCap or MixedCap." fn(p int) } // interface with parameter name with underscore. type Ia interface { - fn(p_a int) // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." + fn(p_a int) // want "p_a contains underscore. You should use mixedCap or MixedCap." } // interface with parameter name with underscore. type Ib interface { - Fn(p_a int) // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." + Fn(p_a int) // want "p_a contains underscore. You should use mixedCap or MixedCap." } // function as struct field, with return name with underscore. type Ic interface { - Fn_a() // ERROR "Fn_a contains underscore. You should use mixedCap or MixedCap." + Fn_a() // want "Fn_a contains underscore. You should use mixedCap or MixedCap." } // interface with return name with underscore. type Id interface { - Fn() (r_a int) // ERROR "r_a contains underscore. You should use mixedCap or MixedCap." + Fn() (r_a int) // want "r_a contains underscore. You should use mixedCap or MixedCap." } // function name with underscore. -func f_a() {} // ERROR "f_a contains underscore. You should use mixedCap or MixedCap." +func f_a() {} // want "f_a contains underscore. You should use mixedCap or MixedCap." // function's parameter name with underscore. -func fb(p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." +func fb(p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." // named return with underscore. -func fc() (r_b int) { // ERROR "r_b contains underscore. You should use mixedCap or MixedCap." +func fc() (r_b int) { // want "r_b contains underscore. You should use mixedCap or MixedCap." return 0 } // local variable (short declaration) with underscore. func fd(p int) int { - v_b := p * 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + v_b := p * 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - return v_b // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + return v_b // want "v_b contains underscore. You should use mixedCap or MixedCap." } // local constant with underscore. func fe(p int) int { - const v_b = 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + const v_b = 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - return v_b * p // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + return v_b * p // want "v_b contains underscore. You should use mixedCap or MixedCap." } // local variable with underscore. func ff(p int) int { - var v_b = 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + var v_b = 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - return v_b * p // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + return v_b * p // want "v_b contains underscore. You should use mixedCap or MixedCap." } // inner function, parameter name with underscore. func fg() { - fgl := func(p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." + fgl := func(p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." fgl(1) } type Foo struct{} // method name with underscore. -func (f Foo) f_a() {} // ERROR "f_a contains underscore. You should use mixedCap or MixedCap." +func (f Foo) f_a() {} // want "f_a contains underscore. You should use mixedCap or MixedCap." // method's parameter name with underscore. -func (f Foo) fb(p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." +func (f Foo) fb(p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." // named return with underscore. -func (f Foo) fc() (r_b int) { return 0 } // ERROR "r_b contains underscore. You should use mixedCap or MixedCap." +func (f Foo) fc() (r_b int) { return 0 } // want "r_b contains underscore. You should use mixedCap or MixedCap." // local variable (short declaration) with underscore. func (f Foo) fd(p int) int { - v_b := p * 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + v_b := p * 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - return v_b // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + return v_b // want "v_b contains underscore. You should use mixedCap or MixedCap." } // local constant with underscore. func (f Foo) fe(p int) int { - const v_b = 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + const v_b = 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - return v_b * p // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + return v_b * p // want "v_b contains underscore. You should use mixedCap or MixedCap." } // local variable with underscore. func (f Foo) ff(p int) int { - var v_b = 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + var v_b = 2 // want "v_b contains underscore. You should use mixedCap or MixedCap." - return v_b * p // ERROR "v_b contains underscore. You should use mixedCap or MixedCap." + return v_b * p // want "v_b contains underscore. You should use mixedCap or MixedCap." } -func fna(a, p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." +func fna(a, p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." -func fna1(a string, p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." +func fna1(a string, p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." -func fnb(a, b, p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." +func fnb(a, b, p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." -func fnb1(a, b string, p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." +func fnb1(a, b string, p_a int) {} // want "p_a contains underscore. You should use mixedCap or MixedCap." func fnd( - p_a int, // ERROR "p_a contains underscore. You should use mixedCap or MixedCap." - p_b int, // ERROR "p_b contains underscore. You should use mixedCap or MixedCap." - p_c int, // ERROR "p_c contains underscore. You should use mixedCap or MixedCap." + p_a int, // want "p_a contains underscore. You should use mixedCap or MixedCap." + p_b int, // want "p_b contains underscore. You should use mixedCap or MixedCap." + p_c int, // want "p_c contains underscore. You should use mixedCap or MixedCap." ) { - f_m_t.Println("") // ERROR "f_m_t contains underscore. You should use mixedCap or MixedCap." + f_m_t.Println("") // want "f_m_t contains underscore. You should use mixedCap or MixedCap." } diff --git a/test/testdata/nosprintfhostport.go b/test/testdata/nosprintfhostport.go index 36f23a4a..065519e7 100644 --- a/test/testdata/nosprintfhostport.go +++ b/test/testdata/nosprintfhostport.go @@ -28,20 +28,20 @@ func _() { _ = fmt.Sprintf("http://example.com:9211") - _ = fmt.Sprintf("gopher://%s:%d", "myHost", 70) // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" + _ = fmt.Sprintf("gopher://%s:%d", "myHost", 70) // want "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" - _ = fmt.Sprintf("telnet+ssl://%s:%d", "myHost", 23) // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" + _ = fmt.Sprintf("telnet+ssl://%s:%d", "myHost", 23) // want "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" - _ = fmt.Sprintf("weird3.6://%s:%d", "myHost", 23) // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" + _ = fmt.Sprintf("weird3.6://%s:%d", "myHost", 23) // want "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" - _ = fmt.Sprintf("https://user@%s:%d", "myHost", 8443) // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" + _ = fmt.Sprintf("https://user@%s:%d", "myHost", 8443) // want "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" - _ = fmt.Sprintf("postgres://%s:%s@%s:5050/%s", "foo", "bar", "baz", "qux") // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" + _ = fmt.Sprintf("postgres://%s:%s@%s:5050/%s", "foo", "bar", "baz", "qux") // want "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" - _ = fmt.Sprintf("https://%s:%d", "myHost", 8443) // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" + _ = fmt.Sprintf("https://%s:%d", "myHost", 8443) // want "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" - _ = fmt.Sprintf("https://%s:9211", "myHost") // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" + _ = fmt.Sprintf("https://%s:9211", "myHost") // want "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" ip := "fd00::1" - _ = fmt.Sprintf("http://%s:1936/healthz", ip) // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" + _ = fmt.Sprintf("http://%s:1936/healthz", ip) // want "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" } diff --git a/test/testdata/notcompiles/typecheck.go b/test/testdata/notcompiles/typecheck.go index ec8a56b5..9b498d0e 100644 --- a/test/testdata/notcompiles/typecheck.go +++ b/test/testdata/notcompiles/typecheck.go @@ -1,5 +1,5 @@ //golangcitest:args -Etypecheck package testdata -fun NotCompiles() { // ERROR "expected declaration, found.* fun" +fun NotCompiles() { // want "expected declaration, found.* fun" } diff --git a/test/testdata/notcompiles/typecheck_many_issues.go b/test/testdata/notcompiles/typecheck_many_issues.go index 10cf5e03..b103d65e 100644 --- a/test/testdata/notcompiles/typecheck_many_issues.go +++ b/test/testdata/notcompiles/typecheck_many_issues.go @@ -2,8 +2,8 @@ package testdata func TypeCheckBadCalls() { - typecheckNotExists1.F1() // ERROR "undeclared name: `typecheckNotExists1`" - typecheckNotExists2.F2() // ERROR "undeclared name: `typecheckNotExists2`" - typecheckNotExists3.F3() // ERROR "undeclared name: `typecheckNotExists3`" - typecheckNotExists4.F4() // ERROR "undeclared name: `typecheckNotExists4`" + typecheckNotExists1.F1() // want "undeclared name: `typecheckNotExists1`" + typecheckNotExists2.F2() // want "undeclared name: `typecheckNotExists2`" + typecheckNotExists3.F3() // want "undeclared name: `typecheckNotExists3`" + typecheckNotExists4.F4() // want "undeclared name: `typecheckNotExists4`" } diff --git a/test/testdata/paralleltest.go b/test/testdata/paralleltest.go index 5f3dac31..bd31b054 100644 --- a/test/testdata/paralleltest.go +++ b/test/testdata/paralleltest.go @@ -21,4 +21,4 @@ func TestFunctionSuccessfulRangeTest(t *testing.T) { } } -func TestFunctionMissingCallToParallel(t *testing.T) {} // ERROR "Function TestFunctionMissingCallToParallel missing the call to method parallel" +func TestFunctionMissingCallToParallel(t *testing.T) {} // want "Function TestFunctionMissingCallToParallel missing the call to method parallel" diff --git a/test/testdata/prealloc.go b/test/testdata/prealloc.go index 8c55b9cf..a17cbfcc 100644 --- a/test/testdata/prealloc.go +++ b/test/testdata/prealloc.go @@ -2,7 +2,7 @@ package testdata func Prealloc(source []int) []int { - var dest []int // ERROR "Consider pre-allocating `dest`" + var dest []int // want "Consider pre-allocating `dest`" for _, v := range source { dest = append(dest, v) } diff --git a/test/testdata/predeclared.go b/test/testdata/predeclared.go index b68e0893..2c722780 100644 --- a/test/testdata/predeclared.go +++ b/test/testdata/predeclared.go @@ -2,9 +2,9 @@ package testdata func hello() { - var real int // ERROR "variable real has same name as predeclared identifier" + var real int // want "variable real has same name as predeclared identifier" a := A{} - copy := Clone(a) // ERROR "variable copy has same name as predeclared identifier" + copy := Clone(a) // want "variable copy has same name as predeclared identifier" // suppress any "declared but not used" errors _ = real @@ -24,4 +24,4 @@ func Clone(a A) A { } } -func recover() {} // ERROR "function recover has same name as predeclared identifier" +func recover() {} // want "function recover has same name as predeclared identifier" diff --git a/test/testdata/predeclared_custom.go b/test/testdata/predeclared_custom.go index 656c1f1b..6b54b5b8 100644 --- a/test/testdata/predeclared_custom.go +++ b/test/testdata/predeclared_custom.go @@ -5,7 +5,7 @@ package testdata func hello() { var real int a := A{} - copy := Clone(a) // ERROR "variable copy has same name as predeclared identifier" + copy := Clone(a) // want "variable copy has same name as predeclared identifier" // suppress any "declared but not used" errors _ = real @@ -14,7 +14,7 @@ func hello() { } type A struct { - true bool // ERROR "field true has same name as predeclared identifier" + true bool // want "field true has same name as predeclared identifier" foo int } diff --git a/test/testdata/promlinter.go b/test/testdata/promlinter.go index 26974453..1ff3c711 100644 --- a/test/testdata/promlinter.go +++ b/test/testdata/promlinter.go @@ -8,26 +8,26 @@ import ( var ( _ = promauto.NewCounterVec( - prometheus.CounterOpts{ // ERROR `Metric: test_metric_name Error: counter metrics should have "_total" suffix` + prometheus.CounterOpts{ // want `Metric: test_metric_name Error: counter metrics should have "_total" suffix` Name: "test_metric_name", Help: "test help text", }, []string{}, ) _ = promauto.NewCounterVec( - prometheus.CounterOpts{ // ERROR "Metric: test_metric_total Error: no help text" + prometheus.CounterOpts{ // want "Metric: test_metric_total Error: no help text" Name: "test_metric_total", }, []string{}, ) _ = promauto.NewCounterVec( - prometheus.CounterOpts{ // ERROR `Metric: metric_type_in_name_counter_total Error: metric name should not include type 'counter'` + prometheus.CounterOpts{ // want `Metric: metric_type_in_name_counter_total Error: metric name should not include type 'counter'` Name: "metric_type_in_name_counter_total", Help: "foo", }, []string{}, ) - _ = prometheus.NewHistogram(prometheus.HistogramOpts{ // ERROR `Metric: test_duration_milliseconds Error: use base unit "seconds" instead of "milliseconds"` + _ = prometheus.NewHistogram(prometheus.HistogramOpts{ // want `Metric: test_duration_milliseconds Error: use base unit "seconds" instead of "milliseconds"` Name: "test_duration_milliseconds", Help: "", }) diff --git a/test/testdata/revive.go b/test/testdata/revive.go index 82bc2672..8f497a89 100644 --- a/test/testdata/revive.go +++ b/test/testdata/revive.go @@ -15,7 +15,7 @@ func SampleRevive(t *time.Duration) error { } } -func testReviveComplexity(s string) { // ERROR "cyclomatic: function testReviveComplexity has cyclomatic complexity 22" +func testReviveComplexity(s string) { // want "cyclomatic: function testReviveComplexity has cyclomatic complexity 22" if s == http.MethodGet || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" { return } diff --git a/test/testdata/revive_default.go b/test/testdata/revive_default.go index e8986b1b..a29d96c1 100644 --- a/test/testdata/revive_default.go +++ b/test/testdata/revive_default.go @@ -9,7 +9,7 @@ import ( func testReviveDefault(t *time.Duration) error { if t == nil { return nil - } else { // ERROR "indent-error-flow: if block ends with a return statement, .*" + } else { // want "indent-error-flow: if block ends with a return statement, .*" return nil } } diff --git a/test/testdata/rowserrcheck.go b/test/testdata/rowserrcheck.go index 95c597af..6e9c68dc 100644 --- a/test/testdata/rowserrcheck.go +++ b/test/testdata/rowserrcheck.go @@ -8,7 +8,7 @@ import ( ) func RowsErrNotChecked(db *sql.DB) { - rows, _ := db.Query("select id from tb") // ERROR "rows.Err must be checked" + rows, _ := db.Query("select id from tb") // want "rows.Err must be checked" for rows.Next() { } diff --git a/test/testdata/scopelint.go b/test/testdata/scopelint.go index 931e31ea..3afd2f06 100644 --- a/test/testdata/scopelint.go +++ b/test/testdata/scopelint.go @@ -8,7 +8,7 @@ func ScopelintTest() { var funcs []func() for _, val := range values { funcs = append(funcs, func() { - fmt.Println(val) // ERROR "Using the variable on range scope `val` in function literal" + fmt.Println(val) // want "Using the variable on range scope `val` in function literal" }) } for _, f := range funcs { diff --git a/test/testdata/sqlclosecheck.go b/test/testdata/sqlclosecheck.go index 8ad73a93..6bbe3291 100644 --- a/test/testdata/sqlclosecheck.go +++ b/test/testdata/sqlclosecheck.go @@ -69,7 +69,7 @@ func rowsCorrectDefer() { } func rowsMissingClose() { - rows, err := db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age) // ERROR "Rows/Stmt was not closed" + rows, err := db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age) // want "Rows/Stmt was not closed" if err != nil { log.Fatal(err) } @@ -112,7 +112,7 @@ func rowsNonDeferClose() { } log.Printf("%s are %d years old", strings.Join(names, ", "), age) - rows.Close() // ERROR "Close should use defer" + rows.Close() // want "Close should use defer" } func rowsPassedAndClosed() { @@ -202,7 +202,7 @@ func stmtCorrectDefer() { func stmtMissingClose() { // In normal use, create one Stmt when your process starts. - stmt, err := db.PrepareContext(ctx, "SELECT username FROM users WHERE id = ?") // ERROR "Rows/Stmt was not closed" + stmt, err := db.PrepareContext(ctx, "SELECT username FROM users WHERE id = ?") // want "Rows/Stmt was not closed" if err != nil { log.Fatal(err) } @@ -240,7 +240,7 @@ func stmtNonDeferClose() { log.Printf("username is %s\n", username) } - stmt.Close() // ERROR "Close should use defer" + stmt.Close() // want "Close should use defer" } func stmtReturn() (*sql.Stmt, error) { diff --git a/test/testdata/staticcheck.go b/test/testdata/staticcheck.go index bf1b4e39..2782ce14 100644 --- a/test/testdata/staticcheck.go +++ b/test/testdata/staticcheck.go @@ -7,7 +7,7 @@ import ( func Staticcheck() { var x int - x = x // ERROR "self-assignment of x to x" + x = x // want "self-assignment of x to x" fmt.Printf("%d", x) } @@ -23,5 +23,5 @@ func StaticcheckNolintMegacheck() { func StaticcheckPrintf() { x := "dummy" - fmt.Printf("%d", x) // ERROR "SA5009: Printf format %d has arg #1 of wrong type" + fmt.Printf("%d", x) // want "SA5009: Printf format %d has arg #1 of wrong type" } diff --git a/test/testdata/staticcheck_in_megacheck.go b/test/testdata/staticcheck_in_megacheck.go index 7c984127..355d2a38 100644 --- a/test/testdata/staticcheck_in_megacheck.go +++ b/test/testdata/staticcheck_in_megacheck.go @@ -5,7 +5,7 @@ import "fmt" func StaticcheckInMegacheck() { var x int - x = x // ERROR staticcheck "self-assignment of x to x" + x = x // want staticcheck:"self-assignment of x to x" fmt.Printf("%d", x) } @@ -21,6 +21,6 @@ func StaticcheckNolintMegacheckInMegacheck() { func Staticcheck2() { var x int - x = x // ERROR staticcheck "self-assignment of x to x" + x = x // want staticcheck:"self-assignment of x to x" fmt.Printf("%d", x) } diff --git a/test/testdata/structcheck.go b/test/testdata/structcheck.go index 8e403b9e..88f06e4d 100644 --- a/test/testdata/structcheck.go +++ b/test/testdata/structcheck.go @@ -2,5 +2,5 @@ package testdata type t struct { - unusedField int // ERROR "`unusedField` is unused" + unusedField int // want "`unusedField` is unused" } diff --git a/test/testdata/stylecheck.go b/test/testdata/stylecheck.go index 9df377ee..44a8cd1f 100644 --- a/test/testdata/stylecheck.go +++ b/test/testdata/stylecheck.go @@ -5,7 +5,7 @@ func Stylecheck(x int) { switch x { case 1: return - default: // ERROR "ST1015: default case should be first or last in switch statement" + default: // want "ST1015: default case should be first or last in switch statement" return case 2: return @@ -27,7 +27,7 @@ func StylecheckNolintMegacheck(x int) { switch x { case 1: return - default: //nolint:megacheck // ERROR "ST1015: default case should be first or last in switch statement" + default: //nolint:megacheck // want "ST1015: default case should be first or last in switch statement" return case 2: return diff --git a/test/testdata/stylecheck_not_in_megacheck.go b/test/testdata/stylecheck_not_in_megacheck.go index f1379efe..18dbae90 100644 --- a/test/testdata/stylecheck_not_in_megacheck.go +++ b/test/testdata/stylecheck_not_in_megacheck.go @@ -1,4 +1,5 @@ //golangcitest:args -Emegacheck +//golangcitest:expected_exitcode 0 package testdata func StylecheckNotInMegacheck(x int) { diff --git a/test/testdata/tagliatelle.go b/test/testdata/tagliatelle.go index bc3320f1..2c32360f 100644 --- a/test/testdata/tagliatelle.go +++ b/test/testdata/tagliatelle.go @@ -4,8 +4,8 @@ package testdata import "time" type TglFoo struct { - ID string `json:"ID"` // ERROR `json\(camel\): got 'ID' want 'id'` - UserID string `json:"UserID"` // ERROR `json\(camel\): got 'UserID' want 'userId'` + ID string `json:"ID"` // want `json\(camel\): got 'ID' want 'id'` + UserID string `json:"UserID"` // want `json\(camel\): got 'UserID' want 'userId'` Name string `json:"name"` Value time.Duration `json:"value,omitempty"` Bar TglBar `json:"bar"` @@ -15,7 +15,7 @@ type TglFoo struct { type TglBar struct { Name string `json:"-"` Value string `json:"value"` - CommonServiceFooItem *TglBir `json:"CommonServiceItem,omitempty"` // ERROR `json\(camel\): got 'CommonServiceItem' want 'commonServiceItem'` + CommonServiceFooItem *TglBir `json:"CommonServiceItem,omitempty"` // want `json\(camel\): got 'CommonServiceItem' want 'commonServiceItem'` } type TglBir struct { @@ -26,7 +26,7 @@ type TglBir struct { type Bur struct { Name string - Value string `yaml:"Value"` // ERROR `yaml\(camel\): got 'Value' want 'value'` + Value string `yaml:"Value"` // want `yaml\(camel\): got 'Value' want 'value'` More string `json:"-"` Also string `json:"also,omitempty"` ReqPerS string `avro:"req_per_s"` diff --git a/test/testdata/tenv.go b/test/testdata/tenv.go index 3ae19de9..7023ead8 100644 --- a/test/testdata/tenv.go +++ b/test/testdata/tenv.go @@ -21,28 +21,28 @@ func setup() { } func TestF(t *testing.T) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" _ = err } } func BenchmarkF(b *testing.B) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" _ = err } } func testTB(tb testing.TB) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" _ = err } } diff --git a/test/testdata/tenv_all.go b/test/testdata/tenv_all.go index 3ae19de9..7023ead8 100644 --- a/test/testdata/tenv_all.go +++ b/test/testdata/tenv_all.go @@ -21,28 +21,28 @@ func setup() { } func TestF(t *testing.T) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" _ = err } } func BenchmarkF(b *testing.B) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" _ = err } } func testTB(tb testing.TB) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" _ = err } } diff --git a/test/testdata/tenv_all_test.go b/test/testdata/tenv_all_test.go index d39c27eb..b370915f 100644 --- a/test/testdata/tenv_all_test.go +++ b/test/testdata/tenv_all_test.go @@ -12,37 +12,37 @@ var ( ) func setup() { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup" _ = err } } func TestF(t *testing.T) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" _ = err } } func BenchmarkF(b *testing.B) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" _ = err } } func testTB(tb testing.TB) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" _ = err } } diff --git a/test/testdata/tenv_go118.go b/test/testdata/tenv_go118.go index 0f143f72..bcdf9dca 100644 --- a/test/testdata/tenv_go118.go +++ b/test/testdata/tenv_go118.go @@ -10,10 +10,10 @@ import ( ) func FuzzF(f *testing.F) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `f\\.Setenv\\(\\)` in FuzzF" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `f\\.Setenv\\(\\)` in FuzzF" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `f\\.Setenv\\(\\)` in FuzzF" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `f\\.Setenv\\(\\)` in FuzzF" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `f\\.Setenv\\(\\)` in FuzzF" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `f\\.Setenv\\(\\)` in FuzzF" _ = err } } diff --git a/test/testdata/tenv_test.go b/test/testdata/tenv_test.go index 0e2a1d04..76f358fd 100644 --- a/test/testdata/tenv_test.go +++ b/test/testdata/tenv_test.go @@ -20,28 +20,28 @@ func setup() { } func TestF(t *testing.T) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" _ = err } } func BenchmarkF(b *testing.B) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" _ = err } } func testTB(tb testing.TB) { - os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" - err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" _ = err - if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" + if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" _ = err } } diff --git a/test/testdata/testpackage_test.go b/test/testdata/testpackage_test.go index c5be3346..d40aa1e1 100644 --- a/test/testdata/testpackage_test.go +++ b/test/testdata/testpackage_test.go @@ -1,2 +1,2 @@ //golangcitest:args -Etestpackage -package testdata // ERROR "package should be `testdata_test` instead of `testdata`" +package testdata // want "package should be `testdata_test` instead of `testdata`" diff --git a/test/testdata/thelper.go b/test/testdata/thelper.go index c5a4760e..6458ab2d 100644 --- a/test/testdata/thelper.go +++ b/test/testdata/thelper.go @@ -3,42 +3,42 @@ package testdata import "testing" -func thelperWithHelperAfterAssignment(t *testing.T) { // ERROR "test helper function should start from t.Helper()" +func thelperWithHelperAfterAssignment(t *testing.T) { // want "test helper function should start from t.Helper()" _ = 0 t.Helper() } -func thelperWithNotFirst(s string, t *testing.T, i int) { // ERROR `parameter \*testing.T should be the first` +func thelperWithNotFirst(s string, t *testing.T, i int) { // want `parameter \*testing.T should be the first` t.Helper() } -func thelperWithIncorrectName(o *testing.T) { // ERROR `parameter \*testing.T should have name t` +func thelperWithIncorrectName(o *testing.T) { // want `parameter \*testing.T should have name t` o.Helper() } -func bhelperWithHelperAfterAssignment(b *testing.B) { // ERROR "test helper function should start from b.Helper()" +func bhelperWithHelperAfterAssignment(b *testing.B) { // want "test helper function should start from b.Helper()" _ = 0 b.Helper() } -func bhelperWithNotFirst(s string, b *testing.B, i int) { // ERROR `parameter \*testing.B should be the first` +func bhelperWithNotFirst(s string, b *testing.B, i int) { // want `parameter \*testing.B should be the first` b.Helper() } -func bhelperWithIncorrectName(o *testing.B) { // ERROR `parameter \*testing.B should have name b` +func bhelperWithIncorrectName(o *testing.B) { // want `parameter \*testing.B should have name b` o.Helper() } -func tbhelperWithHelperAfterAssignment(tb testing.TB) { // ERROR "test helper function should start from tb.Helper()" +func tbhelperWithHelperAfterAssignment(tb testing.TB) { // want "test helper function should start from tb.Helper()" _ = 0 tb.Helper() } -func tbhelperWithNotFirst(s string, tb testing.TB, i int) { // ERROR `parameter testing.TB should be the first` +func tbhelperWithNotFirst(s string, tb testing.TB, i int) { // want `parameter testing.TB should be the first` tb.Helper() } -func tbhelperWithIncorrectName(o testing.TB) { // ERROR `parameter testing.TB should have name tb` +func tbhelperWithIncorrectName(o testing.TB) { // want `parameter testing.TB should have name tb` o.Helper() } diff --git a/test/testdata/thelper_go118.go b/test/testdata/thelper_go118.go index e61c68ee..bea2adf9 100644 --- a/test/testdata/thelper_go118.go +++ b/test/testdata/thelper_go118.go @@ -6,16 +6,16 @@ package testdata import "testing" -func fhelperWithHelperAfterAssignment(f *testing.F) { // ERROR "test helper function should start from f.Helper()" +func fhelperWithHelperAfterAssignment(f *testing.F) { // want "test helper function should start from f.Helper()" _ = 0 f.Helper() } -func fhelperWithNotFirst(s string, f *testing.F, i int) { // ERROR `parameter \*testing.F should be the first` +func fhelperWithNotFirst(s string, f *testing.F, i int) { // want `parameter \*testing.F should be the first` f.Helper() } -func fhelperWithIncorrectName(o *testing.F) { // ERROR `parameter \*testing.F should have name f` +func fhelperWithIncorrectName(o *testing.F) { // want `parameter \*testing.F should have name f` o.Helper() } diff --git a/test/testdata/thelper_with_options.go b/test/testdata/thelper_with_options.go index 83c1586e..cf39e8a9 100644 --- a/test/testdata/thelper_with_options.go +++ b/test/testdata/thelper_with_options.go @@ -4,12 +4,12 @@ package testdata import "testing" -func thelperWithHelperAfterAssignmentWO(t *testing.T) { // ERROR "test helper function should start from t.Helper()" +func thelperWithHelperAfterAssignmentWO(t *testing.T) { // want "test helper function should start from t.Helper()" _ = 0 t.Helper() } -func thelperWithNotFirstWO(s string, t *testing.T, i int) { // ERROR `parameter \*testing.T should be the first` +func thelperWithNotFirstWO(s string, t *testing.T, i int) { // want `parameter \*testing.T should be the first` t.Helper() } diff --git a/test/testdata/tparallel/missing_subtest_test.go b/test/testdata/tparallel/missing_subtest_test.go deleted file mode 100644 index 02e791ec..00000000 --- a/test/testdata/tparallel/missing_subtest_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package testdata - -import ( - "testing" -) - -func TestSubtests(t *testing.T) { - t.Parallel() - - t.Run("", func(t *testing.T) { - }) -} diff --git a/test/testdata/tparallel/missing_toplevel_test.go b/test/testdata/tparallel/missing_toplevel_test.go deleted file mode 100644 index 4b9d6e14..00000000 --- a/test/testdata/tparallel/missing_toplevel_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package testdata - -import ( - "testing" -) - -func TestTopLevel(t *testing.T) { - t.Run("", func(t *testing.T) { - t.Parallel() - }) -} diff --git a/test/testdata/tparallel/happy_path_test.go b/test/testdata/tparallel_happy_path_test.go similarity index 75% rename from test/testdata/tparallel/happy_path_test.go rename to test/testdata/tparallel_happy_path_test.go index 43073e95..cc3f8686 100644 --- a/test/testdata/tparallel/happy_path_test.go +++ b/test/testdata/tparallel_happy_path_test.go @@ -1,3 +1,5 @@ +//golangcitest:args -Etparallel +//golangcitest:expected_exitcode 0 package testdata import ( diff --git a/test/testdata/tparallel_missing_subtest_test.go b/test/testdata/tparallel_missing_subtest_test.go new file mode 100644 index 00000000..44f7275f --- /dev/null +++ b/test/testdata/tparallel_missing_subtest_test.go @@ -0,0 +1,13 @@ +//golangcitest:args -Etparallel +package testdata + +import ( + "testing" +) + +func TestSubtests(t *testing.T) { // want "TestSubtests's subtests should call t.Parallel" + t.Parallel() + + t.Run("", func(t *testing.T) { + }) +} diff --git a/test/testdata/tparallel_missing_toplevel_test.go b/test/testdata/tparallel_missing_toplevel_test.go new file mode 100644 index 00000000..fbf4ac5d --- /dev/null +++ b/test/testdata/tparallel_missing_toplevel_test.go @@ -0,0 +1,12 @@ +//golangcitest:args -Etparallel +package testdata + +import ( + "testing" +) + +func TestTopLevel(t *testing.T) { // want "TestTopLevel should call t.Parallel on the top level as well as its subtests" + t.Run("", func(t *testing.T) { + t.Parallel() + }) +} diff --git a/test/testdata/unconvert.go b/test/testdata/unconvert.go index ce72581e..bbd7ad09 100644 --- a/test/testdata/unconvert.go +++ b/test/testdata/unconvert.go @@ -5,6 +5,6 @@ import "log" func Unconvert() { a := 1 - b := int(a) // ERROR "unnecessary conversion" + b := int(a) // want "unnecessary conversion" log.Print(b) } diff --git a/test/testdata/unparam.go b/test/testdata/unparam.go index 1cba338f..18eb8e2b 100644 --- a/test/testdata/unparam.go +++ b/test/testdata/unparam.go @@ -1,7 +1,7 @@ //golangcitest:args -Eunparam package testdata -func unparamUnused(a, b uint) uint { // ERROR "`unparamUnused` - `b` is unused" +func unparamUnused(a, b uint) uint { // want "`unparamUnused` - `b` is unused" a++ return a } diff --git a/test/testdata/unused.go b/test/testdata/unused.go index 97aa39d5..d514ea51 100644 --- a/test/testdata/unused.go +++ b/test/testdata/unused.go @@ -1,20 +1,20 @@ //golangcitest:args -Eunused package testdata -func fn1() {} // ERROR "func `fn1` is unused" +func fn1() {} // want "func `fn1` is unused" //nolint:unused func fn2() { fn3() } -func fn3() {} // ERROR "func `fn3` is unused" +func fn3() {} // want "func `fn3` is unused" -func fn4() { fn5() } // ERROR "func `fn4` is unused" +func fn4() { fn5() } // want "func `fn4` is unused" -func fn5() {} // ERROR "func `fn5` is unused" +func fn5() {} // want "func `fn5` is unused" -func fn6() { fn4() } // ERROR "func `fn6` is unused" +func fn6() { fn4() } // want "func `fn6` is unused" -type unusedStruct struct{} // ERROR "type `unusedStruct` is unused" +type unusedStruct struct{} // want "type `unusedStruct` is unused" type unusedStructNolintUnused struct{} //nolint:unused diff --git a/test/testdata/usestdlibvars.go b/test/testdata/usestdlibvars.go index c3c4e463..e9af3c9c 100644 --- a/test/testdata/usestdlibvars.go +++ b/test/testdata/usestdlibvars.go @@ -9,5 +9,5 @@ func _200() { func _200_1() { var w http.ResponseWriter - w.WriteHeader(200) // ERROR `"200" can be replaced by http.StatusOK` + w.WriteHeader(200) // want `"200" can be replaced by http.StatusOK` } diff --git a/test/testdata/varcheck.go b/test/testdata/varcheck.go index 654b7bbb..d4bc8f7b 100644 --- a/test/testdata/varcheck.go +++ b/test/testdata/varcheck.go @@ -1,4 +1,4 @@ //golangcitest:args -Evarcheck package testdata -var v string // ERROR "`v` is unused" +var v string // want "`v` is unused" diff --git a/test/testdata/varnamelen.go b/test/testdata/varnamelen.go index b1f9053a..4afee755 100644 --- a/test/testdata/varnamelen.go +++ b/test/testdata/varnamelen.go @@ -4,7 +4,7 @@ package testdata import "math" func varnamelen() { - x := math.MinInt8 // ERROR "variable name 'x' is too short for the scope of its usage" + x := math.MinInt8 // want "variable name 'x' is too short for the scope of its usage" x++ x++ x++ diff --git a/test/testdata/wastedassign.go b/test/testdata/wastedassign.go index f781d0fc..714f3a63 100644 --- a/test/testdata/wastedassign.go +++ b/test/testdata/wastedassign.go @@ -27,28 +27,28 @@ func noUseParams(params string) int { func f(param int) int { println(param) - useOutOfIf := 1212121 // ERROR "assigned to useOutOfIf, but reassigned without using the value" + useOutOfIf := 1212121 // want "assigned to useOutOfIf, but reassigned without using the value" ret := 0 if false { - useOutOfIf = 200 // ERROR "assigned to useOutOfIf, but never used afterwards" + useOutOfIf = 200 // want "assigned to useOutOfIf, but never used afterwards" return 0 } else if param == 100 { - useOutOfIf = 100 // ERROR "assigned to useOutOfIf, but reassigned without using the value" + useOutOfIf = 100 // want "assigned to useOutOfIf, but reassigned without using the value" useOutOfIf = 201 useOutOfIf = pa(useOutOfIf) - useOutOfIf += 200 // ERROR "assigned to useOutOfIf, but reassigned without using the value" + useOutOfIf += 200 // want "assigned to useOutOfIf, but reassigned without using the value" } else { useOutOfIf = 100 useOutOfIf += 100 useOutOfIf = pa(useOutOfIf) - useOutOfIf += 200 // ERROR "assigned to useOutOfIf, but reassigned without using the value" + useOutOfIf += 200 // want "assigned to useOutOfIf, but reassigned without using the value" } if false { - useOutOfIf = 200 // ERROR "assigned to useOutOfIf, but never used afterwards" + useOutOfIf = 200 // want "assigned to useOutOfIf, but never used afterwards" return 0 } else if param == 200 { - useOutOfIf = 100 // ERROR "assigned to useOutOfIf, but reassigned without using the value" + useOutOfIf = 100 // want "assigned to useOutOfIf, but reassigned without using the value" useOutOfIf = 201 useOutOfIf = pa(useOutOfIf) useOutOfIf += 200 @@ -62,7 +62,7 @@ func f(param int) int { println(useOutOfIf) useOutOfIf = 192 useOutOfIf += 100 - useOutOfIf += 200 // ERROR "assigned to useOutOfIf, but never used afterwards" + useOutOfIf += 200 // want "assigned to useOutOfIf, but never used afterwards" return ret } @@ -71,7 +71,7 @@ func checkLoopTest() int { noUse := 1111 println(noUse) - noUse = 1111 // ERROR "assigned to noUse, but never used afterwards" + noUse = 1111 // want "assigned to noUse, but never used afterwards" for { if hoge == 14 { break @@ -86,21 +86,21 @@ func r(param int) int { useOutOfIf := 1212121 ret := 0 if false { - useOutOfIf = 200 // ERROR "assigned to useOutOfIf, but never used afterwards" + useOutOfIf = 200 // want "assigned to useOutOfIf, but never used afterwards" return 0 } else if param == 100 { ret = useOutOfIf } else if param == 200 { - useOutOfIf = 100 // ERROR "assigned to useOutOfIf, but reassigned without using the value" + useOutOfIf = 100 // want "assigned to useOutOfIf, but reassigned without using the value" useOutOfIf = 100 useOutOfIf = pa(useOutOfIf) - useOutOfIf += 200 // ERROR "assigned to useOutOfIf, but reassigned without using the value" + useOutOfIf += 200 // want "assigned to useOutOfIf, but reassigned without using the value" } useOutOfIf = 12 println(useOutOfIf) useOutOfIf = 192 useOutOfIf += 100 - useOutOfIf += 200 // ERROR "assigned to useOutOfIf, but never used afterwards" + useOutOfIf += 200 // want "assigned to useOutOfIf, but never used afterwards" return ret } @@ -108,7 +108,7 @@ func mugen() { var i int var hoge int for { - hoge = 5 // ERROR "assigned to hoge, but reassigned without using the value" + hoge = 5 // want "assigned to hoge, but reassigned without using the value" // break } diff --git a/test/testdata/wrapcheck.go b/test/testdata/wrapcheck.go index 386fec9f..5615906f 100644 --- a/test/testdata/wrapcheck.go +++ b/test/testdata/wrapcheck.go @@ -8,7 +8,7 @@ import ( func do() error { _, err := json.Marshal(struct{}{}) if err != nil { - return err // ERROR "error returned from external package is unwrapped" + return err // want "error returned from external package is unwrapped" } return nil diff --git a/test/testdata/wsl.go b/test/testdata/wsl.go index 75311c5c..af8d92b7 100644 --- a/test/testdata/wsl.go +++ b/test/testdata/wsl.go @@ -11,46 +11,46 @@ func main() { var ( y = 0 ) - if y < 1 { // ERROR "if statements should only be cuddled with assignments" + if y < 1 { // want "if statements should only be cuddled with assignments" fmt.Println("tight") } thisIsNotUsedInIf := true - if 2 > 1 { // ERROR "if statements should only be cuddled with assignments used in the if statement itself" + if 2 > 1 { // want "if statements should only be cuddled with assignments used in the if statement itself" return } one := 1 two := 2 three := 3 - if three == 3 { // ERROR "only one cuddle assignment allowed before if statement" + if three == 3 { // want "only one cuddle assignment allowed before if statement" fmt.Println("too many cuddled assignments", one, two, thisIsNotUsedInIf) } var a = "a" - var b = "b" // ERROR "declarations should never be cuddled" + var b = "b" // want "declarations should never be cuddled" if true { return } - if false { // ERROR "if statements should only be cuddled with assignments" + if false { // want "if statements should only be cuddled with assignments" return } for i := range make([]int, 10) { fmt.Println(i) fmt.Println(i + i) - continue // ERROR "branch statements should not be cuddled if block has more than two lines" + continue // want "branch statements should not be cuddled if block has more than two lines" } assignOne := a fmt.Println(assignOne) - assignTwo := b // ERROR "assignments should only be cuddled with other assignments" + assignTwo := b // want "assignments should only be cuddled with other assignments" fmt.Println(assignTwo) _, cf1 := context.WithCancel(context.Background()) _, cf2 := context.WithCancel(context.Background()) - defer cf1() // ERROR "only one cuddle assignment allowed before defer statement" + defer cf1() // want "only one cuddle assignment allowed before defer statement" defer cf2() err := multiline( @@ -65,7 +65,7 @@ func main() { "spanning", "multiple", ) - if err != nil { // ERROR "if statements should only be cuddled with assignments used in the if statement itself" + if err != nil { // want "if statements should only be cuddled with assignments used in the if statement itself" panic("not from the line above") } @@ -89,7 +89,7 @@ func f1() int { func f2() int { x := 1 y := 3 - return x + y // ERROR "return statements should not be cuddled if block has more than two lines" + return x + y // want "return statements should not be cuddled if block has more than two lines" } func f3() int { @@ -99,7 +99,7 @@ func f3() int { } notSum := 0 - for _, v := range []int{1, 2, 4} { // ERROR "ranges should only be cuddled with assignments used in the iteration" + for _, v := range []int{1, 2, 4} { // want "ranges should only be cuddled with assignments used in the iteration" sum += v } @@ -133,7 +133,7 @@ func sliceExpr() { } notOk := 1 - if v := aSlice[start]; v == 1 { // ERROR "if statements should only be cuddled with assignments used in the if statement itself" + if v := aSlice[start]; v == 1 { // want "if statements should only be cuddled with assignments used in the if statement itself" fmt.Println("notOk") fmt.Println(notOk) } @@ -153,7 +153,7 @@ func indexExpr() { } xxx := "xxx" - if _, ok := aMap[key]; ok { // ERROR "if statements should only be cuddled with assignments used in the if statement itself" + if _, ok := aMap[key]; ok { // want "if statements should only be cuddled with assignments used in the if statement itself" fmt.Println("not ok") fmt.Println(xxx) } @@ -199,7 +199,7 @@ func IncDecStmt() { } func AnonymousBlock() { - func(a, b int) { // ERROR "block should not start with a whitespace" + func(a, b int) { // want "block should not start with a whitespace" fmt.Println(a + b) }(1, 1) diff --git a/test/testshared/analysis.go b/test/testshared/analysis.go new file mode 100644 index 00000000..77e7d858 --- /dev/null +++ b/test/testshared/analysis.go @@ -0,0 +1,200 @@ +package testshared + +import ( + "encoding/json" + "fmt" + "go/parser" + "go/token" + "os" + "path/filepath" + "regexp" + "sort" + "strconv" + "strings" + "testing" + "text/scanner" + + "github.com/stretchr/testify/require" + + "github.com/golangci/golangci-lint/pkg/result" +) + +const keyword = "want" + +const testdataDir = "testdata" + +type jsonResult struct { + Issues []*result.Issue +} + +type expectation struct { + kind string // either "fact" or "diagnostic" + name string // name of object to which fact belongs, or "package" ("fact" only) + rx *regexp.Regexp +} + +type key struct { + file string + line int +} + +// Analyze analyzes the test expectations ('want'). +// inspired by https://github.com/golang/tools/blob/b3b5c13b291f9653da6f31b95db100a2e26bd186/go/analysis/analysistest/analysistest.go +func Analyze(t *testing.T, sourcePath string, rawData []byte) { + fileData, err := os.ReadFile(sourcePath) + require.NoError(t, err) + + want, err := parseComments(sourcePath, fileData) + require.NoError(t, err) + + var reportData jsonResult + err = json.Unmarshal(rawData, &reportData) + require.NoError(t, err) + + for _, issue := range reportData.Issues { + if !strings.HasPrefix(issue.Pos.Filename, testdataDir) { + issue.Pos.Filename = filepath.Join(testdataDir, issue.Pos.Filename) + } + checkMessage(t, want, issue.Pos, "diagnostic", issue.FromLinter, issue.Text) + } + + var surplus []string + for key, expects := range want { + for _, exp := range expects { + err := fmt.Sprintf("%s:%d: no %s was reported matching %#q", key.file, key.line, exp.kind, exp.rx) + surplus = append(surplus, err) + } + } + + sort.Strings(surplus) + + for _, err := range surplus { + t.Errorf("%s", err) + } +} + +// inspired by https://github.com/golang/tools/blob/b3b5c13b291f9653da6f31b95db100a2e26bd186/go/analysis/analysistest/analysistest.go +func parseComments(sourcePath string, fileData []byte) (map[key][]expectation, error) { + fset := token.NewFileSet() + + // the error is ignored to let 'typecheck' handle compilation error + f, _ := parser.ParseFile(fset, sourcePath, fileData, parser.ParseComments) + + want := make(map[key][]expectation) + + for _, comment := range f.Comments { + for _, c := range comment.List { + text := strings.TrimPrefix(c.Text, "//") + if text == c.Text { // not a //-comment. + text = strings.TrimPrefix(text, "/*") + text = strings.TrimSuffix(text, "*/") + } + + if i := strings.Index(text, "// "+keyword); i >= 0 { + text = text[i+len("// "):] + } + + posn := fset.Position(c.Pos()) + + text = strings.TrimSpace(text) + + if rest := strings.TrimPrefix(text, keyword); rest != text { + delta, expects, err := parseExpectations(rest) + if err != nil { + return nil, err + } + + want[key{sourcePath, posn.Line + delta}] = expects + } + } + } + + return want, nil +} + +// inspired by https://github.com/golang/tools/blob/b3b5c13b291f9653da6f31b95db100a2e26bd186/go/analysis/analysistest/analysistest.go +func parseExpectations(text string) (lineDelta int, expects []expectation, err error) { + var scanErr string + sc := new(scanner.Scanner).Init(strings.NewReader(text)) + sc.Error = func(s *scanner.Scanner, msg string) { + scanErr = msg // e.g. bad string escape + } + sc.Mode = scanner.ScanIdents | scanner.ScanStrings | scanner.ScanRawStrings | scanner.ScanInts + + scanRegexp := func(tok rune) (*regexp.Regexp, error) { + if tok != scanner.String && tok != scanner.RawString { + return nil, fmt.Errorf("got %s, want regular expression", + scanner.TokenString(tok)) + } + pattern, _ := strconv.Unquote(sc.TokenText()) // can't fail + return regexp.Compile(pattern) + } + + for { + tok := sc.Scan() + switch tok { + case '+': + tok = sc.Scan() + if tok != scanner.Int { + return 0, nil, fmt.Errorf("got +%s, want +Int", scanner.TokenString(tok)) + } + lineDelta, _ = strconv.Atoi(sc.TokenText()) + case scanner.String, scanner.RawString: + rx, err := scanRegexp(tok) + if err != nil { + return 0, nil, err + } + expects = append(expects, expectation{"diagnostic", "", rx}) + + case scanner.Ident: + name := sc.TokenText() + tok = sc.Scan() + if tok != ':' { + return 0, nil, fmt.Errorf("got %s after %s, want ':'", + scanner.TokenString(tok), name) + } + tok = sc.Scan() + rx, err := scanRegexp(tok) + if err != nil { + return 0, nil, err + } + expects = append(expects, expectation{"diagnostic", name, rx}) + + case scanner.EOF: + if scanErr != "" { + return 0, nil, fmt.Errorf("%s", scanErr) + } + return lineDelta, expects, nil + + default: + return 0, nil, fmt.Errorf("unexpected %s", scanner.TokenString(tok)) + } + } +} + +// inspired by https://github.com/golang/tools/blob/b3b5c13b291f9653da6f31b95db100a2e26bd186/go/analysis/analysistest/analysistest.go +func checkMessage(t *testing.T, want map[key][]expectation, posn token.Position, kind, name, message string) { + k := key{posn.Filename, posn.Line} + expects := want[k] + var unmatched []string + + for i, exp := range expects { + if exp.kind == kind && (exp.name == "" || exp.name == name) { + if exp.rx.MatchString(message) { + // matched: remove the expectation. + expects[i] = expects[len(expects)-1] + expects = expects[:len(expects)-1] + want[k] = expects + return + } + unmatched = append(unmatched, fmt.Sprintf("%#q", exp.rx)) + } + } + + if unmatched == nil { + t.Errorf("%v: unexpected %s: %v", posn, kind, message) + } else { + t.Errorf("%v: %s %q does not match pattern %s", + posn, kind, message, strings.Join(unmatched, " or ")) + } +} diff --git a/test/testshared/analysis_test.go b/test/testshared/analysis_test.go new file mode 100644 index 00000000..2c7f6966 --- /dev/null +++ b/test/testshared/analysis_test.go @@ -0,0 +1,138 @@ +package testshared + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +//nolint:funlen +func Test_parseComments(t *testing.T) { + testCases := []struct { + filename string + data string + expected map[key][]expectation + }{ + { + filename: "a/b.go", + data: `package main // want package:"found" + +`, + expected: map[key][]expectation{ + {file: "a/b.go", line: 1}: { + {kind: "diagnostic", name: "package", rx: regexp.MustCompile(`found`)}, + }, + }, + }, + { + filename: "a/c.go", + data: `package main + +func main() { + println("hello, world") // want "call of println" +} +`, + expected: map[key][]expectation{ + {file: "a/c.go", line: 4}: { + {kind: "diagnostic", name: "", rx: regexp.MustCompile(`call of println`)}, + }, + }, + }, + { + filename: "a/d.go", + data: `package main + +func main() { + // OK /* */-form. + println("hello") /* want "call of println" */ +} +`, + expected: map[key][]expectation{ + {file: "a/d.go", line: 5}: { + {kind: "diagnostic", name: "", rx: regexp.MustCompile(`call of println`)}, + }, + }, + }, + { + filename: "a/e.go", + data: `package main + +func main() { + // OK (nested comment) + println("hello") // some comment // want "call of println" +} +`, + expected: map[key][]expectation{ + {file: "a/e.go", line: 5}: { + {kind: "diagnostic", name: "", rx: regexp.MustCompile(`call of println`)}, + }, + }, + }, + { + filename: "a/f.go", + data: `package main + +func main() { + // OK (nested comment in /**/) + println("hello") /* some comment // want "call of println" */ +} +`, + expected: map[key][]expectation{ + {file: "a/f.go", line: 5}: { + {kind: "diagnostic", name: "", rx: regexp.MustCompile(`call of println`)}, + }, + }, + }, + { + filename: "a/g.go", + data: `package main + +func main() { + // OK (multiple expectations on same line) + println(); println() // want "call of println(...)" "call of println(...)" +} +`, + expected: map[key][]expectation{ + {file: "a/g.go", line: 5}: { + {kind: "diagnostic", name: "", rx: regexp.MustCompile(`call of println(...)`)}, + {kind: "diagnostic", name: "", rx: regexp.MustCompile(`call of println(...)`)}, + }, + }, + }, + { + filename: "a/h.go", + data: `package main + +func println(...interface{}) { println() } // want println:"found" "call of println(...)" +`, + expected: map[key][]expectation{ + {file: "a/h.go", line: 3}: { + {kind: "diagnostic", name: "println", rx: regexp.MustCompile(`found`)}, + {kind: "diagnostic", name: "", rx: regexp.MustCompile(`call of println(...)`)}, + }, + }, + }, + { + filename: "a/b_test.go", + data: `package main + +// Test file shouldn't mess with things +`, + expected: map[key][]expectation{}, + }, + } + + for _, test := range testCases { + test := test + t.Run(test.filename, func(t *testing.T) { + t.Parallel() + + expectations, err := parseComments(test.filename, []byte(test.data)) + require.NoError(t, err) + + assert.Equal(t, test.expected, expectations) + }) + } +} diff --git a/test/testshared/directives.go b/test/testshared/directives.go index 5599ad6a..b29f305f 100644 --- a/test/testshared/directives.go +++ b/test/testshared/directives.go @@ -5,11 +5,14 @@ import ( "go/build/constraint" "os" "runtime" + "strconv" "strings" "testing" hcversion "github.com/hashicorp/go-version" "github.com/stretchr/testify/require" + + "github.com/golangci/golangci-lint/pkg/exitcodes" ) // RunContext FIXME rename? @@ -17,11 +20,12 @@ type RunContext struct { Args []string ConfigPath string ExpectedLinter string + ExitCode int } // ParseTestDirectives parses test directives from sources files. // -//nolint:gocyclo +//nolint:gocyclo,funlen func ParseTestDirectives(tb testing.TB, sourcePath string) *RunContext { tb.Helper() @@ -29,7 +33,9 @@ func ParseTestDirectives(tb testing.TB, sourcePath string) *RunContext { require.NoError(tb, err) tb.Cleanup(func() { _ = f.Close() }) - rc := &RunContext{} + rc := &RunContext{ + ExitCode: exitcodes.IssuesFound, + } scanner := bufio.NewScanner(f) for scanner.Scan() { @@ -82,6 +88,14 @@ func ParseTestDirectives(tb testing.TB, sourcePath string) *RunContext { rc.ExpectedLinter = after continue + case "//golangcitest:expected_exitcode": + require.NotEmpty(tb, after) + val, err := strconv.Atoi(after) + require.NoError(tb, err) + + rc.ExitCode = val + continue + default: require.Failf(tb, "invalid prefix of comment line %s", line) } diff --git a/test/testshared/directives_test.go b/test/testshared/directives_test.go index fa0c6282..bee856cd 100644 --- a/test/testshared/directives_test.go +++ b/test/testshared/directives_test.go @@ -5,6 +5,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/golangci/golangci-lint/pkg/exitcodes" ) func TestParseTestDirectives(t *testing.T) { @@ -15,6 +17,7 @@ func TestParseTestDirectives(t *testing.T) { Args: []string{"-Efoo", "--simple", "--hello=world"}, ConfigPath: "testdata/example.yml", ExpectedLinter: "bar", + ExitCode: exitcodes.Success, } assert.Equal(t, expected, rc) } diff --git a/test/testshared/runner.go b/test/testshared/runner.go index 1b872e83..06c9e730 100644 --- a/test/testshared/runner.go +++ b/test/testshared/runner.go @@ -3,6 +3,7 @@ package testshared import ( "os" "os/exec" + "path/filepath" "strings" "sync" "syscall" @@ -122,8 +123,8 @@ func (b *RunnerBuilder) WithArgs(args ...string) *RunnerBuilder { return b } -func (b *RunnerBuilder) WithTargetPath(target string) *RunnerBuilder { - b.target = target +func (b *RunnerBuilder) WithTargetPath(targets ...string) *RunnerBuilder { + b.target = filepath.Join(targets...) return b } @@ -233,7 +234,7 @@ func (r *Runner) Run() *RunnerResult { } } -func (r *Runner) RawRun() ([]byte, error) { +func (r *Runner) Command() *exec.Cmd { r.tb.Helper() runArgs := append([]string{r.command}, r.args...) @@ -245,7 +246,7 @@ func (r *Runner) RawRun() ([]byte, error) { cmd := exec.Command("../golangci-lint", runArgs...) cmd.Env = append(os.Environ(), r.env...) - return cmd.CombinedOutput() + return cmd } type RunnerResult struct { @@ -319,6 +320,10 @@ func InstallGolangciLint(tb testing.TB) { cmd := exec.Command("make", "-C", "..", "build") - err := cmd.Run() - assert.NoError(tb, err, "Can't go install golangci-lint") + output, err := cmd.CombinedOutput() + if err != nil { + tb.Log(string(output)) + } + + require.NoError(tb, err, "Can't go install golangci-lint") } diff --git a/test/testshared/runner_test.go b/test/testshared/runner_test.go index 36c1e347..af5fe760 100644 --- a/test/testshared/runner_test.go +++ b/test/testshared/runner_test.go @@ -140,7 +140,7 @@ func TestRunnerBuilder_Runner(t *testing.T) { "--go=1.17", "--internal-cmd-test", "--allow-parallel-runners", - "./testdata/all.go", + "testdata/all.go", }, }, }, diff --git a/test/testshared/testdata/all.go b/test/testshared/testdata/all.go index ca997786..dfc78e1c 100644 --- a/test/testshared/testdata/all.go +++ b/test/testshared/testdata/all.go @@ -1,6 +1,7 @@ //golangcitest:args -Efoo --simple --hello=world //golangcitest:config_path testdata/example.yml //golangcitest:expected_linter bar +//golangcitest:expected_exitcode 0 package testdata import "fmt"