From 564f24a0a41114e0fe3d5f52642d2128798e4df2 Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Thu, 3 Aug 2023 08:11:26 -0600 Subject: [PATCH] chore: Enable additional gocritic (#13713) --- .golangci.yml | 4 ++++ plugins/inputs/snmp/netsnmp.go | 7 ++++++- plugins/processors/strings/strings_test.go | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a961ee33f..b1915d385 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -84,6 +84,7 @@ linters-settings: - caseOrder - codegenComment - deferInLoop + - dupArg - dupBranchBody - dupCase - dupSubExpr @@ -92,7 +93,10 @@ linters-settings: - evalOrder - exitAfterDefer - externalErrorReassign + - flagName + - mapKey - nilValReturn + - offBy1 - regexpPattern - sloppyTypeAssert - sortSlice diff --git a/plugins/inputs/snmp/netsnmp.go b/plugins/inputs/snmp/netsnmp.go index 134ca2a2e..7a9ef5f6c 100644 --- a/plugins/inputs/snmp/netsnmp.go +++ b/plugins/inputs/snmp/netsnmp.go @@ -248,7 +248,12 @@ func snmpTranslateCall(oid string) (mibName string, oidNum string, oidText strin } if i := strings.Index(obj, "("); i != -1 { obj = obj[i+1:] - oidNum += "." + obj[:strings.Index(obj, ")")] + if j := strings.Index(obj, ")"); j != -1 { + oidNum += "." + obj[:j] + } else { + return "", "", "", "", fmt.Errorf("getting OID number from: %s", obj) + } + } else { oidNum += "." + obj } diff --git a/plugins/processors/strings/strings_test.go b/plugins/processors/strings/strings_test.go index 26c3e85a9..d6da6496d 100644 --- a/plugins/processors/strings/strings_test.go +++ b/plugins/processors/strings/strings_test.go @@ -35,7 +35,7 @@ func newM2() telegraf.Metric { map[string]interface{}{ "Request": "/mixed/CASE/paTH/?from=-1D&to=now", "req/sec": 5, - " whitespace ": " whitespace\t", + " whitespace ": " whitespace\t", //nolint:gocritic // additional whitespace on purpose for testing }, time.Now(), )