You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+116-1Lines changed: 116 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -144,7 +144,17 @@ come say hi!
144
144
145
145
## Documentation
146
146
147
-
🔥 **New in**`v0.19` 🔥: **Ignore rules with `x-lint-ignore`**
147
+
🔥 **New in**`v0.20` 🔥: **Support for auto fixing custom rules**
148
+
149
+
Got some rules that don't really need a human to look at?
150
+
151
+
Well now you can define an `AutoFixFunction` for your rules, and when you run with the `--fix` flag, the fixes will will be applied to the file, or use `--fix-file` to write them to a different file.
152
+
153
+
See [Auto-Fixing Rule Violations](#auto-fixing-rule-violations) for more specifics.
154
+
155
+
---
156
+
157
+
`v0.19`: **Ignore rules with `x-lint-ignore`**
148
158
149
159
Got an error in your spec you know about but can't get round to fixing yet?
150
160
Migrating from zally and wanting to keep your existing `x-zally-ignore` issues silenced?
@@ -616,4 +626,109 @@ You can configure global vacuum flags using environmental variables in the form
616
626
617
627
If a flag, has a `-` in it, replace with `_`
618
628
629
+
630
+
## Auto-fixing rule violations
631
+
632
+
If you have a rule that doesn't need a human to look at it, and the change can be reliably automated you can configure an `AutoFixFunction` on the rule. When you then run the `lint` command you can pass the `--fix` flag and the violation will be automatically fixed.
633
+
634
+
### Set up
635
+
636
+
1. Define a rule that has an `autoFixFunction`, e.g.:
return fmt.Errorf("failed to write file %s: %w", c.file, err)
715
+
}
716
+
}
717
+
718
+
return nil
719
+
}
720
+
```
721
+
722
+
When the auto fix function runs, if it returns an error the fix will not be applied, the error will be logged, and the violation will be reported in the standard results.
723
+
724
+
If the auto fix function succeeds the yaml node flagged by the violation will be replaced with the transformed version returned by the auto fix function.
725
+
726
+
> [!TIP]
727
+
> When using `vacuum` as a library You can access the fixed yaml content in the `RuleSetExecutionResult.ModifiedSpec`, and choose where to write the file.
728
+
>
729
+
> When using `vacuum` as a cli, the `--fix` flag will overwrite the spec file in place, and `--fix-file` flag lets you specify an alternative file to write the content to, if you want to compare the outputs.
730
+
731
+
### Usage
732
+
733
+
619
734
> Logo gopher is modified, originally from [egonelbre](https://github.com/egonelbre/gophers)
0 commit comments