Skip to content

Commit b4d4810

Browse files
authored
Avoid exception caused by accidental unloading of core rules (#3857)
1 parent 899f44c commit b4d4810

4 files changed

Lines changed: 10 additions & 1 deletion

File tree

.config/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ unindented
389389
uninstallation
390390
unjinja
391391
unlex
392+
unloadable
392393
unnormalized
393394
unskippable
394395
unspaced

src/ansiblelint/_internal/rules.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class BaseRule:
4545
link: str = ""
4646
has_dynamic_tags: bool = False
4747
needs_raw_task: bool = False
48+
# Used to mark rules that we will never unload (internal ones)
49+
unloadable: bool = False
4850
# We use _order to sort rules and to ensure that some run before others,
4951
# _order 0 for internal rules
5052
# _order 1 for rules that check that data can be loaded
@@ -189,6 +191,7 @@ class RuntimeErrorRule(BaseRule):
189191
tags = ["core"]
190192
version_added = "v5.0.0"
191193
_order = 0
194+
unloadable = True
192195

193196

194197
class AnsibleParserErrorRule(BaseRule):
@@ -200,6 +203,7 @@ class AnsibleParserErrorRule(BaseRule):
200203
tags = ["core"]
201204
version_added = "v5.0.0"
202205
_order = 0
206+
unloadable = True
203207

204208

205209
class LoadingFailureRule(BaseRule):
@@ -215,6 +219,7 @@ class LoadingFailureRule(BaseRule):
215219
_ids = {
216220
"load-failure[not-found]": "File not found",
217221
}
222+
unloadable = True
218223

219224

220225
class WarningRule(BaseRule):
@@ -226,3 +231,4 @@ class WarningRule(BaseRule):
226231
tags = ["core", "experimental"]
227232
version_added = "v6.8.0"
228233
_order = 0
234+
unloadable = True

src/ansiblelint/rules/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ def filter_rules_with_profile(rule_col: list[BaseRule], profile: str) -> None:
578578
included.add(rule)
579579
extends = PROFILES[extends].get("extends", None)
580580
for rule in rule_col.copy():
581+
if rule.unloadable:
582+
continue
581583
if rule.id not in included:
582584
_logger.debug(
583585
"Unloading %s rule due to not being part of %s profile.",

test/test_profiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_profile_min() -> None:
2121

2222
filter_rules_with_profile(collection.rules, "min")
2323
assert (
24-
len(collection.rules) == 3
24+
len(collection.rules) == 4
2525
), "Failed to unload rule that is not part of 'min' profile."
2626

2727

0 commit comments

Comments
 (0)