dev: follow standards by using 'want' instead of 'ERROR' for tests (#3104)
This commit is contained in:
parent
57a7e0d7b9
commit
2b4c9ab4fc
2
Makefile
2
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
|
||||
|
18
test/data.go
18
test/data.go
@ -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...)
|
||||
}
|
240
test/errchk.go
240
test/errchk.go
@ -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 <regexp>.
|
||||
// The <regexp> 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("<autogenerated>", 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 (<linter>)".
|
||||
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.
|
||||
// <autogenerated> 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, "<autogenerated>") {
|
||||
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 <autogenerated> 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
|
||||
}
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
82
test/output_test.go
Normal file
82
test/output_test.go
Normal file
@ -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)
|
||||
}
|
132
test/run_test.go
132
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)
|
||||
|
4
test/testdata/asasalint.go
vendored
4
test/testdata/asasalint.go
vendored
@ -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...))
|
||||
}
|
||||
|
8
test/testdata/asciicheck.go
vendored
8
test/testdata/asciicheck.go
vendored
@ -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)
|
||||
}
|
||||
|
2
test/testdata/bidichk.go
vendored
2
test/testdata/bidichk.go
vendored
@ -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"
|
||||
}
|
||||
|
2
test/testdata/bodyclose.go
vendored
2
test/testdata/bodyclose.go
vendored
@ -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)
|
||||
}
|
||||
|
2
test/testdata/containedctx.go
vendored
2
test/testdata/containedctx.go
vendored
@ -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{}
|
||||
|
6
test/testdata/contextcheck.go
vendored
6
test/testdata/contextcheck.go
vendored
@ -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)
|
||||
}
|
||||
|
||||
|
2
test/testdata/cyclop.go
vendored
2
test/testdata/cyclop.go
vendored
@ -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
|
||||
}
|
||||
|
4
test/testdata/deadcode.go
vendored
4
test/testdata/deadcode.go
vendored
@ -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) {
|
||||
|
6
test/testdata/decorder.go
vendored
6
test/testdata/decorder.go
vendored
@ -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"
|
||||
|
1
test/testdata/decorder_default.go
vendored
1
test/testdata/decorder_default.go
vendored
@ -1,4 +1,5 @@
|
||||
//golangcitest:args -Edecorder
|
||||
//golangcitest:expected_exitcode 0
|
||||
package testdata
|
||||
|
||||
import "math"
|
||||
|
4
test/testdata/default_exclude.go
vendored
4
test/testdata/default_exclude.go
vendored
@ -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() {
|
||||
|
4
test/testdata/depguard.go
vendored
4
test/testdata/depguard.go
vendored
@ -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() {
|
||||
|
8
test/testdata/depguard_additional_guards.go
vendored
8
test/testdata/depguard_additional_guards.go
vendored
@ -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() {
|
||||
|
1
test/testdata/depguard_ignore_file_rules.go
vendored
1
test/testdata/depguard_ignore_file_rules.go
vendored
@ -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
|
||||
|
4
test/testdata/dogsled.go
vendored
4
test/testdata/dogsled.go
vendored
@ -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) {
|
||||
|
4
test/testdata/dupl.go
vendored
4
test/testdata/dupl.go
vendored
@ -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...)
|
||||
|
6
test/testdata/durationcheck.go
vendored
6
test/testdata/durationcheck.go
vendored
@ -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)
|
||||
}
|
||||
|
2
test/testdata/errcheck.go
vendored
2
test/testdata/errcheck.go
vendored
@ -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 {
|
||||
|
2
test/testdata/errcheck_exclude.go
vendored
2
test/testdata/errcheck_exclude.go
vendored
@ -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
|
||||
}
|
||||
|
2
test/testdata/errcheck_exclude_functions.go
vendored
2
test/testdata/errcheck_exclude_functions.go
vendored
@ -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
|
||||
}
|
||||
|
2
test/testdata/errcheck_ignore.go
vendored
2
test/testdata/errcheck_ignore.go
vendored
@ -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
|
||||
}
|
||||
|
2
test/testdata/errcheck_ignore_default.go
vendored
2
test/testdata/errcheck_ignore_default.go
vendored
@ -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"
|
||||
}
|
||||
|
1
test/testdata/errcheck_type_assertions.go
vendored
1
test/testdata/errcheck_type_assertions.go
vendored
@ -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 {
|
||||
|
190
test/testdata/errchkjson.go
vendored
190
test/testdata/errchkjson.go
vendored
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
2
test/testdata/errchkjson_no_exported.go
vendored
2
test/testdata/errchkjson_no_exported.go
vendored
@ -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
|
||||
}
|
||||
|
||||
|
22
test/testdata/errname.go
vendored
22
test/testdata/errname.go
vendored
@ -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" }
|
||||
|
6
test/testdata/errorlint.go
vendored
6
test/testdata/errorlint.go
vendored
@ -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")
|
||||
}
|
||||
|
10
test/testdata/errorlint_asserts.go
vendored
10
test/testdata/errorlint_asserts.go
vendored
@ -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)
|
||||
}
|
||||
|
12
test/testdata/errorlint_comparison.go
vendored
12
test/testdata/errorlint_comparison.go
vendored
@ -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")
|
||||
}
|
||||
|
8
test/testdata/errorlint_errorf.go
vendored
8
test/testdata/errorlint_errorf.go
vendored
@ -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)
|
||||
}
|
||||
|
8
test/testdata/execinquery.go
vendored
8
test/testdata/execinquery.go
vendored
@ -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"
|
||||
}
|
||||
|
2
test/testdata/exhaustive.go
vendored
2
test/testdata/exhaustive.go
vendored
@ -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:
|
||||
}
|
||||
}
|
||||
|
1
test/testdata/exhaustive_default.go
vendored
1
test/testdata/exhaustive_default.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Eexhaustive
|
||||
//golangcitest:config_path testdata/configs/exhaustive_default.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package testdata
|
||||
|
||||
type Direction int
|
||||
|
1
test/testdata/exhaustive_generated.go
vendored
1
test/testdata/exhaustive_generated.go
vendored
@ -1,4 +1,5 @@
|
||||
//golangcitest:args -Eexhaustive
|
||||
//golangcitest:expected_exitcode 0
|
||||
package testdata
|
||||
|
||||
// Code generated by some program. DO NOT EDIT.
|
||||
|
@ -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:
|
||||
}
|
||||
}
|
||||
|
6
test/testdata/exhaustivestruct.go
vendored
6
test/testdata/exhaustivestruct.go
vendored
@ -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(),
|
||||
|
12
test/testdata/exhaustivestruct_custom.go
vendored
12
test/testdata/exhaustivestruct_custom.go
vendored
@ -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,
|
||||
|
6
test/testdata/exhaustruct.go
vendored
6
test/testdata/exhaustruct.go
vendored
@ -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(),
|
||||
|
6
test/testdata/exhaustruct_custom.go
vendored
6
test/testdata/exhaustruct_custom.go
vendored
@ -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,
|
||||
|
8
test/testdata/exportloopref.go
vendored
8
test/testdata/exportloopref.go
vendored
@ -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
|
||||
|
1
test/testdata/fix/in/gci.go
vendored
1
test/testdata/fix/in/gci.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Egci
|
||||
//golangcitest:config_path testdata/configs/gci.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package gci
|
||||
|
||||
import (
|
||||
|
1
test/testdata/fix/in/gocritic.go
vendored
1
test/testdata/fix/in/gocritic.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Egocritic
|
||||
//golangcitest:config_path testdata/configs/gocritic-fix.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
import (
|
||||
|
1
test/testdata/fix/in/godot.go
vendored
1
test/testdata/fix/in/godot.go
vendored
@ -1,4 +1,5 @@
|
||||
//golangcitest:args -Egodot
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
/*
|
||||
|
1
test/testdata/fix/in/gofmt.go
vendored
1
test/testdata/fix/in/gofmt.go
vendored
@ -1,4 +1,5 @@
|
||||
//golangcitest:args -Egofmt
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
func gofmt(a, b int) int {
|
||||
|
1
test/testdata/fix/in/gofumpt.go
vendored
1
test/testdata/fix/in/gofumpt.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Egofumpt
|
||||
//golangcitest:config_path testdata/configs/gofumpt-fix.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
import "fmt"
|
||||
|
1
test/testdata/fix/in/goimports.go
vendored
1
test/testdata/fix/in/goimports.go
vendored
@ -1,4 +1,5 @@
|
||||
//golangcitest:args -Egofmt,goimports
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
import (
|
||||
|
1
test/testdata/fix/in/misspell.go
vendored
1
test/testdata/fix/in/misspell.go
vendored
@ -1,4 +1,5 @@
|
||||
//golangcitest:args -Emisspell
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
import "log"
|
||||
|
1
test/testdata/fix/in/whitespace.go
vendored
1
test/testdata/fix/in/whitespace.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Ewhitespace
|
||||
//golangcitest:config_path testdata/configs/whitespace-fix.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
import "fmt"
|
||||
|
1
test/testdata/fix/out/gci.go
vendored
1
test/testdata/fix/out/gci.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Egci
|
||||
//golangcitest:config_path testdata/configs/gci.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package gci
|
||||
|
||||
import (
|
||||
|
1
test/testdata/fix/out/gocritic.go
vendored
1
test/testdata/fix/out/gocritic.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Egocritic
|
||||
//golangcitest:config_path testdata/configs/gocritic-fix.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
import (
|
||||
|
1
test/testdata/fix/out/godot.go
vendored
1
test/testdata/fix/out/godot.go
vendored
@ -1,4 +1,5 @@
|
||||
//golangcitest:args -Egodot
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
/*
|
||||
|
1
test/testdata/fix/out/gofmt.go
vendored
1
test/testdata/fix/out/gofmt.go
vendored
@ -1,4 +1,5 @@
|
||||
//golangcitest:args -Egofmt
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
func gofmt(a, b int) int {
|
||||
|
1
test/testdata/fix/out/gofumpt.go
vendored
1
test/testdata/fix/out/gofumpt.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Egofumpt
|
||||
//golangcitest:config_path testdata/configs/gofumpt-fix.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
import "fmt"
|
||||
|
1
test/testdata/fix/out/goimports.go
vendored
1
test/testdata/fix/out/goimports.go
vendored
@ -1,4 +1,5 @@
|
||||
//golangcitest:args -Egofmt,goimports
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
func goimports(a, b int) int {
|
||||
|
1
test/testdata/fix/out/misspell.go
vendored
1
test/testdata/fix/out/misspell.go
vendored
@ -1,4 +1,5 @@
|
||||
//golangcitest:args -Emisspell
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
import "log"
|
||||
|
1
test/testdata/fix/out/whitespace.go
vendored
1
test/testdata/fix/out/whitespace.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Ewhitespace
|
||||
//golangcitest:config_path testdata/configs/whitespace-fix.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package p
|
||||
|
||||
import "fmt"
|
||||
|
4
test/testdata/forbidigo_example.go
vendored
4
test/testdata/forbidigo_example.go
vendored
@ -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!"
|
||||
}
|
||||
|
1
test/testdata/forbidigo_example_test.go
vendored
1
test/testdata/forbidigo_example_test.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Eforbidigo
|
||||
//golangcitest:config_path testdata/configs/forbidigo.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package testdata
|
||||
|
||||
import "fmt"
|
||||
|
@ -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.*"
|
||||
}
|
||||
|
4
test/testdata/forcetypeassert.go
vendored
4
test/testdata/forcetypeassert.go
vendored
@ -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)
|
||||
}
|
||||
|
||||
|
4
test/testdata/funlen.go
vendored
4
test/testdata/funlen.go
vendored
@ -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
|
||||
|
4
test/testdata/gci.go
vendored
4
test/testdata/gci.go
vendored
@ -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() {
|
||||
|
16
test/testdata/gci/gci.go
vendored
16
test/testdata/gci/gci.go
vendored
@ -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("")
|
||||
}
|
2
test/testdata/go-header_bad.go
vendored
2
test/testdata/go-header_bad.go
vendored
@ -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
|
||||
|
1
test/testdata/go-header_good.go
vendored
1
test/testdata/go-header_good.go
vendored
@ -2,4 +2,5 @@
|
||||
|
||||
//golangcitest:args -Egoheader
|
||||
//golangcitest:config_path testdata/configs/go-header.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package testdata
|
||||
|
4
test/testdata/gochecknoglobals.go
vendored
4
test/testdata/gochecknoglobals.go
vendored
@ -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() {
|
||||
|
2
test/testdata/gochecknoinits.go
vendored
2
test/testdata/gochecknoinits.go
vendored
@ -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()
|
||||
}
|
||||
|
||||
|
6
test/testdata/gocognit.go
vendored
6
test/testdata/gocognit.go
vendored
@ -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:
|
||||
|
4
test/testdata/goconst.go
vendored
4
test/testdata/goconst.go
vendored
@ -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)
|
||||
|
2
test/testdata/goconst_calls_enabled.go
vendored
2
test/testdata/goconst_calls_enabled.go
vendored
@ -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)
|
||||
|
4
test/testdata/goconst_dont_ignore_test.go
vendored
4
test/testdata/goconst_dont_ignore_test.go
vendored
@ -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)
|
||||
|
1
test/testdata/goconst_ignore_test.go
vendored
1
test/testdata/goconst_ignore_test.go
vendored
@ -1,5 +1,6 @@
|
||||
//golangcitest:args -Egoconst
|
||||
//golangcitest:config_path testdata/configs/goconst_ignore.yml
|
||||
//golangcitest:expected_exitcode 0
|
||||
package testdata
|
||||
|
||||
import (
|
||||
|
10
test/testdata/gocritic.go
vendored
10
test/testdata/gocritic.go
vendored
@ -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.*"
|
||||
}
|
||||
|
2
test/testdata/gocyclo.go
vendored
2
test/testdata/gocyclo.go
vendored
@ -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
|
||||
}
|
||||
|
2
test/testdata/godot.go
vendored
2
test/testdata/godot.go
vendored
@ -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
|
||||
}
|
||||
|
14
test/testdata/godox.go
vendored
14
test/testdata/godox.go
vendored
@ -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`
|
||||
}
|
||||
|
6
test/testdata/goerr113.go
vendored
6
test/testdata/goerr113.go
vendored
@ -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
|
||||
|
2
test/testdata/gofmt.go
vendored
2
test/testdata/gofmt.go
vendored
@ -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`"
|
||||
}
|
||||
|
2
test/testdata/gofmt_no_simplify.go
vendored
2
test/testdata/gofmt_no_simplify.go
vendored
@ -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"
|
||||
}
|
||||
|
2
test/testdata/gofumpt.go
vendored
2
test/testdata/gofumpt.go
vendored
@ -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"
|
||||
}
|
||||
|
2
test/testdata/gofumpt_with_extra.go
vendored
2
test/testdata/gofumpt_with_extra.go
vendored
@ -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")
|
||||
}
|
||||
|
2
test/testdata/goimports.go
vendored
2
test/testdata/goimports.go
vendored
@ -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"
|
||||
)
|
||||
|
||||
|
16
test/testdata/goimports/goimports.go
vendored
16
test/testdata/goimports/goimports.go
vendored
@ -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("")
|
||||
}
|
16
test/testdata/goimports_local.go
vendored
Normal file
16
test/testdata/goimports_local.go
vendored
Normal file
@ -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("")
|
||||
}
|
4
test/testdata/golint.go
vendored
4
test/testdata/golint.go
vendored
@ -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"
|
||||
|
4
test/testdata/gomnd.go
vendored
4
test/testdata/gomnd.go
vendored
@ -9,14 +9,14 @@ import (
|
||||
|
||||
func UseMagicNumber() {
|
||||
c := &http.Client{
|
||||
Timeout: 2 * time.Second, // ERROR "Magic number: 2, in <assign> detected"
|
||||
Timeout: 2 * time.Second, // want "Magic number: 2, in <assign> detected"
|
||||
}
|
||||
|
||||
res, err := c.Get("http://www.google.com")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if res.StatusCode != 200 { // ERROR "Magic number: 200, in <condition> detected"
|
||||
if res.StatusCode != 200 { // want "Magic number: 200, in <condition> detected"
|
||||
log.Println("Something went wrong")
|
||||
}
|
||||
}
|
||||
|
2
test/testdata/gomodguard.go
vendored
2
test/testdata/gomodguard.go
vendored
@ -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
|
||||
|
2
test/testdata/goprintffuncname.go
vendored
2
test/testdata/goprintffuncname.go
vendored
@ -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'"
|
||||
}
|
||||
|
6
test/testdata/gosec.go
vendored
6
test/testdata/gosec.go
vendored
@ -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"
|
||||
}
|
||||
|
4
test/testdata/gosec_rules_config.go
vendored
4
test/testdata/gosec_rules_config.go
vendored
@ -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"
|
||||
}
|
||||
|
2
test/testdata/gosec_severity_confidence.go
vendored
2
test/testdata/gosec_severity_confidence.go
vendored
@ -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)
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user