More linter fixes

This commit is contained in:
Kovid Goyal
2023-09-23 10:19:46 +05:30
parent 38bac98c12
commit 627c80125b
7 changed files with 55 additions and 39 deletions

View File

@@ -263,6 +263,9 @@ func walk(base string, patterns []string, names *utils.Set[string], pmap, path_n
return err
}
return filepath.WalkDir(base, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
is_allowed := allowed(path, patterns...)
if !is_allowed {
if d.IsDir() {

View File

@@ -19,16 +19,16 @@ var _ = fmt.Print
func TestDiffCollectWalk(t *testing.T) {
tdir := t.TempDir()
j := func(x ...string) string { return filepath.Join(append([]string{tdir}, x...)...) }
os.MkdirAll(j("a", "b"), 0o700)
os.WriteFile(j("a/b/c"), nil, 0o600)
os.WriteFile(j("b"), nil, 0o600)
os.WriteFile(j("d"), nil, 0o600)
os.WriteFile(j("e"), nil, 0o600)
os.WriteFile(j("#d#"), nil, 0o600)
os.WriteFile(j("e~"), nil, 0o600)
os.MkdirAll(j("f"), 0o700)
os.WriteFile(j("f/g"), nil, 0o600)
os.WriteFile(j("h space"), nil, 0o600)
_ = os.MkdirAll(j("a", "b"), 0o700)
_ = os.WriteFile(j("a/b/c"), nil, 0o600)
_ = os.WriteFile(j("b"), nil, 0o600)
_ = os.WriteFile(j("d"), nil, 0o600)
_ = os.WriteFile(j("e"), nil, 0o600)
_ = os.WriteFile(j("#d#"), nil, 0o600)
_ = os.WriteFile(j("e~"), nil, 0o600)
_ = os.MkdirAll(j("f"), 0o700)
_ = os.WriteFile(j("f/g"), nil, 0o600)
_ = os.WriteFile(j("h space"), nil, 0o600)
expected_names := utils.NewSetWithItems("d", "e", "f/g", "h space")
expected_pmap := map[string]string{

View File

@@ -81,23 +81,37 @@ func clear_background(style *chroma.Style) *chroma.Style {
return style
}
func ansi_formatter(w io.Writer, style *chroma.Style, it chroma.Iterator) error {
func ansi_formatter(w io.Writer, style *chroma.Style, it chroma.Iterator) (err error) {
const SGR_PREFIX = "\033["
const SGR_SUFFIX = "m"
style = clear_background(style)
before, after := make([]byte, 0, 64), make([]byte, 0, 64)
nl := []byte{'\n'}
write_sgr := func(which []byte) {
write_sgr := func(which []byte) (err error) {
if len(which) > 1 {
w.Write(utils.UnsafeStringToBytes(SGR_PREFIX))
w.Write(which[:len(which)-1])
w.Write(utils.UnsafeStringToBytes(SGR_SUFFIX))
if _, err = w.Write(utils.UnsafeStringToBytes(SGR_PREFIX)); err != nil {
return err
}
if _, err = w.Write(which[:len(which)-1]); err != nil {
return err
}
if _, err = w.Write(utils.UnsafeStringToBytes(SGR_SUFFIX)); err != nil {
return err
}
}
return
}
write := func(text string) {
write_sgr(before)
w.Write(utils.UnsafeStringToBytes(text))
write_sgr(after)
write := func(text string) (err error) {
if err = write_sgr(before); err != nil {
return err
}
if _, err = w.Write(utils.UnsafeStringToBytes(text)); err != nil {
return err
}
if err = write_sgr(after); err != nil {
return err
}
return
}
for token := it(); token != chroma.EOF; token = it() {
@@ -127,11 +141,17 @@ func ansi_formatter(w io.Writer, style *chroma.Style, it chroma.Iterator) error
for text != "" {
idx := strings.IndexByte(text, '\n')
if idx < 0 {
write(text)
if err = write(text); err != nil {
return err
}
break
}
write(text[:idx])
w.Write(nl)
if err = write(text[:idx]); err != nil {
return err
}
if _, err = w.Write(nl); err != nil {
return err
}
text = text[idx+1:]
}
}

View File

@@ -76,13 +76,15 @@ func get_ssh_file(hostname, rpath string) (string, error) {
}
ans := filepath.Join(tdir, rpath)
if count == 1 {
filepath.WalkDir(tdir, func(path string, d fs.DirEntry, err error) error {
if err = filepath.WalkDir(tdir, func(path string, d fs.DirEntry, err error) error {
if !d.IsDir() {
ans = path
return fs.SkipAll
}
return nil
})
}); err != nil {
return "", err
}
}
return ans, nil
}

View File

@@ -40,7 +40,7 @@ func read_relevant_kitty_opts(path string) KittyOpts {
return nil
}
cp := config.ConfigParser{LineHandler: handle_line}
cp.ParseFiles(path)
_ = cp.ParseFiles(path)
return ans
}
@@ -53,7 +53,7 @@ func (self *Handler) handle_wheel_event(up bool) {
if up {
amt *= -1
}
self.dispatch_action(`scroll_by`, strconv.Itoa(amt))
_ = self.dispatch_action(`scroll_by`, strconv.Itoa(amt))
}
type line_pos struct {
@@ -113,6 +113,7 @@ func (self *Handler) drag_scroll_tick(timer_id loop.IdType) error {
}
var debugprintln = tty.DebugPrintln
var _ = debugprintln
func (self *Handler) update_mouse_selection(ev *loop.MouseEvent) {
if !self.mouse_selection.IsActive() {

View File

@@ -159,7 +159,7 @@ var format_as_sgr struct {
title, margin, added, removed, added_margin, removed_margin, filler, margin_filler, hunk_margin, hunk, selection, search string
}
var statusline_format, added_count_format, removed_count_format, message_format, selection_format func(...any) string
var statusline_format, added_count_format, removed_count_format, message_format func(...any) string
func create_formatters() {
ctx := style.Context{AllowEscapeCodes: true}
@@ -169,7 +169,6 @@ func create_formatters() {
return ans
}
format_as_sgr.filler = only_open("bg=" + conf.Filler_bg.AsRGBSharp())
debugprintln(11111, conf.Margin_filler_bg.IsSet)
if conf.Margin_filler_bg.IsSet {
format_as_sgr.margin_filler = only_open("bg=" + conf.Margin_filler_bg.Color.AsRGBSharp())
} else {
@@ -392,8 +391,6 @@ func image_lines(left_path, right_path string, screen_size screen_size, margin_s
return append(ans, ll), nil
}
type formatter = func(...any) string
func first_binary_line(left_path, right_path string, columns, margin_size int, renderer func(path string) (string, error)) (*LogicalLine, error) {
available_cols := columns/2 - margin_size
ll := LogicalLine{
@@ -771,10 +768,3 @@ func render(collection *Collection, diff_map map[string]*Patch, screen_size scre
}
return &LogicalLines{lines: ll, margin_size: margin_size, columns: columns}, err
}
func (self *LogicalLines) num_of_screen_lines() (ans int) {
for _, l := range self.lines {
ans += len(l.screen_lines)
}
return
}

View File

@@ -142,7 +142,7 @@ func (self *Handler) initialize() {
func (self *Handler) generate_diff() {
self.diff_map = nil
jobs := make([]diff_job, 0, 32)
self.collection.Apply(func(path, typ, changed_path string) error {
_ = self.collection.Apply(func(path, typ, changed_path string) error {
if typ == "diff" {
if is_path_text(path) && is_path_text(changed_path) {
jobs = append(jobs, diff_job{path, changed_path})
@@ -188,7 +188,7 @@ func (self *Handler) highlight_all() {
}
func (self *Handler) load_all_images() {
self.collection.Apply(func(path, item_type, changed_path string) error {
_ = self.collection.Apply(func(path, item_type, changed_path string) error {
if path != "" && is_image(path) {
image_collection.AddPaths(path)
self.image_count++