-
Notifications
You must be signed in to change notification settings - Fork 313
Open
Description
Describe the bug
enforce-slice-style dictates using var x []int rather than x := []int{} for slice definitions when configured with the "nil" argument, but it also reports the usage of []int{} in an expression context where var x []int can't be used
To Reproduce
Steps to reproduce the behavior:
- I updated revive
go install github.com/mgechev/revive@latest - I run it with the following flags & configuration file:
revive -config=revive.toml ./...[rule.enforce-slice-style]
Arguments = ["nil"]With the following code:
package main
func main() {
foo([]int{})
}
func foo(x []int) {}And got this output:
main.go:4:6: use nil slice declaration (e.g. var args []type) instead of []type{}
Expected behavior
I didn't expect this to be a lint finding because this particular rule seems to be all about declarations, not expressions. The error message makes me think the linter is suggesting the following because it mentions var args []type
func main() {
var x []int
foo(x)
}So I wonder if either:
- Only statements should be checked
- Or, maybe the error message could say something about
use nil instead of []typewhen findings are in an expression context; usingfoo(nil)here also suppresses the lint.
Metadata
Metadata
Assignees
Labels
No labels