Skip to content

Commit 7f7d024

Browse files
authored
unused-param,unused-receiver: fix panic message (#1156)
1 parent a48710b commit 7f7d024

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

rule/unused_param.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,27 @@ type UnusedParamRule struct {
2121
func (r *UnusedParamRule) configure(args lint.Arguments) {
2222
// while by default args is an array, i think it's good to provide structures inside it by default, not arrays or primitives
2323
// it's more compatible to JSON nature of configurations
24-
var allowedRegexStr string
24+
var allowRegexStr string
2525
if len(args) == 0 {
26-
allowedRegexStr = "^_$"
26+
allowRegexStr = "^_$"
2727
r.failureMsg = "parameter '%s' seems to be unused, consider removing or renaming it as _"
2828
} else {
2929
// Arguments = [{}]
3030
options := args[0].(map[string]any)
31-
// Arguments = [{allowedRegex="^_"}]
31+
// Arguments = [{allowRegex="^_"}]
3232

33-
if allowedRegexParam, ok := options["allowRegex"]; ok {
34-
allowedRegexStr, ok = allowedRegexParam.(string)
33+
if allowRegexParam, ok := options["allowRegex"]; ok {
34+
allowRegexStr, ok = allowRegexParam.(string)
3535
if !ok {
36-
panic(fmt.Errorf("error configuring %s rule: allowedRegex is not string but [%T]", r.Name(), allowedRegexParam))
36+
panic(fmt.Errorf("error configuring %s rule: allowRegex is not string but [%T]", r.Name(), allowRegexParam))
3737
}
3838
}
3939
}
4040
var err error
41-
r.allowRegex, err = regexp.Compile(allowedRegexStr)
41+
r.allowRegex, err = regexp.Compile(allowRegexStr)
4242
if err != nil {
43-
panic(fmt.Errorf("error configuring %s rule: allowedRegex is not valid regex [%s]: %v", r.Name(), allowedRegexStr, err))
43+
panic(fmt.Errorf("error configuring %s rule: allowRegex is not valid regex [%s]: %v", r.Name(), allowRegexStr, err))
4444
}
45-
4645
if r.failureMsg == "" {
4746
r.failureMsg = "parameter '%s' seems to be unused, consider removing or renaming it to match " + r.allowRegex.String()
4847
}

rule/unused_receiver.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ type UnusedReceiverRule struct {
2121
func (r *UnusedReceiverRule) configure(args lint.Arguments) {
2222
// while by default args is an array, i think it's good to provide structures inside it by default, not arrays or primitives
2323
// it's more compatible to JSON nature of configurations
24-
var allowedRegexStr string
24+
var allowRegexStr string
2525
if len(args) == 0 {
26-
allowedRegexStr = "^_$"
26+
allowRegexStr = "^_$"
2727
r.failureMsg = "method receiver '%s' is not referenced in method's body, consider removing or renaming it as _"
2828
} else {
2929
// Arguments = [{}]
3030
options := args[0].(map[string]any)
31-
// Arguments = [{allowedRegex="^_"}]
31+
// Arguments = [{allowRegex="^_"}]
3232

33-
if allowedRegexParam, ok := options["allowRegex"]; ok {
34-
allowedRegexStr, ok = allowedRegexParam.(string)
33+
if allowRegexParam, ok := options["allowRegex"]; ok {
34+
allowRegexStr, ok = allowRegexParam.(string)
3535
if !ok {
36-
panic(fmt.Errorf("error configuring [unused-receiver] rule: allowedRegex is not string but [%T]", allowedRegexParam))
36+
panic(fmt.Errorf("error configuring [unused-receiver] rule: allowRegex is not string but [%T]", allowRegexParam))
3737
}
3838
}
3939
}
4040
var err error
41-
r.allowRegex, err = regexp.Compile(allowedRegexStr)
41+
r.allowRegex, err = regexp.Compile(allowRegexStr)
4242
if err != nil {
43-
panic(fmt.Errorf("error configuring [unused-receiver] rule: allowedRegex is not valid regex [%s]: %v", allowedRegexStr, err))
43+
panic(fmt.Errorf("error configuring [unused-receiver] rule: allowRegex is not valid regex [%s]: %v", allowRegexStr, err))
4444
}
4545
if r.failureMsg == "" {
4646
r.failureMsg = "method receiver '%s' is not referenced in method's body, consider removing or renaming it to match " + r.allowRegex.String()

0 commit comments

Comments
 (0)