From c29fd15f0271b8e4e16eeacd5ccccd3fbbec63b9 Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Thu, 14 Sep 2023 13:44:30 +0530 Subject: [PATCH 1/4] List all the transform rules via CLI --- src/ansiblelint/__main__.py | 6 +++++- src/ansiblelint/_internal/rules.py | 1 + src/ansiblelint/cli.py | 7 +++++++ src/ansiblelint/config.py | 1 + src/ansiblelint/rules/__init__.py | 20 ++++++++++++++++++- .../rules/command_instead_of_shell.py | 1 + .../rules/deprecated_local_action.py | 1 + src/ansiblelint/rules/jinja.py | 1 + src/ansiblelint/rules/key_order.py | 1 + src/ansiblelint/rules/name.py | 1 + src/ansiblelint/rules/no_free_form.py | 1 + src/ansiblelint/rules/no_jinja_when.py | 1 + src/ansiblelint/rules/no_log_password.py | 1 + src/ansiblelint/rules/partial_become.py | 1 + 14 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index b7490b0290..35067cac1a 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -170,6 +170,10 @@ def _do_list(rules: RulesCollection) -> int: console.print(render_yaml(rules.list_tags())) return 0 + if options.list_write_rules: + console.print(render_yaml(rules.list_write_rules())) + return 0 + # we should not get here! return 1 @@ -260,7 +264,7 @@ def main(argv: list[str] | None = None) -> int: options=options, ) - if options.list_rules or options.list_tags: + if options.list_rules or options.list_tags or options.list_write_rules: return _do_list(rules) if isinstance(options.tags, str): diff --git a/src/ansiblelint/_internal/rules.py b/src/ansiblelint/_internal/rules.py index acaf0f38c1..6c3fa03ee2 100644 --- a/src/ansiblelint/_internal/rules.py +++ b/src/ansiblelint/_internal/rules.py @@ -38,6 +38,7 @@ class BaseRule: id: str = "" tags: list[str] = [] + is_transformed: bool = False description: str = "" version_added: str = "" severity: str = "" diff --git a/src/ansiblelint/cli.py b/src/ansiblelint/cli.py index c9178a708a..5c2f75a41f 100644 --- a/src/ansiblelint/cli.py +++ b/src/ansiblelint/cli.py @@ -258,6 +258,13 @@ def get_cli_parser() -> argparse.ArgumentParser: help="List all the tags and the rules they cover. Increase the verbosity level " "with `-v` to include 'opt-in' tag and its rules.", ) + listing_group.add_argument( + "-wr", + "--list-write-rules", + dest="list_write_rules", + action="store_true", + help="List all the rules that can use transform/write functionality", + ) parser.add_argument( "-f", "--format", diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py index 519a0358cd..19d672c65f 100644 --- a/src/ansiblelint/config.py +++ b/src/ansiblelint/config.py @@ -117,6 +117,7 @@ class Options: # pylint: disable=too-many-instance-attributes,too-few-public-me lintables: list[str] = field(default_factory=list) list_rules: bool = False list_tags: bool = False + list_write_rules: bool = False write_list: list[str] = field(default_factory=list) parseable: bool = False quiet: bool = False diff --git a/src/ansiblelint/rules/__init__.py b/src/ansiblelint/rules/__init__.py index e87c898b55..f66a95bf7e 100644 --- a/src/ansiblelint/rules/__init__.py +++ b/src/ansiblelint/rules/__init__.py @@ -415,7 +415,11 @@ def __init__( # pylint: disable=too-many-arguments # When we have a profile we unload some of the rules # But we do include all rules when listing all rules or tags - if profile_name and not (self.options.list_rules or self.options.list_tags): + if profile_name and not ( + self.options.list_rules + or self.options.list_tags + or self.options.list_write_rules + ): filter_rules_with_profile(self.rules, profile_name) def register(self, obj: AnsibleLintRule, *, conditional: bool = False) -> None: @@ -541,6 +545,20 @@ def list_tags(self) -> str: result += f" - {name}\n" return result + def list_write_rules(self) -> str: + """Return all the rules covered under transform functionality.""" + transformed_rules = [] + rule_description = [] + for rule in self.rules: + if rule.is_transformed: + transformed_rules.append(rule.id) + rule_description.append(rule.shortdesc) + result = "# List of rules covered under write mode\n\n" + rule_dict = dict(zip(transformed_rules, rule_description)) + for key, value in rule_dict.items(): + result += f"{key}: # {value}\n\n" + return result + def filter_rules_with_profile(rule_col: list[BaseRule], profile: str) -> None: """Unload rules that are not part of the specified profile.""" diff --git a/src/ansiblelint/rules/command_instead_of_shell.py b/src/ansiblelint/rules/command_instead_of_shell.py index 09675c431d..36948eceec 100644 --- a/src/ansiblelint/rules/command_instead_of_shell.py +++ b/src/ansiblelint/rules/command_instead_of_shell.py @@ -45,6 +45,7 @@ class UseCommandInsteadOfShellRule(AnsibleLintRule, TransformMixin): ) severity = "HIGH" tags = ["command-shell", "idiom"] + is_transformed = True version_added = "historic" def matchtask( diff --git a/src/ansiblelint/rules/deprecated_local_action.py b/src/ansiblelint/rules/deprecated_local_action.py index 77f2860168..6f48d7ebb2 100644 --- a/src/ansiblelint/rules/deprecated_local_action.py +++ b/src/ansiblelint/rules/deprecated_local_action.py @@ -24,6 +24,7 @@ class TaskNoLocalAction(AnsibleLintRule, TransformMixin): needs_raw_task = True severity = "MEDIUM" tags = ["deprecations"] + is_transformed = True version_added = "v4.0.0" def matchtask( diff --git a/src/ansiblelint/rules/jinja.py b/src/ansiblelint/rules/jinja.py index d18e8e3940..2e2c804c44 100644 --- a/src/ansiblelint/rules/jinja.py +++ b/src/ansiblelint/rules/jinja.py @@ -89,6 +89,7 @@ class JinjaRule(AnsibleLintRule, TransformMixin): id = "jinja" severity = "LOW" tags = ["formatting"] + is_transformed = True version_added = "v6.5.0" _ansible_error_re = re.compile( r"^(?P.*): (?P.*)\. String: (?P.*)$", diff --git a/src/ansiblelint/rules/key_order.py b/src/ansiblelint/rules/key_order.py index 16b058914c..1ffd09b8f4 100644 --- a/src/ansiblelint/rules/key_order.py +++ b/src/ansiblelint/rules/key_order.py @@ -71,6 +71,7 @@ class KeyOrderRule(AnsibleLintRule, TransformMixin): shortdesc = __doc__ severity = "LOW" tags = ["formatting"] + is_transformed = True version_added = "v6.6.2" needs_raw_task = True _ids = { diff --git a/src/ansiblelint/rules/name.py b/src/ansiblelint/rules/name.py index a6ae7ca422..e37af89220 100644 --- a/src/ansiblelint/rules/name.py +++ b/src/ansiblelint/rules/name.py @@ -27,6 +27,7 @@ class NameRule(AnsibleLintRule, TransformMixin): ) severity = "MEDIUM" tags = ["idiom"] + is_transformed = True version_added = "v6.9.1 (last update)" _re_templated_inside = re.compile(r".*\{\{.*\}\}.*\w.*$") _ids = { diff --git a/src/ansiblelint/rules/no_free_form.py b/src/ansiblelint/rules/no_free_form.py index 6fb1dbcf48..aeffc73b36 100644 --- a/src/ansiblelint/rules/no_free_form.py +++ b/src/ansiblelint/rules/no_free_form.py @@ -25,6 +25,7 @@ class NoFreeFormRule(AnsibleLintRule, TransformMixin): description = "Avoid free-form inside files as it can produce subtle bugs." severity = "MEDIUM" tags = ["syntax", "risk"] + is_transformed = True version_added = "v6.8.0" needs_raw_task = True cmd_shell_re = re.compile( diff --git a/src/ansiblelint/rules/no_jinja_when.py b/src/ansiblelint/rules/no_jinja_when.py index 59350c9bfc..eb31f9373f 100644 --- a/src/ansiblelint/rules/no_jinja_when.py +++ b/src/ansiblelint/rules/no_jinja_when.py @@ -25,6 +25,7 @@ class NoFormattingInWhenRule(AnsibleLintRule, TransformMixin): ) severity = "HIGH" tags = ["deprecations"] + is_transformed = True version_added = "historic" @staticmethod diff --git a/src/ansiblelint/rules/no_log_password.py b/src/ansiblelint/rules/no_log_password.py index 1f18969e16..e62ac50c19 100644 --- a/src/ansiblelint/rules/no_log_password.py +++ b/src/ansiblelint/rules/no_log_password.py @@ -43,6 +43,7 @@ class NoLogPasswordsRule(AnsibleLintRule, TransformMixin): ) severity = "LOW" tags = ["opt-in", "security", "experimental"] + is_transformed = True version_added = "v5.0.9" def matchtask( diff --git a/src/ansiblelint/rules/partial_become.py b/src/ansiblelint/rules/partial_become.py index b8dc417052..6baab519f5 100644 --- a/src/ansiblelint/rules/partial_become.py +++ b/src/ansiblelint/rules/partial_become.py @@ -43,6 +43,7 @@ class BecomeUserWithoutBecomeRule(AnsibleLintRule, TransformMixin): description = "``become_user`` should have a corresponding ``become`` at the play or task level." severity = "VERY_HIGH" tags = ["unpredictability"] + is_transformed = True version_added = "historic" def matchplay( From 76edbf3c142079b1782a3685ced7610ca41a68a3 Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Fri, 15 Sep 2023 11:35:08 +0530 Subject: [PATCH 2/4] Remove the usage of is_transformed attribute and make the output look better on the terminal --- src/ansiblelint/_internal/rules.py | 1 - src/ansiblelint/generate_docs.py | 4 +++- src/ansiblelint/rules/__init__.py | 17 ++++++++++++++--- .../rules/command_instead_of_shell.py | 1 - .../rules/deprecated_local_action.py | 1 - src/ansiblelint/rules/jinja.py | 1 - src/ansiblelint/rules/key_order.py | 1 - src/ansiblelint/rules/name.py | 1 - src/ansiblelint/rules/no_free_form.py | 1 - src/ansiblelint/rules/no_jinja_when.py | 1 - src/ansiblelint/rules/no_log_password.py | 1 - src/ansiblelint/rules/partial_become.py | 1 - 12 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/ansiblelint/_internal/rules.py b/src/ansiblelint/_internal/rules.py index 6c3fa03ee2..acaf0f38c1 100644 --- a/src/ansiblelint/_internal/rules.py +++ b/src/ansiblelint/_internal/rules.py @@ -38,7 +38,6 @@ class BaseRule: id: str = "" tags: list[str] = [] - is_transformed: bool = False description: str = "" version_added: str = "" severity: str = "" diff --git a/src/ansiblelint/generate_docs.py b/src/ansiblelint/generate_docs.py index 1498a67790..dd14036808 100644 --- a/src/ansiblelint/generate_docs.py +++ b/src/ansiblelint/generate_docs.py @@ -9,7 +9,7 @@ from ansiblelint.config import PROFILES from ansiblelint.constants import RULE_DOC_URL -from ansiblelint.rules import RulesCollection +from ansiblelint.rules import RulesCollection, TransformMixin DOC_HEADER = """ # Default Rules @@ -27,6 +27,8 @@ def rules_as_str(rules: RulesCollection) -> RenderableType: """Return rules as string.""" table = Table(show_header=False, header_style="title", box=box.SIMPLE) for rule in rules.alphabetical(): + if issubclass(rule.__class__, TransformMixin): + rule.tags.insert(0, "transform") tag = f"[dim] ({', '.join(rule.tags)})[/dim]" if rule.tags else "" table.add_row( f"[link={RULE_DOC_URL}{rule.id}/]{rule.id}[/link]", diff --git a/src/ansiblelint/rules/__init__.py b/src/ansiblelint/rules/__init__.py index f66a95bf7e..97988d8481 100644 --- a/src/ansiblelint/rules/__init__.py +++ b/src/ansiblelint/rules/__init__.py @@ -6,6 +6,7 @@ import logging import re import sys +from abc import ABC, abstractmethod from collections import defaultdict from collections.abc import Iterable, Iterator, MutableMapping, MutableSequence from importlib import import_module @@ -251,7 +252,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: return matches -class TransformMixin: +class TransformMixin(ABC): """A mixin for AnsibleLintRule to enable transforming files. If ansible-lint is started with the ``--write`` option, then the ``Transformer`` @@ -260,6 +261,7 @@ class TransformMixin: a MatchError can do transforms to fix that match. """ + @abstractmethod def transform( self, match: MatchError, @@ -550,16 +552,25 @@ def list_write_rules(self) -> str: transformed_rules = [] rule_description = [] for rule in self.rules: - if rule.is_transformed: + if issubclass(rule.__class__, TransformMixin): transformed_rules.append(rule.id) rule_description.append(rule.shortdesc) result = "# List of rules covered under write mode\n\n" rule_dict = dict(zip(transformed_rules, rule_description)) for key, value in rule_dict.items(): - result += f"{key}: # {value}\n\n" + result += link(f"{RULE_DOC_URL}{key}/", key) + f": # {value}\n" return result +def link(uri: str, label: str) -> str: + """Generate the ANSI escape code for creating a hyperlinked label in a terminal.""" + if label is None: + label = uri + parameters = "" + escape_mask = "\033[94m\033]8;{};{}\033\\{}\033]8;;\033\\\033[0m" + return escape_mask.format(parameters, uri, label) + + def filter_rules_with_profile(rule_col: list[BaseRule], profile: str) -> None: """Unload rules that are not part of the specified profile.""" included = set() diff --git a/src/ansiblelint/rules/command_instead_of_shell.py b/src/ansiblelint/rules/command_instead_of_shell.py index 36948eceec..09675c431d 100644 --- a/src/ansiblelint/rules/command_instead_of_shell.py +++ b/src/ansiblelint/rules/command_instead_of_shell.py @@ -45,7 +45,6 @@ class UseCommandInsteadOfShellRule(AnsibleLintRule, TransformMixin): ) severity = "HIGH" tags = ["command-shell", "idiom"] - is_transformed = True version_added = "historic" def matchtask( diff --git a/src/ansiblelint/rules/deprecated_local_action.py b/src/ansiblelint/rules/deprecated_local_action.py index 6f48d7ebb2..77f2860168 100644 --- a/src/ansiblelint/rules/deprecated_local_action.py +++ b/src/ansiblelint/rules/deprecated_local_action.py @@ -24,7 +24,6 @@ class TaskNoLocalAction(AnsibleLintRule, TransformMixin): needs_raw_task = True severity = "MEDIUM" tags = ["deprecations"] - is_transformed = True version_added = "v4.0.0" def matchtask( diff --git a/src/ansiblelint/rules/jinja.py b/src/ansiblelint/rules/jinja.py index 2e2c804c44..d18e8e3940 100644 --- a/src/ansiblelint/rules/jinja.py +++ b/src/ansiblelint/rules/jinja.py @@ -89,7 +89,6 @@ class JinjaRule(AnsibleLintRule, TransformMixin): id = "jinja" severity = "LOW" tags = ["formatting"] - is_transformed = True version_added = "v6.5.0" _ansible_error_re = re.compile( r"^(?P.*): (?P.*)\. String: (?P.*)$", diff --git a/src/ansiblelint/rules/key_order.py b/src/ansiblelint/rules/key_order.py index 1ffd09b8f4..16b058914c 100644 --- a/src/ansiblelint/rules/key_order.py +++ b/src/ansiblelint/rules/key_order.py @@ -71,7 +71,6 @@ class KeyOrderRule(AnsibleLintRule, TransformMixin): shortdesc = __doc__ severity = "LOW" tags = ["formatting"] - is_transformed = True version_added = "v6.6.2" needs_raw_task = True _ids = { diff --git a/src/ansiblelint/rules/name.py b/src/ansiblelint/rules/name.py index e37af89220..a6ae7ca422 100644 --- a/src/ansiblelint/rules/name.py +++ b/src/ansiblelint/rules/name.py @@ -27,7 +27,6 @@ class NameRule(AnsibleLintRule, TransformMixin): ) severity = "MEDIUM" tags = ["idiom"] - is_transformed = True version_added = "v6.9.1 (last update)" _re_templated_inside = re.compile(r".*\{\{.*\}\}.*\w.*$") _ids = { diff --git a/src/ansiblelint/rules/no_free_form.py b/src/ansiblelint/rules/no_free_form.py index aeffc73b36..6fb1dbcf48 100644 --- a/src/ansiblelint/rules/no_free_form.py +++ b/src/ansiblelint/rules/no_free_form.py @@ -25,7 +25,6 @@ class NoFreeFormRule(AnsibleLintRule, TransformMixin): description = "Avoid free-form inside files as it can produce subtle bugs." severity = "MEDIUM" tags = ["syntax", "risk"] - is_transformed = True version_added = "v6.8.0" needs_raw_task = True cmd_shell_re = re.compile( diff --git a/src/ansiblelint/rules/no_jinja_when.py b/src/ansiblelint/rules/no_jinja_when.py index eb31f9373f..59350c9bfc 100644 --- a/src/ansiblelint/rules/no_jinja_when.py +++ b/src/ansiblelint/rules/no_jinja_when.py @@ -25,7 +25,6 @@ class NoFormattingInWhenRule(AnsibleLintRule, TransformMixin): ) severity = "HIGH" tags = ["deprecations"] - is_transformed = True version_added = "historic" @staticmethod diff --git a/src/ansiblelint/rules/no_log_password.py b/src/ansiblelint/rules/no_log_password.py index e62ac50c19..1f18969e16 100644 --- a/src/ansiblelint/rules/no_log_password.py +++ b/src/ansiblelint/rules/no_log_password.py @@ -43,7 +43,6 @@ class NoLogPasswordsRule(AnsibleLintRule, TransformMixin): ) severity = "LOW" tags = ["opt-in", "security", "experimental"] - is_transformed = True version_added = "v5.0.9" def matchtask( diff --git a/src/ansiblelint/rules/partial_become.py b/src/ansiblelint/rules/partial_become.py index 6baab519f5..b8dc417052 100644 --- a/src/ansiblelint/rules/partial_become.py +++ b/src/ansiblelint/rules/partial_become.py @@ -43,7 +43,6 @@ class BecomeUserWithoutBecomeRule(AnsibleLintRule, TransformMixin): description = "``become_user`` should have a corresponding ``become`` at the play or task level." severity = "VERY_HIGH" tags = ["unpredictability"] - is_transformed = True version_added = "historic" def matchplay( From 0281774da4206a654f1c8d58e7d690d547443d32 Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Wed, 20 Sep 2023 14:14:18 +0530 Subject: [PATCH 3/4] Show autofix label in --list-rules only --- src/ansiblelint/__main__.py | 6 +----- src/ansiblelint/cli.py | 7 ------- src/ansiblelint/config.py | 1 - src/ansiblelint/generate_docs.py | 2 +- src/ansiblelint/rules/__init__.py | 33 ++----------------------------- 5 files changed, 4 insertions(+), 45 deletions(-) diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index fe0dfda1a9..6bead1fe2f 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -170,10 +170,6 @@ def _do_list(rules: RulesCollection) -> int: console.print(render_yaml(rules.list_tags())) return 0 - if options.list_write_rules: - console.print(render_yaml(rules.list_write_rules())) - return 0 - # we should not get here! return 1 @@ -264,7 +260,7 @@ def main(argv: list[str] | None = None) -> int: options=options, ) - if options.list_rules or options.list_tags or options.list_write_rules: + if options.list_rules or options.list_tags: return _do_list(rules) if isinstance(options.tags, str): diff --git a/src/ansiblelint/cli.py b/src/ansiblelint/cli.py index 726d7acb04..352b8b505f 100644 --- a/src/ansiblelint/cli.py +++ b/src/ansiblelint/cli.py @@ -265,13 +265,6 @@ def get_cli_parser() -> argparse.ArgumentParser: help="List all the tags and the rules they cover. Increase the verbosity level " "with `-v` to include 'opt-in' tag and its rules.", ) - listing_group.add_argument( - "-wr", - "--list-write-rules", - dest="list_write_rules", - action="store_true", - help="List all the rules that can use transform/write functionality", - ) parser.add_argument( "-f", "--format", diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py index 19d672c65f..519a0358cd 100644 --- a/src/ansiblelint/config.py +++ b/src/ansiblelint/config.py @@ -117,7 +117,6 @@ class Options: # pylint: disable=too-many-instance-attributes,too-few-public-me lintables: list[str] = field(default_factory=list) list_rules: bool = False list_tags: bool = False - list_write_rules: bool = False write_list: list[str] = field(default_factory=list) parseable: bool = False quiet: bool = False diff --git a/src/ansiblelint/generate_docs.py b/src/ansiblelint/generate_docs.py index dd14036808..3a95de33aa 100644 --- a/src/ansiblelint/generate_docs.py +++ b/src/ansiblelint/generate_docs.py @@ -28,7 +28,7 @@ def rules_as_str(rules: RulesCollection) -> RenderableType: table = Table(show_header=False, header_style="title", box=box.SIMPLE) for rule in rules.alphabetical(): if issubclass(rule.__class__, TransformMixin): - rule.tags.insert(0, "transform") + rule.tags.insert(0, "autofix") tag = f"[dim] ({', '.join(rule.tags)})[/dim]" if rule.tags else "" table.add_row( f"[link={RULE_DOC_URL}{rule.id}/]{rule.id}[/link]", diff --git a/src/ansiblelint/rules/__init__.py b/src/ansiblelint/rules/__init__.py index afd7df6262..9cacb15530 100644 --- a/src/ansiblelint/rules/__init__.py +++ b/src/ansiblelint/rules/__init__.py @@ -6,7 +6,6 @@ import logging import re import sys -from abc import ABC, abstractmethod from collections import defaultdict from collections.abc import Iterable, Iterator, MutableMapping, MutableSequence from importlib import import_module @@ -252,7 +251,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: return matches -class TransformMixin(ABC): +class TransformMixin: """A mixin for AnsibleLintRule to enable transforming files. If ansible-lint is started with the ``--fix`` option, then the ``Transformer`` @@ -261,7 +260,6 @@ class TransformMixin(ABC): a MatchError can do transforms to fix that match. """ - @abstractmethod def transform( self, match: MatchError, @@ -417,11 +415,7 @@ def __init__( # pylint: disable=too-many-arguments # When we have a profile we unload some of the rules # But we do include all rules when listing all rules or tags - if profile_name and not ( - self.options.list_rules - or self.options.list_tags - or self.options.list_write_rules - ): + if profile_name and not (self.options.list_rules or self.options.list_tags): filter_rules_with_profile(self.rules, profile_name) def register(self, obj: AnsibleLintRule, *, conditional: bool = False) -> None: @@ -556,29 +550,6 @@ def list_tags(self) -> str: result += f" - {name}\n" return result - def list_write_rules(self) -> str: - """Return all the rules covered under transform functionality.""" - transformed_rules = [] - rule_description = [] - for rule in self.rules: - if issubclass(rule.__class__, TransformMixin): - transformed_rules.append(rule.id) - rule_description.append(rule.shortdesc) - result = "# List of rules covered under write mode\n\n" - rule_dict = dict(zip(transformed_rules, rule_description)) - for key, value in rule_dict.items(): - result += link(f"{RULE_DOC_URL}{key}/", key) + f": # {value}\n" - return result - - -def link(uri: str, label: str) -> str: - """Generate the ANSI escape code for creating a hyperlinked label in a terminal.""" - if label is None: - label = uri - parameters = "" - escape_mask = "\033[94m\033]8;{};{}\033\\{}\033]8;;\033\\\033[0m" - return escape_mask.format(parameters, uri, label) - def filter_rules_with_profile(rule_col: list[BaseRule], profile: str) -> None: """Unload rules that are not part of the specified profile.""" From 91ae2a06e803a17809310369b12d2f2a70bcfacc Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Wed, 20 Sep 2023 16:16:09 +0530 Subject: [PATCH 4/4] Add tests --- .github/workflows/tox.yml | 2 +- test/test_list_rules.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 2ee2c8c195..ef1b769eb7 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -71,7 +71,7 @@ jobs: WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY # Number of expected test passes, safety measure for accidental skip of # tests. Update value if you add/remove tests. - PYTEST_REQPASS: 826 + PYTEST_REQPASS: 827 steps: - name: Activate WSL1 if: "contains(matrix.shell, 'wsl')" diff --git a/test/test_list_rules.py b/test/test_list_rules.py index dab16e3012..85ef53fb05 100644 --- a/test/test_list_rules.py +++ b/test/test_list_rules.py @@ -18,6 +18,13 @@ def test_list_rules_includes_opt_in_rules(project_path: Path) -> None: assert ("opt-in" in result_list_rules.stdout) is True +def test_list_rules_includes_autofix() -> None: + """Checks that listing rules also includes the autofix label for applicable rules.""" + result_list_rules = run_ansible_lint("--list-rules") + + assert ("autofix" in result_list_rules.stdout) is True + + @pytest.mark.parametrize( ("result", "returncode", "format_string"), (