From 7425bc25d9915c3f6a290e1681cf170e08b5553c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 15 Apr 2022 13:13:46 +0300 Subject: [PATCH] Add lint to CI and pre-commit --- .github/workflows/go.yml | 53 ++++++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 14 +++++++++++ lib/ansimage/LICENSE | 2 +- matrix/matrix.go | 2 +- ui/autocomplete.go | 2 +- 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/go.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..5056656 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,53 @@ +name: Go + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + go-version: [1.18] + steps: + - uses: actions/checkout@v3 + + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + + - name: Install goimports + run: | + go install golang.org/x/tools/cmd/goimports@latest + export PATH="$HOME/go/bin:$PATH" + + - name: Install pre-commit + run: pip install pre-commit + + - name: Lint + run: pre-commit run -a + + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + go-version: [1.17, 1.18] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + + - name: Install libolm + run: sudo apt-get install libolm-dev libolm3 + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..abb3979 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: trailing-whitespace + exclude_types: [markdown] + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + + - repo: https://github.com/tekwizely/pre-commit-golang + rev: v1.0.0-beta.5 + hooks: + - id: go-imports-repo diff --git a/lib/ansimage/LICENSE b/lib/ansimage/LICENSE index 14e2f77..a612ad9 100644 --- a/lib/ansimage/LICENSE +++ b/lib/ansimage/LICENSE @@ -35,7 +35,7 @@ Mozilla Public License Version 2.0 means any form of the work other than Source Code Form. 1.7. "Larger Work" - means a work that combines Covered Software with other material, in + means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. 1.8. "License" diff --git a/matrix/matrix.go b/matrix/matrix.go index 958bae3..a7b012c 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -840,7 +840,7 @@ func (c *Container) MarkRead(roomID id.RoomID, eventID id.EventID) { defer debug.Recover() err := c.client.MarkRead(roomID, eventID) if err != nil { - debug.Print("Failed to mark %s in %s as read: %v", eventID, roomID, err) + debug.Printf("Failed to mark %s in %s as read: %v", eventID, roomID, err) } }() } diff --git a/ui/autocomplete.go b/ui/autocomplete.go index 1cf9dbb..15c7393 100644 --- a/ui/autocomplete.go +++ b/ui/autocomplete.go @@ -60,7 +60,7 @@ func autocompleteFile(cmd *CommandAutocomplete) (completions []string, newText s func autocompleteToggle(cmd *CommandAutocomplete) (completions []string, newText string) { completions = make([]string, 0, len(toggleMsg)) for k := range toggleMsg { - if (strings.HasPrefix(k, cmd.RawArgs)) { + if strings.HasPrefix(k, cmd.RawArgs) { completions = append(completions, k) } }