aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/charithe
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2022-09-05 14:27:54 +0200
committerGitHub <noreply@github.com>2022-09-05 12:27:54 +0000
commitb2f2446b46bf02821d90ebedadae2bf7ae0e880e (patch)
tree923cf42842918d6bebca1d6bbdc08abed54d274d /vendor/github.com/charithe
parente6654faff4bcca4be92e9a8596fd4b77f747c39e (diff)
go.mod, vendor: update (#3358)
* go.mod, vendor: remove unnecessary dependencies Commands: 1. go mod tidy 2. go mod vendor * go.mod, vendor: update cloud.google.com/go Commands: 1. go get -u cloud.google.com/go 2. go mod tidy 3. go mod vendor * go.mod, vendor: update cloud.google.com/* Commands: 1. go get -u cloud.google.com/storage cloud.google.com/logging 2. go mod tidy 3. go mod vendor * go.mod, .golangci.yml, vendor: update *lint* Commands: 1. go get -u golang.org/x/tools github.com/golangci/golangci-lint@v1.47.0 2. go mod tidy 3. go mod vendor 4. edit .golangci.yml to suppress new errors (resolved in the same PR later) * all: fix lint errors hash.go: copy() recommended by gosimple parse.go: ent is never nil verifier.go: signal.Notify() with unbuffered channel is bad. Have no idea why. * .golangci.yml: adjust godot rules check-all is deprecated, but still work if you're hesitating too - I'll remove this commit
Diffstat (limited to 'vendor/github.com/charithe')
-rw-r--r--vendor/github.com/charithe/durationcheck/README.md23
-rw-r--r--vendor/github.com/charithe/durationcheck/durationcheck.go25
-rw-r--r--vendor/github.com/charithe/durationcheck/go.mod2
-rw-r--r--vendor/github.com/charithe/durationcheck/go.sum24
4 files changed, 49 insertions, 25 deletions
diff --git a/vendor/github.com/charithe/durationcheck/README.md b/vendor/github.com/charithe/durationcheck/README.md
index 122edb745..6f4279bd3 100644
--- a/vendor/github.com/charithe/durationcheck/README.md
+++ b/vendor/github.com/charithe/durationcheck/README.md
@@ -7,22 +7,25 @@ Duration Check
A Go linter to detect cases where two `time.Duration` values are being multiplied in possibly erroneous ways.
-For example, consider the following (highly contrived) function:
+Consider the following (highly contrived) code:
```go
-func waitFor(someDuration time.Duration) {
- timeToWait := someDuration * time.Second
- time.Sleep(timeToWait)
+func waitForSeconds(someDuration time.Duration) {
+ timeToWait := someDuration * time.Second
+ fmt.Printf("Waiting for %s\n", timeToWait)
+}
+
+func main() {
+ waitForSeconds(5) // waits for 5 seconds
+ waitForSeconds(5 * time.Second) // waits for 1388888h 53m 20s
}
```
-Although the above code would compile without any errors, its runtime behaviour would almost certainly be incorrect.
-A caller would reasonably expect `waitFor(5 * time.Seconds)` to wait for ~5 seconds but they would actually end up
-waiting for ~1,388,889 hours.
+Both invocations of the function are syntactically correct but the second one is probably not what most people want.
+In this contrived example it is quite easy to spot the mistake. However, if the incorrect `waitForSeconds` invocation is
+nested deep within a complex piece of code that runs in the background, the mistake could go unnoticed for months (which
+is exactly what happened in a production backend system of fairly well-known software service).
-The above example is just for illustration purposes only. The problem is glaringly obvious in such a simple function
-and even the greenest Gopher would discover the issue immediately. However, imagine a much more complicated function
-with many more lines and it is not inconceivable that such logic errors could go unnoticed.
See the [test cases](testdata/src/a/a.go) for more examples of the types of errors detected by the linter.
diff --git a/vendor/github.com/charithe/durationcheck/durationcheck.go b/vendor/github.com/charithe/durationcheck/durationcheck.go
index 6eccd9c2a..c47b3a761 100644
--- a/vendor/github.com/charithe/durationcheck/durationcheck.go
+++ b/vendor/github.com/charithe/durationcheck/durationcheck.go
@@ -76,7 +76,7 @@ func check(pass *analysis.Pass) func(ast.Node) {
}
func isDuration(x types.Type) bool {
- return x.String() == "time.Duration"
+ return x.String() == "time.Duration" || x.String() == "*time.Duration"
}
// isUnacceptableExpr returns true if the argument is not an acceptable time.Duration expression
@@ -94,9 +94,15 @@ func isUnacceptableExpr(pass *analysis.Pass, expr ast.Expr) bool {
return !isAcceptableNestedExpr(pass, e)
case *ast.SelectorExpr:
return !isAcceptableNestedExpr(pass, e)
+ case *ast.StarExpr:
+ return !isAcceptableNestedExpr(pass, e)
+ case *ast.ParenExpr:
+ return !isAcceptableNestedExpr(pass, e)
+ case *ast.IndexExpr:
+ return !isAcceptableNestedExpr(pass, e)
+ default:
+ return true
}
-
- return true
}
// isAcceptableCast returns true if the argument is an acceptable expression cast to time.Duration
@@ -144,14 +150,23 @@ func isAcceptableNestedExpr(pass *analysis.Pass, n ast.Expr) bool {
case *ast.Ident:
return isAcceptableIdent(pass, e)
case *ast.CallExpr:
+ if isAcceptableCast(pass, e) {
+ return true
+ }
t := pass.TypesInfo.TypeOf(e)
return !isDuration(t)
case *ast.SelectorExpr:
+ return isAcceptableNestedExpr(pass, e.X) && isAcceptableIdent(pass, e.Sel)
+ case *ast.StarExpr:
+ return isAcceptableNestedExpr(pass, e.X)
+ case *ast.ParenExpr:
+ return isAcceptableNestedExpr(pass, e.X)
+ case *ast.IndexExpr:
t := pass.TypesInfo.TypeOf(e)
return !isDuration(t)
+ default:
+ return false
}
-
- return false
}
func isAcceptableIdent(pass *analysis.Pass, ident *ast.Ident) bool {
diff --git a/vendor/github.com/charithe/durationcheck/go.mod b/vendor/github.com/charithe/durationcheck/go.mod
index 12ebca0a0..eb058f21d 100644
--- a/vendor/github.com/charithe/durationcheck/go.mod
+++ b/vendor/github.com/charithe/durationcheck/go.mod
@@ -2,4 +2,4 @@ module github.com/charithe/durationcheck
go 1.14
-require golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b
+require golang.org/x/tools v0.1.0
diff --git a/vendor/github.com/charithe/durationcheck/go.sum b/vendor/github.com/charithe/durationcheck/go.sum
index 89f6e5508..21d696a65 100644
--- a/vendor/github.com/charithe/durationcheck/go.sum
+++ b/vendor/github.com/charithe/durationcheck/go.sum
@@ -1,20 +1,26 @@
-github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
-golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
+golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
+golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b h1:AFZdJUT7jJYXQEC29hYH/WZkoV7+KhwxQGmdZ19yYoY=
-golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
+golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
+golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
-golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=