@@ -235,6 +235,18 @@ allows for sorting data such as Go structs and JSON objects.
235235> sorted as basic strings. e.g., "{\n" comes before "{Name:", so mixing the
236236> line break and whitespace usage may cause unexpected sorting.
237237
238+ > Note: Braces within things that look like string literals are **not** counted
239+ > when pairing braces. A string literal begins an ends with a matching pair of
240+ > quotes, where quotes can be any of the following:
241+ > ````
242+ > '
243+ > '''
244+ > "
245+ > """
246+ > `
247+ > ```
248+ > ````
249+
238250> Note: angle brackets (`<` and `>`) are not supported by block mode due to
239251> being used for mathematical expressions in an unbalanced format.
240252
@@ -467,7 +479,7 @@ progress = (
467479#### Regular expressions
468480
469481It can be useful to sort an entire group based on a non-prefix substring. The
470- option ` by_regex=… ` takes a comma-separated list of [ regular
482+ option ` by_regex=… ` takes a comma-separated list of [ re2 regular
471483expressions] that will be applied to the group, and then sorting
472484will take place on just the results of the regular expressions.
473485
@@ -494,7 +506,7 @@ your regular expressions.
494506> If you want your regular expression itself to be case insensitive, consider
495507> setting the case-insensitive flag ` (?i) ` at the start of your expression.
496508
497- [ regular expressions ] : http ://godoc/pkg/regexp/syntax/
509+ [ regular expressions ] : https ://github.com/google/re2/wiki/Syntax
498510[ lexicographically ] : https://en.wikipedia.org/wiki/Lexicographic_order
499511
500512<table border =" 0 " >
@@ -829,3 +841,96 @@ YAML [flow sequence](https://yaml.org/spec/1.2.2/#flow-sequences).
829841```
830842
831843This works for all options that accept multiple values.
844+
845+ ## FAQ
846+
847+ ### How does keep-sorted handle whitespace?
848+
849+ The goal is for keep-sorted to handle whitespace the same way a human would. For
850+ instance, the default ` group=yes ` behavior groups lines of increasing
851+ indentation together for sorting, the way most people would. keep-sorted also
852+ doesn't consider leading whitespace when sorting strings.
853+
854+ keep-sorted does fall short in a couple areas, however. Unlike humans, perhaps,
855+ keep-sorted preserves any number of trailing newlines. For example, keep-sorted
856+ will not remove the 4 trailing newlines in the following block:
857+
858+ ```
859+ keep-sorted start
860+ 1
861+ 2
862+ 3
863+
864+
865+
866+
867+ keep-sorted end
868+ ```
869+
870+ Additionally, keep-sorted does not preserve other linebreaks like a person
871+ might. All non-trailing linebreaks will be moved to the beginning of the content
872+ (and deduplicated if ` remove_duplicates=yes ` ):
873+
874+ <table border =" 0 " >
875+ <tr >
876+ <td >
877+
878+ ```
879+
880+ 1
881+
882+ 2
883+
884+ 3
885+
886+ ```
887+
888+ </td >
889+ <td >
890+
891+ ```
892+ keep-sorted start
893+
894+ 1
895+ 2
896+ 3
897+
898+ keep-sorted end
899+ ```
900+
901+ </td >
902+ </tr >
903+ </table >
904+
905+ ### How does keep-sorted handle lists that aren't allowed to have trailing
906+ commas?
907+
908+ Some languages allow trailing commas in lists and some don't. Luckily,
909+ keep-sorted tries to do the right thing and handle commas "correctly".
910+
911+ <table border =" 0 " >
912+ <tr >
913+ <td >
914+
915+ ```
916+
917+ 3,
918+ 1,
919+ 2
920+
921+ ```
922+
923+ </td >
924+ <td >
925+
926+ ```
927+ keep-sorted start
928+ 1,
929+ 2,
930+ 3
931+ keep-sorted end
932+ ```
933+
934+ </td >
935+ </tr >
936+ </table >
0 commit comments