-
Notifications
You must be signed in to change notification settings - Fork 664
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
Add support for reformatting YAML files #1943
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Also add more typehints to satisfy mypy
Exclude is no longer used in the test, so drop it.
cognifloyd
requested review from
cidrblock,
ssbarnea and
tadeboro
and removed request for
a team
February 26, 2022 18:16
for more information, see https://pre-commit.ci
cognifloyd
changed the title
New Feature: Reformat YAML files with ruamel.yaml
Add support for reformatting YAML files
Feb 26, 2022
cognifloyd
commented
Feb 26, 2022
Please rebase :P |
|
|
ssbarnea
reviewed
Mar 1, 2022
cognifloyd
force-pushed
the
transformer-write-yaml
branch
4 times, most recently
from
March 1, 2022 18:30
39ed67e
to
6e02c03
Compare
cognifloyd
force-pushed
the
transformer-write-yaml
branch
from
March 2, 2022 01:01
6e02c03
to
2a57c35
Compare
cognifloyd
commented
Mar 3, 2022
This was referenced Mar 3, 2022
ssbarnea
approved these changes
Mar 5, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I want to introduce a feature to
ansible-lint
: It should be able to fix issues identified by rules. The feature in this PR is a pre-requisite to introducing that.In order to fix any issues identified by rules, we will have to read each YAML file with ruamel.yaml and then write it out. Reading/writing YAML files with ruamel.yaml standardizes spacing and quotes while preserving comments. In other words, it does very basic YAML reformatting which might fix some of the issues identified by
yamllint
. Fixing most of the issues identified by ansible-lint (including at least some of theyamllint
-identified issues) requires transforming the files in some way. This PR only implements the read+write part, leaving the actual rule transforms for future PRs.To use this (opt-in) mode, run
ansible-lint --write
(UX discussion summarized in #1910). That makes ansible-lint pass all YAML files it checks through our customizedruamel.yaml.YAML
instance.ansible-lint --write
reports a count of the number of modified files, which looks approximately like this:Notes:
Other merged PRs prepared the basis for this one (which replaces #1828):
--write
option for upcoming reformat/transform features #1926---
throughout repo #1948