From cfcdcdb5beee2df9b2a741f39d420e8dcbd9ba81 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 7 Apr 2026 10:00:06 +0200 Subject: [PATCH] Fix linter warnings --- pkg/gocui/escape_test.go | 1 + pkg/gocui/gui.go | 4 ++-- pkg/gocui/gui_windows.go | 2 -- pkg/gocui/tcell_driver.go | 43 +++++++++++++++++---------------- pkg/gocui/text_area_test.go | 2 +- pkg/gocui/view.go | 48 +++++++++++++++++-------------------- 6 files changed, 49 insertions(+), 51 deletions(-) diff --git a/pkg/gocui/escape_test.go b/pkg/gocui/escape_test.go index 0073463c4..382d27bad 100644 --- a/pkg/gocui/escape_test.go +++ b/pkg/gocui/escape_test.go @@ -151,6 +151,7 @@ func TestParseOneColours(t *testing.T) { } func parseEscRunes(t *testing.T, ei *escapeInterpreter, runes string) { + t.Helper() for _, b := range []byte(runes) { isEscape, err := ei.parseOne([]byte{b}) assert.Equal(t, true, isEscape) diff --git a/pkg/gocui/gui.go b/pkg/gocui/gui.go index 0db418c67..81ddd4ce3 100644 --- a/pkg/gocui/gui.go +++ b/pkg/gocui/gui.go @@ -912,9 +912,9 @@ func calcScrollbarRune( ) rune { if showScrollbar && (position >= scrollbarStart && position <= scrollbarEnd) { return '▐' - } else { - return runeV } + + return runeV } func calcRealScrollbarStartEnd(v *View) (bool, int, int) { diff --git a/pkg/gocui/gui_windows.go b/pkg/gocui/gui_windows.go index 1934a40a9..d8c79ca12 100644 --- a/pkg/gocui/gui_windows.go +++ b/pkg/gocui/gui_windows.go @@ -13,9 +13,7 @@ import ( ) type ( - wchar uint16 short int16 - dword uint32 word uint16 ) diff --git a/pkg/gocui/tcell_driver.go b/pkg/gocui/tcell_driver.go index 6e9c12b4c..696975724 100644 --- a/pkg/gocui/tcell_driver.go +++ b/pkg/gocui/tcell_driver.go @@ -55,17 +55,20 @@ var runeReplacements = map[rune]string{ func (g *Gui) tcellInit(runeReplacements map[rune]string) error { tcell.SetEncodingFallback(tcell.EncodingFallbackASCII) - if s, e := tcell.NewScreen(); e != nil { + s, e := tcell.NewScreen() + if e != nil { return e - } else if e = s.Init(); e != nil { - return e - } else { - registerRuneFallbacks(s, runeReplacements) - - g.screen = s - Screen = s - return nil } + + if e = s.Init(); e != nil { + return e + } + + registerRuneFallbacks(s, runeReplacements) + + g.screen = s + Screen = s + return nil } func registerRuneFallbacks(s tcell.Screen, additional map[rune]string) { @@ -83,15 +86,15 @@ func (g *Gui) tcellInitSimulation(width int, height int) error { s := tcell.NewSimulationScreen("") if e := s.Init(); e != nil { return e - } else { - g.screen = s - Screen = s - // setting to a larger value than the typical terminal size - // so that during a test we're more likely to see an item to select in a view. - s.SetSize(width, height) - s.Sync() - return nil } + + g.screen = s + Screen = s + // setting to a larger value than the typical terminal size + // so that during a test we're more likely to see an item to select in a view. + s.SetSize(width, height) + s.Sync() + return nil } // tcellSetCell sets the character cell at a given location to the given @@ -194,9 +197,9 @@ const ( var ( lastMouseKey tcell.ButtonMask = tcell.ButtonNone lastMouseMod tcell.ModMask = tcell.ModNone - dragState int = NOT_DRAGGING - lastX int = 0 - lastY int = 0 + dragState = NOT_DRAGGING + lastX = 0 + lastY = 0 ) // this wrapper struct has public keys so we can easily serialize/deserialize to JSON diff --git a/pkg/gocui/text_area_test.go b/pkg/gocui/text_area_test.go index 618e1a02e..f0bc2fca8 100644 --- a/pkg/gocui/text_area_test.go +++ b/pkg/gocui/text_area_test.go @@ -1008,7 +1008,7 @@ func Test_AutoWrapContent(t *testing.T) { } } -var testContent string = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. +var testContent = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vehicula mi at elit pellentesque, eu pulvinar ligula molestie. In vitae orci vitae elit fermentum lobortis sed in nisi. Nam non odio nisi. diff --git a/pkg/gocui/view.go b/pkg/gocui/view.go index 16da0a380..1ef40e569 100644 --- a/pkg/gocui/view.go +++ b/pkg/gocui/view.go @@ -881,9 +881,9 @@ func (v *View) writeString(s string) { var linkStartChars = []string{"h", "t", "t", "p", "s", ":", "/", "/"} func findLinkStart(line []cell) int { - for i := 0; i < len(line)-len(linkStartChars); i++ { + for i := range len(line) - len(linkStartChars) { for j := range linkStartChars { - if line[i+j].chr != string(linkStartChars[j]) { + if line[i+j].chr != linkStartChars[j] { break } if j == len(linkStartChars)-1 { @@ -899,7 +899,7 @@ func findLinkStart(line []cell) int { // enough, because in markdown it's common to have a hyperlink followed by a // ')', so we want to stop there. Hopefully URLs containing ')' are uncommon // enough that this is not a problem. -var lineEndCharacters map[string]bool = map[string]bool{ +var lineEndCharacters = map[string]bool{ "": true, " ": true, "\n": true, @@ -927,7 +927,7 @@ func (v *View) autoRenderHyperlinksInCurrentLine() { if _, ok := lineEndCharacters[line[linkEnd].chr]; ok { break } - link.WriteString(string(line[linkEnd].chr)) + link.WriteString(line[linkEnd].chr) } for i := linkStart; i < linkEnd; i++ { v.lines[v.wy][i].hyperlink = link.String() @@ -988,7 +988,7 @@ func (v *View) parseInput(ch []byte, width int, x int, _ int) (bool, []cell) { chr: string(ch), width: width, } - for i := 0; i < repeatCount; i++ { + for range repeatCount { cells = append(cells, c) } } @@ -1265,21 +1265,17 @@ func (v *View) draw() { cellIdx := 0 var c cell - for { - if x >= maxX { - break - } - + for x < maxX { if x < 0 { if cellIdx < len(vline.line) { x += uniseg.StringWidth(vline.line[cellIdx].chr) cellIdx++ continue - } else { - // no more characters to write so we're only going to be printing empty cells - // past this point - x = 0 } + + // no more characters to write so we're only going to be printing empty cells + // past this point + x = 0 } // if we're out of cells to write, we'll just print empty cells. @@ -1424,7 +1420,7 @@ func (v *View) BufferLines() []string { lines := make([]string, len(v.lines)) for i, l := range v.lines { str := lineType(l).String() - str = strings.Replace(str, "\x00", "", -1) + str = strings.ReplaceAll(str, "\x00", "") lines[i] = str } return lines @@ -1447,7 +1443,7 @@ func (v *View) ViewBufferLines() []string { lines := make([]string, len(v.viewLines)) for i, l := range v.viewLines { str := lineType(l.line).String() - str = strings.Replace(str, "\x00", "", -1) + str = strings.ReplaceAll(str, "\x00", "") lines[i] = str } return lines @@ -1696,7 +1692,7 @@ func (v *View) SelectedLines() []string { func (v *View) lineContentAtIdx(idx int) string { line := v.lines[idx] str := lineType(line).String() - return strings.Replace(str, "\x00", "", -1) + return strings.ReplaceAll(str, "\x00", "") } func (v *View) SelectedPoint() (int, int) { @@ -1719,9 +1715,9 @@ func (v *View) SelectedLineRange() (int, int) { if start > end { return end, start - } else { - return start, end } + + return start, end } func (v *View) RenderTextArea() { @@ -1773,7 +1769,7 @@ func (v *View) overwriteLines(y int, content string) { v.wy = y v.clearViewLines() - lines := strings.Replace(content, "\n", "\x1b[K\n", -1) + lines := strings.ReplaceAll(content, "\n", "\x1b[K\n") // If the last line doesn't end with a linefeed, add the erase command at // the end too if !strings.HasSuffix(lines, "\n") { @@ -1799,7 +1795,7 @@ func (v *View) OverwriteLinesAndClearEverythingElse(lineCount int, y int, conten v.overwriteLines(y, content) - for i := 0; i < y; i += 1 { + for i := range y { v.lines[i] = nil } @@ -1924,9 +1920,9 @@ func (v *View) adjustDownwardScrollAmount(scrollHeight int) int { } if oy+scrollHeight < 0 { return 0 - } else { - return scrollHeight } + + return scrollHeight } // scrollMargin is about how many lines must still appear if you scroll @@ -1938,9 +1934,9 @@ func (v *View) scrollMargin() int { // we should make this into a field on the view to be configured by the client. // For now we're hardcoding it. return 2 - } else { - return 0 } + + return 0 } // Returns true if the view contains a line containing the given text with the given @@ -1966,7 +1962,7 @@ func containsColoredTextInLine(fgColorStr string, text string, line []cell) bool cellColor := tcell.NewHexColor(cell.fgColor.Hex()) if cellColor == fgColor { - currentMatch += string(cell.chr) + currentMatch += cell.chr } else if currentMatch != "" { if strings.Contains(currentMatch, text) { return true