Skip to content

Commit

Permalink
Fix minor bug (empty lines fail)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirosen committed Mar 27, 2024
1 parent 63a50f6 commit 8bfcefc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ following sample config:
### Unreleased

<!-- bumpversion-changelog -->
- Bugfix for empty line handling in `alphabetize-codeowners`

### 0.6.5

Expand Down
2 changes: 1 addition & 1 deletion src/texthooks/alphabetize_codeowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _add_files_arg(parser):


def sort_line(line: str) -> str:
if line == "" or line.strip().startswith("#"):
if line.strip() == "" or line.strip().startswith("#"):
return line
# also normalizes whitespace
path, *owners = line.split()
Expand Down
13 changes: 13 additions & 0 deletions tests/acceptance/test_alphabetize_codeowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ def test_alphabetize_codeowners_sorts(runner):
result = runner(alphabetize_codeowners_main, "/foo/bar.txt @Bob @alice @charlie")
assert result.exit_code == 1
assert result.file_data == "/foo/bar.txt @alice @Bob @charlie"


def test_alphabetize_codeowners_ignores_non_semantic_lines(runner):
result = runner(
alphabetize_codeowners_main,
"""
# comment 1: some comment
# comment 2: some non-alphabetized strings
# d c b a
/foo/bar.txt @alice @charlie""",
)
assert result.exit_code == 0

0 comments on commit 8bfcefc

Please sign in to comment.