Skip to content

Commit

Permalink
chore(lint): fix main linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynering committed Feb 27, 2025
1 parent 3ded93d commit 3be937e
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 52 deletions.
12 changes: 6 additions & 6 deletions ansi/sixel/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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) + '?')
Expand Down
20 changes: 8 additions & 12 deletions ansi/sixel/palette.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions ansi/sixel/palette_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ansi/sixel/util.go
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions ansi/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion cellbuf/hardscroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cellbuf/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions colors/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package colors

import "github.com/charmbracelet/lipgloss"

//nolint:revive
var (
WhiteBright = lipgloss.AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"}

Expand Down
1 change: 0 additions & 1 deletion conpty/doc.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/cellbuf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions examples/layout/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion exp/golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion exp/teatest/v2/teatest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions input/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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)}
}

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion term/term_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
4 changes: 2 additions & 2 deletions termios/termios_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion vt/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion vt/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion vt/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions xpty/pty_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3be937e

Please sign in to comment.