File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -385,7 +385,10 @@ func handleTrailingComma(lgs []*lineGroup) (trimTrailingComma func([]*lineGroup)
385385 }
386386 }
387387
388- if n := len (dataGroups ); n > 1 && allEndInComma (dataGroups [0 :n - 1 ]) && ! dataGroups [n - 1 ].matchesSuffix (commaLineEnd ) {
388+ commaLineEnd := regexp .MustCompile ("(,)( *)((#|//).*)?$" )
389+ commentLineEnd := regexp .MustCompile ("( *)((#|//).*)$" )
390+
391+ if n := len (dataGroups ); n > 1 && allMatchSuffix (dataGroups [0 :n - 1 ], commaLineEnd ) && ! dataGroups [n - 1 ].matchesSuffix (commaLineEnd ) {
389392 if dataGroups [n - 1 ].matchesSuffix (commentLineEnd ) {
390393 dataGroups [n - 1 ].replaceSuffix (commentLineEnd , ", $2" )
391394 } else {
@@ -409,16 +412,11 @@ func handleTrailingComma(lgs []*lineGroup) (trimTrailingComma func([]*lineGroup)
409412 return func ([]* lineGroup ) {}
410413}
411414
412- func allEndInComma (lgs []* lineGroup ) bool {
415+ func allMatchSuffix (lgs []* lineGroup , suffix * regexp. Regexp ) bool {
413416 for _ , lg := range lgs {
414- if ! lg .matchesSuffix (commaLineEnd ) {
417+ if ! lg .matchesSuffix (suffix ) {
415418 return false
416419 }
417420 }
418421 return true
419422}
420-
421- var (
422- commaLineEnd = regexp .MustCompile ("(,)( *)((#|//).*)?$" )
423- commentLineEnd = regexp .MustCompile ("( *)((#|//).*)$" )
424- )
You can’t perform that action at this time.
0 commit comments