From 3da6a64b2d5b4c1df762b303c95abd74675b6e70 Mon Sep 17 00:00:00 2001 From: Eng Zer Jun Date: Sat, 16 Sep 2023 12:07:45 +0800 Subject: [PATCH] Remove redundant nil check in `LocalFlagNames` From the Go specification: "1. For a nil slice, the number of iterations is 0." [1] Therefore, an additional nil check for before the loop is unnecessary. [1]: https://go.dev/ref/spec#For_range Signed-off-by: Eng Zer Jun --- command.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/command.go b/command.go index 991894ea82..b847789c89 100644 --- a/command.go +++ b/command.go @@ -922,11 +922,9 @@ func (cmd *Command) LocalFlagNames() []string { cmd.flagSet.Visit(makeFlagNameVisitor(&names)) // Check the flags which have been set via env or file - if cmd.Flags != nil { - for _, f := range cmd.Flags { - if f.IsSet() { - names = append(names, f.Names()...) - } + for _, f := range cmd.Flags { + if f.IsSet() { + names = append(names, f.Names()...) } }