Skip to content

Commit

Permalink
Merge pull request #73 from kurtmckee/sort-code-owners-case-insensiti…
Browse files Browse the repository at this point in the history
…vely

Sort code owners case insensitively
  • Loading branch information
sirosen authored Mar 27, 2024
2 parents 17070c3 + 0ee9de8 commit 3d81a8e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
12 changes: 3 additions & 9 deletions src/texthooks/alphabetize_codeowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
Ignores empty lines and comments, but normalizes whitespace on semantically significant
lines
"""
import re
import sys

from ._common import parse_cli_args
from ._recorders import DiffRecorder

WS_PAT = re.compile(r"\s+")


def main(*, argv=None) -> int:
args = parse_cli_args(
Expand Down Expand Up @@ -48,13 +45,10 @@ def sort_line(line: str) -> str:
if line == "" or line.strip().startswith("#"):
return line
# also normalizes whitespace
dedented = line.lstrip().rstrip()
elements = WS_PAT.split(dedented)
if len(elements) < 2:
path, *owners = line.split()
if not len(owners):
return line
path = elements[0]
owners = sorted(elements[1:])
return " ".join([path] + owners)
return " ".join([path] + sorted(owners, key=str.lower))


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/test_alphabetize_codeowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def test_alphabetize_codeowners_no_changes(runner):


def test_alphabetize_codeowners_normalizes_spaces(runner):
result = runner(alphabetize_codeowners_main, "/foo/bar.txt @alice @bob")
result = runner(alphabetize_codeowners_main, " /foo/bar.txt @alice\t@bob ")
assert result.exit_code == 1
assert result.file_data == "/foo/bar.txt @alice @bob"


def test_alphabetize_codeowners_sorts(runner):
result = runner(alphabetize_codeowners_main, "/foo/bar.txt @bob @alice")
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"
assert result.file_data == "/foo/bar.txt @alice @Bob @charlie"

0 comments on commit 3d81a8e

Please sign in to comment.