aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/curioswitch
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-02-22 22:16:50 +0100
committerTaras Madan <tarasmadan@google.com>2023-02-24 12:47:23 +0100
commit4165372ec8fd142475a4e35fd0cf4f8042132208 (patch)
tree21cd62211b4dd80bee469054c5b65db77342333c /vendor/github.com/curioswitch
parent2b3ed821a493b8936c8bacfa6f8b4f1c90a00855 (diff)
dependencies: update
set go min requirements to 1.19 update dependencies update vendor
Diffstat (limited to 'vendor/github.com/curioswitch')
-rw-r--r--vendor/github.com/curioswitch/go-reassign/.gitattributes2
-rw-r--r--vendor/github.com/curioswitch/go-reassign/.gitignore6
-rw-r--r--vendor/github.com/curioswitch/go-reassign/.golangci.yml38
-rw-r--r--vendor/github.com/curioswitch/go-reassign/.goreleaser.yaml27
-rw-r--r--vendor/github.com/curioswitch/go-reassign/LICENSE21
-rw-r--r--vendor/github.com/curioswitch/go-reassign/README.md53
-rw-r--r--vendor/github.com/curioswitch/go-reassign/analyzer.go13
-rw-r--r--vendor/github.com/curioswitch/go-reassign/internal/analyzer/analyzer.go84
8 files changed, 244 insertions, 0 deletions
diff --git a/vendor/github.com/curioswitch/go-reassign/.gitattributes b/vendor/github.com/curioswitch/go-reassign/.gitattributes
new file mode 100644
index 000000000..d020be8ea
--- /dev/null
+++ b/vendor/github.com/curioswitch/go-reassign/.gitattributes
@@ -0,0 +1,2 @@
+*.go text eol=lf
+
diff --git a/vendor/github.com/curioswitch/go-reassign/.gitignore b/vendor/github.com/curioswitch/go-reassign/.gitignore
new file mode 100644
index 000000000..59fa33613
--- /dev/null
+++ b/vendor/github.com/curioswitch/go-reassign/.gitignore
@@ -0,0 +1,6 @@
+.idea
+.VSCode
+.envrc
+
+build
+dist
diff --git a/vendor/github.com/curioswitch/go-reassign/.golangci.yml b/vendor/github.com/curioswitch/go-reassign/.golangci.yml
new file mode 100644
index 000000000..e3bf79ae7
--- /dev/null
+++ b/vendor/github.com/curioswitch/go-reassign/.golangci.yml
@@ -0,0 +1,38 @@
+linters:
+ enable:
+ - asasalint
+ - bidichk
+ - bodyclose
+ - decorder
+ - durationcheck
+ - errchkjson
+ - errname
+ - errorlint
+ - execinquery
+ - exhaustive
+ - exportloopref
+ - gocritic
+ - goerr113
+ - gofmt
+ - goimports
+ - goprintffuncname
+ - gosec
+ - importas
+ - misspell
+ - nolintlint
+ - nosnakecase
+ - prealloc
+ - predeclared
+ - promlinter
+ - revive
+ - stylecheck
+ - tagliatelle
+ - tenv
+ - thelper
+ - unconvert
+ - usestdlibvars
+issues:
+ exclude-rules:
+ - path: magefile\.go
+ linters:
+ - deadcode
diff --git a/vendor/github.com/curioswitch/go-reassign/.goreleaser.yaml b/vendor/github.com/curioswitch/go-reassign/.goreleaser.yaml
new file mode 100644
index 000000000..25f2dc0c1
--- /dev/null
+++ b/vendor/github.com/curioswitch/go-reassign/.goreleaser.yaml
@@ -0,0 +1,27 @@
+builds:
+ - main: ./cmd
+ env:
+ - CGO_ENABLED=0
+ targets:
+ - linux_amd64
+ - linux_arm64
+ - darwin_amd64
+ - darwin_arm64
+ - windows_amd64
+ - windows_arm64
+archives:
+ - format_overrides:
+ - goos: windows
+ format: zip
+release:
+ mode: append
+checksum:
+ name_template: 'checksums.txt'
+snapshot:
+ name_template: "{{ incpatch .Version }}-next"
+changelog:
+ sort: asc
+ filters:
+ exclude:
+ - '^docs:'
+ - '^test:'
diff --git a/vendor/github.com/curioswitch/go-reassign/LICENSE b/vendor/github.com/curioswitch/go-reassign/LICENSE
new file mode 100644
index 000000000..9f18bde00
--- /dev/null
+++ b/vendor/github.com/curioswitch/go-reassign/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) Choko (choko@curioswitch.org)
+
+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/curioswitch/go-reassign/README.md b/vendor/github.com/curioswitch/go-reassign/README.md
new file mode 100644
index 000000000..ac9c131df
--- /dev/null
+++ b/vendor/github.com/curioswitch/go-reassign/README.md
@@ -0,0 +1,53 @@
+# reassign
+
+A linter that detects when reassigning a top-level variable in another package.
+
+## Install
+
+```bash
+go install github.com/curioswitch/go-reassign
+```
+
+## Usage
+
+```bash
+reassign ./...
+```
+
+Change the pattern to match against variables being reassigned. By default, only `EOF` and `Err*` variables are checked.
+
+```bash
+reassign -pattern ".*" ./...
+```
+
+## Background
+
+Package variables are commonly used to define sentinel errors which callers can use with `errors.Is` to determine the
+type of a returned `error`. Some examples exist in the standard [os](https://pkg.go.dev/os#pkg-variables) library.
+
+Unfortunately, as with any variable, these are mutable, and it is possible to write this very dangerous code.
+
+```go
+package main
+import "io"
+func bad() {
+ // breaks file reading
+ io.EOF = nil
+}
+```
+
+This caused a new pattern for [constant errors](https://dave.cheney.net/2016/04/07/constant-errors)
+to gain popularity, but they don't work well with improvements to the `errors` package in recent versions of Go and may
+be considered to be non-idiomatic compared to normal `errors.New`. If we can catch reassignment of sentinel errors, we
+gain much of the safety of constant errors.
+
+This linter will catch reassignment of variables in other packages. By default it intends to apply to as many codebases
+as possible and only checks a restricted set of variable names, `EOF` and `ErrFoo`, to restrict to sentinel errors.
+Package variable reassignment is generally confusing, though, and we recommend avoiding it for all variables, not just errors.
+The `pattern` flag can be set to a regular expression to define what variables cannot be reassigned, and `.*` is
+recommended if it works with your code.
+
+## Limitations
+
+If a variable shadows the name of an import, an assignment of a field in the variable will trigger the linter. Shadowing
+can be confusing, so it's recommended to rename the variable.
diff --git a/vendor/github.com/curioswitch/go-reassign/analyzer.go b/vendor/github.com/curioswitch/go-reassign/analyzer.go
new file mode 100644
index 000000000..48707adeb
--- /dev/null
+++ b/vendor/github.com/curioswitch/go-reassign/analyzer.go
@@ -0,0 +1,13 @@
+package reassign
+
+import (
+ "github.com/curioswitch/go-reassign/internal/analyzer"
+ "golang.org/x/tools/go/analysis"
+)
+
+const FlagPattern = analyzer.FlagPattern
+
+// NewAnalyzer returns an analyzer for checking that package variables are not reassigned.
+func NewAnalyzer() *analysis.Analyzer {
+ return analyzer.New()
+}
diff --git a/vendor/github.com/curioswitch/go-reassign/internal/analyzer/analyzer.go b/vendor/github.com/curioswitch/go-reassign/internal/analyzer/analyzer.go
new file mode 100644
index 000000000..e1b47d5b9
--- /dev/null
+++ b/vendor/github.com/curioswitch/go-reassign/internal/analyzer/analyzer.go
@@ -0,0 +1,84 @@
+package analyzer
+
+import (
+ "fmt"
+ "go/ast"
+ "go/types"
+ "regexp"
+
+ "golang.org/x/tools/go/analysis"
+ "golang.org/x/tools/go/analysis/passes/inspect"
+ "golang.org/x/tools/go/ast/inspector"
+)
+
+const FlagPattern = "pattern"
+
+func New() *analysis.Analyzer {
+ a := &analysis.Analyzer{
+ Name: "reassign",
+ Doc: "Checks that package variables are not reassigned",
+ Requires: []*analysis.Analyzer{inspect.Analyzer},
+ Run: run,
+ }
+ a.Flags.String(FlagPattern, `^(Err.*|EOF)$`, "Pattern to match package variables against to prevent reassignment")
+ return a
+}
+
+func run(pass *analysis.Pass) (interface{}, error) {
+ checkRE, err := regexp.Compile(pass.Analyzer.Flags.Lookup(FlagPattern).Value.String())
+ if err != nil {
+ return nil, fmt.Errorf("invalid pattern: %w", err)
+ }
+
+ inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
+ inspect.Preorder([]ast.Node{(*ast.AssignStmt)(nil), (*ast.UnaryExpr)(nil)}, func(node ast.Node) {
+ switch node := node.(type) {
+ case *ast.AssignStmt:
+ for _, lhs := range node.Lhs {
+ reportImported(pass, lhs, checkRE, "reassigning")
+ }
+ default:
+ // TODO(chokoswitch): Consider handling operations other than assignment on globals, for example
+ // taking their address.
+ }
+ })
+ return nil, nil
+}
+
+func reportImported(pass *analysis.Pass, expr ast.Expr, checkRE *regexp.Regexp, prefix string) {
+ switch x := expr.(type) {
+ case *ast.SelectorExpr:
+ if !checkRE.MatchString(x.Sel.Name) {
+ return
+ }
+
+ selectIdent, ok := x.X.(*ast.Ident)
+ if !ok {
+ return
+ }
+
+ if selectObj, ok := pass.TypesInfo.Uses[selectIdent]; ok {
+ if pkg, ok := selectObj.(*types.PkgName); !ok || pkg.Imported() == pass.Pkg {
+ return
+ }
+ }
+
+ pass.Reportf(expr.Pos(), "%s variable %s in other package %s", prefix, x.Sel.Name, selectIdent.Name)
+
+ case *ast.Ident:
+ use, ok := pass.TypesInfo.Uses[x].(*types.Var)
+ if !ok {
+ return
+ }
+
+ if use.Pkg() == pass.Pkg {
+ return
+ }
+
+ if !checkRE.MatchString(x.Name) {
+ return
+ }
+
+ pass.Reportf(expr.Pos(), "%s variable %s from other package %s", prefix, x.Name, use.Pkg().Path())
+ }
+}