Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion polymath_code_standard/yaml_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_yaml_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading