Skip to content

Commit

Permalink
Allow a runner to be redefined within a ruleset (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 authored Feb 25, 2023
1 parent 78e0773 commit de8b014
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tflint/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ type RuleSet interface {
// ```
ApplyConfig(*hclext.BodyContent) error

// Check runs inspection for each rule by applying Runner.
// This is a entrypoint for all inspections and can be used as a hook to inject a custom runner.
// NewRunner returns a new runner based on the original runner.
// Custom rulesets can override this method to inject a custom runner.
NewRunner(Runner) (Runner, error)

// Check is a entrypoint for all inspections.
// This is not supposed to be overridden from custom rulesets.
Check(Runner) error

// All Ruleset must embed the builtin ruleset.
Expand Down
11 changes: 11 additions & 0 deletions tflint/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,19 @@ func (r *BuiltinRuleSet) ApplyConfig(content *hclext.BodyContent) error {
return nil
}

// NewRunner returns a new runner based on the original runner.
// Custom rulesets can override this method to inject a custom runner.
func (r *BuiltinRuleSet) NewRunner(runner Runner) (Runner, error) {
return runner, nil
}

// Check runs inspection for each rule by applying Runner.
func (r *BuiltinRuleSet) Check(runner Runner) error {
runner, err := r.NewRunner(runner)
if err != nil {
return err
}

for _, rule := range r.EnabledRules {
if err := rule.Check(runner); err != nil {
return fmt.Errorf("Failed to check `%s` rule: %s", rule.Name(), err)
Expand Down

0 comments on commit de8b014

Please sign in to comment.