Skip to content

Commit 0d886cd

Browse files
ainar-geyechoirs
authored andcommitted
lintcmd: add flag to list all checks
This is a resubmission of gh-880 with @dominikh's comments taken into account. The original GitHub user is deleted now, but I added their E-mail as it was in the original commit as a coauthor. Closes gh-860 Co-Authored-By: eyechoirs <[email protected]> Closes: gh-945 [via git-merge-pr]
1 parent 919f4c9 commit 0d886cd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lintcmd/cmd.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ func FlagSet(name string) *flag.FlagSet {
511511
flags.Bool("show-ignored", false, "Don't filter ignored problems")
512512
flags.String("f", "text", "Output `format` (valid choices are 'stylish', 'text' and 'json')")
513513
flags.String("explain", "", "Print description of `check`")
514+
flags.Bool("list-checks", false, "List all available checks")
514515

515516
flags.String("debug.cpuprofile", "", "Write CPU profile to `file`")
516517
flags.String("debug.memprofile", "", "Write memory profile to `file`")
@@ -552,6 +553,7 @@ func ProcessFlagSet(cs []*analysis.Analyzer, fs *flag.FlagSet) {
552553
printVersion := fs.Lookup("version").Value.(flag.Getter).Get().(bool)
553554
showIgnored := fs.Lookup("show-ignored").Value.(flag.Getter).Get().(bool)
554555
explain := fs.Lookup("explain").Value.(flag.Getter).Get().(string)
556+
listChecks := fs.Lookup("list-checks").Value.(flag.Getter).Get().(bool)
555557

556558
cpuProfile := fs.Lookup("debug.cpuprofile").Value.(flag.Getter).Get().(string)
557559
memProfile := fs.Lookup("debug.memprofile").Value.(flag.Getter).Get().(string)
@@ -617,6 +619,22 @@ func ProcessFlagSet(cs []*analysis.Analyzer, fs *flag.FlagSet) {
617619
exit(0)
618620
}
619621

622+
if listChecks {
623+
titles := make(map[string]string)
624+
names := make([]string, len(cs))
625+
for i, c := range cs {
626+
titles[c.Name] = strings.SplitN(c.Doc, "\n", 2)[0]
627+
names[i] = c.Name
628+
}
629+
630+
sort.Strings(names)
631+
for _, n := range names {
632+
fmt.Fprintf(os.Stderr, "%s %s\n", n, titles[n])
633+
}
634+
635+
exit(0)
636+
}
637+
620638
if printVersion {
621639
version.Print()
622640
exit(0)

0 commit comments

Comments
 (0)