Imagine you're adding a two-player mode to a game. When testing the feature, you launch the game but don't see the option to add a second player. The configuration looks correct; you enabled two-player mode on the last line!
So what happened? Can you spot the bug in the following example?
Using keep-sorted (github.com/google/keep-sorted) to sort lines makes the error easy to spot: the flag enable_two_players is set twice, with different values:
Sorted lists and lines of code are easier to read and maintain, and can help prevent bugs. To use keep-sorted in your source code, config, and text files, install keep-sorted and then follow these instructions:
Add keep-sorted start and keep-sorted end comments in your file, surrounding the lines you want to sort.
Run keep-sorted: keep-sorted [file1] [file2] ...
(Optional) Add keep-sorted to your pre-commit so it runs automatically on git commit
You can add options to override default behavior. For example, you can ignore case, sort numerically, order by prefixes, and even sort by regular expressions:
Remember: before sorting, ensure the original order isn't intentional. For example, order can be critical when loading dependencies.