buildBoilerplate constructs the boilerplate template based on what's missing
(rules *existingRules)
| 128 | |
| 129 | // buildBoilerplate constructs the boilerplate template based on what's missing |
| 130 | func buildBoilerplate(rules *existingRules) (string, error) { |
| 131 | data := boilerplateData{ |
| 132 | NeedsResult: !rules.hasRule[ruleResult], |
| 133 | NeedsDefaultSkipReason: !rules.hasDefault[ruleSkipReason] && !rules.hasRule[ruleSkipReason], |
| 134 | NeedsSkipReasonRule: !rules.hasRule[ruleSkipReason], |
| 135 | NeedsDefaultSkipped: !rules.hasDefault[ruleSkipped] && !rules.hasRule[ruleSkipped], |
| 136 | NeedsSkippedRule: !rules.hasRule[ruleSkipped], |
| 137 | NeedsDefaultIgnore: !rules.hasDefault[ruleIgnore] && !rules.hasRule[ruleIgnore], |
| 138 | NeedsDefaultValidInput: !rules.hasDefault[ruleValidInput] && !rules.hasRule[ruleValidInput], |
| 139 | NeedsDefaultViolations: !rules.hasDefault[ruleViolations] && !rules.hasRule[ruleViolations], |
| 140 | } |
| 141 | |
| 142 | tmpl, err := template.New("boilerplate").Parse(boilerplateTemplate) |
| 143 | if err != nil { |
| 144 | return "", fmt.Errorf("failed to parse boilerplate template: %w", err) |
| 145 | } |
| 146 | |
| 147 | var buf bytes.Buffer |
| 148 | if err := tmpl.Execute(&buf, data); err != nil { |
| 149 | return "", fmt.Errorf("failed to execute boilerplate template: %w", err) |
| 150 | } |
| 151 | |
| 152 | return buf.String(), nil |
| 153 | } |
| 154 | |
| 155 | // injectAfterImports inserts the injection block after the package declaration and existing imports |
| 156 | func injectAfterImports(module *ast.Module, originalPolicy, injection string) (string, error) { |
no test coverage detected