Skip to content

Commit de8b014

Browse files
authored
Allow a runner to be redefined within a ruleset (#225)
1 parent 78e0773 commit de8b014

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

tflint/interface.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ type RuleSet interface {
6464
// ```
6565
ApplyConfig(*hclext.BodyContent) error
6666

67-
// Check runs inspection for each rule by applying Runner.
68-
// This is a entrypoint for all inspections and can be used as a hook to inject a custom runner.
67+
// NewRunner returns a new runner based on the original runner.
68+
// Custom rulesets can override this method to inject a custom runner.
69+
NewRunner(Runner) (Runner, error)
70+
71+
// Check is a entrypoint for all inspections.
72+
// This is not supposed to be overridden from custom rulesets.
6973
Check(Runner) error
7074

7175
// All Ruleset must embed the builtin ruleset.

tflint/ruleset.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,19 @@ func (r *BuiltinRuleSet) ApplyConfig(content *hclext.BodyContent) error {
9898
return nil
9999
}
100100

101+
// NewRunner returns a new runner based on the original runner.
102+
// Custom rulesets can override this method to inject a custom runner.
103+
func (r *BuiltinRuleSet) NewRunner(runner Runner) (Runner, error) {
104+
return runner, nil
105+
}
106+
101107
// Check runs inspection for each rule by applying Runner.
102108
func (r *BuiltinRuleSet) Check(runner Runner) error {
109+
runner, err := r.NewRunner(runner)
110+
if err != nil {
111+
return err
112+
}
113+
103114
for _, rule := range r.EnabledRules {
104115
if err := rule.Check(runner); err != nil {
105116
return fmt.Errorf("Failed to check `%s` rule: %s", rule.Name(), err)

0 commit comments

Comments
 (0)