From 5cbdec3c4e09975196927d0cfc6d71c4bc9e0053 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Thu, 27 Feb 2025 14:15:36 -0300 Subject: [PATCH] chore(lint): fix main linting issues --- ansi/sixel/encoder.go | 12 ++++++------ ansi/sixel/palette.go | 20 ++++++++------------ ansi/sixel/palette_sort.go | 16 ++++++++-------- ansi/sixel/util.go | 2 +- ansi/util.go | 4 ++-- cellbuf/hardscroll.go | 2 +- cellbuf/screen.go | 2 +- colors/colors.go | 1 + conpty/doc.go | 1 - editor/editor.go | 2 +- examples/cellbuf/main.go | 2 +- examples/layout/main.go | 4 ++-- exp/golden/golden.go | 2 +- exp/teatest/v2/teatest.go | 2 +- input/parse.go | 7 +++---- term/term_unix.go | 2 +- termios/termios_other.go | 4 ++-- vt/callbacks.go | 2 +- vt/screen.go | 2 +- vt/terminal.go | 2 +- xpty/pty_unix.go | 8 ++++---- 21 files changed, 47 insertions(+), 52 deletions(-) diff --git a/ansi/sixel/encoder.go b/ansi/sixel/encoder.go index ec77f6cf..1143f8a1 100644 --- a/ansi/sixel/encoder.go +++ b/ansi/sixel/encoder.go @@ -80,12 +80,12 @@ func (e *Encoder) encodePaletteColor(w io.Writer, paletteIndex int, c sixelColor w.Write([]byte{ColorIntroducer}) //nolint:errcheck io.WriteString(w, strconv.Itoa(paletteIndex)) //nolint:errcheck - io.WriteString(w, ";2;") + io.WriteString(w, ";2;") //nolint:errcheck io.WriteString(w, strconv.Itoa(int(c.Red))) //nolint:errcheck w.Write([]byte{';'}) //nolint:errcheck io.WriteString(w, strconv.Itoa(int(c.Green))) //nolint:errcheck - w.Write([]byte{';'}) - io.WriteString(w, strconv.Itoa(int(c.Blue))) //nolint:errcheck + w.Write([]byte{';'}) //nolint:errcheck + io.WriteString(w, strconv.Itoa(int(c.Blue))) //nolint:errcheck } // sixelBuilder is a temporary structure used to create a SixelImage. It handles @@ -166,8 +166,8 @@ func (s *sixelBuilder) GeneratePixels() string { continue } - firstColorBit := uint(s.BandHeight()*s.imageWidth*6*paletteIndex + bandY*s.imageWidth*6) - nextColorBit := firstColorBit + uint(s.imageWidth*6) + firstColorBit := uint(s.BandHeight()*s.imageWidth*6*paletteIndex + bandY*s.imageWidth*6) //nolint:gosec + nextColorBit := firstColorBit + uint(s.imageWidth*6) //nolint:gosec firstSetBitInBand, anySet := s.pixelBands.NextSet(firstColorBit) if !anySet || firstSetBitInBand >= nextColorBit { @@ -183,7 +183,7 @@ func (s *sixelBuilder) GeneratePixels() string { s.writeControlRune(ColorIntroducer) s.imageData.WriteString(strconv.Itoa(paletteIndex)) for x := 0; x < s.imageWidth; x += 4 { - bit := firstColorBit + uint(x*6) + bit := firstColorBit + uint(x*6) //nolint:gosec word := s.pixelBands.GetWord64AtBit(bit) pixel1 := byte((word & 63) + '?') diff --git a/ansi/sixel/palette.go b/ansi/sixel/palette.go index 32818d1e..9efc8b4a 100644 --- a/ansi/sixel/palette.go +++ b/ansi/sixel/palette.go @@ -40,7 +40,9 @@ type sixelPalette struct { type quantizationChannel int const ( - MaxColors int = 256 + // MaxColors is the maximum number of colors a sixelPalette can contain + MaxColors int = 256 + quantizationRed quantizationChannel = iota quantizationGreen quantizationBlue @@ -248,10 +250,10 @@ func (p *sixelPalette) loadColor(uniqueColors []sixelColor, pixelCounts map[sixe } averageColor := sixelColor{ - Red: uint32(totalRed / totalCount), - Green: uint32(totalGreen / totalCount), - Blue: uint32(totalBlue / totalCount), - Alpha: uint32(totalAlpha / totalCount), + Red: uint32(totalRed / totalCount), //nolint:gosec + Green: uint32(totalGreen / totalCount), //nolint:gosec + Blue: uint32(totalBlue / totalCount), //nolint:gosec + Alpha: uint32(totalAlpha / totalCount), //nolint:gosec } p.PaletteColors = append(p.PaletteColors, averageColor) @@ -286,12 +288,6 @@ func sixelConvertChannel(channel uint32) uint32 { return (channel + 328) * 100 / 0xffff } -// imageConvertChannel converts a single color channel from sixel's 0-100 range to -// go's standard 0-0xffff range -func imageConvertChannel(channel uint32) uint32 { - return (channel*0xffff + 50) / 100 -} - // newSixelPalette accepts an image and produces an N-color quantized color palette using the median cut // algorithm. The produced sixelPalette can convert colors from the image to the quantized palette // in O(1) time. @@ -305,7 +301,7 @@ func newSixelPalette(image image.Image, maxColors int) sixelPalette { for y := 0; y < height; y++ { for x := 0; x < width; x++ { c := sixelConvertColor(image.At(x, y)) - count, _ := pixelCounts[c] + count := pixelCounts[c] count++ pixelCounts[c] = count diff --git a/ansi/sixel/palette_sort.go b/ansi/sixel/palette_sort.go index 79f194ff..600c3ab3 100644 --- a/ansi/sixel/palette_sort.go +++ b/ansi/sixel/palette_sort.go @@ -74,7 +74,7 @@ func (r *xorshift) Next() uint64 { } func nextPowerOfTwo(length int) uint { - return 1 << bits.Len(uint(length)) + return 1 << bits.Len(uint(length)) //nolint:gosec } // insertionSortCmpFunc sorts data[a:b] using insertion sort. @@ -153,13 +153,13 @@ func pdqsortCmpFunc[E any](data []E, a, b, limit int, cmp func(a, b E) int) { // If the last partitioning was imbalanced, we need to breaking patterns. if !wasBalanced { - breakPatternsCmpFunc(data, a, b, cmp) + breakPatternsCmpFunc(data, a, b) limit-- } pivot, hint := choosePivotCmpFunc(data, a, b, cmp) if hint == decreasingHint { - reverseRangeCmpFunc(data, a, b, cmp) + reverseRangeCmpFunc(data, a, b) // The chosen pivot was pivot-a elements after the start of the array. // After reversing it is pivot-a elements before the end of the array. // The idea came from Rust's implementation. @@ -308,14 +308,14 @@ func partialInsertionSortCmpFunc[E any](data []E, a, b int, cmp func(a, b E) int // breakPatternsCmpFunc scatters some elements around in an attempt to break some patterns // that might cause imbalanced partitions in quicksort. -func breakPatternsCmpFunc[E any](data []E, a, b int, cmp func(a, b E) int) { +func breakPatternsCmpFunc[E any](data []E, a, b int) { length := b - a if length >= 8 { random := xorshift(length) modulus := nextPowerOfTwo(length) for idx := a + (length/4)*2 - 1; idx <= a+(length/4)*2+1; idx++ { - other := int(uint(random.Next()) & (modulus - 1)) + other := int(uint(random.Next()) & (modulus - 1)) //nolint:gosec if other >= length { other -= length } @@ -377,8 +377,8 @@ func order2CmpFunc[E any](data []E, a, b int, swaps *int, cmp func(a, b E) int) // medianCmpFunc returns x where data[x] is the median of data[a],data[b],data[c], where x is a, b, or c. func medianCmpFunc[E any](data []E, a, b, c int, swaps *int, cmp func(a, b E) int) int { a, b = order2CmpFunc(data, a, b, swaps, cmp) - b, c = order2CmpFunc(data, b, c, swaps, cmp) - a, b = order2CmpFunc(data, a, b, swaps, cmp) + b, _ = order2CmpFunc(data, b, c, swaps, cmp) + _, b = order2CmpFunc(data, a, b, swaps, cmp) return b } @@ -387,7 +387,7 @@ func medianAdjacentCmpFunc[E any](data []E, a int, swaps *int, cmp func(a, b E) return medianCmpFunc(data, a-1, a, a+1, swaps, cmp) } -func reverseRangeCmpFunc[E any](data []E, a, b int, cmp func(a, b E) int) { +func reverseRangeCmpFunc[E any](data []E, a, b int) { i := a j := b - 1 for i < j { diff --git a/ansi/sixel/util.go b/ansi/sixel/util.go index afbddf4d..cbfd4692 100644 --- a/ansi/sixel/util.go +++ b/ansi/sixel/util.go @@ -1,6 +1,6 @@ package sixel -func max(a, b int) int { +func max(a, b int) int { //nolint:predeclared if a > b { return a } diff --git a/ansi/util.go b/ansi/util.go index 301ef15f..0f5cea78 100644 --- a/ansi/util.go +++ b/ansi/util.go @@ -10,7 +10,7 @@ import ( ) // colorToHexString returns a hex string representation of a color. -func colorToHexString(c color.Color) string { +func colorToHexString(c color.Color) string { //nolint:unused if c == nil { return "" } @@ -28,7 +28,7 @@ func colorToHexString(c color.Color) string { // rgbToHex converts red, green, and blue values to a hexadecimal value. // // hex := rgbToHex(0, 0, 255) // 0x0000FF -func rgbToHex(r, g, b uint32) uint32 { +func rgbToHex(r, g, b uint32) uint32 { //nolint:unused return r<<16 + g<<8 + b } diff --git a/cellbuf/hardscroll.go b/cellbuf/hardscroll.go index bbdab1b2..402ac06a 100644 --- a/cellbuf/hardscroll.go +++ b/cellbuf/hardscroll.go @@ -68,7 +68,7 @@ func (s *Screen) scrollOptimize() { } // scrolln scrolls the screen up by n lines. -func (s *Screen) scrolln(n, top, bot, maxY int) (v bool) { +func (s *Screen) scrolln(n, top, bot, maxY int) (v bool) { //nolint:unparam const ( nonDestScrollRegion = false memoryBelow = false diff --git a/cellbuf/screen.go b/cellbuf/screen.go index 09109390..963b9cac 100644 --- a/cellbuf/screen.go +++ b/cellbuf/screen.go @@ -817,7 +817,7 @@ func (s *Screen) clearToEnd(blank *Cell, force bool) { //nolint:unparam s.updatePen(blank) count := s.newbuf.Width() - s.cur.X if s.el0Cost() <= count { - s.buf.WriteString(ansi.EraseLineRight) //nolint:errcheck) + s.buf.WriteString(ansi.EraseLineRight) //nolint:errcheck } else { for i := 0; i < count; i++ { s.putCell(blank) diff --git a/colors/colors.go b/colors/colors.go index e297897c..22ddc601 100644 --- a/colors/colors.go +++ b/colors/colors.go @@ -2,6 +2,7 @@ package colors import "github.com/charmbracelet/lipgloss" +//nolint:revive var ( WhiteBright = lipgloss.AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"} diff --git a/conpty/doc.go b/conpty/doc.go index 60a2a353..461be346 100644 --- a/conpty/doc.go +++ b/conpty/doc.go @@ -1,7 +1,6 @@ // Package conpty implements Windows Console Pseudo-terminal support. // // https://learn.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session - package conpty import "errors" diff --git a/editor/editor.go b/editor/editor.go index f6a49403..61791684 100644 --- a/editor/editor.go +++ b/editor/editor.go @@ -73,7 +73,7 @@ func Command(app, path string, options ...Option) (*exec.Cmd, error) { // if no $EDITOR is set. func CommandContext(ctx context.Context, app, path string, options ...Option) (*exec.Cmd, error) { if os.Getenv("SNAP_REVISION") != "" { - return nil, fmt.Errorf("Did you install with Snap? %[1]s is sandboxed and unable to open an editor. Please install %[1]s with Go or another package manager to enable editing.", app) + return nil, fmt.Errorf("Did you install with Snap? %[1]s is sandboxed and unable to open an editor. Please install %[1]s with Go or another package manager to enable editing.", app) //nolint:revive } editor, args := getEditor() diff --git a/examples/cellbuf/main.go b/examples/cellbuf/main.go index 9e2e9d05..ca370e0d 100644 --- a/examples/cellbuf/main.go +++ b/examples/cellbuf/main.go @@ -61,7 +61,7 @@ func main() { scr.Fill(cellbuf.NewCell('你')) scrw.PrintCropAt(x, y, text, "") scr.Render() - scr.Flush() + scr.Flush() //nolint:errcheck } resize := func(nw, nh int) { diff --git a/examples/layout/main.go b/examples/layout/main.go index 596857bc..2315868f 100644 --- a/examples/layout/main.go +++ b/examples/layout/main.go @@ -414,7 +414,7 @@ func main() { box := cellbuf.Rect(dialogX, dialogY, dialogWidth, dialogHeight) scrw.SetContentRect(dialogBoxStyle.Render(dialogUI), box) scr.Render() - scr.Flush() + scr.Flush() //nolint:errcheck } // First render @@ -480,7 +480,7 @@ func colorGrid(xSteps, ySteps int) [][]string { return grid } -func max(a, b int) int { +func max(a, b int) int { //nolint:predeclared if a > b { return a } diff --git a/exp/golden/golden.go b/exp/golden/golden.go index fd769fda..6c84c908 100644 --- a/exp/golden/golden.go +++ b/exp/golden/golden.go @@ -55,7 +55,7 @@ func RequireEqual(tb testing.TB, out []byte) { // the expected from the golden files, printing its diff in case it is not. // // Deprecated: Use [RequireEqual] instead. -func RequireEqualEscape(tb testing.TB, out []byte, escapes bool) { +func RequireEqualEscape(tb testing.TB, out []byte, escapes bool) { //nolint:revive RequireEqual(tb, out) } diff --git a/exp/teatest/v2/teatest.go b/exp/teatest/v2/teatest.go index 5dee3009..455a09f6 100644 --- a/exp/teatest/v2/teatest.go +++ b/exp/teatest/v2/teatest.go @@ -279,7 +279,7 @@ func (tm *TestModel) GetProgram() *tea.Program { // You can update the golden files by running your tests with the -update flag. func RequireEqualOutput(tb testing.TB, out []byte) { tb.Helper() - golden.RequireEqualEscape(tb, out, true) + golden.RequireEqualEscape(tb, out, true) //nolint:staticcheck } func safe(rw io.ReadWriter) io.ReadWriter { diff --git a/input/parse.go b/input/parse.go index 890e3361..dc76f7e9 100644 --- a/input/parse.go +++ b/input/parse.go @@ -313,7 +313,7 @@ func (p *Parser) parseCsi(b []byte) (int, Event) { if !ok || val == -1 { break } - return i, ModifyOtherKeysEvent(val) + return i, ModifyOtherKeysEvent(val) //nolint:gosec case 'I': return i, FocusEvent{} case 'O': @@ -683,7 +683,7 @@ func (p *Parser) parseOsc(b []byte) (int, Event) { break } - sel := ClipboardSelection(parts[0][0]) + sel := ClipboardSelection(parts[0][0]) //nolint:unconvert return i, ClipboardEvent{Selection: sel, Content: string(bts)} } @@ -704,9 +704,8 @@ func (p *Parser) parseStTerminated(intro8, intro7 byte, fn func([]byte) Event) f // Scan control sequence // Most common control sequence is terminated by a ST character // ST is a 7-bit string terminator character is (ESC \) - // nolint: revive start := i - for ; i < len(b) && b[i] != ansi.ST && b[i] != ansi.ESC; i++ { + for ; i < len(b) && b[i] != ansi.ST && b[i] != ansi.ESC; i++ { // nolint:revive } if i >= len(b) { diff --git a/term/term_unix.go b/term/term_unix.go index 1459cb1b..664bdbc7 100644 --- a/term/term_unix.go +++ b/term/term_unix.go @@ -90,7 +90,7 @@ func readPassword(fd uintptr) ([]byte, error) { return nil, err } - defer unix.IoctlSetTermios(int(fd), ioctlWriteTermios, termios) + defer unix.IoctlSetTermios(int(fd), ioctlWriteTermios, termios) //nolint:errcheck return readPasswordLine(passwordReader(fd)) } diff --git a/termios/termios_other.go b/termios/termios_other.go index 129dfcee..51a6df51 100644 --- a/termios/termios_other.go +++ b/termios/termios_other.go @@ -10,6 +10,6 @@ func setSpeed(term *unix.Termios, ispeed, ospeed uint32) { term.Ospeed = speed(ospeed) } -func getSpeed(term *unix.Termios) (uint32, uint32) { - return uint32(term.Ispeed), uint32(term.Ospeed) +func getSpeed(term *unix.Termios) (uint32, uint32) { //nolint:unused + return uint32(term.Ispeed), uint32(term.Ospeed) //nolint:gosec } diff --git a/vt/callbacks.go b/vt/callbacks.go index 1491bbf5..163d9fdc 100644 --- a/vt/callbacks.go +++ b/vt/callbacks.go @@ -26,7 +26,7 @@ type Callbacks struct { // CursorPosition callback. When set, this function is called when the cursor // position changes. - CursorPosition func(old, new cellbuf.Position) //nolint:predeclared + CursorPosition func(old, new cellbuf.Position) //nolint:predeclared,revive // CursorVisibility callback. When set, this function is called when the // cursor visibility changes. diff --git a/vt/screen.go b/vt/screen.go index ed596f4c..8c1bb2cb 100644 --- a/vt/screen.go +++ b/vt/screen.go @@ -154,7 +154,7 @@ func (s *Screen) setCursorX(x int, margins bool) { // setCursorY sets the cursor Y position. If margins is true, the cursor is // only set if it is within the scroll margins. -func (s *Screen) setCursorY(y int, margins bool) { +func (s *Screen) setCursorY(y int, margins bool) { //nolint:unused s.setCursor(s.cur.X, y, margins) } diff --git a/vt/terminal.go b/vt/terminal.go index 8efe7e65..a780f5d0 100644 --- a/vt/terminal.go +++ b/vt/terminal.go @@ -293,7 +293,7 @@ func (t *Terminal) IndexedColor(i int) color.Color { c := t.colors[i] if c == nil { // Return the default color. - return ansi.ExtendedColor(i) //nolint:gosec + return ansi.ExtendedColor(i) //nolint:gosec,staticcheck } return c diff --git a/xpty/pty_unix.go b/xpty/pty_unix.go index a764138c..5cfa0696 100644 --- a/xpty/pty_unix.go +++ b/xpty/pty_unix.go @@ -13,10 +13,10 @@ func (p *UnixPty) setWinsize(width, height, x, y int) error { var rErr error if err := p.Control(func(fd uintptr) { rErr = termios.SetWinsize(int(fd), &unix.Winsize{ - Row: uint16(height), - Col: uint16(width), - Xpixel: uint16(x), - Ypixel: uint16(y), + Row: uint16(height), //nolint:gosec + Col: uint16(width), //nolint:gosec + Xpixel: uint16(x), //nolint:gosec + Ypixel: uint16(y), //nolint:gosec }) }); err != nil { rErr = err