aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ykadowak
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/ykadowak
parent475a4c203afb8b7d3af51c4fd32bb170ff32a45e (diff)
vendor: delete
Diffstat (limited to 'vendor/github.com/ykadowak')
-rw-r--r--vendor/github.com/ykadowak/zerologlint/.goreleaser.yaml24
-rw-r--r--vendor/github.com/ykadowak/zerologlint/LICENSE21
-rw-r--r--vendor/github.com/ykadowak/zerologlint/README.md63
-rw-r--r--vendor/github.com/ykadowak/zerologlint/zerologlint.go261
4 files changed, 0 insertions, 369 deletions
diff --git a/vendor/github.com/ykadowak/zerologlint/.goreleaser.yaml b/vendor/github.com/ykadowak/zerologlint/.goreleaser.yaml
deleted file mode 100644
index f3af3f212..000000000
--- a/vendor/github.com/ykadowak/zerologlint/.goreleaser.yaml
+++ /dev/null
@@ -1,24 +0,0 @@
-before:
- hooks:
- - go mod tidy
-builds:
- - id: zerologlint
- main: ./cmd/zerologlint
- binary: zerologlint
- env:
- - CGO_ENABLED=0
- goos:
- - linux
- - windows
- - darwin
-checksum:
- name_template: 'checksums.txt'
-snapshot:
- name_template: "{{ incpatch .Version }}-next"
-changelog:
- sort: asc
- filters:
- exclude:
- - '^docs:'
- - '^test:'
- - '^ci:'
diff --git a/vendor/github.com/ykadowak/zerologlint/LICENSE b/vendor/github.com/ykadowak/zerologlint/LICENSE
deleted file mode 100644
index 92a1e3b31..000000000
--- a/vendor/github.com/ykadowak/zerologlint/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2023 Yusuke Kadowaki
-
-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/ykadowak/zerologlint/README.md b/vendor/github.com/ykadowak/zerologlint/README.md
deleted file mode 100644
index b0a5fc0f9..000000000
--- a/vendor/github.com/ykadowak/zerologlint/README.md
+++ /dev/null
@@ -1,63 +0,0 @@
-# zerologlint
-![build](https://github.com/ykadowak/zerologlint/actions/workflows/testing.yaml/badge.svg)
-
-`zerologlint` is a linter for [zerolog](https://github.com/rs/zerolog) that can be run with `go vet` or through [golangci-lint](https://golangci-lint.run/) since `v1.53.0`.
-It detects the wrong usage of `zerolog` that a user forgets to dispatch `zerolog.Event` with `Send` or `Msg` like functions, in which case nothing will be logged. For more detailed explanations of the cases it detects, see [Examples](#Example).
-
-## Install
-
-```bash
-go install github.com/ykadowak/zerologlint/cmd/zerologlint@latest
-```
-
-## Usage
-```bash
-go vet -vettool=`which zerologlint` ./...
-```
-
-or you can also use it with [golangci-lint](https://golangci-lint.run/) since `v1.53.0`.
-
-## Examples
-```go
-package main
-
-import (
- "github.com/rs/zerolog"
- "github.com/rs/zerolog/log"
-)
-
-func main() {
- // 1. Basic case
- log.Info() // "must be dispatched by Msg or Send method"
-
- // 2. Nested case
- log.Info(). // "must be dispatched by Msg or Send method"
- Str("foo", "bar").
- Dict("dict", zerolog.Dict().
- Str("bar", "baz").
- Int("n", 1),
- )
-
- // 3. Reassignment case
- logger := log.Info() // "must be dispatched by Msg or Send method"
- if err != nil {
- logger = log.Error() // "must be dispatched by Msg or Send method"
- }
- logger.Str("foo", "bar")
-
- // 4. Deferred case
- defer log.Info() // "must be dispatched by Msg or Send method"
-
- // 5. zerolog.Logger case
- logger2 := zerolog.New(os.Stdout)
- logger2.Info().Send()
-
- // 6. Dispatch in other function case
- event := log.Info()
- dispatcher(event)
-}
-
-func dispatcher(e *zerolog.Event) {
- e.Send()
-}
-```
diff --git a/vendor/github.com/ykadowak/zerologlint/zerologlint.go b/vendor/github.com/ykadowak/zerologlint/zerologlint.go
deleted file mode 100644
index 8c8fb74fc..000000000
--- a/vendor/github.com/ykadowak/zerologlint/zerologlint.go
+++ /dev/null
@@ -1,261 +0,0 @@
-package zerologlint
-
-import (
- "go/token"
- "go/types"
- "strings"
-
- "golang.org/x/tools/go/analysis"
- "golang.org/x/tools/go/analysis/passes/buildssa"
- "golang.org/x/tools/go/ssa"
-
- "github.com/gostaticanalysis/comment/passes/commentmap"
-)
-
-var Analyzer = &analysis.Analyzer{
- Name: "zerologlint",
- Doc: "Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg`",
- Run: run,
- Requires: []*analysis.Analyzer{
- buildssa.Analyzer,
- commentmap.Analyzer,
- },
-}
-
-type posser interface {
- Pos() token.Pos
-}
-
-// callDefer is an interface just to hold both ssa.Call and ssa.Defer in our set
-type callDefer interface {
- Common() *ssa.CallCommon
- Pos() token.Pos
-}
-
-type linter struct {
- // eventSet holds all the ssa block that is a zerolog.Event type instance
- // that should be dispatched.
- // Everytime the zerolog.Event is dispatched with Msg() or Send(),
- // deletes that block from this set.
- // At the end, check if the set is empty, or report the not dispatched block.
- eventSet map[posser]struct{}
- // deleteLater holds the ssa block that should be deleted from eventSet after
- // all the inspection is done.
- // this is required because `else` ssa block comes after the dispatch of `if`` block.
- // e.g., if err != nil { log.Error() } else { log.Info() } log.Send()
- // deleteLater takes care of the log.Info() block.
- deleteLater map[posser]struct{}
- recLimit uint
-}
-
-func run(pass *analysis.Pass) (interface{}, error) {
- srcFuncs := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA).SrcFuncs
-
- l := &linter{
- eventSet: make(map[posser]struct{}),
- deleteLater: make(map[posser]struct{}),
- recLimit: 100,
- }
-
- for _, sf := range srcFuncs {
- for _, b := range sf.Blocks {
- for _, instr := range b.Instrs {
- if c, ok := instr.(*ssa.Call); ok {
- l.inspect(c)
- } else if c, ok := instr.(*ssa.Defer); ok {
- l.inspect(c)
- }
- }
- }
- }
-
- // apply deleteLater to envetSet for else branches of if-else cases
-
- for k := range l.deleteLater {
- delete(l.eventSet, k)
- }
-
- // At the end, if the set is clear -> ok.
- // Otherwise, there must be a left zerolog.Event var that weren't dispatched. So report it.
- for k := range l.eventSet {
- pass.Reportf(k.Pos(), "must be dispatched by Msg or Send method")
- }
-
- return nil, nil
-}
-
-func (l *linter) inspect(cd callDefer) {
- c := cd.Common()
-
- // check if it's in github.com/rs/zerolog/log since there's some
- // functions in github.com/rs/zerolog that returns zerolog.Event
- // which should not be included. However, zerolog.Logger receiver is an exception.
- if isInLogPkg(*c) || isLoggerRecv(*c) {
- if isZerologEvent(c.Value) {
- // this ssa block should be dispatched afterwards at some point
- l.eventSet[cd] = struct{}{}
- return
- }
- }
-
- // if the call does not return zerolog.Event,
- // check if the base is zerolog.Event.
- // if so, check if the StaticCallee is Send() or Msg().
- // if so, remove the arg[0] from the set.
- f := c.StaticCallee()
- if f == nil {
- return
- }
- if !isDispatchMethod(f) {
- shouldReturn := true
- for _, p := range f.Params {
- if isZerologEvent(p) {
- // check if this zerolog.Event as a parameter is dispatched in the function
- // TODO: technically, it can be dispatched in another function that is called in this function, and
- // this algorithm cannot track that. But I'm tired of thinking about that for now.
- for _, b := range f.Blocks {
- for _, instr := range b.Instrs {
- switch v := instr.(type) {
- case *ssa.Call:
- if inspectDispatchInFunction(v.Common()) {
- shouldReturn = false
- break
- }
- case *ssa.Defer:
- if inspectDispatchInFunction(v.Common()) {
- shouldReturn = false
- break
- }
- }
- }
- }
- }
- }
- if shouldReturn {
- return
- }
- }
- for _, arg := range c.Args {
- if isZerologEvent(arg) {
- // if there's branch, track both ways
- // this is for the case like:
- // logger := log.Info()
- // if err != nil {
- // logger = log.Error()
- // }
- // logger.Send()
- //
- // Similar case like below goes to the same root but that doesn't
- // have any side effect.
- // logger := log.Info()
- // if err != nil {
- // logger = logger.Str("a", "b")
- // }
- // logger.Send()
- if phi, ok := arg.(*ssa.Phi); ok {
- for _, edge := range phi.Edges {
- l.dfsEdge(edge, make(map[ssa.Value]struct{}), 0)
- }
- } else {
- val := getRootSsaValue(arg)
- delete(l.eventSet, val)
- }
- }
- }
-}
-
-func (l *linter) dfsEdge(v ssa.Value, visit map[ssa.Value]struct{}, cnt uint) {
- // only for safety
- if cnt > l.recLimit {
- return
- }
- cnt++
-
- if _, ok := visit[v]; ok {
- return
- }
- visit[v] = struct{}{}
-
- val := getRootSsaValue(v)
- phi, ok := val.(*ssa.Phi)
- if !ok {
- l.deleteLater[val] = struct{}{}
- return
- }
- for _, edge := range phi.Edges {
- l.dfsEdge(edge, visit, cnt)
- }
-}
-
-func inspectDispatchInFunction(cc *ssa.CallCommon) bool {
- if isDispatchMethod(cc.StaticCallee()) {
- for _, arg := range cc.Args {
- if isZerologEvent(arg) {
- return true
- }
- }
- }
- return false
-}
-
-func isInLogPkg(c ssa.CallCommon) bool {
- switch v := c.Value.(type) {
- case ssa.Member:
- p := v.Package()
- if p == nil {
- return false
- }
- return strings.HasSuffix(p.Pkg.Path(), "github.com/rs/zerolog/log")
- }
- return false
-}
-
-func isLoggerRecv(c ssa.CallCommon) bool {
- switch f := c.Value.(type) {
- case *ssa.Function:
- if recv := f.Signature.Recv(); recv != nil {
- return strings.HasSuffix(types.TypeString(recv.Type(), nil), "zerolog.Logger")
- }
- }
- return false
-}
-
-func isZerologEvent(v ssa.Value) bool {
- ts := v.Type().String()
- return strings.HasSuffix(ts, "github.com/rs/zerolog.Event")
-}
-
-func isDispatchMethod(f *ssa.Function) bool {
- if f == nil {
- return false
- }
- m := f.Name()
- if m == "Send" || m == "Msg" || m == "Msgf" || m == "MsgFunc" {
- return true
- }
- return false
-}
-
-func getRootSsaValue(v ssa.Value) ssa.Value {
- if c, ok := v.(*ssa.Call); ok {
- v := c.Value()
-
- // When there is no receiver, that's the block of zerolog.Event
- // eg. Error() method in log.Error().Str("foo", "bar").Send()
- if len(v.Call.Args) == 0 {
- return v
- }
-
- // Even when there is a receiver, if it's a zerolog.Logger instance, return this block
- // eg. Info() method in zerolog.New(os.Stdout).Info()
- root := v.Call.Args[0]
- if !isZerologEvent(root) {
- return v
- }
-
- // Ok to just return the receiver because all the method in this
- // chain is zerolog.Event at this point.
- return getRootSsaValue(root)
- }
- return v
-}