From a8662f7657a0ae58b56f437e2df7417bff06dcc5 Mon Sep 17 00:00:00 2001 From: Remi Bazin Date: Fri, 23 Jan 2026 00:06:54 +0000 Subject: [PATCH 1/4] Add `group_start_regex` and `group_end_regex` options. This change allows users to specify regexes for where sorted groups should begin or end, which is currently not something that the existing `by_regex` option supports. Tested: go test ./keepsorted ./goldens --- goldens/group_regex.in | 68 ++++++++++++++++++++++++++++++++++++ goldens/group_regex.out | 68 ++++++++++++++++++++++++++++++++++++ keepsorted/line_group.go | 43 +++++++++++++++++++++-- keepsorted/options.go | 21 +++++++++-- keepsorted/options_parser.go | 20 ++++++++--- keepsorted/options_test.go | 23 ++++++++++-- 6 files changed, 231 insertions(+), 12 deletions(-) create mode 100644 goldens/group_regex.in create mode 100644 goldens/group_regex.out diff --git a/goldens/group_regex.in b/goldens/group_regex.in new file mode 100644 index 0000000..7356ab5 --- /dev/null +++ b/goldens/group_regex.in @@ -0,0 +1,68 @@ +# keep-sorted-test start group_start_regex=^CREATE newline_separated=yes +# Foo comment +CREATE PUBLIC FUNCTION Foo(x INT64) +RETURNS INT64 +AS ( + x + 1 +); + +# Bar comment +CREATE PUBLIC FUNCTION Bar(x INT64) +RETURNS INT64 +AS ( + x + 2 +); + +# Baz comment +CREATE PUBLIC FUNCTION Baz(x INT64) +RETURNS INT64 +AS ( + x + LENGTH('CREATE') +); +# keep-sorted-test end + +# keep-sorted-test start group_start_regex=^CREATE newline_separated=yes by_regex=["\\bFUNCTION (\\w+)\\b"] +# Foo comment +CREATE PUBLIC FUNCTION Foo(x INT64) +RETURNS INT64 +AS ( + x + 1 +); + +# Bar comment +CREATE PRIVATE FUNCTION Bar(x INT64) +RETURNS INT64 +AS ( + x + 2 +); + +# Baz comment +CREATE PUBLIC AGGREGATE FUNCTION Baz(x INT64) +RETURNS INT64 +AS ( + SUM(x) + LENGTH('CREATE FUNCTION Aaa') +); +# keep-sorted-test end + +# keep-sorted-test start group_end_regex=;$ newline_separated=yes +# Foo comment +CREATE PUBLIC FUNCTION Foo(x INT64) +RETURNS INT64 +AS ( + x + 1 +); + +# Bar comment +CREATE PUBLIC FUNCTION Bar(x INT64) +RETURNS INT64 +AS ( + x + 2 +); + +# Baz comment +CREATE PUBLIC FUNCTION Baz(x INT64) +RETURNS INT64 +AS ( + x + LENGTH('CREATE') +); +# keep-sorted-test end diff --git a/goldens/group_regex.out b/goldens/group_regex.out new file mode 100644 index 0000000..68bcabf --- /dev/null +++ b/goldens/group_regex.out @@ -0,0 +1,68 @@ +# keep-sorted-test start group_start_regex=^CREATE newline_separated=yes +# Bar comment +CREATE PUBLIC FUNCTION Bar(x INT64) +RETURNS INT64 +AS ( + x + 2 +); + +# Baz comment +CREATE PUBLIC FUNCTION Baz(x INT64) +RETURNS INT64 +AS ( + x + LENGTH('CREATE') +); + +# Foo comment +CREATE PUBLIC FUNCTION Foo(x INT64) +RETURNS INT64 +AS ( + x + 1 +); +# keep-sorted-test end + +# keep-sorted-test start group_start_regex=^CREATE newline_separated=yes by_regex=["\\bFUNCTION (\\w+)\\b"] +# Bar comment +CREATE PRIVATE FUNCTION Bar(x INT64) +RETURNS INT64 +AS ( + x + 2 +); + +# Baz comment +CREATE PUBLIC AGGREGATE FUNCTION Baz(x INT64) +RETURNS INT64 +AS ( + SUM(x) + LENGTH('CREATE FUNCTION Aaa') +); + +# Foo comment +CREATE PUBLIC FUNCTION Foo(x INT64) +RETURNS INT64 +AS ( + x + 1 +); +# keep-sorted-test end + +# keep-sorted-test start group_end_regex=;$ newline_separated=yes +# Bar comment +CREATE PUBLIC FUNCTION Bar(x INT64) +RETURNS INT64 +AS ( + x + 2 +); + +# Baz comment +CREATE PUBLIC FUNCTION Baz(x INT64) +RETURNS INT64 +AS ( + x + LENGTH('CREATE') +); + +# Foo comment +CREATE PUBLIC FUNCTION Foo(x INT64) +RETURNS INT64 +AS ( + x + 1 +); +# keep-sorted-test end diff --git a/keepsorted/line_group.go b/keepsorted/line_group.go index 00c29b4..4278c64 100644 --- a/keepsorted/line_group.go +++ b/keepsorted/line_group.go @@ -16,12 +16,11 @@ package keepsorted import ( "fmt" + "github.com/rs/zerolog/log" "regexp" "strings" "sync" "unicode" - - "github.com/rs/zerolog/log" ) // lineGroup is a logical unit of source code. It's one or more lines combined @@ -61,6 +60,16 @@ type accessRecorder struct { joinedComment bool } +// matchesAnyRegex returns true if s matches one of the regexes. +func matchesAnyRegex(s string, regexes []*regexp.Regexp) bool { + for _, regex := range regexes { + if regex.FindStringSubmatch(s) != nil { + return true + } + } + return false +} + // groupLines splits lines into one or more lineGroups based on the provided options. func groupLines(lines []string, metadata blockMetadata) []*lineGroup { var groups []*lineGroup @@ -116,6 +125,12 @@ func groupLines(lines []string, metadata blockMetadata) []*lineGroup { } // finish an outstanding lineGroup and reset our state to prepare for a new lineGroup. finishGroup := func() { + // If the current lineRange ends with an extra empty line, remove it and place it in a separate group. + endingEmptyLines := 0 + for lineRange.size() > 1 && lines[lineRange.end-1] == "" { + endingEmptyLines++ + lineRange.end-- + } groups = append(groups, &lineGroup{ opts: metadata.opts, prefixOrder: prefixOrder, @@ -124,6 +139,14 @@ func groupLines(lines []string, metadata blockMetadata) []*lineGroup { commentRange = indexRange{} lineRange = indexRange{} block = codeBlock{} + for endingEmptyLines > 0 { + groups = append(groups, &lineGroup{ + opts: metadata.opts, + prefixOrder: prefixOrder, + lineGroupContent: lineGroupContent{lines: []string{""}}, + }) + endingEmptyLines-- + } } for i, l := range lines { if metadata.opts.Block && !lineRange.empty() && block.expectsContinuation() { @@ -145,6 +168,15 @@ func groupLines(lines []string, metadata blockMetadata) []*lineGroup { // its appendLine call. countStartDirectives(l) } + } else if metadata.opts.GroupEndRegex != nil { + if matchesAnyRegex(l, metadata.opts.GroupEndRegex) { + appendLine(i, l) + finishGroup() + } else { + appendLine(i, l) + } + } else if metadata.opts.GroupStartRegex != nil && !matchesAnyRegex(l, metadata.opts.GroupStartRegex) { + appendLine(i, l) } else { if !lineRange.empty() { finishGroup() @@ -215,6 +247,13 @@ func (r *indexRange) empty() bool { return !r.init || r.start == r.end } +func (r *indexRange) size() int { + if !r.init { + return 0 + } + return r.end - r.start +} + func (r *indexRange) append(i int) { if !r.init { r.start = i diff --git a/keepsorted/options.go b/keepsorted/options.go index 0b510c1..3c8fb22 100644 --- a/keepsorted/options.go +++ b/keepsorted/options.go @@ -18,6 +18,7 @@ import ( "cmp" "errors" "fmt" + yaml "gopkg.in/yaml.v3" "iter" "maps" "math/big" @@ -27,8 +28,6 @@ import ( "strconv" "strings" "unicode" - - yaml "gopkg.in/yaml.v3" ) // IntOrBool can be unmarshaled from a boolean or an integer value. @@ -44,7 +43,7 @@ type ByRegexOption struct { type SortOrder string const ( - OrderAsc SortOrder = "asc" + OrderAsc SortOrder = "asc" OrderDesc SortOrder = "desc" ) @@ -96,6 +95,15 @@ type blockOptions struct { StickyComments bool `key:"sticky_comments"` // StickyPrefixes tells us about other types of lines that should behave as sticky comments. StickyPrefixes map[string]bool `key:"sticky_prefixes"` + // GroupStartRegex is a list of regexes that match the start of a group of lines (does not need to match the whole line). + // If none of the listed regexes match a given line, the line is considered to be part of the same + // group as the previous line. + GroupStartRegex []*regexp.Regexp `key:"group_start_regex"` + // GroupEndRegex is a list of regexes that match the end of a group of lines (does not need to match the whole line). + // If any of the listed regexes match a given line, the line will end the current group, + // provided that it does not get ignored by other options (indented/prefixed group, block, sticky comment). + // Non-comment lines no longer end groups when GroupEndRegex is used. + GroupEndRegex []*regexp.Regexp `key:"group_end_regex"` /////////////////////// // Sorting options // @@ -240,6 +248,13 @@ func formatValue(val reflect.Value) (string, error) { return fmt.Sprintf("[%s]", strings.Join(vals, ", ")), nil } return formatList(vals) + case reflect.TypeFor[[]*regexp.Regexp](): + regexps := val.Interface().([]*regexp.Regexp) + vals := make([]string, len(regexps)) + for i, regex := range regexps { + vals[i] = regex.String() + } + return formatList(vals) } panic(fmt.Errorf("unsupported blockOptions type: %v", val.Type())) diff --git a/keepsorted/options_parser.go b/keepsorted/options_parser.go index ddd8823..4d09889 100644 --- a/keepsorted/options_parser.go +++ b/keepsorted/options_parser.go @@ -3,13 +3,12 @@ package keepsorted import ( "errors" "fmt" + yaml "gopkg.in/yaml.v3" "reflect" "regexp" "strconv" "strings" "unicode/utf8" - - yaml "gopkg.in/yaml.v3" ) var ( @@ -69,7 +68,13 @@ func (p *parser) popValue(typ reflect.Type) (reflect.Value, error) { val, err := p.popSet() return reflect.ValueOf(val), err case reflect.TypeFor[[]ByRegexOption](): - val, err := p.popListRegexOption() + val, err := p.popByRegexOption() + if err != nil { + return reflect.Zero(typ), err + } + return reflect.ValueOf(val), nil + case reflect.TypeFor[[]*regexp.Regexp](): + val, err := p.popRegexListOption() if err != nil { return reflect.Zero(typ), err } @@ -183,13 +188,20 @@ func (p *parser) popList() ([]string, error) { return popListValue(p, func(s string) (string, error) { return s, nil }) } -func (p *parser) popListRegexOption() ([]ByRegexOption, error) { +func (p *parser) popByRegexOption() ([]ByRegexOption, error) { return popListValue(p, func(s string) (ByRegexOption, error) { pat, err := regexp.Compile(s) return ByRegexOption{Pattern: pat}, err }) } +func (p *parser) popRegexListOption() ([]*regexp.Regexp, error) { + return popListValue(p, func(s string) (*regexp.Regexp, error) { + pat, err := regexp.Compile(s) + return pat, err + }) +} + func (p *parser) popSortOrder() (SortOrder, error) { val, rest, _ := strings.Cut(p.line, " ") p.line = rest diff --git a/keepsorted/options_test.go b/keepsorted/options_test.go index 8967cb7..ad0e10e 100644 --- a/keepsorted/options_test.go +++ b/keepsorted/options_test.go @@ -17,13 +17,12 @@ package keepsorted import ( "errors" "fmt" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "reflect" "regexp" "strings" "testing" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" ) func TestBlockOptions(t *testing.T) { @@ -229,6 +228,24 @@ func TestBlockOptions(t *testing.T) { want: blockOptions{Order: OrderAsc}, wantErr: `while parsing option "order": unrecognized order value "foo", expected 'asc' or 'desc'`, }, + { + name: "GroupStartRegex", + in: "group_start_regex=^CREATE", + + want: blockOptions{ + GroupStartRegex: []*regexp.Regexp{regexp.MustCompile("^CREATE")}, + }, + }, + { + name: "GroupStartRegex_YAML", + in: "group_start_regex=['^CREATE', 'b']", + defaultOptions: blockOptions{AllowYAMLLists: true}, + + want: blockOptions{ + AllowYAMLLists: true, + GroupStartRegex: []*regexp.Regexp{regexp.MustCompile("^CREATE"), regexp.MustCompile("b")}, + }, + }, } { t.Run(tc.name, func(t *testing.T) { initZerolog(t) From 4ac8446461becbc8385b8446e83e54d1742b62f3 Mon Sep 17 00:00:00 2001 From: Remi Bazin Date: Fri, 23 Jan 2026 00:15:50 +0000 Subject: [PATCH 2/4] Undo undesired editor-induced formatting changes --- keepsorted/line_group.go | 3 ++- keepsorted/options.go | 3 ++- keepsorted/options_parser.go | 3 ++- keepsorted/options_test.go | 5 +++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/keepsorted/line_group.go b/keepsorted/line_group.go index 4278c64..088619d 100644 --- a/keepsorted/line_group.go +++ b/keepsorted/line_group.go @@ -16,11 +16,12 @@ package keepsorted import ( "fmt" - "github.com/rs/zerolog/log" "regexp" "strings" "sync" "unicode" + + "github.com/rs/zerolog/log" ) // lineGroup is a logical unit of source code. It's one or more lines combined diff --git a/keepsorted/options.go b/keepsorted/options.go index 3c8fb22..5f8104f 100644 --- a/keepsorted/options.go +++ b/keepsorted/options.go @@ -18,7 +18,6 @@ import ( "cmp" "errors" "fmt" - yaml "gopkg.in/yaml.v3" "iter" "maps" "math/big" @@ -28,6 +27,8 @@ import ( "strconv" "strings" "unicode" + + yaml "gopkg.in/yaml.v3" ) // IntOrBool can be unmarshaled from a boolean or an integer value. diff --git a/keepsorted/options_parser.go b/keepsorted/options_parser.go index 4d09889..aa3f444 100644 --- a/keepsorted/options_parser.go +++ b/keepsorted/options_parser.go @@ -3,12 +3,13 @@ package keepsorted import ( "errors" "fmt" - yaml "gopkg.in/yaml.v3" "reflect" "regexp" "strconv" "strings" "unicode/utf8" + + yaml "gopkg.in/yaml.v3" ) var ( diff --git a/keepsorted/options_test.go b/keepsorted/options_test.go index ad0e10e..dccfd75 100644 --- a/keepsorted/options_test.go +++ b/keepsorted/options_test.go @@ -17,12 +17,13 @@ package keepsorted import ( "errors" "fmt" - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" "reflect" "regexp" "strings" "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" ) func TestBlockOptions(t *testing.T) { From afa4e5e45a1272063f76caef29cbcb6ccfff70e2 Mon Sep 17 00:00:00 2001 From: baz1 Date: Wed, 4 Mar 2026 21:23:58 -0800 Subject: [PATCH 3/4] Update change based on comments. --- README.md | 47 +++++++++++++++++++++++++++++++++++- goldens/group_regex.in | 4 +-- goldens/group_regex.out | 24 +++++++++--------- keepsorted/line_group.go | 31 +++++++++++++++++------- keepsorted/options.go | 9 +++++++ keepsorted/options_parser.go | 5 +--- 6 files changed, 92 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 781b3d0..d8661fa 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,7 @@ allows for sorting data such as Go structs and JSON objects. > Note: angle brackets (`<` and `>`) are not supported by block mode due to > being used for mathematical expressions in an unbalanced format. -#### Custom grouping +#### Prefix grouping Another way to group lines together is with the `group_prefixes` option. This takes a comma-separated list of prefixes. Any line beginning with one of those @@ -291,6 +291,51 @@ and tomatoes +#### Regex-delimited grouping + +Two mutually-exclusive options exist for delimiting groups using regular +expressions: `group_start_regex` and `group_end_regex`. If _part_ of a line +matches the specified regular expression, that line will end the previous group +and start a new group. With `group_start_regex`, the matching line will be at +the start of a new group (potentially preceded by sticky comments), whereas with +`group_end_regex`, the line will end the group. Some matching lines may be +ignored based on the other options that are enabled. + + + + + + +
+ +``` + +// Some comment for foo +define foo = +abc + def; + +// Some other comment for bar +define bar = +ghi + jkl; + +``` + + + +```diff ++// keep-sorted start group_start_regex=["^define\\b"] newline_separated=yes + // Some other comment for bar + define bar = + ghi + jkl; + + // Some comment for foo + define foo = + abc + def; ++// keep-sorted end +``` + +
+ #### Comments Comments embedded within the sorted block are made to stick with their diff --git a/goldens/group_regex.in b/goldens/group_regex.in index 7356ab5..c006547 100644 --- a/goldens/group_regex.in +++ b/goldens/group_regex.in @@ -14,7 +14,7 @@ AS ( ); # Baz comment -CREATE PUBLIC FUNCTION Baz(x INT64) +CREATE PUBLIC AGGREGATE FUNCTION Baz(x INT64) RETURNS INT64 AS ( x + LENGTH('CREATE') @@ -60,7 +60,7 @@ AS ( ); # Baz comment -CREATE PUBLIC FUNCTION Baz(x INT64) +CREATE PUBLIC AGGREGATE FUNCTION Baz(x INT64) RETURNS INT64 AS ( x + LENGTH('CREATE') diff --git a/goldens/group_regex.out b/goldens/group_regex.out index 68bcabf..ce99020 100644 --- a/goldens/group_regex.out +++ b/goldens/group_regex.out @@ -1,16 +1,16 @@ # keep-sorted-test start group_start_regex=^CREATE newline_separated=yes -# Bar comment -CREATE PUBLIC FUNCTION Bar(x INT64) +# Baz comment +CREATE PUBLIC AGGREGATE FUNCTION Baz(x INT64) RETURNS INT64 AS ( - x + 2 + x + LENGTH('CREATE') ); -# Baz comment -CREATE PUBLIC FUNCTION Baz(x INT64) +# Bar comment +CREATE PUBLIC FUNCTION Bar(x INT64) RETURNS INT64 AS ( - x + LENGTH('CREATE') + x + 2 ); # Foo comment @@ -45,18 +45,18 @@ AS ( # keep-sorted-test end # keep-sorted-test start group_end_regex=;$ newline_separated=yes -# Bar comment -CREATE PUBLIC FUNCTION Bar(x INT64) +# Baz comment +CREATE PUBLIC AGGREGATE FUNCTION Baz(x INT64) RETURNS INT64 AS ( - x + 2 + x + LENGTH('CREATE') ); -# Baz comment -CREATE PUBLIC FUNCTION Baz(x INT64) +# Bar comment +CREATE PUBLIC FUNCTION Bar(x INT64) RETURNS INT64 AS ( - x + LENGTH('CREATE') + x + 2 ); # Foo comment diff --git a/keepsorted/line_group.go b/keepsorted/line_group.go index 58e91bd..9516a51 100644 --- a/keepsorted/line_group.go +++ b/keepsorted/line_group.go @@ -114,6 +114,23 @@ func groupLines(lines []string, metadata blockMetadata) []*lineGroup { increasedIndent := !lineRange.empty() && initialIndent != nil && indents[i] > *initialIndent return increasedIndent || numUnmatchedStartDirectives > 0 || metadata.opts.hasGroupPrefix(l) } + // Determines whether the current line should be part of a regex-delimited + // group including any prior lines already visited. + // Returns another boolean indicating whether the group should be ending + // after that line if so. + shouldAddToRegexDelimitedGroup := func(l string) (bool, bool) { + if metadata.opts.GroupStartRegex != nil { + // For GroupStartRegex, all non-regex-matching lines should be + // part of the group including prior lines. + return !matchesAnyRegex(l, metadata.opts.GroupStartRegex), false + } + if metadata.opts.GroupEndRegex != nil { + // For GroupEndRegex, the line should always be included in the + // group including prior lines, but possibly terminate it. + return true, matchesAnyRegex(l, metadata.opts.GroupEndRegex) + } + return false, false + } countStartDirectives := func(l string) { if strings.Contains(l, metadata.startDirective) { numUnmatchedStartDirectives++ @@ -139,6 +156,7 @@ func groupLines(lines []string, metadata blockMetadata) []*lineGroup { // finish an outstanding lineGroup and reset our state to prepare for a new lineGroup. finishGroup := func() { // If the current lineRange ends with an extra empty line, remove it and place it in a separate group. + // This is notably needed to support group_start_regex or group_end_regex being set at the same time as newline_separated. endingEmptyLines := 0 for lineRange.size() > 1 && lines[lineRange.end-1] == "" { endingEmptyLines++ @@ -152,13 +170,12 @@ func groupLines(lines []string, metadata blockMetadata) []*lineGroup { commentRange = indexRange{} lineRange = indexRange{} block = codeBlock{} - for endingEmptyLines > 0 { + for ; endingEmptyLines > 0; endingEmptyLines-- { groups = append(groups, &lineGroup{ opts: metadata.opts, prefixOrder: prefixOrder, lineGroupContent: lineGroupContent{lines: []string{""}}, }) - endingEmptyLines-- } } for i, l := range lines { @@ -178,15 +195,11 @@ func groupLines(lines []string, metadata blockMetadata) []*lineGroup { // count end directives via its appendLine call. countStartDirectives(l) } - } else if metadata.opts.GroupEndRegex != nil { - if matchesAnyRegex(l, metadata.opts.GroupEndRegex) { - appendLine(i, l) + } else if addToGroup, finishGroupAfter := shouldAddToRegexDelimitedGroup(l); addToGroup { + appendLine(i, l) + if finishGroupAfter { finishGroup() - } else { - appendLine(i, l) } - } else if metadata.opts.GroupStartRegex != nil && !matchesAnyRegex(l, metadata.opts.GroupStartRegex) { - appendLine(i, l) } else { // Begin a new block or group. if !lineRange.empty() { diff --git a/keepsorted/options.go b/keepsorted/options.go index 5f8104f..e36d20d 100644 --- a/keepsorted/options.go +++ b/keepsorted/options.go @@ -96,6 +96,10 @@ type blockOptions struct { StickyComments bool `key:"sticky_comments"` // StickyPrefixes tells us about other types of lines that should behave as sticky comments. StickyPrefixes map[string]bool `key:"sticky_prefixes"` + + // Regex-based group options: + // Conceptually, GroupStartRegex lines go to the *next* group while GroupEndRegex lines go to the *current* group. + // GroupStartRegex is a list of regexes that match the start of a group of lines (does not need to match the whole line). // If none of the listed regexes match a given line, the line is considered to be part of the same // group as the previous line. @@ -337,6 +341,11 @@ func validate(opts *blockOptions) (warnings []error) { opts.IgnorePrefixes = nil } + if opts.GroupStartRegex != nil && opts.GroupEndRegex != nil { + warns = append(warns, fmt.Errorf("group_start_regex should not be used together with group_end_regex; ignoring group_end_regex")) + opts.GroupEndRegex = nil + } + return warns } diff --git a/keepsorted/options_parser.go b/keepsorted/options_parser.go index aa3f444..4943842 100644 --- a/keepsorted/options_parser.go +++ b/keepsorted/options_parser.go @@ -197,10 +197,7 @@ func (p *parser) popByRegexOption() ([]ByRegexOption, error) { } func (p *parser) popRegexListOption() ([]*regexp.Regexp, error) { - return popListValue(p, func(s string) (*regexp.Regexp, error) { - pat, err := regexp.Compile(s) - return pat, err - }) + return popListValue(p, regexp.Compile) } func (p *parser) popSortOrder() (SortOrder, error) { From a9533a9640b2a44a31656b97f7bae32cd67f8778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bazin?= Date: Thu, 5 Mar 2026 09:48:27 -0800 Subject: [PATCH 4/4] Name return values in shouldAddToRegexDelimitedGroup function signature --- keepsorted/line_group.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keepsorted/line_group.go b/keepsorted/line_group.go index 9516a51..a637de8 100644 --- a/keepsorted/line_group.go +++ b/keepsorted/line_group.go @@ -118,7 +118,7 @@ func groupLines(lines []string, metadata blockMetadata) []*lineGroup { // group including any prior lines already visited. // Returns another boolean indicating whether the group should be ending // after that line if so. - shouldAddToRegexDelimitedGroup := func(l string) (bool, bool) { + shouldAddToRegexDelimitedGroup := func(l string) (addToGroup bool, finishGroupAfter bool) { if metadata.opts.GroupStartRegex != nil { // For GroupStartRegex, all non-regex-matching lines should be // part of the group including prior lines.