Skip to content

Commit f516771

Browse files
committed
Fix #415: sort linters list in help commands
1 parent fd82548 commit f516771

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

README.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,16 @@ GolangCI-Lint can be used with zero configuration. By default the following lint
185185
```bash
186186
$ golangci-lint help linters
187187
Enabled by default linters:
188-
govet (vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
188+
deadcode: Finds unused code [fast: true, auto-fix: false]
189189
errcheck: Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: true, auto-fix: false]
190-
staticcheck: Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
191-
unused: Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
192190
gosimple: Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]
193-
structcheck: Finds an unused struct fields [fast: true, auto-fix: false]
194-
varcheck: Finds unused global variables and constants [fast: true, auto-fix: false]
191+
govet (vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
195192
ineffassign: Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
196-
deadcode: Finds unused code [fast: true, auto-fix: false]
193+
staticcheck: Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
194+
structcheck: Finds an unused struct fields [fast: true, auto-fix: false]
197195
typecheck: Like the front-end of a Go compiler, parses and type-checks Go code [fast: true, auto-fix: false]
196+
unused: Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
197+
varcheck: Finds unused global variables and constants [fast: true, auto-fix: false]
198198
```
199199
200200
and the following linters are disabled by default:
@@ -203,27 +203,27 @@ and the following linters are disabled by default:
203203
$ golangci-lint help linters
204204
...
205205
Disabled by default linters:
206-
golint: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false]
207-
stylecheck: Stylecheck is a replacement for golint [fast: false, auto-fix: false]
208-
gosec (gas): Inspects source code for security problems [fast: true, auto-fix: false]
209-
interfacer: Linter that suggests narrower interface types [fast: false, auto-fix: false]
210-
unconvert: Remove unnecessary type conversions [fast: true, auto-fix: false]
206+
depguard: Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
211207
dupl: Tool for code clone detection [fast: true, auto-fix: false]
208+
gochecknoglobals: Checks that no globals are present in Go code [fast: true, auto-fix: false]
209+
gochecknoinits: Checks that no init functions are present in Go code [fast: true, auto-fix: false]
212210
goconst: Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
211+
gocritic: The most opinionated Go source code linter [fast: true, auto-fix: false]
213212
gocyclo: Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
214213
gofmt: Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
215214
goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true]
215+
golint: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false]
216+
gosec (gas): Inspects source code for security problems [fast: true, auto-fix: false]
217+
interfacer: Linter that suggests narrower interface types [fast: false, auto-fix: false]
218+
lll: Reports long lines [fast: true, auto-fix: false]
216219
maligned: Tool to detect Go structs that would take less memory if their fields were sorted [fast: true, auto-fix: false]
217-
depguard: Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
218220
misspell: Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
219-
lll: Reports long lines [fast: true, auto-fix: false]
220-
unparam: Reports unused function parameters [fast: false, auto-fix: false]
221221
nakedret: Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
222222
prealloc: Finds slice declarations that could potentially be preallocated [fast: true, auto-fix: false]
223223
scopelint: Scopelint checks for unpinned variables in go programs [fast: true, auto-fix: false]
224-
gocritic: The most opinionated Go source code linter [fast: true, auto-fix: false]
225-
gochecknoinits: Checks that no init functions are present in Go code [fast: true, auto-fix: false]
226-
gochecknoglobals: Checks that no globals are present in Go code [fast: true, auto-fix: false]
224+
stylecheck: Stylecheck is a replacement for golint [fast: false, auto-fix: false]
225+
unconvert: Remove unnecessary type conversions [fast: true, auto-fix: false]
226+
unparam: Reports unused function parameters [fast: false, auto-fix: false]
227227
```
228228
229229
Pass `-E/--enable` to enable linter and `-D/--disable` to disable:
@@ -457,7 +457,7 @@ Flags:
457457
-D, --disable strings Disable specific linter
458458
--enable-all Enable all linters
459459
--disable-all Disable all linters
460-
-p, --presets strings Enable presets (bugs|unused|format|style|complexity|performance) of linters. Run 'golangci-lint linters' to see them. This option implies option --disable-all
460+
-p, --presets strings Enable presets (bugs|complexity|format|performance|style|unused) of linters. Run 'golangci-lint linters' to see them. This option implies option --disable-all
461461
--fast Run only fast linters from enabled linters set (first run won't be fast)
462462
-e, --exclude strings Exclude issue by regexp
463463
--exclude-use-default Use or not use default excludes:

pkg/commands/help.go

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package commands
33
import (
44
"fmt"
55
"os"
6+
"sort"
67
"strings"
78

89
"github.com/fatih/color"
@@ -36,6 +37,9 @@ func (e *Executor) initHelp() {
3637
}
3738

3839
func printLinterConfigs(lcs []*linter.Config) {
40+
sort.Slice(lcs, func(i, j int) bool {
41+
return strings.Compare(lcs[i].Name(), lcs[j].Name()) < 0
42+
})
3943
for _, lc := range lcs {
4044
altNamesStr := ""
4145
if len(lc.AlternativeNames) != 0 {
@@ -72,6 +76,7 @@ func (e *Executor) executeLintersHelp(_ *cobra.Command, args []string) {
7276
for _, lc := range linters {
7377
linterNames = append(linterNames, lc.Name())
7478
}
79+
sort.Strings(linterNames)
7580
fmt.Fprintf(logutils.StdOut, "%s: %s\n", color.YellowString(p), strings.Join(linterNames, ", "))
7681
}
7782

pkg/lint/lintersdb/manager.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func NewManager(cfg *config.Config) *Manager {
2828
}
2929

3030
func (Manager) AllPresets() []string {
31-
return []string{linter.PresetBugs, linter.PresetUnused, linter.PresetFormatting,
32-
linter.PresetStyle, linter.PresetComplexity, linter.PresetPerformance}
31+
return []string{linter.PresetBugs, linter.PresetComplexity, linter.PresetFormatting,
32+
linter.PresetPerformance, linter.PresetStyle, linter.PresetUnused}
3333
}
3434

3535
func (m Manager) allPresetsSet() map[string]bool {

0 commit comments

Comments
 (0)