simplify code - eliminate type assertions

"gosimple" linter says:
S1034: assigning the result of this type assertion to a variable (switch f := f.(type)) could eliminate the following type assertions:
	flag.go:267:26
	flag.go:270:28
	flag.go:273:30
	flag.go:276:29
This commit is contained in:
Dmitry Kutakov 2019-12-26 14:05:50 +01:00
parent a56a0b93c8
commit 62597fe929
No known key found for this signature in database
GPG Key ID: E90B6246CD197433

10
flag.go
View File

@ -261,19 +261,19 @@ func flagValue(f Flag) reflect.Value {
func stringifyFlag(f Flag) string { func stringifyFlag(f Flag) string {
fv := flagValue(f) fv := flagValue(f)
switch f.(type) { switch f := f.(type) {
case *IntSliceFlag: case *IntSliceFlag:
return withEnvHint(flagStringSliceField(f, "EnvVars"), return withEnvHint(flagStringSliceField(f, "EnvVars"),
stringifyIntSliceFlag(f.(*IntSliceFlag))) stringifyIntSliceFlag(f))
case *Int64SliceFlag: case *Int64SliceFlag:
return withEnvHint(flagStringSliceField(f, "EnvVars"), return withEnvHint(flagStringSliceField(f, "EnvVars"),
stringifyInt64SliceFlag(f.(*Int64SliceFlag))) stringifyInt64SliceFlag(f))
case *Float64SliceFlag: case *Float64SliceFlag:
return withEnvHint(flagStringSliceField(f, "EnvVars"), return withEnvHint(flagStringSliceField(f, "EnvVars"),
stringifyFloat64SliceFlag(f.(*Float64SliceFlag))) stringifyFloat64SliceFlag(f))
case *StringSliceFlag: case *StringSliceFlag:
return withEnvHint(flagStringSliceField(f, "EnvVars"), return withEnvHint(flagStringSliceField(f, "EnvVars"),
stringifyStringSliceFlag(f.(*StringSliceFlag))) stringifyStringSliceFlag(f))
} }
placeholder, usage := unquoteUsage(fv.FieldByName("Usage").String()) placeholder, usage := unquoteUsage(fv.FieldByName("Usage").String())