# Sort Lines in Source Code

DevFeed: [Sort Lines in Source Code](<https://devfeed.tech/articles/sort-lines-in-source-code-23864.md>)

Original publisher: [Read original article](<http://testing.googleblog.com/2025/09/sort-lines-in-source-code.html>)

Author: Google Testing Bloggers (noreply@blogger.com)

Published: 2025-09-15T13:45:00Z

Content type: tutorial

Language: en

Sources: [Google Testing Blog](<https://devfeed.tech/sources/google-testing-blog.md>)

Topics: [Sorting](<https://devfeed.tech/topics/sorting.md>), [Code](<https://devfeed.tech/topics/code.md>), [bug](<https://devfeed.tech/topics/bug.md>), [configuration](<https://devfeed.tech/topics/configuration.md>)

Tags: [bug](<https://devfeed.tech/tags/bug.md>), [code](<https://devfeed.tech/tags/code.md>), [config](<https://devfeed.tech/tags/config.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [env-file-security](<https://devfeed.tech/tags/env-file-security.md>), [git](<https://devfeed.tech/tags/git.md>), [kyle-freeman](<https://devfeed.tech/tags/kyle-freeman.md>), [sorting](<https://devfeed.tech/tags/sorting.md>), [tott](<https://devfeed.tech/tags/tott.md>)

## AI overview

This Google Tech on the Toilet article explains how duplicate configuration flags can cause bugs and shows how the keep-sorted tool can sort source code, configuration, and text files to make such errors easier to spot and maintain.

## Source excerpt

This article was adapted from a Google Tech on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office. By Kyle Freeman 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? allow_warping: false enable_two_players: false show_end_credits: true enable_frost_band: false enable_two_players: true 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: # keep-sorted start allow_warping: false enable_frost_band: false enable_two_players: false enable_two_players: true show_end_credits: true # keep-sorted end 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: bosses := []int{ // keep-sorted start by_regex=//.* 111213, // Aethon Annie 52816, // Blazing Benny 711, // Daisy Dragon 1003, // Kenzie Kraken // keep-sorted end } Remember: before sorting, ensure the original order isn't intentional. For example, order can be critical when loading dependencies.