Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
robbydyer committed May 30, 2024
1 parent 3d375a1 commit 3fd9817
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 5 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ linters:
enable:
- asciicheck
- bodyclose
- contextcheck
- durationcheck
- errcheck
- errorlint
Expand Down
1 change: 1 addition & 0 deletions internal/board/calendar/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (s *CalendarBoard) Render(ctx context.Context, canvas board.Canvas) error {
}

// Render ...
// nolint:contextcheck
func (s *CalendarBoard) render(ctx context.Context, canvas board.Canvas) error {
s.boardCtx, s.boardCancel = context.WithCancel(ctx)

Expand Down
2 changes: 2 additions & 0 deletions internal/board/image/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type jumpRequest struct {
}

// GetHTTPHandlers ...
//
//nolint:contextcheck
func (i *ImageBoard) GetHTTPHandlers() ([]*board.HTTPHandler, error) {
return []*board.HTTPHandler{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/board/image/imageboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ IMAGES:

if nextIndex < len(images) {
if images[nextIndex].isGif {
pCtx, pCancel := context.WithTimeout(context.Background(), preloaderTimeout)
pCtx, pCancel := context.WithTimeout(ctx, preloaderTimeout)
defer pCancel()
wg.Add(1)
go preloadGif(pCtx, images[nextIndex])
Expand Down
4 changes: 4 additions & 0 deletions internal/board/image/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

func TestFilenameCompare(t *testing.T) {
t.Parallel()
tests := []struct {
name string
a string
Expand Down Expand Up @@ -61,12 +62,14 @@ func TestFilenameCompare(t *testing.T) {
test := test

t.Run(test.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, test.expected, filenameCompare(test.a, test.b))
})
}
}

func TestReverseStrs(t *testing.T) {
t.Parallel()
tests := []struct {
name string
in []string
Expand All @@ -93,6 +96,7 @@ func TestReverseStrs(t *testing.T) {
test := test

t.Run(test.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, test.expected, reverseStrs(test.in))
})
}
Expand Down
2 changes: 2 additions & 0 deletions internal/board/racing/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func (s *RacingBoard) Render(ctx context.Context, canvas board.Canvas) error {
}

// Render ...
//
//nolint:contextcheck
func (s *RacingBoard) render(ctx context.Context, canvas board.Canvas) error {
s.boardCtx, s.boardCancel = context.WithCancel(ctx)

Expand Down
2 changes: 2 additions & 0 deletions internal/board/sport/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
)

// GetHTTPHandlers ...
//
//nolint:contextcheck
func (s *SportBoard) GetHTTPHandlers() ([]*board.HTTPHandler, error) {
return []*board.HTTPHandler{
{
Expand Down
9 changes: 8 additions & 1 deletion internal/canvas/canvas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@ import (
)

func TestNewCanvas(t *testing.T) {
t.Parallel()
canvas := NewCanvas(NewMatrixMock(64, 32))
require.NotNil(t, canvas)
require.Equal(t, 64, canvas.w)
require.Equal(t, 32, canvas.h)
}

func TestRender(t *testing.T) {
t.Parallel()
m := NewMatrixMock(10, 20)
canvas := &Canvas{m: m}
err := canvas.Render(context.Background())
require.NoError(t, err)
}

func TestColorModel(t *testing.T) {
t.Parallel()
canvas := &Canvas{}
require.Equal(t, color.RGBAModel, canvas.ColorModel())
}

func TestBounds(t *testing.T) {
t.Parallel()
canvas := &Canvas{w: 10, h: 20}

b := canvas.Bounds()
Expand All @@ -41,6 +45,7 @@ func TestBounds(t *testing.T) {
}

func TestSet(t *testing.T) {
t.Parallel()
m := NewMatrixMock(10, 20)
canvas := &Canvas{w: 10, h: 20, m: m}
canvas.Set(5, 15, color.White)
Expand All @@ -49,6 +54,7 @@ func TestSet(t *testing.T) {
}

func TestClear(t *testing.T) {
t.Parallel()
m := NewMatrixMock(10, 20)

canvas := &Canvas{w: 10, h: 20, m: m}
Expand All @@ -61,6 +67,7 @@ func TestClear(t *testing.T) {
}

func TestClose(t *testing.T) {
t.Parallel()
m := NewMatrixMock(10, 20)
canvas := &Canvas{w: 10, h: 20, m: m}
err := canvas.Close()
Expand All @@ -85,7 +92,7 @@ func NewMatrixMock(w int, h int) *MatrixMock {
}
}

func (m *MatrixMock) Geometry() (width, height int) {
func (m *MatrixMock) Geometry() (int, int) {
return 64, 32
}

Expand Down
1 change: 1 addition & 0 deletions internal/espnboard/espnboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (e *ESPNBoard) logoCacheDir() (string, error) {
}

// New ...
// nolint:contextcheck
func New(ctx context.Context, leaguer Leaguer, logger *zap.Logger, r rankSetter, rec rankSetter, opts ...Option) (*ESPNBoard, error) {
e := &ESPNBoard{
leaguer: leaguer,
Expand Down
2 changes: 1 addition & 1 deletion internal/nhl/nhl.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func New(ctx context.Context, logger *zap.Logger) (*NHL, error) {
}

c := cron.New()
if _, err := c.AddFunc("0 5 * * *", func() { n.CacheClear(context.Background()) }); err != nil {
if _, err := c.AddFunc("0 5 * * *", func() { n.CacheClear(ctx) }); err != nil {
return n, fmt.Errorf("failed to set cron job for cacheClear: %w", err)
}
c.Start()
Expand Down
1 change: 1 addition & 0 deletions internal/rgbrender/grid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestGridLayout(t *testing.T) {
}

func TestGrid(t *testing.T) {
t.Parallel()
log, err := zap.NewDevelopment()
require.NoError(t, err)
canvas := board.NewBlankCanvas(100, 100, log)
Expand Down
3 changes: 3 additions & 0 deletions internal/rgbrender/layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func TestPriorities(t *testing.T) {
}

func TestRender(t *testing.T) {
t.Parallel()
layers, err := NewLayerDrawer(60*time.Second, nil)
require.NoError(t, err)

Expand Down Expand Up @@ -203,6 +204,7 @@ func TestRender(t *testing.T) {
}

func TestBadPrepare(t *testing.T) {
t.Parallel()
layers, err := NewLayerDrawer(60*time.Second, nil)
require.NoError(t, err)

Expand All @@ -219,6 +221,7 @@ func TestBadPrepare(t *testing.T) {
}

func TestBadRender(t *testing.T) {
t.Parallel()
layers, err := NewLayerDrawer(60*time.Second, nil)
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions internal/rgbrender/rgbrender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ func TestZoomImageSize(t *testing.T) {
}

func TestNegativeImagePoint(t *testing.T) {
t.Parallel()
i := image.NewRGBA(image.Rect(-10, -10, 10, 10))

i.Set(-5, -5, color.Gray16{0xffff})
Expand Down
2 changes: 2 additions & 0 deletions internal/rgbrender/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

func TestBreakText(t *testing.T) {
t.Parallel()
tests := []struct {
name string
in string
Expand Down Expand Up @@ -53,6 +54,7 @@ func TestBreakText(t *testing.T) {
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, test.expected, breakText(test.max, test.in))
})
}
Expand Down
1 change: 1 addition & 0 deletions internal/scrollcanvas/scroll_canvas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

func TestScrollCanvas(t *testing.T) {
t.Parallel()
l := zaptest.NewLogger(t)
m := matrix.NewConsoleMatrix(64, 32, io.Discard, l)
c, err := NewScrollCanvas(m, l)
Expand Down
1 change: 1 addition & 0 deletions internal/sportsmatrix/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (s *SportsMatrix) startHTTP() chan error {
return errChan
}

//nolint:contextcheck
func (s *SportsMatrix) httpHandlers() []*board.HTTPHandler {
return []*board.HTTPHandler{
{
Expand Down
4 changes: 3 additions & 1 deletion internal/sportsmatrix/sportsmatrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sportsmatrix

import (
"context"
"errors"
"fmt"
"net/http"
_ "net/http/pprof"
Expand Down Expand Up @@ -122,6 +123,7 @@ func (c *Config) Defaults() {
}

// New ...
// nolint:contextcheck
func New(ctx context.Context, logger *zap.Logger, cfg *Config, canvases []board.Canvas, boards ...board.Board) (*SportsMatrix, error) {
cfg.Defaults()

Expand Down Expand Up @@ -329,7 +331,7 @@ func (s *SportsMatrix) startWebBoard(ctx context.Context) {
default:
}
if err := s.launchWebBoard(ctx); err != nil {
if err == context.Canceled {
if errors.Is(err, context.Canceled) {
s.log.Warn("web board context canceled, closing", zap.Error(err))
return
}
Expand Down
2 changes: 2 additions & 0 deletions internal/sportsmatrix/sportsmatrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (b *TestBoard) SetStateChangeNotifier(st board.StateChangeNotifier) {
}

func TestSportsMatrix(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := zaptest.NewLogger(t, zaptest.Level(zapcore.ErrorLevel))
Expand Down Expand Up @@ -151,6 +152,7 @@ func TestSportsMatrix(t *testing.T) {
}

func TestScreenSwitch(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down
1 change: 1 addition & 0 deletions script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if [ "${IN_DOCKER}" = "no" ]; then
-v "${ROOT}":/src${MOUNTOPTION} \
-w /src \
-e GOCACHE="/src/.cache" \
-e GOFLAGS="-buildvcs=false" \
-e GOLANGCI_LINT_CACHE="/src/.cache" \
-e GO111MODULE=on \
-e CGO_ENABLED=1 \
Expand Down

0 comments on commit 3fd9817

Please sign in to comment.