feature: add support for auto fixing rule violations #748
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
👋 me again.
One thing I'd like to use for some of my custom rules is the ability to auto fix simple things with a
--fixflag, so this PR adds that.Note
This doesn't add any fixes for any built-ins so needs to be added in the same way you would custom functions, so I've tried to stick to the same sort of approach as used there.
Approach
AutoFixFunctionto the rule struct (so you can defineautoFixFunctionon your custom rules)The auto fix functions takes in the yaml node with the error, the whole document (which enables you to refer to other parts of the document, which I anticipate being useful for something like adding examples using schema components defined in the file), and the rule context.
/tmpdirectory, then overwrite the file in place with the fixed version.Example in use
Warning
Tested it out where I'm using vacuum as library inside another tool, so note the output here is a custom output, but the processing of results and auto fixing is all done by vacuum, I'm just displaying the results in a custom manner.
Screen.Recording.2025-10-31.at.14.39.40.mov
The lint is flagging a custom rule not use
enumfields, and then the fix is replacing theenumwithx-extensible-enumas per our requirements.Additional improvements
I've not covered off all the functionality in this to prevent it from getting too big, so once this is merged I'll add functionality for:
simple spec used in screen recording.