From 0ae9462e5556936aa94061c751ba58fb2dd23083 Mon Sep 17 00:00:00 2001 From: rhysd Date: Fri, 9 Feb 2024 23:58:33 +0900 Subject: [PATCH] rename `GetConfig` to `Config` to align getter method names in `RuleBase` --- rule.go | 7 ++++--- rule_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 rule_test.go diff --git a/rule.go b/rule.go index 8a84030e7..e6eeb1987 100644 --- a/rule.go +++ b/rule.go @@ -90,8 +90,9 @@ func (r *RuleBase) SetConfig(cfg *Config) { r.config = cfg } -// GetConfig returns the config of the rule -func (r *RuleBase) GetConfig() *Config { +// Config returns the user configuration of actionlint. When no config was set to this rule by SetConfig, +// this method returns nil. +func (r *RuleBase) Config() *Config { return r.config } @@ -103,5 +104,5 @@ type Rule interface { Description() string EnableDebug(out io.Writer) SetConfig(cfg *Config) - GetConfig() *Config + Config() *Config } diff --git a/rule_test.go b/rule_test.go new file mode 100644 index 000000000..5e0d66684 --- /dev/null +++ b/rule_test.go @@ -0,0 +1,15 @@ +package actionlint + +import "testing" + +func TestRuleBaseConfig(t *testing.T) { + r := NewRuleBase("", "") + if r.Config() != nil { + t.Error("Config must be nil after creating a rule") + } + want := &Config{} + r.SetConfig(want) + if have := r.Config(); have != want { + t.Errorf("Wanted config %v but got %v", want, have) + } +}