aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/breml/errchkjson
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2025-01-22 16:07:17 +0100
committerTaras Madan <tarasmadan@google.com>2025-01-23 10:42:36 +0000
commit7b4377ad9d8a7205416df8d6217ef2b010f89481 (patch)
treee6fec4fd12ff807a16d847923f501075bf71d16c /vendor/github.com/breml/errchkjson
parent475a4c203afb8b7d3af51c4fd32bb170ff32a45e (diff)
vendor: delete
Diffstat (limited to 'vendor/github.com/breml/errchkjson')
-rw-r--r--vendor/github.com/breml/errchkjson/.gitignore29
-rw-r--r--vendor/github.com/breml/errchkjson/.goreleaser.yml37
-rw-r--r--vendor/github.com/breml/errchkjson/LICENSE21
-rw-r--r--vendor/github.com/breml/errchkjson/README.md131
-rw-r--r--vendor/github.com/breml/errchkjson/errchkjson.go348
-rw-r--r--vendor/github.com/breml/errchkjson/noexported_error.go23
-rw-r--r--vendor/github.com/breml/errchkjson/unsupported_error.go23
-rw-r--r--vendor/github.com/breml/errchkjson/version.go19
8 files changed, 0 insertions, 631 deletions
diff --git a/vendor/github.com/breml/errchkjson/.gitignore b/vendor/github.com/breml/errchkjson/.gitignore
deleted file mode 100644
index 0362de301..000000000
--- a/vendor/github.com/breml/errchkjson/.gitignore
+++ /dev/null
@@ -1,29 +0,0 @@
-# Binaries for programs and plugins
-*.exe
-*.exe~
-*.dll
-*.so
-*.dylib
-/errchkjson
-/cmd/errchkjson/errchkjson
-
-# Test binary, build with `go test -c`
-*.test
-
-# Output of the go coverage tool, specifically when used with LiteIDE
-*.out
-coverage.html
-
-# Log files
-*.log
-
-# Env files
-.env
-
-# Exclude todo
-TODO.md
-
-# Exclude IDE settings
-.idea/
-*.iml
-.vscode/
diff --git a/vendor/github.com/breml/errchkjson/.goreleaser.yml b/vendor/github.com/breml/errchkjson/.goreleaser.yml
deleted file mode 100644
index 111369053..000000000
--- a/vendor/github.com/breml/errchkjson/.goreleaser.yml
+++ /dev/null
@@ -1,37 +0,0 @@
----
-version: 2
-
-# This is an example .goreleaser.yml file with some sane defaults.
-# Make sure to check the documentation at http://goreleaser.com
-before:
- hooks:
- # You may remove this if you don't use go modules.
- - go mod tidy
-builds:
- - main: ./cmd/errchkjson
- binary: errchkjson
- env:
- - CGO_ENABLED=0
- goos:
- - linux
- - windows
- - darwin
-archives:
- - name_template: >-
- {{- .Binary }}_
- {{- .Version }}_
- {{- title .Os }}_
- {{- if eq .Arch "amd64" }}x86_64
- {{- else if eq .Arch "386" }}i386
- {{- else }}{{ .Arch }}{{ end }}
- {{- if .Arm }}v{{ .Arm }}{{ end -}}
-snapshot:
- version_template: "{{ .Tag }}-next"
-changelog:
- disable: true
-release:
- github:
- owner: breml
- name: errchkjson
-gomod:
- proxy: true
diff --git a/vendor/github.com/breml/errchkjson/LICENSE b/vendor/github.com/breml/errchkjson/LICENSE
deleted file mode 100644
index 08db5cb6f..000000000
--- a/vendor/github.com/breml/errchkjson/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2019 Lucas Bremgartner
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/vendor/github.com/breml/errchkjson/README.md b/vendor/github.com/breml/errchkjson/README.md
deleted file mode 100644
index a387ea23d..000000000
--- a/vendor/github.com/breml/errchkjson/README.md
+++ /dev/null
@@ -1,131 +0,0 @@
-# errchkjson
-
-[![Test Status](https://github.com/breml/errchkjson/actions/workflows/ci.yml/badge.svg)](https://github.com/breml/errchkjson/actions/workflows/ci.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/breml/errchkjson)](https://goreportcard.com/report/github.com/breml/errchkjson) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
-
-Checks types passed to the json encoding functions. Reports unsupported types and reports occurrences where the check for the returned error can be omitted.
-
-Consider this [http.Handler](https://pkg.go.dev/net/http#Handler):
-
-```Go
-func JSONHelloWorld(w http.ResponseWriter, r *http.Request) {
- response := struct {
- Message string
- Code int
- }{
- Message: "Hello World",
- Code: 200,
- }
-
- body, err := json.Marshal(response)
- if err != nil {
- panic(err) // unreachable, because json encoding of a struct with just a string and an int will never return an error.
- }
-
- w.Write(body)
-}
-```
-
-Because the `panic` is not possible to happen, one might refactor the code like this:
-
-```Go
-func JSONHelloWorld(w http.ResponseWriter, r *http.Request) {
- response := struct {
- Message string
- Code int
- }{
- Message: "Hello World",
- Code: 200,
- }
-
- body, _ := json.Marshal(response)
-
- w.Write(body)
-}
-```
-
-This is ok, as long as the struct is not altered in such a way, that could potentially lead
-to `json.Marshal` returning an error.
-
-`errchkjson` allows you to lint your code such that the above error returned from `json.Marshal`
-can be omitted while still staying safe, because as soon as an unsafe type is added to the
-response type, the linter will warn you.
-
-## Installation
-
-Download `errchkjson` from the [releases](https://github.com/breml/errchkjson/releases) or get the latest version from source with:
-
-```shell
-go install github.com/breml/errchkjson/cmd/errchkjson@latest
-```
-
-## Usage
-
-### Shell
-
-Check everything:
-
-```shell
-errchkjson ./...
-```
-
-`errchkjson` also recognizes the following command-line options:
-
-The `-omit-safe` flag disables checking for safe returns of errors from json.Marshal
-
-## Types
-
-### Safe
-
-The following types are safe to use with [json encoding functions](https://pkg.go.dev/encoding/json), that is, the encoding to JSON can not fail:
-
-Safe basic types:
-
-* `bool`
-* `int`, `int8`, `int16`, `int32`, `int64`, `uint`, `uint8`, `uint16`, `uint32`, `uint64`, `uintptr`
-* `string`
-* Pointer type of the above listed basic types
-
-Composed types (struct, map, slice, array) are safe, if the type of the value is
-safe. For structs, only exported fields are relevant. For maps, the key needs to be either an integer type or a string.
-
-### Unsafe
-
-The following types are unsafe to use with [json encoding functions](https://pkg.go.dev/encoding/json), that is, the encoding to JSON can fail (return an error):
-
-Unsafe basic types:
-
-* `float32`, `float64`
-* `interface{}`
-* Pointer type of the above listed basic types
-
-Any composed types (struct, map, slice, array) containing an unsafe basic type.
-
-If a type implements the `json.Marshaler` or `encoding.TextMarshaler` interface (e.g. `json.Number`).
-
-### Forbidden
-
-Forbidden basic types:
-
-* `complex64`, `complex128`
-* `chan`
-* `func`
-* `unsafe.Pointer`
-
-Any composed types (struct, map, slice, array) containing a forbidden basic type. Any map
-using a key with a forbidden type (`bool`, `float32`, `float64`, `struct`).
-
-## Accepted edge case
-
-For `encoding/json.MarshalIndent`, there is a (pathological) edge case, where this
-function could [return an error](https://cs.opensource.google/go/go/+/refs/tags/go1.18:src/encoding/json/scanner.go;drc=refs%2Ftags%2Fgo1.18;l=181) for an otherwise safe argument, if the argument has
-a nesting depth larger than [`10000`](https://cs.opensource.google/go/go/+/refs/tags/go1.18:src/encoding/json/scanner.go;drc=refs%2Ftags%2Fgo1.18;l=144) (as of Go 1.18).
-
-## Bugs found during development
-
-During the development of `errcheckjson`, the following issues in package `encoding/json` of the Go standard library have been found and PR have been merged:
-
-* [Issue #34154: encoding/json: string option (struct tag) on string field with SetEscapeHTML(false) escapes anyway](https://github.com/golang/go/issues/34154)
-* [PR #34127: encoding/json: fix and optimize marshal for quoted string](https://github.com/golang/go/pull/34127)
-* [Issue #34268: encoding/json: wrong encoding for json.Number field with string option (struct tag)](https://github.com/golang/go/issues/34268)
-* [PR #34269: encoding/json: make Number with the ,string option marshal with quotes](https://github.com/golang/go/pull/34269)
-* [PR #34272: encoding/json: validate strings when decoding into Number](https://github.com/golang/go/pull/34272)
diff --git a/vendor/github.com/breml/errchkjson/errchkjson.go b/vendor/github.com/breml/errchkjson/errchkjson.go
deleted file mode 100644
index 7c8cd82e9..000000000
--- a/vendor/github.com/breml/errchkjson/errchkjson.go
+++ /dev/null
@@ -1,348 +0,0 @@
-// Package errchkjson defines an Analyzer that finds places, where it is
-// safe to omit checking the error returned from json.Marshal.
-package errchkjson
-
-import (
- "flag"
- "fmt"
- "go/ast"
- "go/token"
- "go/types"
- "reflect"
-
- "golang.org/x/tools/go/analysis"
- "golang.org/x/tools/go/types/typeutil"
-)
-
-type errchkjson struct {
- omitSafe bool // -omit-safe flag
- reportNoExported bool // -report-no-exported flag
-}
-
-// NewAnalyzer returns a new errchkjson analyzer.
-func NewAnalyzer() *analysis.Analyzer {
- errchkjson := &errchkjson{}
-
- a := &analysis.Analyzer{
- Name: "errchkjson",
- Doc: "Checks types passed to the json encoding functions. Reports unsupported types and reports occurrences where the check for the returned error can be omitted.",
- Run: errchkjson.run,
- }
-
- a.Flags.Init("errchkjson", flag.ExitOnError)
- a.Flags.BoolVar(&errchkjson.omitSafe, "omit-safe", false, "if omit-safe is true, checking of safe returns is omitted")
- a.Flags.BoolVar(&errchkjson.reportNoExported, "report-no-exported", false, "if report-no-exported is true, encoding a struct without exported fields is reported as issue")
- a.Flags.Var(versionFlag{}, "V", "print version and exit")
-
- return a
-}
-
-func (e *errchkjson) run(pass *analysis.Pass) (interface{}, error) {
- for _, file := range pass.Files {
- ast.Inspect(file, func(n ast.Node) bool {
- if n == nil {
- return true
- }
-
- // if the error is returned, it is the caller's responsibility to check
- // the return value.
- if _, ok := n.(*ast.ReturnStmt); ok {
- return false
- }
-
- ce, ok := n.(*ast.CallExpr)
- if ok {
- fn, _ := typeutil.Callee(pass.TypesInfo, ce).(*types.Func)
- if fn == nil {
- return true
- }
-
- switch fn.FullName() {
- case "encoding/json.Marshal", "encoding/json.MarshalIndent":
- e.handleJSONMarshal(pass, ce, fn.FullName(), blankIdentifier, e.omitSafe)
- case "(*encoding/json.Encoder).Encode":
- e.handleJSONMarshal(pass, ce, fn.FullName(), blankIdentifier, true)
- default:
- e.inspectArgs(pass, ce.Args)
- }
- return false
- }
-
- as, ok := n.(*ast.AssignStmt)
- if !ok {
- return true
- }
-
- ce, ok = as.Rhs[0].(*ast.CallExpr)
- if !ok {
- return true
- }
-
- fn, _ := typeutil.Callee(pass.TypesInfo, ce).(*types.Func)
- if fn == nil {
- return true
- }
-
- switch fn.FullName() {
- case "encoding/json.Marshal", "encoding/json.MarshalIndent":
- e.handleJSONMarshal(pass, ce, fn.FullName(), evaluateMarshalErrorTarget(as.Lhs[1]), e.omitSafe)
- case "(*encoding/json.Encoder).Encode":
- e.handleJSONMarshal(pass, ce, fn.FullName(), evaluateMarshalErrorTarget(as.Lhs[0]), true)
- default:
- return true
- }
- return false
- })
- }
-
- return nil, nil
-}
-
-func evaluateMarshalErrorTarget(n ast.Expr) marshalErrorTarget {
- if errIdent, ok := n.(*ast.Ident); ok {
- if errIdent.Name == "_" {
- return blankIdentifier
- }
- }
- return variableAssignment
-}
-
-type marshalErrorTarget int
-
-const (
- blankIdentifier = iota // the returned error from the JSON marshal function is assigned to the blank identifier "_".
- variableAssignment // the returned error from the JSON marshal function is assigned to a variable.
- functionArgument // the returned error from the JSON marshal function is passed to an other function as argument.
-)
-
-func (e *errchkjson) handleJSONMarshal(pass *analysis.Pass, ce *ast.CallExpr, fnName string, errorTarget marshalErrorTarget, omitSafe bool) {
- t := pass.TypesInfo.TypeOf(ce.Args[0])
- if t == nil {
- // Not sure, if this is at all possible
- if errorTarget == blankIdentifier {
- pass.Reportf(ce.Pos(), "Type of argument to `%s` could not be evaluated and error return value is not checked", fnName)
- }
- return
- }
-
- if _, ok := t.(*types.Pointer); ok {
- t = t.(*types.Pointer).Elem()
- }
-
- err := e.jsonSafe(t, 0, map[types.Type]struct{}{})
- if err != nil {
- if _, ok := err.(unsupported); ok {
- pass.Reportf(ce.Pos(), "`%s` for %v", fnName, err)
- return
- }
- if _, ok := err.(noexported); ok {
- pass.Reportf(ce.Pos(), "Error argument passed to `%s` does not contain any exported field", fnName)
- }
- // Only care about unsafe types if they are assigned to the blank identifier.
- if errorTarget == blankIdentifier {
- pass.Reportf(ce.Pos(), "Error return value of `%s` is not checked: %v", fnName, err)
- }
- }
- if err == nil && errorTarget == variableAssignment && !omitSafe {
- pass.Reportf(ce.Pos(), "Error return value of `%s` is checked but passed argument is safe", fnName)
- }
- // Report an error, if err for json.Marshal is not checked and safe types are omitted
- if err == nil && errorTarget == blankIdentifier && omitSafe {
- pass.Reportf(ce.Pos(), "Error return value of `%s` is not checked", fnName)
- }
-}
-
-const (
- allowedBasicTypes = types.IsBoolean | types.IsInteger | types.IsString
- allowedMapKeyBasicTypes = types.IsInteger | types.IsString
- unsupportedBasicTypes = types.IsComplex
-)
-
-func (e *errchkjson) jsonSafe(t types.Type, level int, seenTypes map[types.Type]struct{}) error {
- if _, ok := seenTypes[t]; ok {
- return nil
- }
-
- if types.Implements(t, textMarshalerInterface()) || types.Implements(t, jsonMarshalerInterface()) {
- return fmt.Errorf("unsafe type `%s` found", t.String())
- }
-
- switch ut := t.Underlying().(type) {
- case *types.Basic:
- if ut.Info()&allowedBasicTypes > 0 { // bool, int-family, string
- if ut.Info()&types.IsString > 0 && t.String() == "encoding/json.Number" {
- return fmt.Errorf("unsafe type `%s` found", t.String())
- }
- return nil
- }
- if ut.Info()&unsupportedBasicTypes > 0 { // complex64, complex128
- return newUnsupportedError(fmt.Errorf("unsupported type `%s` found", ut.String()))
- }
- switch ut.Kind() {
- case types.UntypedNil:
- return nil
- case types.UnsafePointer:
- return newUnsupportedError(fmt.Errorf("unsupported type `%s` found", ut.String()))
- default:
- // E.g. float32, float64
- return fmt.Errorf("unsafe type `%s` found", ut.String())
- }
-
- case *types.Array:
- err := e.jsonSafe(ut.Elem(), level+1, seenTypes)
- if err != nil {
- return err
- }
- return nil
-
- case *types.Slice:
- err := e.jsonSafe(ut.Elem(), level+1, seenTypes)
- if err != nil {
- return err
- }
- return nil
-
- case *types.Struct:
- seenTypes[t] = struct{}{}
- exported := 0
- for i := 0; i < ut.NumFields(); i++ {
- if !ut.Field(i).Exported() {
- // Unexported fields can be ignored
- continue
- }
- if tag, ok := reflect.StructTag(ut.Tag(i)).Lookup("json"); ok {
- if tag == "-" {
- // Fields omitted in json can be ignored
- continue
- }
- }
- err := e.jsonSafe(ut.Field(i).Type(), level+1, seenTypes)
- if err != nil {
- return err
- }
- exported++
- }
- if e.reportNoExported && level == 0 && exported == 0 {
- return newNoexportedError(fmt.Errorf("struct does not export any field"))
- }
- return nil
-
- case *types.Pointer:
- err := e.jsonSafe(ut.Elem(), level+1, seenTypes)
- if err != nil {
- return err
- }
- return nil
-
- case *types.Map:
- err := jsonSafeMapKey(ut.Key())
- if err != nil {
- return err
- }
- err = e.jsonSafe(ut.Elem(), level+1, seenTypes)
- if err != nil {
- return err
- }
- return nil
-
- case *types.Chan, *types.Signature:
- // Types that are not supported for encoding to json:
- return newUnsupportedError(fmt.Errorf("unsupported type `%s` found", ut.String()))
-
- default:
- // Types that are not supported for encoding to json or are not completely safe, like: interfaces
- return fmt.Errorf("unsafe type `%s` found", t.String())
- }
-}
-
-func jsonSafeMapKey(t types.Type) error {
- if types.Implements(t, textMarshalerInterface()) || types.Implements(t, jsonMarshalerInterface()) {
- return fmt.Errorf("unsafe type `%s` as map key found", t.String())
- }
- switch ut := t.Underlying().(type) {
- case *types.Basic:
- if ut.Info()&types.IsString > 0 && t.String() == "encoding/json.Number" {
- return fmt.Errorf("unsafe type `%s` as map key found", t.String())
- }
- if ut.Info()&allowedMapKeyBasicTypes > 0 { // bool, int-family, string
- return nil
- }
- // E.g. bool, float32, float64, complex64, complex128
- return newUnsupportedError(fmt.Errorf("unsupported type `%s` as map key found", t.String()))
- case *types.Interface:
- return fmt.Errorf("unsafe type `%s` as map key found", t.String())
- default:
- // E.g. struct composed solely of basic types, that are comparable
- return newUnsupportedError(fmt.Errorf("unsupported type `%s` as map key found", t.String()))
- }
-}
-
-func (e *errchkjson) inspectArgs(pass *analysis.Pass, args []ast.Expr) {
- for _, a := range args {
- ast.Inspect(a, func(n ast.Node) bool {
- if n == nil {
- return true
- }
-
- ce, ok := n.(*ast.CallExpr)
- if !ok {
- return false
- }
-
- fn, _ := typeutil.Callee(pass.TypesInfo, ce).(*types.Func)
- if fn == nil {
- return true
- }
-
- switch fn.FullName() {
- case "encoding/json.Marshal", "encoding/json.MarshalIndent":
- e.handleJSONMarshal(pass, ce, fn.FullName(), functionArgument, e.omitSafe)
- case "(*encoding/json.Encoder).Encode":
- e.handleJSONMarshal(pass, ce, fn.FullName(), functionArgument, true)
- default:
- e.inspectArgs(pass, ce.Args)
- }
- return false
- })
- }
-}
-
-// Construct *types.Interface for interface encoding.TextMarshaler
-//
-// type TextMarshaler interface {
-// MarshalText() (text []byte, err error)
-// }
-func textMarshalerInterface() *types.Interface {
- textMarshalerInterface := types.NewInterfaceType([]*types.Func{
- types.NewFunc(token.NoPos, nil, "MarshalText", types.NewSignatureType(
- nil, nil, nil, nil, types.NewTuple(
- types.NewVar(token.NoPos, nil, "text",
- types.NewSlice(
- types.Universe.Lookup("byte").Type())),
- types.NewVar(token.NoPos, nil, "err", types.Universe.Lookup("error").Type())),
- false)),
- }, nil)
- textMarshalerInterface.Complete()
-
- return textMarshalerInterface
-}
-
-// Construct *types.Interface for interface json.Marshaler
-//
-// type Marshaler interface {
-// MarshalJSON() ([]byte, error)
-// }
-func jsonMarshalerInterface() *types.Interface {
- textMarshalerInterface := types.NewInterfaceType([]*types.Func{
- types.NewFunc(token.NoPos, nil, "MarshalJSON", types.NewSignatureType(
- nil, nil, nil, nil, types.NewTuple(
- types.NewVar(token.NoPos, nil, "",
- types.NewSlice(
- types.Universe.Lookup("byte").Type())),
- types.NewVar(token.NoPos, nil, "", types.Universe.Lookup("error").Type())),
- false)),
- }, nil)
- textMarshalerInterface.Complete()
-
- return textMarshalerInterface
-}
diff --git a/vendor/github.com/breml/errchkjson/noexported_error.go b/vendor/github.com/breml/errchkjson/noexported_error.go
deleted file mode 100644
index 07b7a07d2..000000000
--- a/vendor/github.com/breml/errchkjson/noexported_error.go
+++ /dev/null
@@ -1,23 +0,0 @@
-package errchkjson
-
-type noexported interface {
- noexported()
-}
-
-var _ noexported = noexportedError{}
-
-type noexportedError struct {
- err error
-}
-
-func newNoexportedError(err error) error {
- return noexportedError{
- err: err,
- }
-}
-
-func (u noexportedError) noexported() {}
-
-func (u noexportedError) Error() string {
- return u.err.Error()
-}
diff --git a/vendor/github.com/breml/errchkjson/unsupported_error.go b/vendor/github.com/breml/errchkjson/unsupported_error.go
deleted file mode 100644
index 1a38c3f53..000000000
--- a/vendor/github.com/breml/errchkjson/unsupported_error.go
+++ /dev/null
@@ -1,23 +0,0 @@
-package errchkjson
-
-type unsupported interface {
- unsupported()
-}
-
-var _ unsupported = unsupportedError{}
-
-type unsupportedError struct {
- err error
-}
-
-func newUnsupportedError(err error) error {
- return unsupportedError{
- err: err,
- }
-}
-
-func (u unsupportedError) unsupported() {}
-
-func (u unsupportedError) Error() string {
- return u.err.Error()
-}
diff --git a/vendor/github.com/breml/errchkjson/version.go b/vendor/github.com/breml/errchkjson/version.go
deleted file mode 100644
index 77d8ef8bb..000000000
--- a/vendor/github.com/breml/errchkjson/version.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package errchkjson
-
-import (
- "fmt"
- "os"
-)
-
-var Version = "errchkjson version dev"
-
-type versionFlag struct{}
-
-func (versionFlag) IsBoolFlag() bool { return true }
-func (versionFlag) Get() interface{} { return nil }
-func (versionFlag) String() string { return "" }
-func (versionFlag) Set(s string) error {
- fmt.Println(Version)
- os.Exit(0)
- return nil
-}