From 75296b4b7eb566a5d6251aae2dacc2ba02cb7ffd Mon Sep 17 00:00:00 2001 From: SuperQ Date: Sun, 5 Jan 2025 18:36:25 +0100 Subject: [PATCH] Chore: Enable golangci-lint Add a GitHub actions workflow to run golangci-lint. Signed-off-by: SuperQ --- .github/workflows/golangci-lint.yml | 34 +++++++++++++++++++++++++++++ .golangci.yml | 12 ++++++++++ display.go | 6 ++--- go.mod | 1 - go.sum | 2 -- jsonrpc.go | 13 +++++------ network.go | 2 +- ntp.go | 2 -- serial.go | 14 ++++++------ 9 files changed, 63 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .golangci.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..8c828cf --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,34 @@ +--- +name: golangci-lint +on: + push: + paths: + - "go.sum" + - "go.mod" + - "**.go" + - ".github/workflows/golangci-lint.yml" + - ".golangci.yml" + pull_request: + +permissions: # added using https://github.com/step-security/secure-repo + contents: read + +jobs: + golangci: + permissions: + contents: read # for actions/checkout to fetch code + pull-requests: read # for golangci/golangci-lint-action to fetch pull requests + name: lint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Install Go + uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 + with: + go-version: 1.23.x + - name: Lint + uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 + with: + args: --verbose + version: v1.62.0 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..ddf4443 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,12 @@ +--- +linters: + enable: + # - goimports + # - misspell + # - revive + +issues: + exclude-rules: + - path: _test.go + linters: + - errcheck diff --git a/display.go b/display.go index 8e4ad72..f4e8cf7 100644 --- a/display.go +++ b/display.go @@ -211,7 +211,7 @@ func startBacklightTickers() { // Don't start the tickers if the display is switched off. // Set the display to off if that's the case. if config.DisplayMaxBrightness == 0 { - setDisplayBrightness(0) + _ = setDisplayBrightness(0) return } @@ -221,7 +221,7 @@ func startBacklightTickers() { defer dimTicker.Stop() go func() { - for { + for { //nolint:gosimple select { case <-dimTicker.C: tick_displayDim() @@ -236,7 +236,7 @@ func startBacklightTickers() { defer offTicker.Stop() go func() { - for { + for { //nolint:gosimple select { case <-offTicker.C: tick_displayOff() diff --git a/go.mod b/go.mod index 6e57f47..93fedab 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,6 @@ require ( github.com/gwatts/rootcerts v0.0.0-20240401182218-3ab9db955caf github.com/hanwen/go-fuse/v2 v2.5.1 github.com/hashicorp/go-envparse v0.1.0 - github.com/openstadia/go-usb-gadget v0.0.0-20231115171102-aebd56bbb965 github.com/pion/logging v0.2.2 github.com/pion/mdns/v2 v2.0.7 github.com/pion/webrtc/v4 v4.0.0 diff --git a/go.sum b/go.sum index a5ce4cd..b5769d8 100644 --- a/go.sum +++ b/go.sum @@ -87,8 +87,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/openstadia/go-usb-gadget v0.0.0-20231115171102-aebd56bbb965 h1:bZGtUfkOl0dqvem8ltx9KCYied0gSlRuDhaZDxgppN4= -github.com/openstadia/go-usb-gadget v0.0.0-20231115171102-aebd56bbb965/go.mod h1:6cAIK2c4O3/yETSrRjmNwsBL3yE4Vcu9M9p/Qwx5+gM= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pilebones/go-udev v0.9.0 h1:N1uEO/SxUwtIctc0WLU0t69JeBxIYEYnj8lT/Nabl9Q= diff --git a/jsonrpc.go b/jsonrpc.go index 7c06388..48ea0d4 100644 --- a/jsonrpc.go +++ b/jsonrpc.go @@ -195,8 +195,7 @@ func rpcSetEDID(edid string) error { // Save EDID to config, allowing it to be restored on reboot. config.EdidString = edid - SaveConfig() - + _ = SaveConfig() return nil } @@ -596,18 +595,18 @@ func rpcSetActiveExtension(extensionId string) error { return nil } if config.ActiveExtension == "atx-power" { - unmountATXControl() + _ = unmountATXControl() } else if config.ActiveExtension == "dc-power" { - unmountDCControl() + _ = unmountDCControl() } config.ActiveExtension = extensionId if err := SaveConfig(); err != nil { return fmt.Errorf("failed to save config: %w", err) } if extensionId == "atx-power" { - mountATXControl() + _ = mountATXControl() } else if extensionId == "dc-power" { - mountDCControl() + _ = mountDCControl() } return nil } @@ -728,7 +727,7 @@ func rpcSetSerialSettings(settings SerialSettings) error { Parity: parity, } - port.SetMode(serialPortMode) + _ = port.SetMode(serialPortMode) return nil } diff --git a/network.go b/network.go index 339f71c..66b8616 100644 --- a/network.go +++ b/network.go @@ -107,7 +107,7 @@ func checkNetworkState() { if newState != networkState { logger.Info("network state changed") // restart MDNS - startMDNS() + _ = startMDNS() networkState = newState requestDisplayUpdate() } diff --git a/ntp.go b/ntp.go index 06cb201..39ea7af 100644 --- a/ntp.go +++ b/ntp.go @@ -20,7 +20,6 @@ const ( ) var ( - timeSynced = false timeSyncRetryInterval = 0 * time.Second defaultNTPServers = []string{ "time.cloudflare.com", @@ -58,7 +57,6 @@ func TimeSyncLoop() { continue } logger.Infof("Time sync successful, now is: %v, time taken: %v", time.Now(), time.Since(start)) - timeSynced = true time.Sleep(timeSyncInterval) // after the first sync is done } } diff --git a/serial.go b/serial.go index 3ad56d3..a4ab7d5 100644 --- a/serial.go +++ b/serial.go @@ -16,14 +16,14 @@ const serialPortPath = "/dev/ttyS3" var port serial.Port func mountATXControl() error { - port.SetMode(defaultMode) + _ = port.SetMode(defaultMode) go runATXControl() return nil } func unmountATXControl() error { - reopenSerialPort() + _ = reopenSerialPort() return nil } @@ -122,13 +122,13 @@ func pressATXResetButton(duration time.Duration) error { } func mountDCControl() error { - port.SetMode(defaultMode) + _ = port.SetMode(defaultMode) go runDCControl() return nil } func unmountDCControl() error { - reopenSerialPort() + _ = reopenSerialPort() return nil } @@ -212,11 +212,11 @@ var defaultMode = &serial.Mode{ } func initSerialPort() { - reopenSerialPort() + _ = reopenSerialPort() if config.ActiveExtension == "atx-power" { - mountATXControl() + _ = mountATXControl() } else if config.ActiveExtension == "dc-power" { - mountDCControl() + _ = mountDCControl() } }