1 Star 0 Fork 0

Laomo. / golangci-lint

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
linters.go 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
package commands
import (
"fmt"
"os"
"strings"
"github.com/fatih/color"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/spf13/cobra"
)
func (e *Executor) initLinters() {
var lintersCmd = &cobra.Command{
Use: "linters",
Short: "List linters",
Run: e.executeLinters,
}
e.rootCmd.AddCommand(lintersCmd)
}
func printLinterConfigs(lcs []linter.Config) {
for _, lc := range lcs {
fmt.Fprintf(logutils.StdOut, "%s: %s [fast: %t]\n", color.YellowString(lc.Linter.Name()),
lc.Linter.Desc(), !lc.DoesFullImport)
}
}
func (e Executor) executeLinters(cmd *cobra.Command, args []string) {
var enabledLCs, disabledLCs []linter.Config
for _, lc := range lintersdb.GetAllSupportedLinterConfigs() {
if lc.EnabledByDefault {
enabledLCs = append(enabledLCs, lc)
} else {
disabledLCs = append(disabledLCs, lc)
}
}
color.Green("Enabled by default linters:\n")
printLinterConfigs(enabledLCs)
color.Red("\nDisabled by default linters:\n")
printLinterConfigs(disabledLCs)
color.Green("\nLinters presets:")
for _, p := range lintersdb.AllPresets() {
linters := lintersdb.GetAllLinterConfigsForPreset(p)
linterNames := []string{}
for _, lc := range linters {
linterNames = append(linterNames, lc.Linter.Name())
}
fmt.Fprintf(logutils.StdOut, "%s: %s\n", color.YellowString(p), strings.Join(linterNames, ", "))
}
os.Exit(0)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LaomoBK/golangci-lint.git
git@gitee.com:LaomoBK/golangci-lint.git
LaomoBK
golangci-lint
golangci-lint
v1.9.2

搜索帮助

344bd9b3 5694891 D2dac590 5694891