From 97acfcf79c25ee33a945f25b5d8d2b9907e165fb Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Sat, 6 Apr 2024 08:56:48 +0900 Subject: [PATCH] Fix lint errors Signed-off-by: Sora Morimoto --- .golangci.yaml | 36 +++++++++++++++++++----------------- parser/parse.go | 6 +++--- parser/parse_test.go | 2 +- parser/syslog.go | 4 ++-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index b5aae46..37d2dc9 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,10 +1,18 @@ run: modules-download-mode: readonly - skip-dirs: - - .git - - .github - - .vscode - - dist + +linters-settings: + gofmt: + simplify: true + goimports: + local-prefixes: github.com/axiomhq/axiom-syslog-proxy + govet: + enable: + - shadow + nolintlint: + allow-unused: false + require-explanation: true + require-specific: true linters: disable-all: true @@ -34,15 +42,9 @@ linters: - unused - whitespace -linters-settings: - gofmt: - simplify: true - goimports: - local-prefixes: github.com/axiomhq/axiom-syslog-proxy - govet: - check-shadowing: true - nolintlint: - allow-unused: false - allow-leading-space: false - require-explanation: true - require-specific: true +issues: + exclude-dirs: + - .git + - .github + - .vscode + - dist diff --git a/parser/parse.go b/parser/parse.go index d5f7332..c65d6e9 100755 --- a/parser/parse.go +++ b/parser/parse.go @@ -146,7 +146,7 @@ func parseJSON(data []byte) (*Log, error) { Metadata: map[string]interface{}{}, } - if err := jsonparser.ObjectEach(data, func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error { + if err := jsonparser.ObjectEach(data, func(key []byte, value []byte, dataType jsonparser.ValueType, _ int) error { return extractJSONProperty(key, value, dataType, msg) }); err != nil { return nil, err @@ -197,7 +197,7 @@ func extractMetadataValue(concatKey string, value []byte, dataType jsonparser.Va switch dataType { case jsonparser.Object: level++ - if err := jsonparser.ObjectEach(value, func(kk []byte, vv []byte, dtdt jsonparser.ValueType, offset int) error { + if err := jsonparser.ObjectEach(value, func(kk []byte, vv []byte, dtdt jsonparser.ValueType, _ int) error { return extractMetadataValue(joinKey(concatKey, string(kk)), vv, dtdt, level, msg) }); err != nil { return err @@ -205,7 +205,7 @@ func extractMetadataValue(concatKey string, value []byte, dataType jsonparser.Va case jsonparser.Array: arrayIndex := 0 level++ - if _, err := jsonparser.ArrayEach(value, func(vv []byte, dtdt jsonparser.ValueType, offset int, err error) { + if _, err := jsonparser.ArrayEach(value, func(vv []byte, dtdt jsonparser.ValueType, _ int, err error) { if err != nil { return } diff --git a/parser/parse_test.go b/parser/parse_test.go index d0367de..98bfece 100755 --- a/parser/parse_test.go +++ b/parser/parse_test.go @@ -694,7 +694,7 @@ func BenchmarkParserDifferentMetadataTypes(b *testing.B) { } func BenchmarkParser(b *testing.B) { - p := New(func(msg *Log) {}) + p := New(func(_ *Log) {}) const msg = "<1> 2009-10-16T11:51:56+02:00 ip-34-23-211-23 symbolicator ERROR 2008 SOMEMSG - hello" rawMsg := []byte(msg) diff --git a/parser/syslog.go b/parser/syslog.go index 5d25455..4ab04da 100755 --- a/parser/syslog.go +++ b/parser/syslog.go @@ -570,10 +570,10 @@ func parseStructuredData(data []byte, index *int, length *int) (map[string]map[s sc := scanner.Scanner{} sc.Init(bytes.NewBuffer(data[offset+1:])) sc.Mode = scanner.ScanStrings | scanner.ScanIdents - sc.IsIdentRune = func(ch rune, i int) bool { + sc.IsIdentRune = func(ch rune, _ int) bool { return unicode.IsLetter(ch) || unicode.IsDigit(ch) || ch == '@' || ch == '.' } - sc.Error = func(s *scanner.Scanner, msg string) {} + sc.Error = func(_ *scanner.Scanner, _ string) {} var ( sdID, sdParam string