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
1 change: 1 addition & 0 deletions src/yamlfix/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ def _fix_comments(self, source_code: str) -> str:
config.comments_min_spaces_from_content > 1
and " #" in line
and line[-1] not in ["'", '"']
and not line.lstrip().startswith("#")
):
line = re.sub(
r"^([^\"']*[^\"' \t])(\s+?)#", rf"\1{comment_start}", line
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_adapter_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def test_comment_spacing_config(self) -> None:
# comment
project_name: yamlfix #comment
"key #1": 'value #2'
# comment
# #!/usr/bin/env bash
"""
)
fixed_source = dedent(
Expand All @@ -89,6 +91,8 @@ def test_comment_spacing_config(self) -> None:
# comment
project_name: yamlfix # comment
'key #1': 'value #2'
# comment
# #!/usr/bin/env bash
"""
)
config = YamlfixConfig()
Expand Down