Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/golangci-lint-install.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- dev
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
lint:
runs-on: ubuntu-latest
name: "Lint all"
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: '1.22'
cache: false
- name: "Install golangci-lint v2.5.0"
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0
- name: "Run linter by calling 'make fmt_check'"
run: make fmt_check
59 changes: 59 additions & 0 deletions .github/workflows/golangci-lint-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- dev
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
collectpackages:
name: "Collect all packages to a list"
runs-on: ubuntu-latest
outputs:
packages: "${{ steps.create-package-list.outputs.packages }}"
steps:
- uses: actions/checkout@v5
- name: "Collect by calling 'make print_collected_packages'"
id: create-package-list
run: |
pkgs=$(make print_collected_packages)
# replace space by comma, add double quotes and copy to output
echo "packages=[\"${pkgs// /\",\"}\"]" >> $GITHUB_OUTPUT
- name: "Debug the collected packages as JSON array"
run: echo "The collected packages are ${{ steps.create-package-list.outputs.packages }}"

golangci:
needs: collectpackages
runs-on: ubuntu-latest
strategy:
matrix:
package: "${{ fromJson(needs.collectpackages.outputs.packages) }}"
name: "Lint ${{ matrix.package }}"
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: '1.22'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.5.0
working-directory: ${{ matrix.package }}

# Optional: golangci-lint command line arguments.
# Note: exclude arguments, e.g. --exclude-files="my_file", will not affect the "typecheck" linter,
# at least since v1.61.0 - use build tags instead.
#args: --exclude-files="platforms/digispark/digispark_adaptor.go"

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true
308 changes: 308 additions & 0 deletions .golangci.yml

Large diffs are not rendered by default.

45 changes: 43 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# sub-directory used for build
BUILD_DIR := build
# find all packages without any dependency to underlying tiny-go packages, e.g. "machine" or "device/arm"
BUILD_TAGS_CHECK := m5stack_core2,microbit,xiao_ble
ALL_WITHOUT_MACHINE := $(shell go list -e -tags $(BUILD_TAGS_CHECK) -f '{{.Dir}},{{.Deps}}' ./... | awk -F, '$$2 !~ /machine/ && $$2 !~ /device\/arm/ {print $$1}')
# exclude anything found in build output and "image" directory, and exclude some further folders, which contains problematic dependencies in sub-folders
EXCLUDE_PACKAGES = $(CURDIR)/$(BUILD_DIR)/% $(CURDIR)/image/% $(CURDIR)/touch $(CURDIR)/waveshare-epd
ALL_TO_CHECK := $(filter-out $(EXCLUDE_PACKAGES),$(ALL_WITHOUT_MACHINE))

.PHONY: clean fmt-check smoke-test unit-test test check fmt_check fmt_fix $(ALL_TO_CHECK)

clean:
@rm -rf build
@rm -rf $(BUILD_DIR)

FMT_PATHS = ./

Expand All @@ -9,7 +19,7 @@ fmt-check:

XTENSA ?= 1
smoke-test:
@mkdir -p build
@mkdir -p $(BUILD_DIR)
@go run ./smoketest.go -xtensa=$(XTENSA) smoketest.sh


Expand All @@ -26,3 +36,34 @@ unit-test:
@go test -v $(addprefix ./,$(TESTS))

test: clean fmt-check unit-test smoke-test

fmt_quick_check:
@# a very fast check before build, but depends on accessibility of all imports
@# switch off the "stdmethods" analyzer is needed due to finding:
@# at24cx/at24cx.go:57:18: method WriteByte(eepromAddress uint16, value uint8) error should have signature WriteByte(byte) error
@# at24cx/at24cx.go:67:18: method ReadByte(eepromAddress uint16) (uint8, error) should have signature ReadByte() (byte, error)
@# switch off the "shift" analyzer is needed due to finding:
@#tmc5160/registers.go:1939:16: m.CUR_A (16 bits) too small for shift of 16
@#tmc5160/registers.go:1996:16: m.X3 (8 bits) too small for shift of 27
@#tmc5160/registers.go:1996:27: m.X2 (8 bits) too small for shift of 24
@#tmc5160/registers.go:1996:38: m.X1 (8 bits) too small for shift of 21
@#tmc5160/registers.go:1996:49: m.W3 (8 bits) too small for shift of 18
@#tmc5160/registers.go:1996:60: m.W2 (8 bits) too small for shift of 16
@#tmc5160/registers.go:1996:71: m.W1 (8 bits) too small for shift of 14
@#tmc5160/registers.go:1996:82: m.W0 (8 bits) too small for shift of 12
go vet -tags $(BUILD_TAGS_CHECK) -stdmethods=false -shift=false $(ALL_TO_CHECK)

fmt_check:
@# a complete format check, but depends on accessibility of all imports
golangci-lint -v run $(ALL_TO_CHECK)

fmt_fix:
@# an automatic reformat and complete format check, but depends on accessibility of all imports
@#TODO: activate when ready
@#gofumpt -l -w $(ALL_TO_CHECK)
golangci-lint -v run $(ALL_TO_CHECK) --fix

print_collected_packages:
@#this target is used to unify mechanism in CI with the local one, see ".github/workflows/golangci-lint.yml"
@#we need additional exclude the root folder here, because will be checked recursive when used as working directory
@echo $(filter-out $(CURDIR),$(ALL_TO_CHECK))
1 change: 1 addition & 0 deletions adafruit4650/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"testing"
"time"

"tinygo.org/x/drivers"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freemono"
Expand Down
2 changes: 1 addition & 1 deletion cmd/convert2bin/convert2bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {

func run(args []string) error {
if len(args) < 2 {
return fmt.Errorf("usage: %s FILE")
return fmt.Errorf("usage: %s FILE", args[0])
}

b, err := ioutil.ReadFile(args[1])
Expand Down
2 changes: 0 additions & 2 deletions hts221/hts221_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

package hts221

import "tinygo.org/x/drivers"

// Configure sets up the HTS221 device for communication.
func (d *Device) Configure() {
// read calibration data
Expand Down
1 change: 1 addition & 0 deletions pcf8523/pcf8523.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package pcf8523

import (
"time"

"tinygo.org/x/drivers"
)

Expand Down
1 change: 1 addition & 0 deletions pcf8523/pcf8523_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"testing"
"time"

"tinygo.org/x/drivers/tester"
)

Expand Down
2 changes: 1 addition & 1 deletion tmc2209/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func ReadRegister(comm RegisterComm, driverIndex uint8, register uint8) (uint32,
// Read the register value using the comm interface

value, err := comm.ReadRegister(register, driverIndex)
log.Printf("Request read ", register, driverIndex, value)
log.Print("Request read ", register, driverIndex, value)
if err != nil {
return 0, err
}
Expand Down