Skip to content

Commit

Permalink
chore(golangci): add new linters
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Aug 11, 2021
1 parent 08d1305 commit cb4b57f
Show file tree
Hide file tree
Showing 55 changed files with 665 additions and 265 deletions.
35 changes: 13 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ linters-settings:
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
goimports:
Expand Down Expand Up @@ -72,28 +66,25 @@ linters:
- unused
- varcheck
- whitespace
- wsl
- godot

# disabled want to fix
#- scopelint
#- gomnd
#- goconst
#- gocyclo
#- funlen
#- dogsled
# disabled for now
#- godox
run:

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
- lll
- revive
- wsl
- govet
- godot
- errcheck
- stylecheck
- dupl
- gocritic
- gochecknoinits

exclude:
- G107
- G204
- commentedOutCode

run:
tests: false
8 changes: 6 additions & 2 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/Jguer/yay/v10/pkg/text"
)

// CleanDependencies removes all dangling dependencies in system
// CleanDependencies removes all dangling dependencies in system.
func cleanDependencies(cmdArgs *parser.Arguments, dbExecutor db.Executor, removeOptional bool) error {
hanging := hangingPackages(removeOptional, dbExecutor)
if len(hanging) != 0 {
Expand All @@ -27,7 +27,7 @@ func cleanDependencies(cmdArgs *parser.Arguments, dbExecutor db.Executor, remove
return nil
}

// CleanRemove sends a full removal command to pacman with the pkgName slice
// CleanRemove sends a full removal command to pacman with the pkgName slice.
func cleanRemove(cmdArgs *parser.Arguments, pkgNames []string) error {
if len(pkgNames) == 0 {
return nil
Expand Down Expand Up @@ -107,6 +107,7 @@ func cleanAUR(keepInstalled, keepCurrent, removeAll bool, dbExecutor db.Executor
}

cachedPackages := make([]string, 0, len(files))

for _, file := range files {
if !file.IsDir() {
continue
Expand Down Expand Up @@ -179,10 +180,12 @@ func cleanUntracked() error {
if isGitRepository(dir) {
if err := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildGitCmd(dir, "clean", "-fx")); err != nil {
text.Warnln(gotext.Get("Unable to clean:"), dir)

return err
}
}
}

return nil
}

Expand Down Expand Up @@ -217,6 +220,7 @@ func cleanBuilds(bases []dep.Base) {
for i, base := range bases {
dir := filepath.Join(config.BuildDir, base.Pkgbase())
text.OperationInfoln(gotext.Get("Deleting (%d/%d): %s", i+1, len(bases), text.Cyan(dir)))

if err := os.RemoveAll(dir); err != nil {
fmt.Fprintln(os.Stderr, err)
}
Expand Down
64 changes: 39 additions & 25 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/Jguer/yay/v10/pkg/completion"
"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/download"
"github.com/Jguer/yay/v10/pkg/intrange"
"github.com/Jguer/yay/v10/pkg/news"
"github.com/Jguer/yay/v10/pkg/query"
Expand Down Expand Up @@ -156,6 +157,7 @@ func handleCmd(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
switch cmdArgs.Op {
case "V", "version":
handleVersion()

return nil
case "D", "database":
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(
Expand Down Expand Up @@ -191,6 +193,7 @@ func handleCmd(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
// updates or their count.
func getFilter(cmdArgs *parser.Arguments) (upgrade.Filter, error) {
deps, explicit := cmdArgs.ExistsArg("d", "deps"), cmdArgs.ExistsArg("e", "explicit")

switch {
case deps && explicit:
return nil, fmt.Errorf(gotext.Get("invalid option: '--deps' and '--explicit' may not be used together"))
Expand All @@ -203,6 +206,7 @@ func getFilter(cmdArgs *parser.Arguments) (upgrade.Filter, error) {
return pkg.Reason == alpm.PkgReasonExplicit
}, nil
}

return func(pkg upgrade.Upgrade) bool {
return true
}, nil
Expand All @@ -214,8 +218,10 @@ func handleQuery(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
if err != nil {
return err
}

return printUpdateList(cmdArgs, dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"), filter)
}

return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
}
Expand All @@ -225,6 +231,7 @@ func handleHelp(cmdArgs *parser.Arguments) error {
usage()
return nil
}

return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
}
Expand All @@ -238,19 +245,23 @@ func handlePrint(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
case cmdArgs.ExistsArg("d", "defaultconfig"):
tmpConfig := settings.DefaultConfig()
fmt.Printf("%v", tmpConfig)

return nil
case cmdArgs.ExistsArg("g", "currentconfig"):
fmt.Printf("%v", config)

return nil
case cmdArgs.ExistsArg("n", "numberupgrades"):
filter, err := getFilter(cmdArgs)
if err != nil {
return err
}

return printNumberOfUpdates(dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"), filter)
case cmdArgs.ExistsArg("w", "news"):
double := cmdArgs.ExistsDouble("w", "news")
quiet := cmdArgs.ExistsArg("q", "quiet")

return news.PrintNewsFeed(config.Runtime.HTTPClient, dbExecutor.LastBuildTime(), config.SortMode, double, quiet)
case cmdArgs.ExistsDouble("c", "complete"):
return completion.Show(config.Runtime.HTTPClient, dbExecutor,
Expand All @@ -261,29 +272,30 @@ func handlePrint(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
case cmdArgs.ExistsArg("s", "stats"):
return localStatistics(dbExecutor)
}

return nil
}

func handleYay(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
if cmdArgs.ExistsArg("gendb") {
switch {
case cmdArgs.ExistsArg("gendb"):
return createDevelDB(config, dbExecutor)
}
if cmdArgs.ExistsDouble("c") {
case cmdArgs.ExistsDouble("c"):
return cleanDependencies(cmdArgs, dbExecutor, true)
}
if cmdArgs.ExistsArg("c", "clean") {
case cmdArgs.ExistsArg("c", "clean"):
return cleanDependencies(cmdArgs, dbExecutor, false)
}
if len(cmdArgs.Targets) > 0 {
case len(cmdArgs.Targets) > 0:
return handleYogurt(cmdArgs, dbExecutor)
}

return nil
}

func handleGetpkgbuild(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
func handleGetpkgbuild(cmdArgs *parser.Arguments, dbExecutor download.DBSearcher) error {
if cmdArgs.ExistsArg("p", "print") {
return printPkgbuilds(dbExecutor, config.Runtime.HTTPClient, cmdArgs.Targets, config.Runtime.Mode, config.AURURL)
}

return getPkgbuilds(dbExecutor, config, cmdArgs.Targets, cmdArgs.ExistsArg("f", "force"))
}

Expand All @@ -295,41 +307,36 @@ func handleYogurt(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
func handleSync(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
targets := cmdArgs.Targets

if cmdArgs.ExistsArg("s", "search") {
switch {
case cmdArgs.ExistsArg("s", "search"):
if cmdArgs.ExistsArg("q", "quiet") {
config.SearchMode = minimal
} else {
config.SearchMode = detailed
}

return syncSearch(targets, config.Runtime.AURClient, dbExecutor)
}
if cmdArgs.ExistsArg("p", "print", "print-format") {
case cmdArgs.ExistsArg("p", "print", "print-format"):
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
}
if cmdArgs.ExistsArg("c", "clean") {
case cmdArgs.ExistsArg("c", "clean"):
return syncClean(cmdArgs, dbExecutor)
}
if cmdArgs.ExistsArg("l", "list") {
case cmdArgs.ExistsArg("l", "list"):
return syncList(config.Runtime.HTTPClient, cmdArgs, dbExecutor)
}
if cmdArgs.ExistsArg("g", "groups") {
case cmdArgs.ExistsArg("g", "groups"):
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
}
if cmdArgs.ExistsArg("i", "info") {
case cmdArgs.ExistsArg("i", "info"):
return syncInfo(cmdArgs, targets, dbExecutor)
}
if cmdArgs.ExistsArg("u", "sysupgrade") {
case cmdArgs.ExistsArg("u", "sysupgrade"):
return install(cmdArgs, dbExecutor, false)
}
if len(cmdArgs.Targets) > 0 {
case len(cmdArgs.Targets) > 0:
return install(cmdArgs, dbExecutor, false)
}
if cmdArgs.ExistsArg("y", "refresh") {
case cmdArgs.ExistsArg("y", "refresh"):
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
}

return nil
}

Expand Down Expand Up @@ -358,9 +365,11 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *parser.Ar
aq, aurErr = narrowSearch(config.Runtime.AURClient, pkgS, true)
lenaq = len(aq)
}

if config.Runtime.Mode.AtLeastRepo() {
pq = queryRepo(pkgS, dbExecutor)
lenpq = len(pq)

if repoErr != nil {
return repoErr
}
Expand All @@ -375,13 +384,15 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *parser.Ar
if config.Runtime.Mode.AtLeastRepo() {
pq.printSearch(dbExecutor)
}

if config.Runtime.Mode.AtLeastAUR() {
aq.printSearch(lenpq+1, dbExecutor)
}
case settings.BottomUp:
if config.Runtime.Mode.AtLeastAUR() {
aq.printSearch(lenpq+1, dbExecutor)
}

if config.Runtime.Mode.AtLeastRepo() {
pq.printSearch(dbExecutor)
}
Expand All @@ -403,6 +414,7 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *parser.Ar
if err != nil {
return err
}

if overflow {
return fmt.Errorf(gotext.Get("input too long"))
}
Expand All @@ -414,6 +426,7 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *parser.Ar

for i, pkg := range pq {
var target int

switch config.SortMode {
case settings.TopDown:
target = i + 1
Expand Down Expand Up @@ -478,6 +491,7 @@ func syncList(httpClient *http.Client, cmdArgs *parser.Arguments, dbExecutor db.
scanner := bufio.NewScanner(resp.Body)

scanner.Scan()

for scanner.Scan() {
name := scanner.Text()
if cmdArgs.ExistsArg("q", "quiet") {
Expand Down
8 changes: 7 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/Jguer/yay/v10/pkg/text"
)

// Verbosity settings for search
// Verbosity settings for search.
const (
numberMenu = iota
detailed
Expand All @@ -37,6 +37,7 @@ func editor() (editor string, args []string) {
} else {
return editor, strings.Fields(config.EditorFlags)
}

fallthrough
case os.Getenv("EDITOR") != "":
if editorArgs := strings.Fields(os.Getenv("EDITOR")); len(editorArgs) != 0 {
Expand All @@ -47,6 +48,7 @@ func editor() (editor string, args []string) {
return editor, editorArgs[1:]
}
}

fallthrough
case os.Getenv("VISUAL") != "":
if editorArgs := strings.Fields(os.Getenv("VISUAL")); len(editorArgs) != 0 {
Expand All @@ -57,6 +59,7 @@ func editor() (editor string, args []string) {
return editor, editorArgs[1:]
}
}

fallthrough
default:
fmt.Fprintln(os.Stderr)
Expand All @@ -65,6 +68,7 @@ func editor() (editor string, args []string) {

for {
text.Infoln(gotext.Get("Edit PKGBUILD with?"))

editorInput, err := getInput("")
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand All @@ -81,13 +85,15 @@ func editor() (editor string, args []string) {
fmt.Fprintln(os.Stderr, err)
continue
}

return editor, editorArgs[1:]
}
}
}

func getInput(defaultValue string) (string, error) {
text.Info()

if defaultValue != "" || settings.NoConfirm {
fmt.Println(defaultValue)
return defaultValue, nil
Expand Down
Loading

0 comments on commit cb4b57f

Please sign in to comment.