File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -64,8 +64,12 @@ type RuleSet interface {
64
64
// ```
65
65
ApplyConfig (* hclext.BodyContent ) error
66
66
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.
69
73
Check (Runner ) error
70
74
71
75
// All Ruleset must embed the builtin ruleset.
Original file line number Diff line number Diff line change @@ -98,8 +98,19 @@ func (r *BuiltinRuleSet) ApplyConfig(content *hclext.BodyContent) error {
98
98
return nil
99
99
}
100
100
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
+
101
107
// Check runs inspection for each rule by applying Runner.
102
108
func (r * BuiltinRuleSet ) Check (runner Runner ) error {
109
+ runner , err := r .NewRunner (runner )
110
+ if err != nil {
111
+ return err
112
+ }
113
+
103
114
for _ , rule := range r .EnabledRules {
104
115
if err := rule .Check (runner ); err != nil {
105
116
return fmt .Errorf ("Failed to check `%s` rule: %s" , rule .Name (), err )
You can’t perform that action at this time.
0 commit comments