From 9eea653bf892a8ce21d1e6bf62a7560ba3193ccf Mon Sep 17 00:00:00 2001 From: dbrennand <52419383+dbrennand@users.noreply.github.com> Date: Mon, 8 Sep 2025 22:44:35 +0100 Subject: [PATCH] fix: #4705 https://github.com/ansible/ansible-lint/issues/4705 --- .../local/testcollection/playbooks/playbook_4705.yml | 8 ++++++++ src/ansiblelint/rules/yaml_rule.py | 4 +--- test/fixtures/yamllint.yml | 2 +- test/test_yaml_utils.py | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 collections/ansible_collections/local/testcollection/playbooks/playbook_4705.yml diff --git a/collections/ansible_collections/local/testcollection/playbooks/playbook_4705.yml b/collections/ansible_collections/local/testcollection/playbooks/playbook_4705.yml new file mode 100644 index 0000000000..f8d359cefc --- /dev/null +++ b/collections/ansible_collections/local/testcollection/playbooks/playbook_4705.yml @@ -0,0 +1,8 @@ +--- +- name: Playbook issue 4705 + hosts: localhost + gather_facts: false + tasks: + - name: Debug for 4705 + ansible.builtin.debug: + msg: "Hello, World! - This line is far too long and goes over the 111 lines which is allowed by our custom yamllint configuration." diff --git a/src/ansiblelint/rules/yaml_rule.py b/src/ansiblelint/rules/yaml_rule.py index ef161391e4..3d339e6960 100644 --- a/src/ansiblelint/rules/yaml_rule.py +++ b/src/ansiblelint/rules/yaml_rule.py @@ -10,7 +10,6 @@ from ansiblelint.file_utils import Lintable from ansiblelint.rules import AnsibleLintRule, TransformMixin -from ansiblelint.yaml_utils import load_yamllint_config if TYPE_CHECKING: from collections.abc import MutableMapping, MutableSequence @@ -29,7 +28,6 @@ class YamllintRule(AnsibleLintRule, TransformMixin): severity = "VERY_LOW" tags = ["formatting", "yaml"] version_changed = "5.0.0" - config = load_yamllint_config() has_dynamic_tags = True link = "https://yamllint.readthedocs.io/en/stable/rules.html" # ensure this rule runs before most of other common rules @@ -68,7 +66,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: for problem in run_yamllint( # type: ignore[no-untyped-call] file.content, - YamllintRule.config, + self._collection.app.yamllint_config, filepath=file.path, ): self.severity = "VERY_LOW" diff --git a/test/fixtures/yamllint.yml b/test/fixtures/yamllint.yml index 1bd6d359c9..a131f958fb 100644 --- a/test/fixtures/yamllint.yml +++ b/test/fixtures/yamllint.yml @@ -1,4 +1,4 @@ --- rules: line-length: - max: 222 + max: 111 diff --git a/test/test_yaml_utils.py b/test/test_yaml_utils.py index 3f1e31dab9..f9c7387414 100644 --- a/test/test_yaml_utils.py +++ b/test/test_yaml_utils.py @@ -1041,4 +1041,4 @@ def test_yamllint_file_config_loaded() -> None: """Ensure the yamllint configuration from a file is loaded correctly.""" config_fixture = Path(fixtures_dir / "yamllint.yml") config = ansiblelint.yaml_utils.load_yamllint_config(yamllint_file=config_fixture) - assert config.rules["line-length"]["max"] == 222 + assert config.rules["line-length"]["max"] == 111