Skip to content

Commit

Permalink
Fix lint problems, add some explanations in the docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyCat committed Mar 29, 2024
1 parent cfc42b9 commit 9f594fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ issues:
# excluded by default patterns execute `golangci-lint run --help`
exclude:
- Using the variable on range scope `tt` in function literal
- "var-naming: don't use underscores in Go names; method Kaitai_IO should be KaitaiIO"
- "ST1003: should not use underscores in Go names; method Kaitai_IO should be KaitaiIO"
9 changes: 7 additions & 2 deletions kaitai/struct.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package kaitai

// Struct is the common interface guaranteed to be implemented by all types generated
// by Kaitai Struct compiler.
// Struct is the common interface guaranteed to be implemented by all types generated by
// Kaitai Struct compiler.
type Struct interface {
// Kaitai_IO returns the stream object associated with the struct.
//
// This is deliberately named with a `Kaitai_` prefix and underscore to avoid conflicts
// with other methods that may result from the attributes in Kaitai Struct type, e.g.
// is a user will define attribute `i_o` this will conflict with the method `IO()`.
Kaitai_IO() *Stream
}
8 changes: 5 additions & 3 deletions kaitai/struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kaitai
import (
"bytes"
"testing"

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

Expand All @@ -25,7 +26,8 @@ func (s *twoStruct) Kaitai_IO() *Stream {
return s._io
}

func WorkWithStruct(s Struct, t *testing.T, expectedSize int) {
func WorkWithStruct(t *testing.T, s Struct, expectedSize int) {
t.Helper()
actualSize, err := s.Kaitai_IO().Size()
assert.Nil(t, err)
assert.Equal(t, actualSize, int64(expectedSize))
Expand All @@ -41,6 +43,6 @@ func TestKaitaiStruct(t *testing.T) {
two := twoStruct{222, twoStream}

// Check if the structs implement the Struct interface
WorkWithStruct(&one, t, 7)
WorkWithStruct(&two, t, 9)
WorkWithStruct(t, &one, 7)
WorkWithStruct(t, &two, 9)
}

0 comments on commit 9f594fd

Please sign in to comment.