chore: Enable `revive:enforce-map-style` rule (#16077)

This commit is contained in:
Paweł Żak 2024-10-28 13:59:26 +01:00 committed by GitHub
parent 7c9d5e52b0
commit c8a30655cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 31 additions and 28 deletions

View File

@ -262,6 +262,9 @@ linters-settings:
- name: early-return
- name: empty-block
- name: empty-lines
- name: enforce-map-style
arguments: ["make"]
exclude: [ "TEST" ]
- name: error-naming
- name: error-return
- name: error-strings

View File

@ -115,7 +115,7 @@ func (op OrderedPlugins) Less(i, j int) bool { return op[i].Line < op[j].Line }
// once the configuration is parsed.
func NewConfig() *Config {
c := &Config{
UnusedFields: map[string]bool{},
UnusedFields: make(map[string]bool),
unusedFieldsMutex: &sync.Mutex{},
// Agent defaults:

View File

@ -103,7 +103,7 @@ func (t *Table) initBuild() error {
t.Name = oidText
}
knownOIDs := map[string]bool{}
knownOIDs := make(map[string]bool, len(t.Fields))
for _, f := range t.Fields {
knownOIDs[f.Oid] = true
}
@ -118,7 +118,7 @@ func (t *Table) initBuild() error {
// Build retrieves all the fields specified in the table and constructs the RTable.
func (t Table) Build(gs Connection, walk bool) (*RTable, error) {
rows := map[string]RTableRow{}
rows := make(map[string]RTableRow)
// translation table for secondary index (when performing join on two tables)
secIdxTab := make(map[string]string)
@ -151,7 +151,7 @@ func (t Table) Build(gs Connection, walk bool) (*RTable, error) {
}
// ifv contains a mapping of table OID index to field value
ifv := map[string]interface{}{}
ifv := make(map[string]interface{})
if !walk {
// This is used when fetching non-table fields. Fields configured a the top
@ -240,8 +240,8 @@ func (t Table) Build(gs Connection, walk bool) (*RTable, error) {
rtr, ok := rows[idx]
if !ok {
rtr = RTableRow{}
rtr.Tags = map[string]string{}
rtr.Fields = map[string]interface{}{}
rtr.Tags = make(map[string]string)
rtr.Fields = make(map[string]interface{})
rows[idx] = rtr
}
if t.IndexAsTag && idx != "" {

View File

@ -92,10 +92,10 @@ func (g *gosmiTranslator) SnmpFormatDisplayHint(oid string, value interface{}) (
func getIndex(mibPrefix string, node gosmi.SmiNode) (col []string, tagOids map[string]struct{}) {
// first attempt to get the table's tags
tagOids = map[string]struct{}{}
// mimcks grabbing INDEX {} that is returned from snmptranslate -Td MibName
for _, index := range node.GetIndex() {
indices := node.GetIndex()
tagOids = make(map[string]struct{}, len(indices))
for _, index := range indices {
tagOids[mibPrefix+index.Name] = struct{}{}
}

View File

@ -21,7 +21,7 @@ func newMatcher(defaultTemplate *Template) *matcher {
func (m *matcher) addSpec(tmplt templateSpec) error {
// Parse out the default tags specific to this template
tags := map[string]string{}
tags := make(map[string]string)
if tmplt.tagstring != "" {
for _, kv := range strings.Split(tmplt.tagstring, ",") {
parts := strings.Split(kv, "=")

View File

@ -10,8 +10,8 @@ import (
)
var (
AgentMetricsWritten = selfstat.Register("agent", "metrics_written", map[string]string{})
AgentMetricsDropped = selfstat.Register("agent", "metrics_dropped", map[string]string{})
AgentMetricsWritten = selfstat.Register("agent", "metrics_written", make(map[string]string))
AgentMetricsDropped = selfstat.Register("agent", "metrics_dropped", make(map[string]string))
registerGob = sync.OnceFunc(func() { metric.Init() })
)

View File

@ -12,9 +12,9 @@ import (
)
var (
GlobalMetricsGathered = selfstat.Register("agent", "metrics_gathered", map[string]string{})
GlobalGatherErrors = selfstat.Register("agent", "gather_errors", map[string]string{})
GlobalGatherTimeouts = selfstat.Register("agent", "gather_timeouts", map[string]string{})
GlobalMetricsGathered = selfstat.Register("agent", "metrics_gathered", make(map[string]string))
GlobalGatherErrors = selfstat.Register("agent", "gather_errors", make(map[string]string))
GlobalGatherTimeouts = selfstat.Register("agent", "gather_timeouts", make(map[string]string))
)
type RunningInput struct {

View File

@ -135,7 +135,7 @@ func walkXML(nodes []xmlnode, parents []string, separator string, f func(xmlnode
// UniqueFieldNames forms unique field names
// by adding _<num> if there are several of them
func UniqueFieldNames(fields []EventField, fieldsUsage map[string]int, separator string) []EventField {
var fieldsCounter = map[string]int{}
var fieldsCounter = make(map[string]int, len(fields))
fieldsUnique := make([]EventField, 0, len(fields))
for _, field := range fields {
fieldName := field.Name

View File

@ -156,10 +156,10 @@ func (w *WinEventLog) Gather(acc telegraf.Accumulator) error {
for i := range events {
// Prepare fields names usage counter
var fieldsUsage = map[string]int{}
fieldsUsage := make(map[string]int)
tags := map[string]string{}
fields := map[string]interface{}{}
tags := make(map[string]string)
fields := make(map[string]interface{})
event := events[i]
evt := reflect.ValueOf(&event).Elem()
timeStamp := time.Now()
@ -168,7 +168,7 @@ func (w *WinEventLog) Gather(acc telegraf.Accumulator) error {
fieldName := evt.Type().Field(i).Name
fieldType := evt.Field(i).Type().String()
fieldValue := evt.Field(i).Interface()
computedValues := map[string]interface{}{}
computedValues := make(map[string]interface{})
switch fieldName {
case "Source":
fieldValue = event.Source.Name

View File

@ -164,7 +164,7 @@ func (m *Method) execute(acc telegraf.Accumulator) error {
defer outputPropertiesRaw.Clear()
// Convert the results to fields and tags
tags, fields := map[string]string{}, map[string]interface{}{}
tags, fields := make(map[string]string), make(map[string]interface{})
// Add a source tag if we use remote queries
if m.host != "" {

View File

@ -144,7 +144,7 @@ func (q *Query) execute(acc telegraf.Accumulator) error {
}
func (q *Query) extractProperties(acc telegraf.Accumulator, itemRaw *ole.VARIANT) error {
tags, fields := map[string]string{}, map[string]interface{}{}
tags, fields := make(map[string]string), make(map[string]interface{})
if q.host != "" {
tags["source"] = q.host

View File

@ -84,7 +84,7 @@ func Metrics() []telegraf.Metric {
if len(stats) > 0 {
var tags map[string]string
var name string
fields := map[string]interface{}{}
fields := make(map[string]interface{}, len(stats))
j := 0
for fieldname, stat := range stats {
if j == 0 {

View File

@ -109,12 +109,12 @@ func (a *Accumulator) addMeasurement(
return
}
tagsCopy := map[string]string{}
tagsCopy := make(map[string]string, len(tags))
for k, v := range tags {
tagsCopy[k] = v
}
fieldsCopy := map[string]interface{}{}
fieldsCopy := make(map[string]interface{}, len(fields))
for k, v := range fields {
fieldsCopy[k] = v
}

View File

@ -60,7 +60,7 @@ func ImportConfigurations(files, dirs []string) (*selection, int, error) {
func (s *selection) Filter(p packageCollection) (*packageCollection, error) {
enabled := packageCollection{
packages: map[string][]packageInfo{},
packages: make(map[string][]packageInfo),
}
implicitlyConfigured := make(map[string]bool)

View File

@ -178,8 +178,8 @@ func main() {
// Get the superset of licenses
if debug {
licenseSet := map[string]bool{}
licenseNames := []string{}
licenseSet := make(map[string]bool, len(packageInfos))
licenseNames := make([]string, 0, len(packageInfos))
for _, info := range packageInfos {
if found := licenseSet[info.license]; !found {
licenseNames = append(licenseNames, info.license)