Skip to content

Commit

Permalink
chore(lint): add support for prealloc and asasalint
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone committed Feb 1, 2024
1 parent 9e44b12 commit f73dcd9
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ linters:
# Run golangci-lint linters to see the list of all linters
# Please keep them sorted alphabetically
enable:
- asasalint # check for pass []any as any in variadic func(...any) [fast: false, auto-fix: false]
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false]
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
Expand Down Expand Up @@ -44,6 +45,7 @@ linters:
- noctx # noctx finds sending http request without context.Context [fast: false, auto-fix: false]
- nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false]
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false]
- prealloc # Finds slice declarations that could potentially be pre-allocated [fast: true, auto-fix: false]
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
- promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
Expand Down
20 changes: 10 additions & 10 deletions scaleway/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,21 +377,21 @@ func zoneSchema() *schema.Schema {
}

func allZones() []string {
var allZones []string
zones := make([]string, 0, len(scw.AllZones))
for _, z := range scw.AllZones {
allZones = append(allZones, z.String())
zones = append(zones, z.String())
}

return allZones
return zones
}

func allRegions() []string {
var allRegions []string
regions := make([]string, 0, len(scw.AllRegions))
for _, z := range scw.AllRegions {
allRegions = append(allRegions, z.String())
regions = append(regions, z.String())
}

return allRegions
return regions
}

// regionSchema returns a standard schema for a zone
Expand Down Expand Up @@ -487,7 +487,7 @@ func expandStringWithDefault(data interface{}, defaultValue string) string {
}

func expandStrings(data interface{}) []string {
var stringSlice []string
stringSlice := make([]string, 0, len(data.([]interface{})))
for _, s := range data.([]interface{}) {
// zero-value is nil, ["foo", ""]
if s == nil {
Expand All @@ -499,7 +499,7 @@ func expandStrings(data interface{}) []string {
}

func expandStringsPtr(data interface{}) *[]string {
var stringSlice []string
stringSlice := make([]string, 0, len(data.([]interface{})))
if _, ok := data.([]interface{}); !ok || data == nil {
return nil
}
Expand Down Expand Up @@ -534,7 +534,7 @@ func expandUpdatedStringsPtr(data interface{}) *[]string {
}

func expandSliceIDsPtr(rawIDs interface{}) *[]string {
var stringSlice []string
stringSlice := make([]string, 0, len(rawIDs.([]interface{})))
if _, ok := rawIDs.([]interface{}); !ok || rawIDs == nil {
return &stringSlice
}
Expand All @@ -545,7 +545,7 @@ func expandSliceIDsPtr(rawIDs interface{}) *[]string {
}

func expandStringsOrEmpty(data interface{}) []string {
var stringSlice []string
stringSlice := make([]string, 0, len(data.([]interface{})))
if _, ok := data.([]interface{}); !ok || data == nil {
return stringSlice
}
Expand Down
2 changes: 1 addition & 1 deletion scaleway/helpers_baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func expandBaremetalOptions(i interface{}) ([]*baremetal.ServerOption, error) {
}

func expandBaremetalPrivateNetworks(pn interface{}) []string {
var privateNetworkIDs []string
privateNetworkIDs := make([]string, 0, len(pn.(*schema.Set).List()))

for _, op := range pn.(*schema.Set).List() {
rawPN := op.(map[string]interface{})
Expand Down
2 changes: 1 addition & 1 deletion scaleway/helpers_flexible_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func flattenFlexibleIPMacAddress(mac *flexibleip.MACAddress) interface{} {
}

func expandServerIDs(data interface{}) []string {
var expandedIDs []string
expandedIDs := make([]string, 0, len(data.([]interface{})))
for _, s := range data.([]interface{}) {
if s == nil {
s = ""
Expand Down
10 changes: 6 additions & 4 deletions scaleway/helpers_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ func instanceAPIWithZoneAndNestedID(m interface{}, zonedNestedID string) (*insta

// orderVolumes return an ordered slice based on the volume map key "0", "1", "2",...
func orderVolumes(v map[string]*instance.Volume) []*instance.Volume {
var indexes []string
indexes := make([]string, 0, len(v))
for index := range v {
indexes = append(indexes, index)
}
sort.Strings(indexes)
var orderedVolumes []*instance.Volume

orderedVolumes := make([]*instance.Volume, 0, len(indexes))
for _, index := range indexes {
orderedVolumes = append(orderedVolumes, v[index])
}
Expand All @@ -96,12 +97,13 @@ func orderVolumes(v map[string]*instance.Volume) []*instance.Volume {

// sortVolumeServer return an ordered slice based on the volume map key "0", "1", "2",...
func sortVolumeServer(v map[string]*instance.VolumeServer) []*instance.VolumeServer {
var indexes []string
indexes := make([]string, 0, len(v))
for index := range v {
indexes = append(indexes, index)
}
sort.Strings(indexes)
var sortedVolumes []*instance.VolumeServer

sortedVolumes := make([]*instance.VolumeServer, 0, len(indexes))
for _, index := range indexes {
sortedVolumes = append(sortedVolumes, v[index])
}
Expand Down
2 changes: 1 addition & 1 deletion scaleway/helpers_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func waitK8SPoolReady(ctx context.Context, k8sAPI *k8s.API, region scw.Region, p

// convert a list of nodes to a list of map
func convertNodes(res *k8s.ListNodesResponse) []map[string]interface{} {
var result []map[string]interface{}
result := make([]map[string]interface{}, 0, len(res.Nodes))
for _, node := range res.Nodes {
n := make(map[string]interface{})
n["name"] = node.Name
Expand Down
2 changes: 1 addition & 1 deletion scaleway/helpers_mnq_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var SQSAttributesToResourceMap = map[string]string{

// Returns all managed SQS attribute names
func getSQSAttributeNames() []*string {
var attributeNames []*string
attributeNames := make([]*string, 0, len(SQSAttributesToResourceMap))

for attribute := range SQSAttributesToResourceMap {
attributeNames = append(attributeNames, aws.String(attribute))
Expand Down
4 changes: 2 additions & 2 deletions scaleway/helpers_rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func flattenInstanceSettings(settings []*rdb.InstanceSetting) interface{} {

func expandInstanceSettings(i interface{}) []*rdb.InstanceSetting {
rawRule := i.(map[string]interface{})
var res []*rdb.InstanceSetting
res := make([]*rdb.InstanceSetting, 0, len(rawRule))
for key, value := range rawRule {
res = append(res, &rdb.InstanceSetting{
Name: key,
Expand Down Expand Up @@ -114,7 +114,7 @@ func expandPrivateNetwork(data interface{}, exist bool, enableIpam bool) ([]*rdb
return nil, nil
}

var res []*rdb.EndpointSpec
res := make([]*rdb.EndpointSpec, 0, len(data.([]interface{})))
for _, pn := range data.([]interface{}) {
r := pn.(map[string]interface{})
spec := &rdb.EndpointSpec{
Expand Down
2 changes: 1 addition & 1 deletion scaleway/helpers_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func expandRedisPrivateNetwork(data []interface{}) ([]*redis.EndpointSpec, error
if data == nil {
return nil, nil
}
var epSpecs []*redis.EndpointSpec
epSpecs := make([]*redis.EndpointSpec, 0, len(data))

for _, rawPN := range data {
pn := rawPN.(map[string]interface{})
Expand Down
4 changes: 2 additions & 2 deletions scaleway/resource_object_bucket_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func expandBucketACLAccessControlPolicy(l []interface{}) *s3.AccessControlPolicy
}

func expandBucketACLAccessControlPolicyGrants(l []interface{}) []*s3.Grant {
var grants []*s3.Grant
grants := make([]*s3.Grant, 0, len(l))

for _, tfMapRaw := range l {
tfMap, ok := tfMapRaw.(map[string]interface{})
Expand Down Expand Up @@ -297,7 +297,7 @@ func flattenBucketACLAccessControlPolicy(output *s3.GetBucketAclOutput) []interf
}

func flattenBucketACLAccessControlPolicyGrants(grants []*s3.Grant) []interface{} {
var results []interface{}
results := make([]interface{}, 0, len(grants))

for _, grant := range grants {
if grant == nil {
Expand Down
4 changes: 2 additions & 2 deletions scaleway/resource_rdb_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func rdbACLExpand(data []interface{}) ([]*rdb.ACLRuleRequest, error) {
}

func rdbACLRulesFlattenFromSchema(rules []*rdb.ACLRule, dataFromSchema []interface{}) ([]map[string]interface{}, []error) {
var res []map[string]interface{}
res := make([]map[string]interface{}, 0, len(dataFromSchema))
var errors []error
ruleMap := make(map[string]*rdb.ACLRule)
for _, rule := range rules {
Expand Down Expand Up @@ -300,7 +300,7 @@ func mergeDiffToSchema(rulesFromSchema map[string]struct{}, ruleMap map[string]*
}

func rdbACLRulesFlatten(rules []*rdb.ACLRule) []map[string]interface{} {
var res []map[string]interface{}
res := make([]map[string]interface{}, 0, len(rules))
for _, rule := range rules {
r := map[string]interface{}{
"ip": rule.IP.String(),
Expand Down

0 comments on commit f73dcd9

Please sign in to comment.