Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: return configure rule error #1193

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

12 changes: 12 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -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",
@@ -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 {
@@ -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)
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"]
Loading