Skip to content

Commit

Permalink
Merge pull request #531 from navidys/golangci_lint
Browse files Browse the repository at this point in the history
golangci-lint update 1.61.0
  • Loading branch information
navidys authored Oct 26, 2024
2 parents d1cb59b + 0e4b01f commit fd933d0
Show file tree
Hide file tree
Showing 71 changed files with 304 additions and 308 deletions.
22 changes: 9 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
run:
timeout: 10m
deadline: 5m
skip-files:
- ".*_test.go"
linters:
enable-all: true
disable:
Expand All @@ -17,22 +16,19 @@ linters:
- wastedassign
- rowserrcheck
# deprecated
- nosnakecase
- varcheck
- structcheck
- ifshort
- deadcode
- golint
- maligned
- interfacer
- scopelint
- exhaustivestruct
- gomnd
- gomoddirectives
- exportloopref
linters-settings:
# typecheck:
# enabled: false
errcheck:
check-blank: false
ignore: fmt:.*
exclude-functions:
- fmt:.*
nolintlint:
require-specific: true

issues:
exclude-files:
- ".*_test.go"
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.56.2 ./hack/install_golangci.sh
VERSION=1.61.0 ./hack/install_golangci.sh

.PHONY: .install.codespell
.install.codespell:
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewApp(name string, version string) *App {
Application: tview.NewApplication(),
pages: tview.NewPages(),
needInitUI: false,
fastRefreshChan: make(chan bool, 10), //nolint:gomnd
fastRefreshChan: make(chan bool, 10), //nolint:mnd
}

var err error
Expand Down
4 changes: 2 additions & 2 deletions app/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func newMenu(menuItems [][]string) *tview.TextView {

menu.SetBackgroundColor(style.BgColor)

var menuList []string
menuList := []string{}

for i := 0; i < len(menuItems); i++ {
for i := range menuItems {
key, item := genMenuItem(menuItems[i])
if i == len(menuItems)-1 {
item += " "
Expand Down
2 changes: 1 addition & 1 deletion app/screens.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ func (app *App) clearViewsData() {

func (app *App) clearInfoUIData() {
app.infoBar.UpdateBasicInfo("", "", "")
app.infoBar.UpdateSystemUsageInfo(0.00, 0.00) //nolint:gomnd
app.infoBar.UpdateSystemUsageInfo(0.00, 0.00) //nolint:mnd
app.infoBar.UpdatePodmanInfo("", "", "", "")
}
4 changes: 2 additions & 2 deletions config/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func (c *Config) Write() error {

log.Debug().Msgf("config: write configuration file %q", path)

if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { //nolint:gomnd
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { //nolint:mnd
return err
}

configFile, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o640) //nolint:gomnd
configFile, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o640) //nolint:mnd
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pdcs/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func Create(opts CreateOptions) ([]string, error) { //nolint:cyclop,gocognit,goc
return warningResponse, fmt.Errorf("%w: %s", ErrInvalidCreateTimeout, opts.Timeout)
}

createOptions.Timeout = uint(timeout)
createOptions.Timeout = uint(timeout) //nolint:gosec
}

createOptions.Hostname = opts.Hostname
Expand Down
4 changes: 2 additions & 2 deletions pdcs/containers/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func Top(id string) ([][]string, error) {
log.Debug().Msgf("pdcs: podman container top %s", id)

var report [][]string
report := [][]string{}

conn, err := registry.GetConnection()
if err != nil {
Expand All @@ -25,7 +25,7 @@ func Top(id string) ([][]string, error) {
return report, err
}

for i := 0; i < len(response); i++ {
for i := range response {
space := regexp.MustCompile(`\s+`)
line := space.ReplaceAllString(response[i], " ")
split := strings.Split(line, " ")
Expand Down
4 changes: 2 additions & 2 deletions pdcs/images/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func History(id string) ([][]string, error) {
log.Debug().Msgf("pdcs: podman image history %s", id)

var report [][]string
report := [][]string{}

conn, err := registry.GetConnection()
if err != nil {
Expand All @@ -26,7 +26,7 @@ func History(id string) ([][]string, error) {
return report, err
}

for i := 0; i < len(response); i++ {
for i := range response {
report = append(report, []string{
response[i].ID,
units.HumanDuration(time.Since(time.Unix(response[i].Created, 0))) + " ago",
Expand Down
2 changes: 1 addition & 1 deletion pdcs/images/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Save(imageID string, opts ImageSaveOptions) error { //nolint:cyclop
defer outputFile.Close()

cancelChan := make(chan bool, 1)
writerChan := make(chan []byte, 1024) //nolint:gomnd
writerChan := make(chan []byte, 1024) //nolint:mnd
outputWriter := channel.NewWriter(writerChan)

writeOutputFunc := func() {
Expand Down
4 changes: 2 additions & 2 deletions pdcs/pods/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func Top(id string) ([][]string, error) {
log.Debug().Msgf("pdcs: podman pod top %s", id)

var report [][]string
report := [][]string{}

conn, err := registry.GetConnection()
if err != nil {
Expand All @@ -26,7 +26,7 @@ func Top(id string) ([][]string, error) {
return report, err
}

for i := 0; i < len(response); i++ {
for i := range response {
if response[i] == "" {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pdcs/sysinfo/df.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (dfsum *DfSummary) Size() string {

// Reclaimable returns reclaimable value of df summary.
func (dfsum *DfSummary) Reclaimable() string {
percent := int(float64(dfsum.reclaimable)/float64(dfsum.size)) * 100 //nolint:gomnd
percent := int(float64(dfsum.reclaimable)/float64(dfsum.size)) * 100 //nolint:mnd

return fmt.Sprintf("%s (%d%%)", units.HumanSize(float64(dfsum.reclaimable)), percent)
}
4 changes: 2 additions & 2 deletions pdcs/sysinfo/sysinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func SysInfo() (*SystemInfo, error) {
info.Kernel = response.Host.Kernel
memUsed := response.Host.MemTotal - response.Host.MemFree
swapUsed := response.Host.SwapTotal - response.Host.SwapFree
info.MemUsagePC = float64(memUsed*100) / float64(response.Host.MemTotal) //nolint:gomnd
info.SwapUsagePC = float64(swapUsed*100) / float64(response.Host.SwapTotal) //nolint:gomnd
info.MemUsagePC = float64(memUsed*100) / float64(response.Host.MemTotal) //nolint:mnd
info.SwapUsagePC = float64(swapUsed*100) / float64(response.Host.SwapTotal) //nolint:mnd

info.Runtime = response.Host.OCIRuntime.Version
info.BuildahVersion = response.Host.BuildahVersion
Expand Down
2 changes: 1 addition & 1 deletion pdcs/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// SizeToStr converts size to human readable format.
func SizeToStr(size int64) string {
return units.HumanSizeWithPrecision(float64(size), 3) //nolint:gomnd
return units.HumanSizeWithPrecision(float64(size), 3) //nolint:mnd
}

// CreatedToStr converts duration to human readable format.
Expand Down
10 changes: 5 additions & 5 deletions ui/containers/cntdialogs/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ func NewContainerCheckpointDialog() *ContainerCheckpointDialog {
optionsLayoutRow01.AddItem(dialog.export, 1, 0, true)

optionsLayoutRow02 := tview.NewFlex().SetDirection(tview.FlexColumn)
optionsLayoutRow02.AddItem(dialog.fileLock, labelWidth+2, 0, true) //nolint:gomnd
optionsLayoutRow02.AddItem(dialog.fileLock, labelWidth+2, 0, true) //nolint:mnd
optionsLayoutRow02.AddItem(dialog.ignoreRootFS, 0, 1, true)
optionsLayoutRow02.AddItem(dialog.tcpEstablished, 0, 1, true)
optionsLayoutRow02.AddItem(dialog.preCheckpoint, 0, 1, true)

optionsLayoutRow03 := tview.NewFlex().SetDirection(tview.FlexColumn)
optionsLayoutRow03.AddItem(dialog.printStats, labelWidth+2, 1, true) //nolint:gomnd
optionsLayoutRow03.AddItem(dialog.printStats, labelWidth+2, 1, true) //nolint:mnd
optionsLayoutRow03.AddItem(dialog.keep, 0, 1, true)
optionsLayoutRow03.AddItem(dialog.leaveRunning, 0, 1, true)
optionsLayoutRow03.AddItem(dialog.withPrevious, 0, 1, true)
Expand Down Expand Up @@ -433,13 +433,13 @@ func (d *ContainerCheckpointDialog) InputHandler() func(event *tcell.EventKey, s
// SetRect set rects for this primitive.
func (d *ContainerCheckpointDialog) SetRect(x, y, width, height int) {
if width > cntCheckpointDialogMaxWidth {
emptySpace := (width - cntCheckpointDialogMaxWidth) / 2 //nolint:gomnd
emptySpace := (width - cntCheckpointDialogMaxWidth) / 2 //nolint:mnd
x += emptySpace
width = cntCheckpointDialogMaxWidth
}

if height > cntCheckpointDialogMaxHeight {
emptySpace := (height - cntCheckpointDialogMaxHeight) / 2 //nolint:gomnd
emptySpace := (height - cntCheckpointDialogMaxHeight) / 2 //nolint:mnd
y += emptySpace
height = cntCheckpointDialogMaxHeight
}
Expand Down Expand Up @@ -474,7 +474,7 @@ func (d *ContainerCheckpointDialog) SetCheckpointFunc(handler func()) *Container
// SetCancelFunc sets form cancel button selected function.
func (d *ContainerCheckpointDialog) SetCancelFunc(handler func()) *ContainerCheckpointDialog {
d.cancelHandler = handler
cancelButton := d.form.GetButton(d.form.GetButtonCount() - 2) //nolint:gomnd
cancelButton := d.form.GetButton(d.form.GetButtonCount() - 2) //nolint:mnd

cancelButton.SetSelectedFunc(handler)

Expand Down
10 changes: 5 additions & 5 deletions 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) //nolint:goconst
dialog.cntInfo.SetLabel("[::b]" + cntInfoLabel)
dialog.cntInfo.SetLabelWidth(len(cntInfoLabel) + 1)
dialog.cntInfo.SetFieldBackgroundColor(style.DialogBgColor)
dialog.cntInfo.SetLabelStyle(tcell.StyleDefault.
Expand Down Expand Up @@ -154,7 +154,7 @@ func NewContainerCommitDialog() *ContainerCommitDialog {
iaLayout := tview.NewFlex().SetDirection(tview.FlexColumn)
iaLayout.SetBackgroundColor(style.DialogBgColor)
iaLayout.AddItem(dialog.image, 0, 1, true)
iaLayout.AddItem(utils.EmptyBoxSpace(style.DialogBgColor), 2, 0, false) //nolint:gomnd
iaLayout.AddItem(utils.EmptyBoxSpace(style.DialogBgColor), 2, 0, false) //nolint:mnd
iaLayout.AddItem(dialog.author, 0, 1, true)

// dropdown and checkbox layout row
Expand Down Expand Up @@ -388,13 +388,13 @@ func (d *ContainerCommitDialog) setFocusElement() {
// SetRect set rects for this primitive.
func (d *ContainerCommitDialog) SetRect(x, y, width, height int) {
if width > cntCommitDialogMaxWidth {
emptySpace := (width - cntCommitDialogMaxWidth) / 2 //nolint:gomnd
emptySpace := (width - cntCommitDialogMaxWidth) / 2 //nolint:mnd
x += emptySpace
width = cntCommitDialogMaxWidth
}

if height > cntCommitDialogMaxHeight {
emptySpace := (height - cntCommitDialogMaxHeight) / 2 //nolint:gomnd
emptySpace := (height - cntCommitDialogMaxHeight) / 2 //nolint:mnd
y += emptySpace
height = cntCommitDialogMaxHeight
}
Expand Down Expand Up @@ -429,7 +429,7 @@ func (d *ContainerCommitDialog) SetCommitFunc(handler func()) *ContainerCommitDi
// SetCancelFunc sets form cancel button selected function.
func (d *ContainerCommitDialog) SetCancelFunc(handler func()) *ContainerCommitDialog {
d.cancelHandler = handler
cancelButton := d.form.GetButton(d.form.GetButtonCount() - 2) //nolint:gomnd
cancelButton := d.form.GetButton(d.form.GetButtonCount() - 2) //nolint:mnd

cancelButton.SetSelectedFunc(handler)

Expand Down
20 changes: 10 additions & 10 deletions ui/containers/cntdialogs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (d *ContainerCreateDialog) setupLayout() {
_, layoutWidth := utils.AlignStringListWidth(d.categoryLabels)
layout := tview.NewFlex().SetDirection(tview.FlexColumn)

layout.AddItem(d.categories, layoutWidth+6, 0, true) //nolint:gomnd
layout.AddItem(d.categories, layoutWidth+6, 0, true) //nolint:mnd
layout.AddItem(d.categoryPages, 0, 1, true)
layout.SetBackgroundColor(bgColor)
d.layout.AddItem(layout, 0, 1, true)
Expand Down Expand Up @@ -1273,13 +1273,13 @@ func (d *ContainerCreateDialog) InputHandler() func(event *tcell.EventKey, setFo
// SetRect set rects for this primitive.
func (d *ContainerCreateDialog) SetRect(x, y, width, height int) {
if width > containerCreateDialogMaxWidth {
emptySpace := (width - containerCreateDialogMaxWidth) / 2 //nolint:gomnd
emptySpace := (width - containerCreateDialogMaxWidth) / 2 //nolint:mnd
x += emptySpace
width = containerCreateDialogMaxWidth
}

if height > containerCreateDialogHeight {
emptySpace := (height - containerCreateDialogHeight) / 2 //nolint:gomnd
emptySpace := (height - containerCreateDialogHeight) / 2 //nolint:mnd
y += emptySpace
height = containerCreateDialogHeight
}
Expand All @@ -1304,7 +1304,7 @@ func (d *ContainerCreateDialog) Draw(screen tcell.Screen) {
// SetCancelFunc sets form cancel button selected function.
func (d *ContainerCreateDialog) SetCancelFunc(handler func()) *ContainerCreateDialog {
d.cancelHandler = handler
cancelButton := d.form.GetButton(d.form.GetButtonCount() - 2) //nolint:gomnd
cancelButton := d.form.GetButton(d.form.GetButtonCount() - 2) //nolint:mnd

cancelButton.SetSelectedFunc(handler)

Expand All @@ -1331,11 +1331,11 @@ func (d *ContainerCreateDialog) setActiveCategory(index int) {

d.categories.Clear()

var ctgList []string
ctgList := []string{}

alignedList, _ := utils.AlignStringListWidth(d.categoryLabels)

for i := 0; i < len(alignedList); i++ {
for i := range alignedList {
if i == index {
ctgList = append(ctgList, fmt.Sprintf("[%s:%s:b]-> %s ", ctgTextColor, ctgBgColor, alignedList[i]))

Expand Down Expand Up @@ -1383,7 +1383,7 @@ func (d *ContainerCreateDialog) initData() {
d.imageList = imgList
imgOptions := []string{""}

for i := 0; i < len(d.imageList); i++ {
for i := range d.imageList {
if d.imageList[i].ID == "<none>" {
imgOptions = append(imgOptions, d.imageList[i].ID)

Expand All @@ -1399,15 +1399,15 @@ func (d *ContainerCreateDialog) initData() {
podList, _ := pods.List()
d.podList = podList

for i := 0; i < len(podList); i++ {
for i := range podList {
podOptions = append(podOptions, podList[i].Name)
}

// get available networks
networkOptions := []string{""}
networkList, _ := networks.List()

for i := 0; i < len(networkList); i++ {
for i := range networkList {
networkOptions = append(networkOptions, networkList[i][1])
}

Expand All @@ -1416,7 +1416,7 @@ func (d *ContainerCreateDialog) initData() {
volumeOptions := []string{""}
volList, _ := volumes.List()

for i := 0; i < len(volList); i++ {
for i := range volList {
volumeOptions = append(volumeOptions, volList[i].Name)
}

Expand Down
8 changes: 4 additions & 4 deletions ui/containers/cntdialogs/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func NewContainerExecDialog() *ContainerExecDialog {
mLayout.AddItem(dialog.command, 1, 0, true)

// interactive, tty, privileged and detach
checkBoxWidth := execDialogLabelWidth + 4 //nolint:gomnd
checkBoxWidth := execDialogLabelWidth + 4 //nolint:mnd
labelPaddings := 5
checkBoxLayout := tview.NewFlex().SetDirection(tview.FlexColumn)

Expand Down Expand Up @@ -578,7 +578,7 @@ func (d *ContainerExecDialog) SetRect(x, y, width, height int) {
if width > execDialogMaxWidth {
wEmptySpace := width - execDialogMaxWidth
if wEmptySpace > 0 {
dX = x + (wEmptySpace / 2) //nolint:gomnd
dX = x + (wEmptySpace / 2) //nolint:mnd
}

dWidth = execDialogMaxWidth
Expand All @@ -591,7 +591,7 @@ func (d *ContainerExecDialog) SetRect(x, y, width, height int) {
hEmptySpace := height - execDialogMaxHeight

if hEmptySpace > 0 {
dY = y + (hEmptySpace / 2) //nolint:gomnd
dY = y + (hEmptySpace / 2) //nolint:mnd
}

dHeight = execDialogMaxHeight
Expand All @@ -618,7 +618,7 @@ func (d *ContainerExecDialog) Draw(screen tcell.Screen) {
// SetCancelFunc sets form cancel button selected function.
func (d *ContainerExecDialog) SetCancelFunc(handler func()) *ContainerExecDialog {
d.cancelHandler = handler
cancelButton := d.form.GetButton(d.form.GetButtonCount() - 2) //nolint:gomnd
cancelButton := d.form.GetButton(d.form.GetButtonCount() - 2) //nolint:mnd

cancelButton.SetSelectedFunc(handler)

Expand Down
Loading

0 comments on commit fd933d0

Please sign in to comment.