Skip to content
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

--write: Optionally pass rule names to --write in cli #2051

Merged
merged 24 commits into from Mar 30, 2022

Conversation

cognifloyd
Copy link
Member

@cognifloyd cognifloyd commented Mar 28, 2022

Allow users to control which transforms ansible-lint --write will run.

Introduces write_list config file setting to complement the --write command line option.
Each of these accept special keywords all and none as well as a list of rule ids and rule tags.

  • --write defaults to whatever is in the config file. If write_list is not populated in the config file, then --write is effectively the same thing as --write=all.
  • --write=all allows all transforms to run.
  • --write=none resets the list of transforms so that people can reformat YAML without running any of the transforms.
    You can also use the none keyword to reset the list so you can run only a different set of rules than what is in the config file (as in --write=none,rule-id will run just rule-id even if all is in the config file).
  • --write=rule-id adds rule-id to write_list from the config file. If the config file does not populate write_list, then this means only run the transform for rule rule-id.
  • --write=rule-tag works just like --write=rule-id but references rule tags instead of rule ids.

Here are some examples that ignore write_list in the config file and selects rules tagged with ansible-2-11-upgrade:

ansible-lint --write none --write ansible-2-11-upgrade
ansible-lint --write none,ansible-2-11-upgrade

This example just adds ansible-2-11-upgrade to write_list from the config file:

ansible-lint --write ansible-2-11-upgrade

src/ansiblelint/cli.py Outdated Show resolved Hide resolved
click v8.1.0 was just released which breaks black v22.1.0.
black v22.3.0 fixes the incompatibility.
@github-actions github-actions bot added the skip-changelog Can be missed from the changelog. label Mar 28, 2022
@cognifloyd cognifloyd removed the skip-changelog Can be missed from the changelog. label Mar 28, 2022
@cognifloyd cognifloyd self-assigned this Mar 28, 2022
@cognifloyd cognifloyd marked this pull request as ready for review March 28, 2022 21:44
@cognifloyd

This comment was marked as outdated.

@cognifloyd cognifloyd force-pushed the filter-write branch 2 times, most recently from 5f5b968 to 8f38659 Compare March 29, 2022 17:21
Comment on lines +282 to +293
help="Allow ansible-lint to reformat YAML files and run rule transforms "
"(Reformatting YAML files standardizes spacing, quotes, etc. "
"A rule transform can fix or simplify fixing issues identified by that rule). "
"You can limit the effective rule transforms (the 'write_list') by passing a "
"keywords 'all' or 'none' or a comma separated list of rule ids or rule tags. "
"YAML reformatting happens whenever '--write' or '--write=' is used. "
"'--write' and '--write=all' are equivalent: they allow all transforms to run. "
"The effective list of transforms comes from 'write_list' in the config file, "
"followed whatever '--write' args are provided on the commandline. "
"'--write=none' resets the list of transforms to allow reformatting YAML "
"without running any of the transforms (ie '--write=none,rule-id' will "
"ignore write_list in the config file and only run the rule-id transform).",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too long for a help text. It presents as this wall of text:

  --write [WRITE_LIST]  Allow ansible-lint to reformat YAML files and run rule
                        transforms (Reformatting YAML files standardizes
                        spacing, quotes, etc. A rule transform can fix or
                        simplify fixing issues identified by that rule). You
                        can limit the effective rule transforms (the
                        'write_list') by passing a keywords 'all' or 'none' or
                        a comma separated list of rule ids or rule tags. YAML
                        reformatting happens whenever '--write' or '--write='
                        is used. '--write' and '--write=all' are equivalent:
                        they allow all transforms to run. The effective list
                        of transforms comes from 'write_list' in the config
                        file, followed whatever '--write' args are provided on
                        the commandline. '--write=none' resets the list of
                        transforms to allow reformatting YAML without running
                        any of the transforms (ie '--write=none,rule-id' will
                        ignore write_list in the config file and only run the
                        rule-id transform).

I guess the next thing to do is figure out where this might go in the docs and then post a link from the help text.

@ssbarnea ssbarnea merged commit 3c21b63 into ansible:main Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants