diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6e8a84e2..1d2fe1a7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -39,6 +39,6 @@ jobs: - uses: actions/setup-go@v5 with: go-version-file: go.mod - - uses: golangci/golangci-lint-action@v6.5.1 + - uses: golangci/golangci-lint-action@v7.0.0 with: args: --config .golangci.yml diff --git a/.golangci.yml b/.golangci.yml index e0800e48..d6b81eda 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,5 @@ --- +version: "2" run: # Timeout for analysis, e.g. 30s, 5m. # Default: 1m @@ -12,16 +13,35 @@ linters: - gocyclo # Inspects source code for security problems. - gosec -linters-settings: - gocyclo: - # Minimal code complexity to report. - # https://github.com/fzipp/gocyclo#readme - min-complexity: 28 - gosec: - excludes: - - G115 + settings: + gocyclo: + # Minimal code complexity to report. + # https://github.com/fzipp/gocyclo#readme + min-complexity: 28 + gosec: + excludes: + # Ignore controversial integer overflow warnings. + - G115 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ issues: # Disable max issues per linter. max-issues-per-linter: 0 # Disable max same issues. max-same-issues: 0 +formatters: + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/internal/command/meta.go b/internal/command/meta.go index c37a805f..f37a255c 100644 --- a/internal/command/meta.go +++ b/internal/command/meta.go @@ -340,7 +340,7 @@ func getOptions(args []string, log Logger, mopts ...MetaOption) optionsFlags { } } - if opts.ShowGUID && !(_platform.Equal(opts.SourceType) || _all.Equal(opts.SourceType) || _default.Equal(opts.SourceType)) { + if opts.ShowGUID && !_platform.Equal(opts.SourceType) && !_all.Equal(opts.SourceType) && !_default.Equal(opts.SourceType) { log.Fatalf("Source type must be 'platform' when using the --guid flag") } diff --git a/internal/command/query.go b/internal/command/query.go index b45154a5..07579467 100644 --- a/internal/command/query.go +++ b/internal/command/query.go @@ -132,15 +132,15 @@ func newQueryOptions(cli plugin.CliConnection, args []string, log Logger) (query } if len(args) != 1 { - return queryOptions{}, fmt.Errorf("Expected 1 argument, got %d.", len(args)) + return queryOptions{}, fmt.Errorf("expected 1 argument, got %d", len(args)) } if isInstantQuery(opts) && !validInstantQueryArgs(opts) { - return queryOptions{}, errors.New("When issuing an instant query, you cannot specify --start, --end, or --step") + return queryOptions{}, errors.New("when issuing an instant query, you cannot specify --start, --end, or --step") } if isRangeQuery(opts) && !validRangeQueryArgs(opts) { - return queryOptions{}, errors.New("When issuing a range query, you must specify all of --start, --end, and --step") + return queryOptions{}, errors.New("when issuing a range query, you must specify all of --start, --end, and --step") } if isInstantQuery(opts) { @@ -150,7 +150,7 @@ func newQueryOptions(cli plugin.CliConnection, args []string, log Logger) (query parsedTime, err := getParsedTime(opts.Time) if err != nil { - return queryOptions{}, fmt.Errorf("Couldn't parse --time: %s", err.Error()) + return queryOptions{}, fmt.Errorf("couldn't parse --time: %s", err.Error()) } return queryOptions{timeProvided: true, time: parsedTime}, nil @@ -159,11 +159,11 @@ func newQueryOptions(cli plugin.CliConnection, args []string, log Logger) (query if isRangeQuery(opts) { parsedStart, err := getParsedTime(opts.Start) if err != nil { - return queryOptions{}, fmt.Errorf("Couldn't parse --start: %s", err.Error()) + return queryOptions{}, fmt.Errorf("couldn't parse --start: %s", err.Error()) } parsedEnd, err := getParsedTime(opts.End) if err != nil { - return queryOptions{}, fmt.Errorf("Couldn't parse --end: %s", err.Error()) + return queryOptions{}, fmt.Errorf("couldn't parse --end: %s", err.Error()) } return queryOptions{start: parsedStart, end: parsedEnd, step: opts.Step, rangeQuery: true}, nil diff --git a/internal/command/query_test.go b/internal/command/query_test.go index f208a968..c2e0ef90 100644 --- a/internal/command/query_test.go +++ b/internal/command/query_test.go @@ -73,7 +73,7 @@ var _ = Describe("LogCache", func() { }).To(Panic()) Expect(tc.logger.fatalfMessage).To(HavePrefix( - "When issuing a range query, you must specify all of --start, --end, and --step", + "when issuing a range query, you must specify all of --start, --end, and --step", )) }) @@ -85,7 +85,7 @@ var _ = Describe("LogCache", func() { }).To(Panic()) Expect(tc.logger.fatalfMessage).To(HavePrefix( - "When issuing an instant query, you cannot specify --start, --end, or --step", + "when issuing an instant query, you cannot specify --start, --end, or --step", )) }) @@ -152,7 +152,7 @@ var _ = Describe("LogCache", func() { }).To(Panic()) Expect(tc.logger.fatalfMessage).To(HavePrefix( - fmt.Sprintf("Couldn't parse --time: invalid time format: %s", timeArg), + fmt.Sprintf("couldn't parse --time: invalid time format: %s", timeArg), )) }, Entry("with an arbitary string", "asdfkj"), @@ -229,7 +229,7 @@ var _ = Describe("LogCache", func() { }).To(Panic()) Expect(tc.logger.fatalfMessage).To(HavePrefix( - fmt.Sprintf("Couldn't parse --%s: invalid time format: %s", invalidField, invalidArg), + fmt.Sprintf("couldn't parse --%s: invalid time format: %s", invalidField, invalidArg), )) }, Entry("with an arbitary string for start", "start", "asdfkj"), diff --git a/internal/command/tail.go b/internal/command/tail.go index ffbbbaaa..892a7902 100644 --- a/internal/command/tail.go +++ b/internal/command/tail.go @@ -238,11 +238,11 @@ func newTailOptions(cli plugin.CliConnection, args []string, log Logger) (tailOp } if len(args) != 1 { - return tailOptions{}, fmt.Errorf("Expected 1 argument, got %d.", len(args)) + return tailOptions{}, fmt.Errorf("expected 1 argument, got %d", len(args)) } if opts.JSONOutput && opts.OutputFormat != "" { - return tailOptions{}, errors.New("Cannot use output-format and json flags together") + return tailOptions{}, errors.New("cannot use output-format and json flags together") } if opts.EnvelopeType != "" && opts.EnvelopeClass != "" { @@ -331,16 +331,16 @@ func typeFilter(e *loggregator_v2.Envelope, o tailOptions) bool { func (o tailOptions) validate() error { if o.startTime.After(o.endTime) && o.endTime != time.Unix(0, 0) { - return errors.New("Invalid date/time range. Ensure your start time is prior or equal the end time.") + return errors.New("invalid date/time range. Ensure your start time is prior or equal the end time") } if o.lines > 1000 || o.lines < 0 { - return errors.New("Lines cannot be greater than 1000.") + return errors.New("lines cannot be greater than 1000") } _, err := regexp.Compile(o.nameFilter) if err != nil { - return fmt.Errorf("Invalid name filter '%s'. Ensure your name-filter is a valid regex.", o.nameFilter) + return fmt.Errorf("invalid name filter '%s'. Ensure your name-filter is a valid regex", o.nameFilter) } return nil diff --git a/internal/command/tail_test.go b/internal/command/tail_test.go index dd587e19..b50367a6 100644 --- a/internal/command/tail_test.go +++ b/internal/command/tail_test.go @@ -1102,7 +1102,7 @@ var _ = Describe("LogCache", func() { ) }).To(Panic()) - Expect(logger.fatalfMessage).To(Equal("Cannot use output-format and json flags together")) + Expect(logger.fatalfMessage).To(Equal("cannot use output-format and json flags together")) }) It("fatally logs if an output-format is malformed", func() { @@ -1158,7 +1158,7 @@ var _ = Describe("LogCache", func() { ) }).To(Panic()) - Expect(logger.fatalfMessage).To(Equal("Lines cannot be greater than 1000.")) + Expect(logger.fatalfMessage).To(Equal("lines cannot be greater than 1000")) }) It("accepts 0 for --lines", func() { @@ -1245,7 +1245,7 @@ var _ = Describe("LogCache", func() { ) }).To(Panic()) - Expect(logger.fatalfMessage).To(Equal("Invalid date/time range. Ensure your start time is prior or equal the end time.")) + Expect(logger.fatalfMessage).To(Equal("invalid date/time range. Ensure your start time is prior or equal the end time")) }) It("fatally logs if the name-filter regex is invalid", func() { @@ -1261,7 +1261,7 @@ var _ = Describe("LogCache", func() { ) }).To(Panic()) - Expect(logger.fatalfMessage).To(Equal("Invalid name filter '*foo'. Ensure your name-filter is a valid regex.")) + Expect(logger.fatalfMessage).To(Equal("invalid name filter '*foo'. Ensure your name-filter is a valid regex")) }) It("fatally logs if too many arguments are given", func() { @@ -1276,7 +1276,7 @@ var _ = Describe("LogCache", func() { ) }).To(Panic()) - Expect(logger.fatalfMessage).To(Equal("Expected 1 argument, got 2.")) + Expect(logger.fatalfMessage).To(Equal("expected 1 argument, got 2")) }) It("fatally logs if not enough arguments are given", func() { @@ -1291,7 +1291,7 @@ var _ = Describe("LogCache", func() { ) }).To(Panic()) - Expect(logger.fatalfMessage).To(Equal("Expected 1 argument, got 0.")) + Expect(logger.fatalfMessage).To(Equal("expected 1 argument, got 0")) }) Context("when name-filter argument is not supplied", func() {