golangci/golangci-lint

CLI flag for sorting results

Closed this issue · 2 comments

Welcome

How did you install golangci-lint?

AUR

Your feature request related to a problem? Please describe

The output of golangci-lint run is not ordered. This is for the most part fine, except fixing the reported errors.

My workflow is:

  1. Run golangci-lint
  2. Address the first issue in the list
  3. Save, re-run golangci-lint to verify the results
  4. Repeat

Since the results are not ordered it's hard to distinguish between resolving a warning and the order changing when re-running after making changes (step 3).

Describe the solution you'd like

A flag that lets me control how the results are ordered.
For example --order-by=file,line,linter should re-order the following:

b.go:39:52: example warning (err113)
a.go:50:59: example warning (mnd)
a.go:32:17: example warning (revive)
a.go:32:17: example warning (mnd)

to:

a.go:32:17: example warning (mnd)
a.go:32:17: example warning (revive)
a.go:50:59: example warning (mnd)
b.go:39:52: example warning (err113)

Describe alternatives you've considered

  • Output json and manipulate <-- Not worth the trouble
  • Change config on disk <-- Enforces sorting everywhere which is not desirable

Additional context

No response

Supporter

ldez commented

Hello,

The output of golangci-lint is ordered by default.

You'll need to use the configuration file if you want to customize it.

output:
  # Order to use when sorting results.
  # Possible values: `file`, `linter`, and `severity`.
  #
  # If the severity values are inside the following list, they are ordered in this order:
  #   1. error
  #   2. warning
  #   3. high
  #   4. medium
  #   5. low
  # Either they are sorted alphabetically.
  #
  # Default: ["linter", "file"]
  sort-order:
    - linter
    - severity
    - file # filepath, line, and column.

https://golangci-lint.run/docs/configuration/file/#output-configuration

My mistake. Thanks