Skip to content

Commit

Permalink
fix golangci-lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
flier committed Dec 1, 2024
1 parent 33d4d87 commit eae7b52
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 35 deletions.
20 changes: 9 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ run:
issues-exit-code: 1

# include test files or not, default is true
tests: true
tests: false

# list of build tags, all linters use it. Default is empty list.
build-tags:
- !privileged_tests
- chimera

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
Expand Down Expand Up @@ -68,27 +69,24 @@ linters-settings:
linters:
enable-all: true
disable:
- deadcode
- copyloopvar
- depguard
- dupword
- exhaustive
- exhaustivestruct
- exhaustruct
- exportloopref
- gci
- gochecknoglobals
- gochecknoinits
- gocritic
- godox
- golint
- ifshort
- interfacer
- gofumpt
- gosec
- intrange
- ireturn
- maligned
- nlreturn
- nonamedreturns
- nosnakecase
- paralleltest
- scopelint
- structcheck
- varcheck
- revive
- varnamelen
- wsl
2 changes: 1 addition & 1 deletion chimera/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Match(pattern string, data []byte) (bool, error) {
h := &ch.MatchRecorder{}

if err = db.Scan(data, s, h, nil); err != nil {
return false, err // nolint: wrapcheck
return false, err //nolint: wrapcheck
}

return h.Matched(), h.Err
Expand Down
2 changes: 1 addition & 1 deletion chimera/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (bs *blockScanner) Scan(data []byte, s *Scratch, h Handler, ctx interface{}
}()
}

return ch.Scan(bs.db, data, 0, s.s, h.OnMatch, h.OnError, ctx) // nolint: wrapcheck
return ch.Scan(bs.db, data, 0, s.s, h.OnMatch, h.OnError, ctx) //nolint: wrapcheck
}

type blockMatcher struct {
Expand Down
9 changes: 4 additions & 5 deletions chimera/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const (
)

// DbInfo identify the version and platform information for the supplied database.
// nolint: stylecheck
type DbInfo string
type DbInfo string //nolint: stylecheck

// parse `Chimera Version: 5.4.0 Features: AVX2 Mode: BLOCK`.
var regexDBInfo = regexp.MustCompile(`^Chimera Version: (\d+\.\d+\.\d+) Features: ([\w\s]+)? Mode: (\w+)$`)
Expand Down Expand Up @@ -77,7 +76,7 @@ func (i DbInfo) Mode() (hyperscan.ModeFlag, error) {
return 0, err
}

return hyperscan.ParseModeFlag(mode) // nolint: wrapcheck
return hyperscan.ParseModeFlag(mode) //nolint: wrapcheck
}

// Database is an immutable database that can be used by the Chimera scanning API.
Expand All @@ -104,7 +103,7 @@ func newDatabase(db ch.Database) *baseDatabase { return &baseDatabase{db} }

func (d *baseDatabase) c() ch.Database { return d.db }

func (d *baseDatabase) Size() (int, error) { return ch.DatabaseSize(d.db) } // nolint: wrapcheck
func (d *baseDatabase) Size() (int, error) { return ch.DatabaseSize(d.db) } //nolint: wrapcheck

func (d *baseDatabase) Info() (DbInfo, error) {
i, err := ch.DatabaseInfo(d.db)
Expand All @@ -115,7 +114,7 @@ func (d *baseDatabase) Info() (DbInfo, error) {
return DbInfo(i), nil
}

func (d *baseDatabase) Close() error { return ch.FreeDatabase(d.db) } // nolint: wrapcheck
func (d *baseDatabase) Close() error { return ch.FreeDatabase(d.db) } //nolint: wrapcheck

// Version identify this release version.
//
Expand Down
12 changes: 7 additions & 5 deletions chimera/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,22 @@ func (b *DatabaseBuilder) Build() (Database, error) {

db, err := ch.CompileExtMulti(b.Patterns, b.Mode, platform, b.MatchLimit, b.MatchLimitRecursion)
if err != nil {
return nil, err // nolint: wrapcheck
return nil, err //nolint: wrapcheck
}

return newBlockDatabase(db), nil
}

// NewBlockDatabase compile expressions into a pattern database.
func NewBlockDatabase(patterns ...*Pattern) (BlockDatabase, error) {
db, err := Patterns(patterns).Build(Groups)
func NewBlockDatabase(patterns ...*Pattern) (bdb BlockDatabase, err error) {
var db Database
db, err = Patterns(patterns).Build(Groups)
if err != nil {
return nil, err
}

return db.(BlockDatabase), err
bdb, _ = db.(*blockDatabase)
return
}

// NewManagedBlockDatabase is a wrapper for NewBlockDatabase that
Expand All @@ -181,7 +183,7 @@ func NewManagedBlockDatabase(patterns ...*Pattern) (BlockDatabase, error) {
func Compile(expr string) (Database, error) {
db, err := ch.Compile(expr, 0, ch.Groups, nil)
if err != nil {
return nil, err // nolint: wrapcheck
return nil, err //nolint: wrapcheck
}

return newBlockDatabase(db), nil
Expand Down
2 changes: 1 addition & 1 deletion chimera/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
type Capture = ch.Capture

// Type used to differentiate the errors raised with the `ErrorEventHandler` callback.
type ErrorEvent = ch.ErrorEvent
type ErrorEvent = ch.ErrorEvent //nolint: errname

const (
// PCRE hits its match limit and reports PCRE_ERROR_MATCHLIMIT.
Expand Down
4 changes: 2 additions & 2 deletions chimera/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var blockDatabaseConstructors = map[string]BlockDatabaseConstructor{
func TestBlockScanner(t *testing.T) {
for dbType, dbConstructor := range blockDatabaseConstructors {
Convey("Given a "+dbType+" block database", t, func() {
bdb, err := dbConstructor(chimera.NewPattern(`\d+`, 0)) // nolint: scopelint
bdb, err := dbConstructor(chimera.NewPattern(`\d+`, 0)) //nolint: scopelint

So(err, ShouldBeNil)
So(bdb, ShouldNotBeNil)
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestBlockScanner(t *testing.T) {
func TestBlockMatcher(t *testing.T) {
for dbType, dbConstructor := range blockDatabaseConstructors {
Convey("Given a "+dbType+" block database", t, func() {
bdb, err := dbConstructor(chimera.NewPattern(`\d+`, 0)) // nolint: scopelint
bdb, err := dbConstructor(chimera.NewPattern(`\d+`, 0)) //nolint: scopelint

So(err, ShouldBeNil)
So(bdb, ShouldNotBeNil)
Expand Down
12 changes: 7 additions & 5 deletions chimera/scratch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Scratch struct {
func NewScratch(db Database) (*Scratch, error) {
s, err := ch.AllocScratch(db.(database).c())
if err != nil {
return nil, err // nolint: wrapcheck
return nil, err //nolint: wrapcheck
}

return &Scratch{s}, nil
Expand All @@ -39,22 +39,24 @@ func NewManagedScratch(db Database) (*Scratch, error) {
}

// Size provides the size of the given scratch space.
func (s *Scratch) Size() (int, error) { return ch.ScratchSize(s.s) } // nolint: wrapcheck
func (s *Scratch) Size() (int, error) { return ch.ScratchSize(s.s) } //nolint: wrapcheck

// Realloc reallocate the scratch for another database.
func (s *Scratch) Realloc(db Database) error {
return ch.ReallocScratch(db.(database).c(), &s.s) // nolint: wrapcheck
r, _ := db.(database)

return ch.ReallocScratch(r.c(), &s.s) //nolint: wrapcheck
}

// Clone allocate a scratch space that is a clone of an existing scratch space.
func (s *Scratch) Clone() (*Scratch, error) {
cloned, err := ch.CloneScratch(s.s)
if err != nil {
return nil, err // nolint: wrapcheck
return nil, err //nolint: wrapcheck
}

return &Scratch{cloned}, nil
}

// Free a scratch block previously allocated.
func (s *Scratch) Free() error { return ch.FreeScratch(s.s) } // nolint: wrapcheck
func (s *Scratch) Free() error { return ch.FreeScratch(s.s) } //nolint: wrapcheck
2 changes: 1 addition & 1 deletion hyperscan/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Database interface {
Marshal() ([]byte, error)

// Reconstruct a pattern database from a stream of bytes at a given memory location.
Unmarshal([]byte) error
Unmarshal(b []byte) error
}

// DbInfo identify the version and platform information for the supplied database.
Expand Down
2 changes: 1 addition & 1 deletion hyperscan/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func ParseExprExt(s string) (ext *ExprExt, err error) {
var n int

if n, err = strconv.Atoi(value); err != nil {
return
return ext, fmt.Errorf("parse value, %w", err)
}

switch key {
Expand Down
2 changes: 1 addition & 1 deletion internal/ch/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
ErrCompileError Error = C.CH_COMPILER_ERROR
// ErrDatabaseVersionError is the error returned if the given database was built for a different version of Hyperscan.
ErrDatabaseVersionError Error = C.CH_DB_VERSION_ERROR
// ErrDatabasePlatformError is the error returned if the given database was built for a different platform (i.e., CPU type).
// ErrDatabasePlatformError is the error returned if the given database was built for a different platform.
ErrDatabasePlatformError Error = C.CH_DB_PLATFORM_ERROR
// ErrDatabaseModeError is the error returned if the given database was built for a different mode of operation.
ErrDatabaseModeError Error = C.CH_DB_MODE_ERROR
Expand Down
2 changes: 1 addition & 1 deletion internal/ch/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Capture struct {
type MatchEventHandler func(id uint, from, to uint64, flags uint, captured []*Capture, context interface{}) Callback

// Type used to differentiate the errors raised with the `ErrorEventHandler` callback.
type ErrorEvent C.ch_error_event_t // nolint: errname
type ErrorEvent C.ch_error_event_t //nolint: errname

const (
// PCRE hits its match limit and reports PCRE_ERROR_MATCHLIMIT.
Expand Down

0 comments on commit eae7b52

Please sign in to comment.