Skip to content

Commit

Permalink
Merge pull request #453 from navidys/golangci_lint
Browse files Browse the repository at this point in the history
golangci-lint update 1.56.2
  • Loading branch information
navidys authored Mar 5, 2024
2 parents a7d677f + 34bd642 commit bdef014
Show file tree
Hide file tree
Showing 59 changed files with 180 additions and 140 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ linters:
- wrapcheck
- execinquery
- funlen
- depguard
# generics disabled
- wastedassign
- rowserrcheck
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ install.tools: .install.ginkgo .install.bats .install.pre-commit .install.codesp

.PHONY: .install.golangci-lint
.install.golangci-lint:
VERSION=1.51.1 ./hack/install_golangci.sh
VERSION=1.56.2 ./hack/install_golangci.sh

.PHONY: .install.codespell
.install.codespell:
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Execute() {
cobra.CheckErr(rootCmd.Execute())
}

func run(cmd *cobra.Command, args []string) error { //nolint:cyclop
func run(cmd *cobra.Command, args []string) error { //nolint:cyclop,revive
var (
logOutput = io.Discard
runLog = fmt.Sprintf("starting %s version %s", appName, appVersion)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: fmt.Sprintf("Display %s version and exit.\n", appName),
Long: fmt.Sprintf("Display %s version and exit.\n", appName),
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, args []string) { //nolint:revive
fmt.Printf("%s v%s\n", appName, appVersion) //nolint:forbidigo
},
}
Expand Down
4 changes: 2 additions & 2 deletions config/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *Config) add(name string, newService Service) error {

// most of codes are from:
// https://github.com/containers/podman/blob/main/cmd/podman/system/connection/add.go.
func validateNewService(name string, dest string, identity string) (Service, error) { //nolint:gocognit,cyclop
func validateNewService(name string, dest string, identity string) (Service, error) { //nolint:cyclop
var (
service Service
serviceIdentity string
Expand All @@ -63,7 +63,7 @@ func validateNewService(name string, dest string, identity string) (Service, err
return service, ErrEmptyURIDestination
}

if match, err := regexp.Match("^[A-Za-z][A-Za-z0-9+.-]*://", []byte(dest)); err != nil {
if match, err := regexp.Match("^[A-Za-z][A-Za-z0-9+.-]*://", []byte(dest)); err != nil { //nolint:mirror
return service, fmt.Errorf("%w invalid destition", err)
} else if !match {
dest = "ssh://" + dest
Expand Down
2 changes: 2 additions & 0 deletions pdcs/images/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func Import(opts ImageImportOptions) (string, error) {
if err != nil {
return "", err
}

defer tarFile.Close()

reader = bufio.NewReader(tarFile)
}

Expand Down
4 changes: 2 additions & 2 deletions pdcs/images/search.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package images

import (
"fmt"
"strconv"

"github.com/containers/podman-tui/pdcs/registry"
"github.com/containers/podman/v4/pkg/bindings/images"
Expand Down Expand Up @@ -29,7 +29,7 @@ func Search(term string) ([][]string, error) {
sReport.Index,
sReport.Name,
sReport.Description,
fmt.Sprintf("%d", sReport.Stars),
strconv.Itoa(sReport.Stars),
sReport.Official,
sReport.Automated,
})
Expand Down
2 changes: 1 addition & 1 deletion pdcs/registry/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func GetConnection() (context.Context, error) {

ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
conn, err = bindings.NewConnectionWithIdentity(ctx, connURI.String(), ConnectionIdentity(), false)

conn, err = bindings.NewConnectionWithIdentity(ctx, connURI.String(), ConnectionIdentity(), false)
if err != nil {
cancel()

Expand Down
5 changes: 3 additions & 2 deletions pdcs/sysinfo/df.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sysinfo

import (
"fmt"
"strconv"

"github.com/containers/podman-tui/pdcs/registry"
"github.com/containers/podman/v4/pkg/bindings/system"
Expand Down Expand Up @@ -124,12 +125,12 @@ func (dfsum *DfSummary) Type() string {

// Total returns total value of df summary.
func (dfsum *DfSummary) Total() string {
return fmt.Sprintf("%d", dfsum.total)
return strconv.Itoa(dfsum.total)
}

// Active returns active value of df summary.
func (dfsum *DfSummary) Active() string {
return fmt.Sprintf("%d", dfsum.active)
return strconv.Itoa(dfsum.active)
}

// Size returns size value of df summary.
Expand Down
10 changes: 5 additions & 5 deletions pdcs/utils/defaults.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package utils

import (
"fmt"
"errors"

"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
Expand All @@ -14,13 +14,13 @@ const (

var (
// ErrEmptyVolDest empty volume destination error.
ErrEmptyVolDest = fmt.Errorf("volume destination cannot be empty")
ErrEmptyVolDest = errors.New("volume destination cannot be empty")
// ErrTopPodNotRunning top error while pod not running.
ErrTopPodNotRunning = fmt.Errorf("pods top can only be used on running pods")
ErrTopPodNotRunning = errors.New("pods top can only be used on running pods")
// ErrInvalidIPAddress invalid IP address error.
ErrInvalidIPAddress = fmt.Errorf("invalid IP address")
ErrInvalidIPAddress = errors.New("invalid IP address")
// ErrInvalidDNSAddress invalid DNS server address error.
ErrInvalidDNSAddress = fmt.Errorf("invalid DNS address")
ErrInvalidDNSAddress = errors.New("invalid DNS address")
)

// DefineCreateDefaults sets default container create options.
Expand Down
2 changes: 1 addition & 1 deletion ui/containers/cntdialogs/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewContainerCommitDialog() *ContainerCommitDialog {
cntInfoLabel := "CONTAINER ID:" //nolint:goconst

dialog.cntInfo.SetBackgroundColor(style.DialogBgColor)
dialog.cntInfo.SetLabel("[::b]" + cntInfoLabel)
dialog.cntInfo.SetLabel("[::b]" + cntInfoLabel) //nolint:goconst
dialog.cntInfo.SetLabelWidth(len(cntInfoLabel) + 1)
dialog.cntInfo.SetFieldBackgroundColor(style.DialogBgColor)
dialog.cntInfo.SetLabelStyle(tcell.StyleDefault.
Expand Down
1 change: 1 addition & 0 deletions ui/containers/cntdialogs/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ func (d *ContainerExecDialog) Focus(delegate func(p tview.Primitive)) { //nolint

return nil
}

if event.Key() == tcell.KeyEnter {
d.execHandler()

Expand Down
2 changes: 1 addition & 1 deletion ui/containers/cntdialogs/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (d *ContainerStatsDialog) setContainerPID(pids uint64) {
defer d.mu.Unlock()

if pids != 0 {
cntPIDS = fmt.Sprintf("%d", pids)
cntPIDS = fmt.Sprintf("%d", pids) //nolint:perfsprint
}

d.table.GetCell(containerPidsCell.row, containerPidsCell.col).SetText(cntPIDS).SetTextColor(fgColor)
Expand Down
3 changes: 2 additions & 1 deletion ui/containers/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ func (cnt *Containers) rm() {
bgColor := style.GetColorHex(style.DialogBorderColor)
fgColor := style.GetColorHex(style.DialogFgColor)
containerItem := fmt.Sprintf("[%s:%s:b]CONTAINER ID:[:-:-] %s(%s)", fgColor, bgColor, cntID, cntName)
description := fmt.Sprintf("%s\n\nAre you sure you want to remove the selected container ?", containerItem)
description := fmt.Sprintf("%s\n\nAre you sure you want to remove the selected container ?", //nolint:perfsprint
containerItem)

cnt.confirmDialog.SetText(description)
cnt.confirmDialog.Display()
Expand Down
13 changes: 7 additions & 6 deletions ui/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ func NewContainers() *Containers {

for i := 0; i < len(containers.headers); i++ {
containers.table.SetCell(0, i,
tview.NewTableCell(fmt.Sprintf("[black::b]%s", strings.ToUpper(containers.headers[i]))).
SetExpansion(1).
SetBackgroundColor(style.PageHeaderBgColor).
SetTextColor(style.PageHeaderFgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
tview.NewTableCell(fmt.Sprintf("[black::b]%s", strings.ToUpper(containers.headers[i]))). //nolint:perfsprint
SetExpansion(1).
SetBackgroundColor(style.PageHeaderBgColor).
SetTextColor(style.PageHeaderFgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
}

containers.table.SetFixed(1, 1)
Expand All @@ -164,6 +164,7 @@ func NewContainers() *Containers {
// set confirm dialogs functions
containers.confirmDialog.SetSelectedFunc(func() {
containers.confirmDialog.Hide()

switch containers.confirmData {
case "prune":
containers.prune()
Expand Down
12 changes: 6 additions & 6 deletions ui/containers/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func (cnt *Containers) ClearData() {

for i := 0; i < len(cnt.headers); i++ {
cnt.table.SetCell(0, i,
tview.NewTableCell(fmt.Sprintf("[::b]%s", strings.ToUpper(cnt.headers[i]))).
SetExpansion(expand).
SetBackgroundColor(bgColor).
SetTextColor(fgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
tview.NewTableCell(fmt.Sprintf("[::b]%s", strings.ToUpper(cnt.headers[i]))). //nolint:perfsprint
SetExpansion(expand).
SetBackgroundColor(bgColor).
SetTextColor(fgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
}

cnt.table.SetTitle(fmt.Sprintf("[::b]%s[0]", strings.ToUpper(cnt.title)))
Expand Down
12 changes: 6 additions & 6 deletions ui/containers/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func (cnt *Containers) refresh() {

for i := 0; i < len(cnt.headers); i++ {
cnt.table.SetCell(0, i,
tview.NewTableCell(fmt.Sprintf("[::b]%s", strings.ToUpper(cnt.headers[i]))).
SetExpansion(expand).
SetBackgroundColor(style.PageHeaderBgColor).
SetTextColor(style.PageHeaderFgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
tview.NewTableCell(fmt.Sprintf("[::b]%s", strings.ToUpper(cnt.headers[i]))). //nolint:perfsprint
SetExpansion(expand).
SetBackgroundColor(style.PageHeaderBgColor).
SetTextColor(style.PageHeaderFgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
}

rowIndex := 1
Expand Down
1 change: 1 addition & 0 deletions ui/dialogs/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (d *ConfirmDialog) Draw(screen tcell.Screen) {
func (d *ConfirmDialog) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
return d.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
log.Debug().Msgf("confirm dialog: event %v received", event)

if event.Key() == tcell.KeyEsc {
d.cancelHandler()

Expand Down
5 changes: 3 additions & 2 deletions ui/dialogs/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewErrorDialog() *ErrorDialog {

dialog.modal.SetButtonBackgroundColor(style.ErrorDialogButtonBgColor)

dialog.modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
dialog.modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) { //nolint:revive
dialog.Hide()
})

Expand Down Expand Up @@ -78,6 +78,7 @@ func (d *ErrorDialog) Focus(delegate func(p tview.Primitive)) {
func (d *ErrorDialog) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
return d.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
log.Debug().Msgf("error dialog: event %v received", event)

if modalHandler := d.modal.InputHandler(); modalHandler != nil {
modalHandler(event, setFocus)

Expand Down Expand Up @@ -115,7 +116,7 @@ func (d *ErrorDialog) Draw(screen tcell.Screen) {

// SetDoneFunc sets modal done function.
func (d *ErrorDialog) SetDoneFunc(handler func()) *ErrorDialog {
d.modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
d.modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) { //nolint:revive
handler()
})

Expand Down
3 changes: 2 additions & 1 deletion ui/dialogs/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (d *SimpleInputDialog) SetLabel(text string) {

d.input.SetFieldWidth(d.inputWidth)

label := fmt.Sprintf("%s: ", text)
label := fmt.Sprintf("%s: ", text) //nolint:perfsprint

d.input.SetLabel(label)
}
Expand Down Expand Up @@ -228,6 +228,7 @@ func (d *SimpleInputDialog) Focus(delegate func(p tview.Primitive)) {
func (d *SimpleInputDialog) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
return d.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
log.Debug().Msgf("input dialog: event %v received", event)

if event.Key() == tcell.KeyEsc {
d.cancelHandler()

Expand Down
1 change: 1 addition & 0 deletions ui/dialogs/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func (d *MessageDialog) Draw(screen tcell.Screen) {
func (d *MessageDialog) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
return d.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
log.Debug().Msgf("message dialog: event %v received", event)

if event.Key() == tcell.KeyEsc {
d.cancelHandler()

Expand Down
8 changes: 4 additions & 4 deletions ui/dialogs/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (d *ProgressDialog) IsDisplay() bool {
}

// Focus is called when this primitive receives focus.
func (d *ProgressDialog) Focus(delegate func(p tview.Primitive)) {}
func (d *ProgressDialog) Focus(delegate func(p tview.Primitive)) {} //nolint:revive

// HasFocus returns whether or not this primitive has focus.
func (d *ProgressDialog) HasFocus() bool {
Expand All @@ -99,7 +99,7 @@ func (d *ProgressDialog) HasFocus() bool {

// InputHandler returns input handler function for this primitive.
func (d *ProgressDialog) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
return d.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
return d.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p tview.Primitive)) { //nolint:revive
log.Debug().Msgf("progress dialog: event %v received", event)
})
}
Expand All @@ -120,14 +120,14 @@ func (d *ProgressDialog) tickStr(max int) string {
prgStr := ""

for i := 0; i < d.counterValue; i++ {
prgHeadStr += fmt.Sprintf("[black::]%s", prgCell)
prgHeadStr += fmt.Sprintf("[black::]%s", prgCell) //nolint:perfsprint
hWidth++
}

prgStr = prgCell + prgCell + prgCell + prgCell

for i := 0; i < max+hWidth+4; i++ {
prgEndStr += fmt.Sprintf("[black::]%s", prgCell)
prgEndStr += fmt.Sprintf("[black::]%s", prgCell) //nolint:perfsprint
}

progress := fmt.Sprintf("%s[%s::]%s%s", prgHeadStr, barColor, prgStr, prgEndStr)
Expand Down
8 changes: 4 additions & 4 deletions ui/help/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func NewHelp(appName string, appVersion string) *Help {
}

keyinfo.SetCell(rowIndex, colIndex,
tview.NewTableCell(fmt.Sprintf("%s:", utils.UIKeysBindings[i].KeyLabel)).
SetAlign(tview.AlignRight).
SetBackgroundColor(bgColor).
SetSelectable(true).SetTextColor(headerColor))
tview.NewTableCell(fmt.Sprintf("%s:", utils.UIKeysBindings[i].KeyLabel)). //nolint:perfsprint
SetAlign(tview.AlignRight).
SetBackgroundColor(bgColor).
SetSelectable(true).SetTextColor(headerColor))

keyinfo.SetCell(rowIndex, colIndex+1,
tview.NewTableCell(utils.UIKeysBindings[i].KeyDesc).
Expand Down
2 changes: 1 addition & 1 deletion ui/images/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (img *Images) rm() {
bgColor := style.GetColorHex(style.DialogBorderColor)
fgColor := style.GetColorHex(style.DialogFgColor)
imageItem := fmt.Sprintf("[%s:%s:b]IMAGE ID:[:-:-] %s (%s)", fgColor, bgColor, imageID, imageName)
description := fmt.Sprintf("%s\n\nAre you sure you want to remove the selected image?", imageItem)
description := fmt.Sprintf("%s\n\nAre you sure you want to remove the selected image?", imageItem) //nolint:perfsprint

img.confirmDialog.SetText(description)
img.confirmDialog.Display()
Expand Down
12 changes: 6 additions & 6 deletions ui/images/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func (img *Images) ClearData() {

for i := 0; i < len(img.headers); i++ {
img.table.SetCell(0, i,
tview.NewTableCell(fmt.Sprintf("[::b]%s", strings.ToUpper(img.headers[i]))).
SetExpansion(expand).
SetBackgroundColor(bgColor).
SetTextColor(fgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
tview.NewTableCell(fmt.Sprintf("[::b]%s", strings.ToUpper(img.headers[i]))). //nolint:perfsprint
SetExpansion(expand).
SetBackgroundColor(bgColor).
SetTextColor(fgColor).
SetAlign(tview.AlignLeft).
SetSelectable(false))
}

img.table.SetTitle(fmt.Sprintf("[::b]%s[0]", strings.ToUpper(img.title)))
Expand Down
Loading

0 comments on commit bdef014

Please sign in to comment.