Skip to content

Commit

Permalink
Merge pull request #15 from lyz-code/fix/lines-with-comments
Browse files Browse the repository at this point in the history
fix: correct indentation of parent lists with comments
  • Loading branch information
lyz-code committed Nov 30, 2020
2 parents 95f0a5b + 76f36d9 commit 4fb1adc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/yamlfix/services.py
Expand Up @@ -111,6 +111,7 @@ def _fix_top_level_lists(source_code: str) -> str:
```yaml
---
# Comment
- item 1
- item 2
```
Expand All @@ -119,6 +120,7 @@ def _fix_top_level_lists(source_code: str) -> str:
```yaml
---
# Comment
- item 1
- item 2
```
Expand All @@ -138,7 +140,7 @@ def _fix_top_level_lists(source_code: str) -> str:
for line in source_lines:

# Skip the heading and first empty lines
if line in ["---", ""]:
if re.match(r"^(---|#.*|)$", line):
fixed_source_lines.append(line)
continue

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_services.py
Expand Up @@ -108,6 +108,21 @@ def test_fix_code_preserves_comments() -> None:
assert result == source


def test_fix_code_respects_parent_lists_with_comments() -> None:
"""Do not indent lists at the first level even if there is a comment."""
source = dedent(
"""\
---
# Comment
- item1
- item2"""
)

result = fix_code(source)

assert result == source


def test_fix_code_removes_extra_apostrophes() -> None:
"""Remove not needed apostrophes."""
source = dedent(
Expand Down

0 comments on commit 4fb1adc

Please sign in to comment.