Skip to content

Commit

Permalink
fix: return configure rule error (#1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Dec 23, 2024
1 parent 3d1115d commit 7998011
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,

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

Expand Down
12 changes: 12 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestGetLintingRules(t *testing.T) {
tt := map[string]struct {
confPath string
wantRulesCount int
wantErr string
}{
"no rules": {
confPath: "testdata/noRules.toml",
Expand All @@ -105,6 +106,10 @@ func TestGetLintingRules(t *testing.T) {
confPath: "testdata/enable2.toml",
wantRulesCount: 2,
},
"var-naming configure error": {
confPath: "testdata/varNamingConfigureError.toml",
wantErr: `cannot configure rule: "var-naming": invalid argument to the var-naming rule. Expecting a allowlist of type slice with initialisms, got string`,
},
}

for name, tc := range tt {
Expand All @@ -114,6 +119,13 @@ func TestGetLintingRules(t *testing.T) {
t.Fatalf("Unexpected error while loading conf: %v", err)
}
rules, err := GetLintingRules(cfg, []lint.Rule{})
if tc.wantErr != "" {
if err == nil || err.Error() != tc.wantErr {
t.Fatalf("Expected error %q, got %q", tc.wantErr, err)
}
return
}

switch {
case err != nil:
t.Fatalf("Unexpected error\n\t%v", err)
Expand Down
4 changes: 4 additions & 0 deletions config/testdata/varNamingConfigureError.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enableAllRules = false

[rule.var-naming]
arguments = ["ID", "VM"]

0 comments on commit 7998011

Please sign in to comment.