Skip to content

Commit c5817c2

Browse files
authored
Normalize version field for rules (#4431)
1 parent 3a181f0 commit c5817c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+64
-51
lines changed

src/ansiblelint/_internal/rules.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from pathlib import Path
88
from typing import TYPE_CHECKING, Any
99

10+
from packaging.version import InvalidVersion, Version
11+
1012
from ansiblelint.constants import RULE_DOC_URL
1113

1214
if TYPE_CHECKING:
@@ -41,7 +43,7 @@ class BaseRule:
4143
id: str = ""
4244
tags: list[str] = []
4345
description: str = ""
44-
version_added: str = ""
46+
version_changed: str = ""
4547
severity: str = ""
4648
link: str = ""
4749
has_dynamic_tags: bool = False
@@ -59,6 +61,13 @@ class BaseRule:
5961
# Allow rules to provide a custom short description instead of using __doc__
6062
_shortdesc: str = ""
6163

64+
def __init__(self) -> None:
65+
try:
66+
Version(self.version_changed)
67+
except InvalidVersion:
68+
msg = f"Rule {self.__class__.__name__} has an invalid version_changed field '{self.version_changed}', is should be a 'X.Y.Z' format value."
69+
_logger.warning(msg)
70+
6271
@property
6372
def help(self) -> str:
6473
"""Return a help markdown string for the rule."""
@@ -195,7 +204,7 @@ class RuntimeErrorRule(BaseRule):
195204
_shortdesc = "Unexpected internal error"
196205
severity = "VERY_HIGH"
197206
tags = ["core"]
198-
version_added = "v5.0.0"
207+
version_changed = "5.0.0"
199208
_order = 0
200209
unloadable = True
201210

@@ -207,7 +216,7 @@ class AnsibleParserErrorRule(BaseRule):
207216
description = "Ansible parser fails; this usually indicates an invalid file."
208217
severity = "VERY_HIGH"
209218
tags = ["core"]
210-
version_added = "v5.0.0"
219+
version_changed = "5.0.0"
211220
_order = 0
212221
unloadable = True
213222

@@ -219,7 +228,7 @@ class LoadingFailureRule(BaseRule):
219228
description = "Linter failed to process a file, possible invalid file."
220229
severity = "VERY_HIGH"
221230
tags = ["core", "unskippable"]
222-
version_added = "v4.3.0"
231+
version_changed = "4.3.0"
223232
_help = LOAD_FAILURE_MD
224233
_order = 0
225234
_ids = {
@@ -235,6 +244,6 @@ class WarningRule(BaseRule):
235244
severity = "LOW"
236245
# should remain experimental as that would keep it warning only
237246
tags = ["core", "experimental"]
238-
version_added = "v6.8.0"
247+
version_changed = "6.8.0"
239248
_order = 0
240249
unloadable = True

src/ansiblelint/generate_docs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def rules_as_rich(rules: RulesCollection) -> Iterable[Table]:
8181
if rule.link:
8282
description += f" [(more)]({rule.link})"
8383
table.add_row("description", Markdown(description))
84-
if rule.version_added:
85-
table.add_row("version_added", rule.version_added)
84+
if rule.version_changed:
85+
table.add_row("version_changed", rule.version_changed)
8686
if rule.tags:
8787
table.add_row("tags", ", ".join(rule.tags))
8888
if rule.severity:

src/ansiblelint/rules/args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ArgsRule(AnsibleLintRule):
8888
severity = "HIGH"
8989
description = "Check whether tasks are using correct module options."
9090
tags = ["syntax", "experimental"]
91-
version_added = "v6.10.0"
91+
version_changed = "6.10.0"
9292
module_aliases: dict[str, str] = {"block/always/rescue": "block/always/rescue"}
9393
_ids = {
9494
"args[module]": description,

src/ansiblelint/rules/avoid_implicit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AvoidImplicitRule(AnsibleLintRule):
2424
)
2525
severity = "MEDIUM"
2626
tags = ["unpredictability"]
27-
version_added = "v6.8.0"
27+
version_changed = "6.8.0"
2828

2929
def matchtask(
3030
self,

src/ansiblelint/rules/command_instead_of_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CommandsInsteadOfModulesRule(AnsibleLintRule):
4242
)
4343
severity = "HIGH"
4444
tags = ["command-shell", "idiom"]
45-
version_added = "historic"
45+
version_changed = "24.10.0"
4646

4747
_commands = ["command", "shell"]
4848
_modules = {

src/ansiblelint/rules/command_instead_of_shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class UseCommandInsteadOfShellRule(AnsibleLintRule, TransformMixin):
4646
)
4747
severity = "HIGH"
4848
tags = ["command-shell", "idiom"]
49-
version_added = "historic"
49+
version_changed = "6.18.0"
5050

5151
def matchtask(
5252
self,

src/ansiblelint/rules/complexity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ComplexityRule(AnsibleLintRule):
2323
description = "There should be limited tasks executed inside any file"
2424
severity = "MEDIUM"
2525
tags = ["experimental", "idiom"]
26-
version_added = "v6.18.0 (last update)"
26+
version_changed = "6.18.0"
2727
_re_templated_inside = re.compile(r".*\{\{.*\}\}.*\w.*$")
2828

2929
def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]:

src/ansiblelint/rules/deprecated_bare_vars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class UsingBareVariablesIsDeprecatedRule(AnsibleLintRule):
4545
)
4646
severity = "VERY_HIGH"
4747
tags = ["deprecations"]
48-
version_added = "historic"
48+
version_changed = "6.19.0"
4949

5050
def matchtask(
5151
self,

src/ansiblelint/rules/deprecated_local_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TaskNoLocalActionRule(AnsibleLintRule, TransformMixin):
3535
needs_raw_task = True
3636
severity = "MEDIUM"
3737
tags = ["deprecations"]
38-
version_added = "v4.0.0"
38+
version_changed = "4.0.0"
3939

4040
def matchtask(
4141
self,

src/ansiblelint/rules/deprecated_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DeprecatedModuleRule(AnsibleLintRule):
2323
link = "https://docs.ansible.com/ansible/latest/collections/index_module.html"
2424
severity = "HIGH"
2525
tags = ["deprecations"]
26-
version_added = "v4.0.0"
26+
version_changed = "4.0.0"
2727

2828
_modules = [
2929
"accelerate",

0 commit comments

Comments
 (0)