Skip to content

Commit

Permalink
Avoid exception caused by accidental unloading of core rules
Browse files Browse the repository at this point in the history
Fixes: #3853
  • Loading branch information
ssbarnea committed Oct 19, 2023
1 parent 899f44c commit c636d28
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ unindented
uninstallation
unjinja
unlex
unloadable
unnormalized
unskippable
unspaced
Expand Down
6 changes: 6 additions & 0 deletions src/ansiblelint/_internal/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class BaseRule:
link: str = ""
has_dynamic_tags: bool = False
needs_raw_task: bool = False
# Used to mark rules that we will never unload (internal ones)
unloadable: bool = False
# We use _order to sort rules and to ensure that some run before others,
# _order 0 for internal rules
# _order 1 for rules that check that data can be loaded
Expand Down Expand Up @@ -189,6 +191,7 @@ class RuntimeErrorRule(BaseRule):
tags = ["core"]
version_added = "v5.0.0"
_order = 0
unloadable = True


class AnsibleParserErrorRule(BaseRule):
Expand All @@ -200,6 +203,7 @@ class AnsibleParserErrorRule(BaseRule):
tags = ["core"]
version_added = "v5.0.0"
_order = 0
unloadable = True


class LoadingFailureRule(BaseRule):
Expand All @@ -215,6 +219,7 @@ class LoadingFailureRule(BaseRule):
_ids = {
"load-failure[not-found]": "File not found",
}
unloadable = True


class WarningRule(BaseRule):
Expand All @@ -226,3 +231,4 @@ class WarningRule(BaseRule):
tags = ["core", "experimental"]
version_added = "v6.8.0"
_order = 0
unloadable = True
2 changes: 2 additions & 0 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ def filter_rules_with_profile(rule_col: list[BaseRule], profile: str) -> None:
included.add(rule)
extends = PROFILES[extends].get("extends", None)
for rule in rule_col.copy():
if rule.unloadable:
continue
if rule.id not in included:
_logger.debug(
"Unloading %s rule due to not being part of %s profile.",
Expand Down

0 comments on commit c636d28

Please sign in to comment.