appease linter

pull/325/head
Jesse Duffield 2 years ago
parent 212b9d0b03
commit 6bc57b7628

@ -83,13 +83,11 @@ type Details struct {
Binds []string `json:"Binds"`
ContainerIDFile string `json:"ContainerIDFile"`
LogConfig struct {
Type string `json:"Type"`
Config struct {
} `json:"Config"`
Type string `json:"Type"`
Config struct{} `json:"Config"`
} `json:"LogConfig"`
NetworkMode string `json:"NetworkMode"`
PortBindings struct {
} `json:"PortBindings"`
NetworkMode string `json:"NetworkMode"`
PortBindings struct{} `json:"PortBindings"`
RestartPolicy struct {
Name string `json:"Name"`
MaximumRetryCount int `json:"MaximumRetryCount"`
@ -185,10 +183,8 @@ type Details struct {
Cmd []string `json:"Cmd"`
Image string `json:"Image"`
Volumes struct {
APIBundle struct {
} `json:"/api-bundle"`
App struct {
} `json:"/app"`
APIBundle struct{} `json:"/api-bundle"`
App struct{} `json:"/app"`
} `json:"Volumes"`
WorkingDir string `json:"WorkingDir"`
Entrypoint interface{} `json:"Entrypoint"`

@ -56,10 +56,9 @@ type ContainerStats struct {
IoTimeRecursive []interface{} `json:"io_time_recursive"`
SectorsRecursive []interface{} `json:"sectors_recursive"`
} `json:"blkio_stats"`
NumProcs int `json:"num_procs"`
StorageStats struct {
} `json:"storage_stats"`
CPUStats struct {
NumProcs int `json:"num_procs"`
StorageStats struct{} `json:"storage_stats"`
CPUStats struct {
CPUUsage struct {
TotalUsage int64 `json:"total_usage"`
PercpuUsage []int64 `json:"percpu_usage"`
@ -161,7 +160,6 @@ func (s *ContainerStats) CalculateContainerCPUPercentage() float64 {
// CalculateContainerMemoryUsage calculates the memory usage of the container as a percent of total available memory
func (s *ContainerStats) CalculateContainerMemoryUsage() float64 {
value := float64(s.MemoryStats.Usage*100) / float64(s.MemoryStats.Limit)
if math.IsNaN(value) {
return 0

@ -68,7 +68,7 @@ type CommandObject struct {
// NewCommandObject takes a command object and returns a default command object with the passed command object merged in
func (c *DockerCommand) NewCommandObject(obj CommandObject) CommandObject {
defaultObj := CommandObject{DockerCompose: c.Config.UserConfig.CommandTemplates.DockerCompose}
mergo.Merge(&defaultObj, obj)
_ = mergo.Merge(&defaultObj, obj)
return defaultObj
}
@ -139,7 +139,7 @@ func (c *DockerCommand) MonitorCLIContainerStats() {
return
}
cmd.Start()
_ = cmd.Start()
scanner := bufio.NewScanner(r)
scanner.Split(bufio.ScanLines)
@ -160,7 +160,7 @@ func (c *DockerCommand) MonitorCLIContainerStats() {
c.ContainerMutex.Unlock()
}
cmd.Wait()
_ = cmd.Wait()
}
// MonitorClientContainerStats is a function
@ -192,7 +192,7 @@ func (c *DockerCommand) createClientStatMonitor(container *Container) {
for scanner.Scan() {
data := scanner.Bytes()
var stats ContainerStats
json.Unmarshal(data, &stats)
_ = json.Unmarshal(data, &stats)
recordedStats := RecordedStats{
ClientStats: stats,

@ -2,9 +2,10 @@ package commands
import (
"context"
"github.com/docker/docker/api/types/image"
"strings"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
@ -27,7 +28,6 @@ type Image struct {
// GetDisplayStrings returns the display string of Image
func (i *Image) GetDisplayStrings(isFocused bool) []string {
return []string{i.Name, i.Tag, utils.FormatDecimalBytes(int(i.Image.Size))}
}
@ -87,7 +87,6 @@ func (l *Layer) GetDisplayStrings(isFocused bool) []string {
// RenderHistory renders the history of the image
func (i *Image) RenderHistory() (string, error) {
history, err := i.Client.ImageHistory(context.Background(), i.ID)
if err != nil {
return "", err

@ -190,7 +190,7 @@ func (c *OSCommand) Unquote(message string) string {
// AppendLineToFile adds a new line in file
func (c *OSCommand) AppendLineToFile(filename, line string) error {
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o600)
if err != nil {
return WrapError(err)
}
@ -272,7 +272,6 @@ func (c *OSCommand) RunCustomCommand(command string) *exec.Cmd {
// PipeCommands runs a heap of commands and pipes their inputs/outputs together like A | B | C
func (c *OSCommand) PipeCommands(commandStrings ...string) error {
cmds := make([]*exec.Cmd, len(commandStrings))
for i, str := range commandStrings {

@ -235,7 +235,7 @@ func TestOSCommandFileType(t *testing.T) {
{
"testDirectory",
func() {
if err := os.Mkdir("testDirectory", 0644); err != nil {
if err := os.Mkdir("testDirectory", 0o644); err != nil {
panic(err)
}
},

@ -23,7 +23,6 @@ type Service struct {
// GetDisplayStrings returns the dispaly string of Container
func (s *Service) GetDisplayStrings(isFocused bool) []string {
if s.Container == nil {
return []string{utils.ColoredString("none", color.FgBlue), "", s.Name, ""}
}

@ -1,10 +1,11 @@
package commands
import (
"testing"
"github.com/docker/docker/api/types"
"github.com/jesseduffield/lazydocker/pkg/config"
"github.com/stretchr/testify/assert"
"testing"
)
func sampleContainers(userConfig *config.AppConfig) []*Container {
@ -119,6 +120,7 @@ func expectedLegacySortedContainers(appConfig *config.AppConfig) []*Container {
}
func assertEqualContainers(t *testing.T, left *Container, right *Container) {
t.Helper()
assert.Equal(t, left.Container.State, right.Container.State)
assert.Equal(t, left.Container.ID, right.Container.ID)
assert.Equal(t, left.Name, right.Name)

@ -10,7 +10,6 @@ import (
func TestDockerComposeCommandNoFiles(t *testing.T) {
composeFiles := []string{}
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, composeFiles, "projectDir")
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
@ -25,7 +24,6 @@ func TestDockerComposeCommandNoFiles(t *testing.T) {
func TestDockerComposeCommandSingleFile(t *testing.T) {
composeFiles := []string{"one.yml"}
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, composeFiles, "projectDir")
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
@ -40,7 +38,6 @@ func TestDockerComposeCommandSingleFile(t *testing.T) {
func TestDockerComposeCommandMultipleFiles(t *testing.T) {
composeFiles := []string{"one.yml", "two.yml", "three.yml"}
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, composeFiles, "projectDir")
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
@ -53,14 +50,15 @@ func TestDockerComposeCommandMultipleFiles(t *testing.T) {
}
func TestWritingToConfigFile(t *testing.T) {
//init the AppConfig
// init the AppConfig
emptyComposeFiles := []string{}
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, emptyComposeFiles, "projectDir")
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
testFn := func(ac *AppConfig, newValue bool, t *testing.T) {
testFn := func(t *testing.T, ac *AppConfig, newValue bool) {
t.Helper()
updateFn := func(uc *UserConfig) error {
uc.ConfirmOnQuit = newValue
return nil
@ -71,7 +69,7 @@ func TestWritingToConfigFile(t *testing.T) {
t.Fatalf("Unexpected error: %s", err)
}
file, err := os.OpenFile(ac.ConfigFilename(), os.O_RDONLY, 0660)
file, err := os.OpenFile(ac.ConfigFilename(), os.O_RDONLY, 0o660)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
@ -93,8 +91,8 @@ func TestWritingToConfigFile(t *testing.T) {
}
// insert value into an empty file
testFn(conf, true, t)
testFn(t, conf, true)
// modifying an existing file that already has 'ConfirmOnQuit'
testFn(conf, false, t)
testFn(t, conf, false)
}

@ -90,9 +90,11 @@ func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt
}
func (gui *Gui) onNewPopupPanel() {
viewNames := []string{"commitMessage",
viewNames := []string{
"commitMessage",
"credentials",
"menu"}
"menu",
}
for _, viewName := range viewNames {
_, _ = gui.g.SetViewOnBottom(viewName)
}

@ -120,7 +120,7 @@ func (gui *Gui) renderContainerEnv(container *commands.Container) error {
}
}
return gui.T.NewTask(func(stop chan struct{}) {
gui.renderString(gui.g, "main", renderedTable)
_ = gui.renderString(gui.g, "main", renderedTable)
})
}
@ -170,7 +170,7 @@ func (gui *Gui) renderContainerConfig(container *commands.Container) error {
output += fmt.Sprintf("\nFull details:\n\n%s", string(data))
return gui.T.NewTask(func(stop chan struct{}) {
gui.renderString(gui.g, "main", output)
_ = gui.renderString(gui.g, "main", output)
})
}
@ -184,10 +184,10 @@ func (gui *Gui) renderContainerStats(container *commands.Container) error {
contents, err := container.RenderStats(width)
if err != nil {
gui.createErrorPanel(gui.g, err.Error())
_ = gui.createErrorPanel(gui.g, err.Error())
}
gui.reRenderString(gui.g, "main", contents)
_ = gui.reRenderString(gui.g, "main", contents)
})
}
@ -199,10 +199,10 @@ func (gui *Gui) renderContainerTop(container *commands.Container) error {
return gui.T.NewTickerTask(time.Second, func(stop chan struct{}) { gui.clearMainView() }, func(stop, notifyStopped chan struct{}) {
contents, err := container.RenderTop()
if err != nil {
gui.reRenderString(gui.g, "main", err.Error())
_ = gui.reRenderString(gui.g, "main", err.Error())
}
gui.reRenderString(gui.g, "main", contents)
_ = gui.reRenderString(gui.g, "main", contents)
})
}
@ -234,7 +234,7 @@ func (gui *Gui) renderContainerLogsAux(container *commands.Container, stop, noti
cmd.Stdout = mainView
cmd.Stderr = mainView
cmd.Start()
_ = cmd.Start()
go func() {
<-stop
@ -245,7 +245,7 @@ func (gui *Gui) renderContainerLogsAux(container *commands.Container, stop, noti
return
}()
cmd.Wait()
_ = cmd.Wait()
// if we are here because the task has been stopped, we should return
// if we are here then the container must have exited, meaning we should wait until it's back again before
@ -389,7 +389,7 @@ func (gui *Gui) handleContainersNextContext(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.Containers.ContextIndex++
}
gui.handleContainerSelect(gui.g, v)
_ = gui.handleContainerSelect(gui.g, v)
return nil
}
@ -402,7 +402,7 @@ func (gui *Gui) handleContainersPrevContext(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.Containers.ContextIndex--
}
gui.handleContainerSelect(gui.g, v)
_ = gui.handleContainerSelect(gui.g, v)
return nil
}

@ -93,7 +93,7 @@ func (gui *Gui) renderImageConfig(mainView *gocui.View, image *commands.Image) e
mainView.Autoscroll = false
mainView.Wrap = false // don't care what your config is this page is ugly without wrapping
gui.renderString(gui.g, "main", output)
_ = gui.renderString(gui.g, "main", output)
})
}
@ -174,7 +174,7 @@ func (gui *Gui) handleImagesNextContext(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.Images.ContextIndex++
}
gui.handleImageSelect(gui.g, v)
_ = gui.handleImageSelect(gui.g, v)
return nil
}
@ -187,7 +187,7 @@ func (gui *Gui) handleImagesPrevContext(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.Images.ContextIndex--
}
gui.handleImageSelect(gui.g, v)
_ = gui.handleImageSelect(gui.g, v)
return nil
}

@ -152,7 +152,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
_, _ = g.SetViewOnBottom("limit")
g.DeleteView("limit")
_ = g.DeleteView("limit")
v, err := g.SetView("main", leftSideWidth+1, 0, width-1, height-2, gocui.LEFT)
if err != nil {

@ -9,9 +9,7 @@ import (
)
func (gui *Gui) getBindings(v *gocui.View) []*Binding {
var (
bindingsGlobal, bindingsPanel []*Binding
)
var bindingsGlobal, bindingsPanel []*Binding
bindings := gui.GetInitialKeybindings()

@ -108,7 +108,7 @@ func (gui *Gui) renderCredits() error {
mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel
var configBuf bytes.Buffer
yaml.NewEncoder(&configBuf, yaml.IncludeOmitted).Encode(gui.Config.UserConfig)
_ = yaml.NewEncoder(&configBuf, yaml.IncludeOmitted).Encode(gui.Config.UserConfig)
dashboardString := strings.Join(
[]string{
@ -122,7 +122,7 @@ func (gui *Gui) renderCredits() error {
configBuf.String(),
}, "\n\n")
gui.renderString(gui.g, "main", dashboardString)
_ = gui.renderString(gui.g, "main", dashboardString)
})
}
@ -145,7 +145,7 @@ func (gui *Gui) renderAllLogs() error {
cmd.Stderr = mainView
gui.OSCommand.PrepareForChildren(cmd)
cmd.Start()
_ = cmd.Start()
go func() {
<-stop
@ -154,7 +154,7 @@ func (gui *Gui) renderAllLogs() error {
}
}()
cmd.Wait()
_ = cmd.Wait()
})
}
@ -165,7 +165,7 @@ func (gui *Gui) renderDockerComposeConfig() error {
mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel
config := gui.DockerCommand.DockerComposeConfig()
gui.renderString(gui.g, "main", config)
_ = gui.renderString(gui.g, "main", config)
})
}
@ -198,7 +198,7 @@ func (gui *Gui) handleProjectNextContext(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.Project.ContextIndex++
}
gui.handleProjectSelect(gui.g, v)
_ = gui.handleProjectSelect(gui.g, v)
return nil
}
@ -211,7 +211,7 @@ func (gui *Gui) handleProjectPrevContext(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.Project.ContextIndex--
}
gui.handleProjectSelect(gui.g, v)
_ = gui.handleProjectSelect(gui.g, v)
return nil
}

@ -118,10 +118,10 @@ func (gui *Gui) renderServiceTop(service *commands.Service) error {
return gui.T.NewTickerTask(time.Second, func(stop chan struct{}) { gui.clearMainView() }, func(stop, notifyStopped chan struct{}) {
contents, err := service.RenderTop()
if err != nil {
gui.reRenderString(gui.g, "main", err.Error())
_ = gui.reRenderString(gui.g, "main", err.Error())
}
gui.reRenderString(gui.g, "main", contents)
_ = gui.reRenderString(gui.g, "main", contents)
})
}
@ -170,7 +170,7 @@ func (gui *Gui) handleServicesNextContext(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.Services.ContextIndex++
}
gui.handleServiceSelect(gui.g, v)
_ = gui.handleServiceSelect(gui.g, v)
return nil
}
@ -183,7 +183,7 @@ func (gui *Gui) handleServicesPrevContext(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.Services.ContextIndex--
}
gui.handleServiceSelect(gui.g, v)
_ = gui.handleServiceSelect(gui.g, v)
return nil
}

@ -354,8 +354,8 @@ func (gui *Gui) popupPanelFocused() bool {
func (gui *Gui) clearMainView() {
mainView := gui.getMainView()
mainView.Clear()
mainView.SetOrigin(0, 0)
mainView.SetCursor(0, 0)
_ = mainView.SetOrigin(0, 0)
_ = mainView.SetCursor(0, 0)
}
func (gui *Gui) handleClick(v *gocui.View, itemCount int, selectedLine *int, handleSelect func(*gocui.Gui, *gocui.View) error) error {

@ -99,7 +99,7 @@ func (gui *Gui) renderVolumeConfig(mainView *gocui.View, volume *commands.Volume
output += utils.WithPadding("Size: ", padding) + utils.FormatBinaryBytes(int(volume.Volume.UsageData.Size)) + "\n"
}
gui.renderString(gui.g, "main", output)
_ = gui.renderString(gui.g, "main", output)
})
}
@ -168,7 +168,7 @@ func (gui *Gui) handleVolumesNextContext(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.Volumes.ContextIndex++
}
gui.handleVolumeSelect(gui.g, v)
_ = gui.handleVolumeSelect(gui.g, v)
return nil
}
@ -181,7 +181,7 @@ func (gui *Gui) handleVolumesPrevContext(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.Volumes.ContextIndex--
}
gui.handleVolumeSelect(gui.g, v)
_ = gui.handleVolumeSelect(gui.g, v)
return nil
}

@ -43,7 +43,7 @@ func getLogLevel() logrus.Level {
func newDevelopmentLogger(config *config.AppConfig) *logrus.Logger {
log := logrus.New()
log.SetLevel(getLogLevel())
file, err := os.OpenFile(filepath.Join(config.ConfigDir, "development.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
file, err := os.OpenFile(filepath.Join(config.ConfigDir, "development.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666)
if err != nil {
fmt.Println("unable to log to file")
os.Exit(1)

@ -269,7 +269,7 @@ func FormatDecimalBytes(b int) string {
func ApplyTemplate(str string, object interface{}) string {
var buf bytes.Buffer
template.Must(template.New("").Parse(str)).Execute(&buf, object)
_ = template.Must(template.New("").Parse(str)).Execute(&buf, object)
return buf.String()
}

@ -68,7 +68,7 @@ func TestNormalizeLinefeeds(t *testing.T) {
byteArray []byte
expected []byte
}
var scenarios = []scenario{
scenarios := []scenario{
{
// \r\n
[]byte{97, 115, 100, 102, 13, 10},

@ -12,7 +12,6 @@ import (
"fmt"
"log"
"os"
"strings"
"github.com/jesseduffield/lazydocker/pkg/app"
"github.com/jesseduffield/lazydocker/pkg/config"
@ -135,11 +134,3 @@ func formatSections(mApp *app.App, bindingSections []*bindingSection) string {
return content
}
func getProjectRoot() string {
dir, err := os.Getwd()
if err != nil {
panic(err)
}
return strings.Split(dir, "lazydocker")[0] + "lazydocker"
}

Loading…
Cancel
Save