diff --git a/.config/dictionary.txt b/.config/dictionary.txt index 080f7d9a0d..15d00626d8 100644 --- a/.config/dictionary.txt +++ b/.config/dictionary.txt @@ -389,6 +389,7 @@ unindented uninstallation unjinja unlex +unloadable unnormalized unskippable unspaced diff --git a/src/ansiblelint/_internal/rules.py b/src/ansiblelint/_internal/rules.py index 3c3f475ac5..c4746aa7db 100644 --- a/src/ansiblelint/_internal/rules.py +++ b/src/ansiblelint/_internal/rules.py @@ -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 @@ -189,6 +191,7 @@ class RuntimeErrorRule(BaseRule): tags = ["core"] version_added = "v5.0.0" _order = 0 + unloadable = True class AnsibleParserErrorRule(BaseRule): @@ -200,6 +203,7 @@ class AnsibleParserErrorRule(BaseRule): tags = ["core"] version_added = "v5.0.0" _order = 0 + unloadable = True class LoadingFailureRule(BaseRule): @@ -215,6 +219,7 @@ class LoadingFailureRule(BaseRule): _ids = { "load-failure[not-found]": "File not found", } + unloadable = True class WarningRule(BaseRule): @@ -226,3 +231,4 @@ class WarningRule(BaseRule): tags = ["core", "experimental"] version_added = "v6.8.0" _order = 0 + unloadable = True diff --git a/src/ansiblelint/rules/__init__.py b/src/ansiblelint/rules/__init__.py index 9273130e3a..e056359069 100644 --- a/src/ansiblelint/rules/__init__.py +++ b/src/ansiblelint/rules/__init__.py @@ -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.", diff --git a/test/test_profiles.py b/test/test_profiles.py index a40382c830..473015f4a7 100644 --- a/test/test_profiles.py +++ b/test/test_profiles.py @@ -21,7 +21,7 @@ def test_profile_min() -> None: filter_rules_with_profile(collection.rules, "min") assert ( - len(collection.rules) == 3 + len(collection.rules) == 4 ), "Failed to unload rule that is not part of 'min' profile."