diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 11fa6141ce..b2c18a90c2 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,3 +1,3 @@ --- -# see https://github.com/ansible/devtools -_extends: ansible/devtools +# see https://github.com/ansible/team-devtools +_extends: ansible/team-devtools diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 47d821bb5c..00d6b0e95f 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -73,7 +73,7 @@ jobs: env: # Number of expected test passes, safety measure for accidental skip of # tests. Update value if you add/remove tests. - PYTEST_REQPASS: 859 + PYTEST_REQPASS: 860 steps: - uses: actions/checkout@v4 with: diff --git a/src/ansiblelint/yaml_utils.py b/src/ansiblelint/yaml_utils.py index feb6b2f8d1..1b2a67c6a1 100644 --- a/src/ansiblelint/yaml_utils.py +++ b/src/ansiblelint/yaml_utils.py @@ -24,7 +24,7 @@ # To make the type checkers happy, we import from ruamel.yaml.main instead. from ruamel.yaml.main import YAML from ruamel.yaml.parser import ParserError -from ruamel.yaml.scalarint import ScalarInt +from ruamel.yaml.scalarint import HexInt, ScalarInt from yamllint.config import YamlLintConfig from ansiblelint.constants import ( @@ -541,7 +541,9 @@ def construct_yaml_int(self, node: ScalarNode) -> Any: value_s = value_su.replace("_", "") if value_s[0] in "+-": value_s = value_s[1:] - if value_s[0] == "0": + if value_s[0:2] == "0x": + ret = HexInt(ret, width=len(value_s) - 2) + elif value_s[0] == "0": # got an octal in YAML 1.1 ret = OctalIntYAML11( ret, @@ -630,6 +632,9 @@ def choose_scalar_style(self) -> Any: and len(self.event.value) > 1 ): if self.event.tag == "tag:yaml.org,2002:int" and self.event.implicit[0]: + if self.event.value.startswith("0x"): + self.event.tag = "tag:yaml.org,2002:str" + return "" # ensures that "0123" string does not lose its quoting self.event.tag = "tag:yaml.org,2002:str" self.event.implicit = (True, True, True) diff --git a/test/fixtures/formatting-after/fmt-hex.yml b/test/fixtures/formatting-after/fmt-hex.yml new file mode 100644 index 0000000000..7f09cb9426 --- /dev/null +++ b/test/fixtures/formatting-after/fmt-hex.yml @@ -0,0 +1,3 @@ +--- +d: 0x123 # <-- hex +e: 0x0123 diff --git a/test/fixtures/formatting-before/fmt-hex.yml b/test/fixtures/formatting-before/fmt-hex.yml new file mode 100644 index 0000000000..3bc15a75f0 --- /dev/null +++ b/test/fixtures/formatting-before/fmt-hex.yml @@ -0,0 +1,3 @@ +--- +d: 0x123 # <-- hex +e: 0x0123 diff --git a/test/fixtures/formatting-prettier/fmt-hex.yml b/test/fixtures/formatting-prettier/fmt-hex.yml new file mode 100644 index 0000000000..7f09cb9426 --- /dev/null +++ b/test/fixtures/formatting-prettier/fmt-hex.yml @@ -0,0 +1,3 @@ +--- +d: 0x123 # <-- hex +e: 0x0123 diff --git a/test/test_yaml_utils.py b/test/test_yaml_utils.py index 3513ed47d8..f885cf47c6 100644 --- a/test/test_yaml_utils.py +++ b/test/test_yaml_utils.py @@ -262,6 +262,7 @@ def test_fmt(before: str, after: str, version: tuple[int, int] | None) -> None: pytest.param("fmt-3.yml", (1, 1), id="3"), pytest.param("fmt-4.yml", (1, 1), id="4"), pytest.param("fmt-5.yml", (1, 1), id="5"), + pytest.param("fmt-hex.yml", (1, 1), id="hex"), ), ) def test_formatted_yaml_loader_dumper(