Skip to content

Commit 7998011

Browse files
authoredDec 23, 2024
fix: return configure rule error (#1193)
1 parent 3d1115d commit 7998011

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed
 

‎config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
151151

152152
if r, ok := r.(lint.ConfigurableRule); ok {
153153
if err := r.Configure(ruleConfig.Arguments); err != nil {
154-
return nil, fmt.Errorf("cannot configure rule: %s", name)
154+
return nil, fmt.Errorf("cannot configure rule: %q: %w", name, err)
155155
}
156156
}
157157

‎config/config_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func TestGetLintingRules(t *testing.T) {
8888
tt := map[string]struct {
8989
confPath string
9090
wantRulesCount int
91+
wantErr string
9192
}{
9293
"no rules": {
9394
confPath: "testdata/noRules.toml",
@@ -105,6 +106,10 @@ func TestGetLintingRules(t *testing.T) {
105106
confPath: "testdata/enable2.toml",
106107
wantRulesCount: 2,
107108
},
109+
"var-naming configure error": {
110+
confPath: "testdata/varNamingConfigureError.toml",
111+
wantErr: `cannot configure rule: "var-naming": invalid argument to the var-naming rule. Expecting a allowlist of type slice with initialisms, got string`,
112+
},
108113
}
109114

110115
for name, tc := range tt {
@@ -114,6 +119,13 @@ func TestGetLintingRules(t *testing.T) {
114119
t.Fatalf("Unexpected error while loading conf: %v", err)
115120
}
116121
rules, err := GetLintingRules(cfg, []lint.Rule{})
122+
if tc.wantErr != "" {
123+
if err == nil || err.Error() != tc.wantErr {
124+
t.Fatalf("Expected error %q, got %q", tc.wantErr, err)
125+
}
126+
return
127+
}
128+
117129
switch {
118130
case err != nil:
119131
t.Fatalf("Unexpected error\n\t%v", err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
enableAllRules = false
2+
3+
[rule.var-naming]
4+
arguments = ["ID", "VM"]

0 commit comments

Comments
 (0)
Please sign in to comment.