summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pedersen <Limero@users.noreply.github.com>2024-04-20 21:42:28 +0200
committerGitHub <noreply@github.com>2024-04-20 21:42:28 +0200
commita018257d5019e1b50032ca023c484035778ae2e9 (patch)
treea5e03e801a3a0cbec7da562447619fe6e122133e
parent6cabb0e8e43c8a374fcb1e0d4225141f478ce212 (diff)
gofumpt lint and misc cleanup (#1682)
* gofumpt lint and misc cleanup * Reorder fileInfo dircounts code to be clearer
-rw-r--r--app.go3
-rw-r--r--client.go2
-rw-r--r--colors.go6
-rw-r--r--copy.go3
-rw-r--r--icons.go6
-rw-r--r--misc_test.go2
-rw-r--r--nav.go4
-rw-r--r--os.go4
-rw-r--r--server.go2
-rw-r--r--ui.go55
10 files changed, 42 insertions, 45 deletions
diff --git a/app.go b/app.go
index 2f1fec9..a95b180 100644
--- a/app.go
+++ b/app.go
@@ -232,7 +232,7 @@ func (app *app) writeHistory() error {
}
for _, cmd := range app.cmdHistory {
- _, err = f.WriteString(fmt.Sprintf("%s %s\n", cmd.prefix, cmd.value))
+ _, err = fmt.Fprintf(f, "%s %s\n", cmd.prefix, cmd.value)
if err != nil {
return fmt.Errorf("writing history file: %s", err)
}
@@ -585,5 +585,4 @@ func (app *app) runShell(s string, args []string, prefix string) {
app.ui.exprChan <- &callExpr{"load", nil, 1}
}()
}
-
}
diff --git a/client.go b/client.go
index 559102d..52360b4 100644
--- a/client.go
+++ b/client.go
@@ -38,7 +38,7 @@ func run() {
}
if gLogPath != "" {
- f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
+ f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
panic(err)
}
diff --git a/colors.go b/colors.go
index 8558b3f..2d5d8c9 100644
--- a/colors.go
+++ b/colors.go
@@ -295,9 +295,9 @@ func (sm styleMap) get(f *file) tcell.Style {
key = "ln"
case f.linkState == broken:
key = "or"
- case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
+ case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0o002 != 0:
key = "tw"
- case f.IsDir() && f.Mode()&0002 != 0:
+ case f.IsDir() && f.Mode()&0o002 != 0:
key = "ow"
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
key = "st"
@@ -315,7 +315,7 @@ func (sm styleMap) get(f *file) tcell.Style {
key = "su"
case f.Mode()&os.ModeSetgid != 0:
key = "sg"
- case f.Mode()&0111 != 0:
+ case f.Mode()&0o111 != 0:
key = "ex"
}
diff --git a/copy.go b/copy.go
index ea84811..cec83c2 100644
--- a/copy.go
+++ b/copy.go
@@ -20,14 +20,13 @@ func copySize(srcs []string) (int64, error) {
return total, fmt.Errorf("src does not exist: %q", src)
}
- err = filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
+ err = filepath.Walk(src, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("walk: %s", err)
}
total += info.Size()
return nil
})
-
if err != nil {
return total, err
}
diff --git a/icons.go b/icons.go
index 963a7a2..49a522a 100644
--- a/icons.go
+++ b/icons.go
@@ -147,9 +147,9 @@ func (im iconMap) get(f *file) iconDef {
key = "ln"
case f.linkState == broken:
key = "or"
- case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
+ case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0o002 != 0:
key = "tw"
- case f.IsDir() && f.Mode()&0002 != 0:
+ case f.IsDir() && f.Mode()&0o002 != 0:
key = "ow"
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
key = "st"
@@ -167,7 +167,7 @@ func (im iconMap) get(f *file) iconDef {
key = "su"
case f.Mode()&os.ModeSetgid != 0:
key = "sg"
- case f.Mode()&0111 != 0:
+ case f.Mode()&0o111 != 0:
key = "ex"
}
diff --git a/misc_test.go b/misc_test.go
index f991c3a..f409560 100644
--- a/misc_test.go
+++ b/misc_test.go
@@ -330,7 +330,7 @@ func TestGetFileExtension(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := getFileExtension(fakeFileInfo{test.fileName, test.isDir}); got != test.expectedExtension {
- t.Errorf("at input %q expected %q but got %q", test.fileName, test.expectedExtension, got)
+ t.Errorf("at input '%s' expected '%s' but got '%s'", test.fileName, test.expectedExtension, got)
}
})
}
diff --git a/nav.go b/nav.go
index 0a16cfb..dc95498 100644
--- a/nav.go
+++ b/nav.go
@@ -1884,7 +1884,7 @@ func (nav *nav) writeMarks() error {
sort.Strings(keys)
for _, k := range keys {
- _, err = f.WriteString(fmt.Sprintf("%s:%s\n", k, nav.marks[k]))
+ _, err = fmt.Fprintf(f, "%s:%s\n", k, nav.marks[k])
if err != nil {
return fmt.Errorf("writing marks file: %s", err)
}
@@ -1945,7 +1945,7 @@ func (nav *nav) writeTags() error {
sort.Strings(keys)
for _, k := range keys {
- _, err = f.WriteString(fmt.Sprintf("%s:%s\n", k, nav.tags[k]))
+ _, err = fmt.Fprintf(f, "%s:%s\n", k, nav.tags[k])
if err != nil {
return fmt.Errorf("writing tags file: %s", err)
}
diff --git a/os.go b/os.go
index 962bb41..0a35f1c 100644
--- a/os.go
+++ b/os.go
@@ -177,11 +177,11 @@ func setDefaults() {
}
func setUserUmask() {
- unix.Umask(0077)
+ unix.Umask(0o077)
}
func isExecutable(f os.FileInfo) bool {
- return f.Mode()&0111 != 0
+ return f.Mode()&0o111 != 0
}
func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
diff --git a/server.go b/server.go
index b278b13..7bb6e73 100644
--- a/server.go
+++ b/server.go
@@ -17,7 +17,7 @@ var (
func serve() {
if gLogPath != "" {
- f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
+ f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
panic(err)
}
diff --git a/ui.go b/ui.go
index 0a26c2e..f7684ec 100644
--- a/ui.go
+++ b/ui.go
@@ -293,27 +293,27 @@ func fileInfo(f *file, d *dir) string {
for _, s := range getInfo(d.path) {
switch s {
case "size":
- if !(f.IsDir() && gOpts.dircounts) {
- var sz string
- if f.IsDir() && f.dirSize < 0 {
- sz = "-"
- } else {
- sz = humanize(f.TotalSize())
+ if f.IsDir() && gOpts.dircounts {
+ switch {
+ case f.dirCount < -1:
+ info = fmt.Sprintf("%s !", info)
+ case f.dirCount < 0:
+ info = fmt.Sprintf("%s ?", info)
+ case f.dirCount < 1000:
+ info = fmt.Sprintf("%s %4d", info, f.dirCount)
+ default:
+ info = fmt.Sprintf("%s 999+", info)
}
- info = fmt.Sprintf("%s %4s", info, sz)
continue
}
- switch {
- case f.dirCount < -1:
- info = fmt.Sprintf("%s !", info)
- case f.dirCount < 0:
- info = fmt.Sprintf("%s ?", info)
- case f.dirCount < 1000:
- info = fmt.Sprintf("%s %4d", info, f.dirCount)
- default:
- info = fmt.Sprintf("%s 999+", info)
+ var sz string
+ if f.IsDir() && f.dirSize < 0 {
+ sz = "-"
+ } else {
+ sz = humanize(f.TotalSize())
}
+ info = fmt.Sprintf("%s %4s", info, sz)
case "time":
info = fmt.Sprintf("%s %*s", info, max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.ModTime()))
case "atime":
@@ -474,7 +474,7 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
filename = append(filename, []rune(gOpts.truncatechar)...)
filename = append(filename, lastPart...)
}
- for i := runeSliceWidth(filename); i < maxFilenameWidth; i++ {
+ for j := runeSliceWidth(filename); j < maxFilenameWidth; j++ {
filename = append(filename, ' ')
}
s = append(s, filename...)
@@ -785,11 +785,11 @@ func (ui *ui) drawPromptLine(nav *nav) {
var prompt string
- prompt = strings.Replace(gOpts.promptfmt, "%u", gUser.Username, -1)
- prompt = strings.Replace(prompt, "%h", gHostname, -1)
- prompt = strings.Replace(prompt, "%f", fname, -1)
+ prompt = strings.ReplaceAll(gOpts.promptfmt, "%u", gUser.Username)
+ prompt = strings.ReplaceAll(prompt, "%h", gHostname)
+ prompt = strings.ReplaceAll(prompt, "%f", fname)
- if printLength(strings.Replace(strings.Replace(prompt, "%w", pwd, -1), "%d", pwd, -1)) > ui.promptWin.w {
+ if printLength(strings.ReplaceAll(strings.ReplaceAll(prompt, "%w", pwd), "%d", pwd)) > ui.promptWin.w {
names := strings.Split(pwd, sep)
for i := range names {
if names[i] == "" {
@@ -797,23 +797,23 @@ func (ui *ui) drawPromptLine(nav *nav) {
}
r, _ := utf8.DecodeRuneInString(names[i])
names[i] = string(r)
- if printLength(strings.Replace(strings.Replace(prompt, "%w", strings.Join(names, sep), -1), "%d", strings.Join(names, sep), -1)) <= ui.promptWin.w {
+ if printLength(strings.ReplaceAll(strings.ReplaceAll(prompt, "%w", strings.Join(names, sep)), "%d", strings.Join(names, sep))) <= ui.promptWin.w {
break
}
}
pwd = strings.Join(names, sep)
}
- prompt = strings.Replace(prompt, "%w", pwd, -1)
+ prompt = strings.ReplaceAll(prompt, "%w", pwd)
if !strings.HasSuffix(pwd, sep) {
pwd += sep
}
- prompt = strings.Replace(prompt, "%d", pwd, -1)
+ prompt = strings.ReplaceAll(prompt, "%d", pwd)
if len(dir.filter) != 0 {
- prompt = strings.Replace(prompt, "%F", fmt.Sprint(dir.filter), -1)
+ prompt = strings.ReplaceAll(prompt, "%F", fmt.Sprint(dir.filter))
} else {
- prompt = strings.Replace(prompt, "%F", "", -1)
+ prompt = strings.ReplaceAll(prompt, "%F", "")
}
// spacer
@@ -821,7 +821,7 @@ func (ui *ui) drawPromptLine(nav *nav) {
if avail > 0 {
prompt = strings.Replace(prompt, "%S", strings.Repeat(" ", avail), 1)
}
- prompt = strings.Replace(prompt, "%S", "", -1)
+ prompt = strings.ReplaceAll(prompt, "%S", "")
ui.promptWin.print(ui.screen, 0, 0, st, prompt)
}
@@ -1116,7 +1116,6 @@ func (ui *ui) draw(nav *nav) {
ui.sxScreen.lastFile = ui.regPrev.path
ui.sxScreen.showSixels()
}
-
}
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {