gofumpt lint and misc cleanup (#1682)

* gofumpt lint and misc cleanup

* Reorder fileInfo dircounts code to be clearer
This commit is contained in:
David Pedersen authored and GitHub committed 2024-04-20 21:42:28 +02:00
1 parent 6cabb0e8e4
commit a018257d50
10 files changed
+42 -45

No files matched your search

+1 -2
View File
@@ -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}
}()
}
}
+1 -1
View File
@@ -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)
}
+3 -3
View File
@@ -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"
}
+1 -2
View File
@@ -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
}
+3 -3
View File
@@ -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"
}
+1 -1
View File
@@ -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)
}
})
}
+2 -2
View File
@@ -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)
}
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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)
}
+27 -28
View File
@@ -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) {