Feature: Cleanup command
After some discussion I am suggesting to add a cleanup command to tackle the following problems:
Problem
When a CODEOWNERS file becomes bigger the following problems arise:
- Duplicate patterns
- Hard to find what belongs to the same owner (lack of sorting)
- Obsolete patterns (no file matches the given pattern)
Proposal
Add a new command --cleanup to do the following things.
- Sort the file based on the rules listed below (See
sorting - Remove duplicate patterns (only full duplications)
- Expand each pattern and if finds 0 files, remove the pattern
Sorting
Our initial discussion lead to the following proposal:
- Sort (and thus group) by owner
- Within one owner sort patterns alphabetically
Related issues
#21 also asks for some of these topics.
Hi, I'm tackling this issue right now but I'd like to discuss about the sorting thing.
When generating the new CODEOWNERS file after sorting, should we keep the comments?
Comments right now are being treated as part of the "syntax" because of the "grouping" feature. I'm afraid it may be hard to keep comments and still order by the owner.
My idea was to simply start a new codeowners file from scratch and just "group" with the name of the owner, like such
# Owned by @owner_a
file_b @owner_a
file_c @owner_a
# Owned by @owner_b
file_a @owner_b
Any suggestions on how to do this in a simple way?
Also, how should we handle patterns with multiple owners?
The only reasonably solution is to treat a collection of owners as a "unique owner" when grouping
Something like
# Owned by @owner_a and @owner_b
file_d @owner_a @owner_b
# Owned by @owner_a
file_b @owner_a
file_c @owner_a
# Owned by @owner_b
file_a @owner_b
But we still need to think how to sort them.
Another question: should we check for consistency on this command as well? Or just rewrite the file?