Skip to content

Commit

Permalink
Add linter and formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarten van der Heijden committed Sep 20, 2023
1 parent 3134bd9 commit 04c2de9
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: Go-results-${{ matrix.go-version }}
path: TestResults-${{ matrix.go-version }}.json
path: TestResults-${{ matrix.go-version }}.json
84 changes: 84 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
linters-settings:
gocritic:
enabled-tags:
- "performance"
- "style"
- "diagnostic"
linters:
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- cyclop
- decorder
- dogsled
- dupword
- durationcheck
- errcheck
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forbidigo
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
- ifshort
- importas
- ineffassign
- interfacebloat
- interfacer
# - ireturn # We disable this one since we're returning any's anyway.
- loggercheck
- maintidx
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- nonamedreturns
- nosprintfhostport
- paralleltest
- prealloc
- predeclared
- promlinter
- reassign
- rowserrcheck
- sqlclosecheck
- staticcheck
- tenv
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
- zerologlint
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ test: fmt ## Run unit tests, alias: t

fmt: ## Format go code
@go mod tidy
@go fmt ./...
@gofumpt -l -w .

tools: ## Install extra tools for development
go install mvdan.cc/gofumpt@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

lint: ## Lint the code locally
golangci-lint run
20 changes: 9 additions & 11 deletions map_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tsyncmap

import (
"github.com/stretchr/testify/assert"
"sync"
"testing"

"github.com/stretchr/testify/assert"
)

type testKey struct {
Expand Down Expand Up @@ -170,6 +171,7 @@ func TestMap_Range_Ranges(t *testing.T) {
item.Range(func(k testKey, v testValue) bool {
calledWithKey = append(calledWithKey, k)
calledWithValue = append(calledWithValue, v)

return true
})

Expand All @@ -180,10 +182,6 @@ func TestMap_Range_Ranges(t *testing.T) {

// Benchmarks

// Necessary to assign to in benchmarks
var result any
var ok bool

func BenchmarkMap_Load(b *testing.B) {
object := new(Map[testKey, testValue])

Expand All @@ -194,7 +192,7 @@ func BenchmarkMap_Load(b *testing.B) {

b.StartTimer()
for i := 0; i < b.N; i++ {
result, ok = object.Load(key)
object.Load(key)
}
}

Expand All @@ -208,7 +206,7 @@ func BenchmarkSyncMap_Load(b *testing.B) {

b.StartTimer()
for i := 0; i < b.N; i++ {
result, ok = object.Load(key)
object.Load(key)
}
}

Expand Down Expand Up @@ -244,7 +242,7 @@ func BenchmarkMap_LoadOrStore(b *testing.B) {

b.StartTimer()
for i := 0; i < b.N; i++ {
result, ok = object.LoadOrStore(key, value)
object.LoadOrStore(key, value)
}
}

Expand All @@ -256,7 +254,7 @@ func BenchmarkSyncMap_LoadOrStore(b *testing.B) {

b.StartTimer()
for i := 0; i < b.N; i++ {
result, ok = object.LoadOrStore(key, value)
object.LoadOrStore(key, value)
}
}

Expand Down Expand Up @@ -298,7 +296,7 @@ func BenchmarkMap_LoadAndDelete(b *testing.B) {

b.StartTimer()
for i := 0; i < b.N; i++ {
result, ok = object.LoadAndDelete(key)
object.LoadAndDelete(key)
}
}

Expand All @@ -312,7 +310,7 @@ func BenchmarkSyncMap_LoadAndDelete(b *testing.B) {

b.StartTimer()
for i := 0; i < b.N; i++ {
result, ok = object.LoadAndDelete(key)
object.LoadAndDelete(key)
}
}

Expand Down

0 comments on commit 04c2de9

Please sign in to comment.