Skip to content

Commit

Permalink
style(golangci-lint): add new linters
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbrad committed Jan 3, 2025
1 parent 98c0280 commit 9c6ece2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
16 changes: 15 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ linters:
- err113 # Golang linter to check the errors handling expressions
- gocritic # Provides many diagnostics that check for bugs, performance and style issues.
- exhaustive # Check exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables -- VERY IMPORTANT TO USE
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error.
- forcetypeassert # finds forced type assertions
- importas # Enforces consistent import aliases
Expand Down Expand Up @@ -178,6 +177,21 @@ linters:
- reassign # Checks that package variables are not reassigne
- musttag # linter that enforces field tags in (un)marshaled structslinter that enforces field tags in (un)marshaled structs
- dupword # checks for duplicate words in the source code comments.
- testableexamples # checks if examples are testable (have an expected output)
- fatcontext # Detects potential fat contexts in loops or function literals.
- copyloopvar # Detects places where loop variables are copied.
- intrange # Detect loops that could use the Go 1.22 integer range feature.
- perfsprint # Detects performance issues with fmt.Sprintf.
- inamedparam # Detects interfaces with unnamed method parameters.
- gochecksumtype # Detects the use of checksum types in Go code.
- mirror # Use right mirror functions for string/[]byte performance bust.
- tagalign # Align and sort tags for Go struct.
- exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions.
- nilnesserr # Detects nil errors in Go code.
- usetesting # Detects when some calls can be replaced by methods from the testing package.
- recvcheck # Golang linter checks for receiver type consistency.
- iface # Detects the incorrect use of interfaces.

issues:
exclude-use-default: false
include:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.42.1
rev: v4.1.0
hooks:
- id: commitizen
- repo: https://github.com/golangci/golangci-lint
rev: v1.52.0
rev: v1.63.3
hooks:
- id: golangci-lint
name: golangci-lint
Expand Down
6 changes: 3 additions & 3 deletions blocking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestBlocking(t *testing.T) {
queueElems := blockingQueue.Clear()

if !reflect.DeepEqual(elems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", elems, queueElems)
t.Fatalf("expected elements to be %v, got %v", elems, queueElems)
}
})

Expand All @@ -167,7 +167,7 @@ func TestBlocking(t *testing.T) {
queueElems := blockingQueue.Clear()

if len(queueElems) != 0 {
t.Fatalf("expected elems to be empty, got %v", queueElems)
t.Fatalf("expected elements to be empty, got %v", queueElems)
}
})
})
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestBlocking(t *testing.T) {
}

if !reflect.DeepEqual(elems, iterElems) {
t.Fatalf("expected elems to be %v, got %v", elems, iterElems)
t.Fatalf("expected elements to be %v, got %v", elems, iterElems)
}
})

Expand Down
10 changes: 5 additions & 5 deletions circular_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestCircular(t *testing.T) {
expectedElems := []int{1, 2}

if !reflect.DeepEqual(expectedElems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", expectedElems, queueElems)
t.Fatalf("expected elements to be %v, got %v", expectedElems, queueElems)
}
})

Expand Down Expand Up @@ -170,7 +170,7 @@ func TestCircular(t *testing.T) {
expectedElems := []int{5, 6, 3, 4}

if !reflect.DeepEqual(expectedElems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", expectedElems, queueElems)
t.Fatalf("expected elements to be %v, got %v", expectedElems, queueElems)
}
})
})
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestCircular(t *testing.T) {
expectedElems := []int{2, 3, 4}

if !reflect.DeepEqual(expectedElems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", expectedElems, queueElems)
t.Fatalf("expected elements to be %v, got %v", expectedElems, queueElems)
}
})

Expand Down Expand Up @@ -265,7 +265,7 @@ func TestCircular(t *testing.T) {
expectedElems := []int{1, 2, 3, 4}

if !reflect.DeepEqual(expectedElems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", expectedElems, queueElems)
t.Fatalf("expected elements to be %v, got %v", expectedElems, queueElems)
}
})

Expand All @@ -287,7 +287,7 @@ func TestCircular(t *testing.T) {
}

if !reflect.DeepEqual(elems, iterElems) {
t.Fatalf("expected elems to be %v, got %v", elems, iterElems)
t.Fatalf("expected elements to be %v, got %v", elems, iterElems)
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions linked_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestLinked(t *testing.T) {
expectedElems := []int{1, 2}

if !reflect.DeepEqual(expectedElems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", expectedElems, queueElems)
t.Fatalf("expected elements to be %v, got %v", expectedElems, queueElems)
}
})
})
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestLinked(t *testing.T) {
expectedElems := []int{2, 3, 4}

if !reflect.DeepEqual(expectedElems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", expectedElems, queueElems)
t.Fatalf("expected elements to be %v, got %v", expectedElems, queueElems)
}
})

Expand Down Expand Up @@ -206,7 +206,7 @@ func TestLinked(t *testing.T) {
expectedElems := []int{1, 2, 3, 4}

if !reflect.DeepEqual(expectedElems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", expectedElems, queueElems)
t.Fatalf("expected elements to be %v, got %v", expectedElems, queueElems)
}
})

Expand All @@ -228,7 +228,7 @@ func TestLinked(t *testing.T) {
}

if !reflect.DeepEqual(elems, iterElems) {
t.Fatalf("expected elems to be %v, got %v", elems, iterElems)
t.Fatalf("expected elements to be %v, got %v", elems, iterElems)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type options struct {

// An Option configures a Queue using the functional options paradigm.
type Option interface {
apply(*options)
apply(o *options)
}

type capacityOption int
Expand Down
14 changes: 7 additions & 7 deletions priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func TestPriority(t *testing.T) {
size := priorityQueue.Size()

if priorityQueue.Size() != 2 {
t.Fatalf("expected size to be 2, got %d with elems: %v", size, priorityQueue.Clear())
t.Fatalf("expected size to be 2, got %d with elements: %v", size, priorityQueue.Clear())
}

elems = priorityQueue.Clear()
expectedElems := []int{1, 2}

if !reflect.DeepEqual([]int{1, 2}, elems) {
t.Fatalf("expected elems to be %v, got %v", expectedElems, elems)
t.Fatalf("expected elements to be %v, got %v", expectedElems, elems)
}
})

Expand Down Expand Up @@ -76,7 +76,7 @@ func TestPriority(t *testing.T) {
expectedElems := []int{1, 2, 4, 5}

if !reflect.DeepEqual(expectedElems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", expectedElems, queueElems)
t.Fatalf("expected elements to be %v, got %v", expectedElems, queueElems)
}

newElems := make([]int, 10)
Expand All @@ -91,7 +91,7 @@ func TestPriority(t *testing.T) {

queueElems = priorityQueue.Clear()
if !reflect.DeepEqual(newElems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", newElems, queueElems)
t.Fatalf("expected elements to be %v, got %v", newElems, queueElems)
}
})

Expand Down Expand Up @@ -161,7 +161,7 @@ func TestPriority(t *testing.T) {
queueElems := priorityQueue.Clear()

if !reflect.DeepEqual(elems, queueElems) {
t.Fatalf("expected elems to be %v, got %v", elems, queueElems)
t.Fatalf("expected elements to be %v, got %v", elems, queueElems)
}
})

Expand All @@ -173,7 +173,7 @@ func TestPriority(t *testing.T) {
queueElems := priorityQueue.Clear()

if len(queueElems) != 0 {
t.Fatalf("expected elems to be empty, got %v", queueElems)
t.Fatalf("expected elements to be empty, got %v", queueElems)
}
})
})
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestPriority(t *testing.T) {
}

if !reflect.DeepEqual(elems, iterElems) {
t.Fatalf("expected elems to be %v, got %v", elems, iterElems)
t.Fatalf("expected elements to be %v, got %v", elems, iterElems)
}
})

Expand Down
4 changes: 2 additions & 2 deletions queue_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ type Queue[T comparable] interface {
Get() (T, error)

// Offer inserts the element to the tail of the queue.
Offer(T) error
Offer(elem T) error

// Reset sets the queue to its initial state.
Reset()

// Contains returns true if the queue contains the element.
Contains(T) bool
Contains(elem T) bool

// Peek retrieves but does not remove the head of the queue.
Peek() (T, error)
Expand Down

0 comments on commit 9c6ece2

Please sign in to comment.