Skip to content

Commit

Permalink
Replaces use of sort.IsSorted
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavison committed Oct 30, 2024
1 parent 659b5f6 commit ffd816a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .ci/semgrep/stdlib/sort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ rules:
- pattern: StringsAreSorted
fix: slices.IsSorted($X)
severity: WARNING

- id: prefer-slices-issortedfunc
languages: [go]
message: Prefer slices.IsSortedFunc to sort.IsSorted
pattern: sort.IsSorted($X)
severity: WARNING
10 changes: 4 additions & 6 deletions internal/service/meta/ip_ranges_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package meta_test
import (
"fmt"
"net"
"sort"
"slices"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -169,7 +169,6 @@ func testAccIPRangesCheckCIDRBlocksAttribute(name, attribute string) resource.Te

var (
cidrBlockSize int
cidrBlocks sort.StringSlice
err error
)

Expand All @@ -181,8 +180,7 @@ func testAccIPRangesCheckCIDRBlocksAttribute(name, attribute string) resource.Te
return fmt.Errorf("%s for eu-west-1 seem suspiciously low: %d", attribute, cidrBlockSize) // lintignore:AWSAT003
}

cidrBlocks = make([]string, cidrBlockSize)

cidrBlocks := make([]string, cidrBlockSize)
for i := range cidrBlocks {
cidrBlock := a[fmt.Sprintf("%s.%d", attribute, i)]

Expand All @@ -194,8 +192,8 @@ func testAccIPRangesCheckCIDRBlocksAttribute(name, attribute string) resource.Te
cidrBlocks[i] = cidrBlock
}

if !sort.IsSorted(cidrBlocks) {
return fmt.Errorf("unexpected order of %s: %s", attribute, cidrBlocks)
if !slices.IsSorted(cidrBlocks) {
return fmt.Errorf("expected %s to be sorted: %s", attribute, cidrBlocks)
}

return nil
Expand Down

0 comments on commit ffd816a

Please sign in to comment.