Add lint to CI and pre-commit

This commit is contained in:
Tulir Asokan 2022-04-15 13:13:46 +03:00
parent c9633c095d
commit 7425bc25d9
5 changed files with 70 additions and 3 deletions

53
.github/workflows/go.yml vendored Normal file
View File

@ -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 ./...

14
.pre-commit-config.yaml Normal file
View File

@ -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

View File

@ -840,7 +840,7 @@ func (c *Container) MarkRead(roomID id.RoomID, eventID id.EventID) {
defer debug.Recover() defer debug.Recover()
err := c.client.MarkRead(roomID, eventID) err := c.client.MarkRead(roomID, eventID)
if err != nil { 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)
} }
}() }()
} }

View File

@ -60,7 +60,7 @@ func autocompleteFile(cmd *CommandAutocomplete) (completions []string, newText s
func autocompleteToggle(cmd *CommandAutocomplete) (completions []string, newText string) { func autocompleteToggle(cmd *CommandAutocomplete) (completions []string, newText string) {
completions = make([]string, 0, len(toggleMsg)) completions = make([]string, 0, len(toggleMsg))
for k := range toggleMsg { for k := range toggleMsg {
if (strings.HasPrefix(k, cmd.RawArgs)) { if strings.HasPrefix(k, cmd.RawArgs) {
completions = append(completions, k) completions = append(completions, k)
} }
} }