From 9c409082ece789c4cacb3f6524b2569d49c242b0 Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Sat, 15 Aug 2026 14:16:54 +0200 Subject: [PATCH 1/2] Add test for root sequence indentation --- tests/test_yaml_format.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_yaml_format.py b/tests/test_yaml_format.py index 5d80989..3b11f5a 100644 --- a/tests/test_yaml_format.py +++ b/tests/test_yaml_format.py @@ -104,6 +104,15 @@ def test_adds_document_start(self): result = format_yaml('key: value\n') assert result.startswith('---\n') + def test_no_explicit_start_preserves_root_sequence_indentation(self): + source = textwrap.dedent("""\ + - name: first + enabled: true + - name: second + enabled: false + """) + assert format_yaml(source, explicit_start=False) == source + def test_true_normalised(self): result = format_yaml('enabled: True\n') assert 'enabled: true' in result From 0ed48efc0de8575140c476320b17f7d43d6c0dbb Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Sat, 15 Aug 2026 14:35:29 +0200 Subject: [PATCH 2/2] Workaround yamlfix issue https://github.com/lyz-code/yamlfix/issues/274 --- polymath_code_standard/yaml_format.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/polymath_code_standard/yaml_format.py b/polymath_code_standard/yaml_format.py index 0eec21a..f063aaf 100644 --- a/polymath_code_standard/yaml_format.py +++ b/polymath_code_standard/yaml_format.py @@ -323,7 +323,10 @@ def format_yaml(source: str, explicit_start: bool = True) -> str: if not source: return source matrices = detect_matrices(source) - fixed = fix_code(source, _yamlfix_config(explicit_start=explicit_start)) + source_has_explicit_start = source.startswith('---\n') + fixed = fix_code(source, _yamlfix_config(explicit_start=True)) + if not explicit_start and not source_has_explicit_start and fixed.startswith('---\n'): + fixed = fixed[4:] if matrices: fixed = apply_matrices(fixed, matrices) return _strip_trailing_whitespace(fixed)