Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gofumpt lint and misc cleanup #1682

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,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)
}
Expand Down Expand Up @@ -587,5 +587,4 @@ func (app *app) runShell(s string, args []string, prefix string) {
app.ui.exprChan <- &callExpr{"load", nil, 1}
}()
}

}
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}

Expand Down
3 changes: 1 addition & 2 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func (im iconMap) get(f *file) string {
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"
Expand All @@ -142,7 +142,7 @@ func (im iconMap) get(f *file) string {
key = "su"
case f.Mode()&os.ModeSetgid != 0:
key = "sg"
case f.Mode()&0111 != 0:
case f.Mode()&0o111 != 0:
key = "ex"
}

Expand Down
2 changes: 1 addition & 1 deletion misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%q quotes strings with double quotes, so changing to '%s' to match output of other tests

}
})
}
Expand Down
4 changes: 2 additions & 2 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
55 changes: 27 additions & 28 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -471,7 +471,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++ {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i is used in parent for, so this shadowed it

filename = append(filename, ' ')
}
s = append(s, filename...)
Expand Down Expand Up @@ -778,43 +778,43 @@ 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] == "" {
continue
}
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
avail := ui.promptWin.w - printLength(prompt) + 2
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)
}
Expand Down Expand Up @@ -1109,7 +1109,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) {
Expand Down