Skip to content

Commit

Permalink
Refactoring due to aggressive linting; add golanglint-ci github action
Browse files Browse the repository at this point in the history
  • Loading branch information
momer committed May 2, 2024
1 parent e888ddb commit 3dedf76
Show file tree
Hide file tree
Showing 26 changed files with 1,461 additions and 1,221 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: golangci-lint
on:
push:
branches:
- '**' # Run on all branches
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
go-version: '1.22'
- name: golangci-lint
uses: golangci/golangci-lint-action@v5
with:
version: v1.57
skip-cache: true
args: --timeout=5m

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
go-version: '1.22'
- name: Test all
run: go test ./...
330 changes: 330 additions & 0 deletions .golangci.yml

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,5 @@ pre-commit run --all-files

#### Go-licenses pre-commit hook

Windows users will not be able to run the `go-licenses` hook as yet - @momer will be sending through a
PR to that project to resolve the issue, which is to do with OS-agnostic filepath support!


Windows users: Ensure that you have `C:\Program Files\Git\usr\bin` added
to your `PATH`!
4 changes: 4 additions & 0 deletions bonsai/bonsai.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// Package bonsai wraps the Bonsai.io HTTP API to create a Go API Client.
package bonsai

const (
Float64Epsilon = 1e-9
)
10 changes: 6 additions & 4 deletions bonsai/bonsai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package bonsai_test

import (
"fmt"
"log"
"log/slog"
"os"

_ "github.com/stretchr/testify/require"
)

func init() {
Expand All @@ -18,9 +17,12 @@ func initLogger() {

logHandler := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
AddSource: true,
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
ReplaceAttr: func(_ []string, a slog.Attr) slog.Attr {
if a.Key == slog.SourceKey {
src := a.Value.Any().(*slog.Source)
src, ok := a.Value.Any().(*slog.Source)
if !ok {
log.Fatalf("sourceKey attr is not a Source: %v", a.Value)
}
// Ruby on Rails-ish formatting
a.Value = slog.StringValue(fmt.Sprintf("%s:%d:in '%s'", src.File, src.Line, src.Function))
}
Expand Down
Loading

0 comments on commit 3dedf76

Please sign in to comment.