Skip to content

Commit

Permalink
modify linter message
Browse files Browse the repository at this point in the history
  • Loading branch information
ykadowak committed Mar 19, 2023
1 parent cfed0db commit 6ac5121
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ import (

func main() {
// 1. Basic case
log.Info() // "missing to dispatch with Msg or Send function. nothing will be logged"
log.Info() // "must be dispatched by Msg or Send method"

// 2. Nested case
log.Info(). // "missing to dispatch with Msg or Send function. nothing will be logged"
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() // "missing to dispatch with Msg or Send function. nothing will be logged"
logger := log.Info() // "must be dispatched by Msg or Send method"
if err != nil {
logger = log.Error() // "missing to dispatch with Msg or Send function. nothing will be logged"
logger = log.Error() // "must be dispatched by Msg or Send method"
}
logger.Str("foo", "bar")
}
Expand Down
22 changes: 11 additions & 11 deletions testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ import (
)

func bad() {
log.Error() // want "missing to dispatch with Msg or Send function. nothing will be logged"
log.Info() // want "missing to dispatch with Msg or Send function. nothing will be logged"
log.Fatal() // want "missing to dispatch with Msg or Send function. nothing will be logged"
log.Debug() // want "missing to dispatch with Msg or Send function. nothing will be logged"
log.Warn() // want "missing to dispatch with Msg or Send function. nothing will be logged"
log.Error() // want "must be dispatched by Msg or Send method"
log.Info() // want "must be dispatched by Msg or Send method"
log.Fatal() // want "must be dispatched by Msg or Send method"
log.Debug() // want "must be dispatched by Msg or Send method"
log.Warn() // want "must be dispatched by Msg or Send method"

var err error
log.Error().Err(err) // want "missing to dispatch with Msg or Send function. nothing will be logged"
log.Error().Err(err).Str("foo", "bar").Int("foo", 1) // want "missing to dispatch with Msg or Send function. nothing will be logged"
log.Error().Err(err) // want "must be dispatched by Msg or Send method"
log.Error().Err(err).Str("foo", "bar").Int("foo", 1) // want "must be dispatched by Msg or Send method"

logger := log.Error() // want "missing to dispatch with Msg or Send function. nothing will be logged"
logger := log.Error() // want "must be dispatched by Msg or Send method"
logger.Err(err).Str("foo", "bar").Int("foo", 1)

// include zerolog.Dict()
log.Info(). // want "missing to dispatch with Msg or Send function. nothing will be logged"
log.Info(). // want "must be dispatched by Msg or Send method"
Str("foo", "bar").
Dict("dict", zerolog.Dict().
Str("bar", "baz").
Int("n", 1),
)

// conditional
logger2 := log.Info() // want "missing to dispatch with Msg or Send function. nothing will be logged"
logger2 := log.Info() // want "must be dispatched by Msg or Send method"
if err != nil {
logger2 = log.Error() // want "missing to dispatch with Msg or Send function. nothing will be logged"
logger2 = log.Error() // want "must be dispatched by Msg or Send method"
}
logger2.Str("foo", "bar")
}
Expand Down
2 changes: 1 addition & 1 deletion zerologlint.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
// At the end, if the set is clear -> ok.
// Otherwise, there must be a left zerolog.Event var that weren't dispached. So report it.
for k := range set {
pass.Reportf(k.Pos(), "missing to dispatch with Msg or Send function. nothing will be logged")
pass.Reportf(k.Pos(), "must be dispatched by Msg or Send method")
}
return nil, nil
}
Expand Down

0 comments on commit 6ac5121

Please sign in to comment.