Skip to content

Commit b9cc6ac

Browse files
authored
feat: improve report positions (#85)
1 parent c66b63f commit b9cc6ac

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sloglint.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func visit(pass *analysis.Pass, opts *Options, node ast.Node, stack []ast.Node)
252252

253253
// NOTE: "With" functions have no message argument and must be skipped.
254254
if opts.StaticMsg && msgPos >= 0 && !isStaticMsg(call.Args[msgPos]) {
255-
pass.Reportf(call.Pos(), "message should be a string literal or a constant")
255+
pass.Reportf(call.Args[msgPos].Pos(), "message should be a string literal or a constant")
256256
}
257257

258258
if opts.MsgStyle != "" && msgPos >= 0 {
@@ -262,7 +262,7 @@ func visit(pass *analysis.Pass, opts *Options, node ast.Node, stack []ast.Node)
262262
panic("unreachable") // string literals are always quoted.
263263
}
264264
if ok := isValidMsgStyle(value, opts.MsgStyle); !ok {
265-
pass.Reportf(call.Pos(), "message should be %s", opts.MsgStyle)
265+
pass.Reportf(call.Args[msgPos].Pos(), "message should be %s", opts.MsgStyle)
266266
}
267267
}
268268
}
@@ -315,7 +315,7 @@ func visit(pass *analysis.Pass, opts *Options, node ast.Node, stack []ast.Node)
315315
}
316316
}
317317
if !isConst {
318-
pass.Reportf(call.Pos(), "raw keys should not be used")
318+
pass.Reportf(key.Pos(), "raw keys should not be used")
319319
}
320320
})
321321
}
@@ -342,7 +342,7 @@ func visit(pass *analysis.Pass, opts *Options, node ast.Node, stack []ast.Node)
342342
if len(opts.ForbiddenKeys) > 0 {
343343
forEachKey(pass.TypesInfo, keys, attrs, func(key ast.Expr) {
344344
if name, ok := getKeyName(key); ok && slices.Contains(opts.ForbiddenKeys, name) {
345-
pass.Reportf(call.Pos(), "%q key is forbidden and should not be used", name)
345+
pass.Reportf(key.Pos(), "%q key is forbidden and should not be used", name)
346346
}
347347
})
348348
}

0 commit comments

Comments
 (0)