Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow a runner to be redefined within a ruleset #225

Merged
merged 1 commit into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
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
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