Skip to content

Commit 10751ed

Browse files
committed
fmt: introduce golangci-lint and go vet
1 parent 297ad41 commit 10751ed

File tree

9 files changed

+416
-4
lines changed

9 files changed

+416
-4
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- dev
8+
pull_request:
9+
permissions:
10+
contents: read
11+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
12+
# pull-requests: read
13+
jobs:
14+
collectpackages:
15+
name: "Collect all packages to a list"
16+
runs-on: ubuntu-latest
17+
outputs:
18+
packages: "${{ steps.create-package-list.outputs.packages }}"
19+
steps:
20+
- uses: actions/checkout@v5
21+
- name: "Collect by calling 'make print_collected'"
22+
id: create-package-list
23+
run: |
24+
pkgs=$(make print_collected)
25+
# replace space by comma, add double quotes and copy to output
26+
echo "packages=[\"${pkgs// /\",\"}\"]" >> $GITHUB_OUTPUT
27+
- name: "Debug the collected packages as JSON array"
28+
env:
29+
COLLECTED_PACKAGES: ${{ steps.create-package-list.outputs.packages }}
30+
run: echo "The collected packages are $COLLECTED_PACKAGES"
31+
32+
golangci:
33+
needs: collectpackages
34+
runs-on: ubuntu-latest
35+
strategy:
36+
matrix:
37+
package: "${{ fromJson(needs.collectpackages.outputs.packages) }}"
38+
name: "lint ${{ matrix.package }}"
39+
# we need to exclude the root folder, because the CI action would lint all packages recursively again
40+
# additionally the driver "touch" needs to be skipped here, because contains sub-folders with "machine" imports
41+
#${{ format('{0}/{1}/{2}', env.TEMP_DB_FOLDER, env.PROJECT_NAME, 'artifacts') }}
42+
#if: ${{ matrix.package != github.workspace }} && ${{ matrix.package != format('{0}/{1}', github.workspace, 'touch') }}
43+
if: ${{ matrix.package != github.workspace }}
44+
steps:
45+
- uses: actions/checkout@v5
46+
- uses: actions/setup-go@v6
47+
with:
48+
go-version: '1.22'
49+
cache: false
50+
- name: golangci-lint
51+
uses: golangci/golangci-lint-action@v8
52+
with:
53+
version: v2.5.0
54+
working-directory: ${{ matrix.package }}
55+
56+
# Optional: golangci-lint command line arguments.
57+
# Note: exclude arguments, e.g. --exclude-files="my_file", will not affect the "typecheck" linter,
58+
# at least since v1.61.0 - use build tags instead.
59+
#args: --exclude-files="platforms/digispark/digispark_adaptor.go"
60+
61+
# Optional: show only new issues if it's a pull request. The default value is `false`.
62+
# only-new-issues: true
63+
64+
# Optional: if set to true then the all caching functionality will be complete disabled,
65+
# takes precedence over all other caching options.
66+
# skip-cache: true

.golangci.yml

Lines changed: 308 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# all packages without any dependency to underlying tiny-go packages, e.g. "machine" or "device/arm"
2+
# also the complete image folder should be omitted
3+
BUILD_TAGS_CHECK := m5stack_core2,microbit,xiao_ble
4+
ALL_WITHOUT_MACHINE := $(shell go list -e -tags $(BUILD_TAGS_CHECK) -f '{{.Dir}},{{.Deps}}' ./... | awk -F, '$$1 !~ /image/ && $$2 !~ /machine/ && $$2 !~ /device\/arm/ {print $$1}')
5+
ALL_TO_CHECK := $(ALL_WITHOUT_MACHINE)
6+
7+
.PHONY: clean fmt-check smoke-test unit-test test check fmt_check fmt_fix $(ALL_TO_CHECK)
18

29
clean:
310
@rm -rf build
@@ -26,3 +33,33 @@ unit-test:
2633
@go test -v $(addprefix ./,$(TESTS))
2734

2835
test: clean fmt-check unit-test smoke-test
36+
37+
fmt_quick_check:
38+
@# a very fast check before build, but depends on accessibility of all imports
39+
@# switch off the "stdmethods" analyzer is needed due to finding:
40+
@# at24cx/at24cx.go:57:18: method WriteByte(eepromAddress uint16, value uint8) error should have signature WriteByte(byte) error
41+
@# at24cx/at24cx.go:67:18: method ReadByte(eepromAddress uint16) (uint8, error) should have signature ReadByte() (byte, error)
42+
@# switch off the "shift" analyzer is needed due to finding:
43+
@#tmc5160/registers.go:1939:16: m.CUR_A (16 bits) too small for shift of 16
44+
@#tmc5160/registers.go:1996:16: m.X3 (8 bits) too small for shift of 27
45+
@#tmc5160/registers.go:1996:27: m.X2 (8 bits) too small for shift of 24
46+
@#tmc5160/registers.go:1996:38: m.X1 (8 bits) too small for shift of 21
47+
@#tmc5160/registers.go:1996:49: m.W3 (8 bits) too small for shift of 18
48+
@#tmc5160/registers.go:1996:60: m.W2 (8 bits) too small for shift of 16
49+
@#tmc5160/registers.go:1996:71: m.W1 (8 bits) too small for shift of 14
50+
@#tmc5160/registers.go:1996:82: m.W0 (8 bits) too small for shift of 12
51+
go vet -tags $(BUILD_TAGS_CHECK) -stdmethods=false -shift=false $(ALL_TO_CHECK)
52+
53+
fmt_check:
54+
@# a complete format check, but depends on accessibility of all imports
55+
golangci-lint -v run $(ALL_TO_CHECK)
56+
57+
fmt_fix:
58+
@# an automatic reformat and complete format check, but depends on accessibility of all imports
59+
@#TODO: activate when ready
60+
@#gofumpt -l -w $(ALL_TO_CHECK)
61+
golangci-lint -v run $(ALL_TO_CHECK) --fix
62+
63+
print_collected:
64+
@#this target is used to unify mechanism in CI with the local one, see ".github/workflows/golangci-lint.yml"
65+
@echo $(ALL_TO_CHECK)

adafruit4650/device_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"testing"
1414
"time"
15+
1516
"tinygo.org/x/drivers"
1617
"tinygo.org/x/tinyfont"
1718
"tinygo.org/x/tinyfont/freemono"

cmd/convert2bin/convert2bin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func main() {
1919

2020
func run(args []string) error {
2121
if len(args) < 2 {
22-
return fmt.Errorf("usage: %s FILE")
22+
return fmt.Errorf("usage: %s FILE", args[0])
2323
}
2424

2525
b, err := ioutil.ReadFile(args[1])

hts221/hts221_generic.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
package hts221
44

5-
import "tinygo.org/x/drivers"
6-
75
// Configure sets up the HTS221 device for communication.
86
func (d *Device) Configure() {
97
// read calibration data

pcf8523/pcf8523.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package pcf8523
55

66
import (
77
"time"
8+
89
"tinygo.org/x/drivers"
910
)
1011

pcf8523/pcf8523_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/hex"
55
"testing"
66
"time"
7+
78
"tinygo.org/x/drivers/tester"
89
)
910

tmc2209/address.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func ReadRegister(comm RegisterComm, driverIndex uint8, register uint8) (uint32,
9292
// Read the register value using the comm interface
9393

9494
value, err := comm.ReadRegister(register, driverIndex)
95-
log.Printf("Request read ", register, driverIndex, value)
95+
log.Print("Request read ", register, driverIndex, value)
9696
if err != nil {
9797
return 0, err
9898
}

0 commit comments

Comments
 (0)