Skip to content

Commit eae7b52

Browse files
committed
fix golangci-lint warnings
1 parent 33d4d87 commit eae7b52

File tree

12 files changed

+36
-35
lines changed

12 files changed

+36
-35
lines changed

.golangci.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ run:
1010
issues-exit-code: 1
1111

1212
# include test files or not, default is true
13-
tests: true
13+
tests: false
1414

1515
# list of build tags, all linters use it. Default is empty list.
1616
build-tags:
1717
- !privileged_tests
18+
- chimera
1819

1920
# default is true. Enables skipping of directories:
2021
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
@@ -68,27 +69,24 @@ linters-settings:
6869
linters:
6970
enable-all: true
7071
disable:
71-
- deadcode
72+
- copyloopvar
73+
- depguard
7274
- dupword
7375
- exhaustive
74-
- exhaustivestruct
7576
- exhaustruct
77+
- exportloopref
7678
- gci
7779
- gochecknoglobals
7880
- gochecknoinits
7981
- gocritic
8082
- godox
81-
- golint
82-
- ifshort
83-
- interfacer
83+
- gofumpt
84+
- gosec
85+
- intrange
8486
- ireturn
85-
- maligned
8687
- nlreturn
8788
- nonamedreturns
88-
- nosnakecase
8989
- paralleltest
90-
- scopelint
91-
- structcheck
92-
- varcheck
90+
- revive
9391
- varnamelen
9492
- wsl

chimera/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func Match(pattern string, data []byte) (bool, error) {
3333
h := &ch.MatchRecorder{}
3434

3535
if err = db.Scan(data, s, h, nil); err != nil {
36-
return false, err // nolint: wrapcheck
36+
return false, err //nolint: wrapcheck
3737
}
3838

3939
return h.Matched(), h.Err

chimera/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (bs *blockScanner) Scan(data []byte, s *Scratch, h Handler, ctx interface{}
9595
}()
9696
}
9797

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

101101
type blockMatcher struct {

chimera/common.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ const (
3838
)
3939

4040
// DbInfo identify the version and platform information for the supplied database.
41-
// nolint: stylecheck
42-
type DbInfo string
41+
type DbInfo string //nolint: stylecheck
4342

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

80-
return hyperscan.ParseModeFlag(mode) // nolint: wrapcheck
79+
return hyperscan.ParseModeFlag(mode) //nolint: wrapcheck
8180
}
8281

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

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

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

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

118-
func (d *baseDatabase) Close() error { return ch.FreeDatabase(d.db) } // nolint: wrapcheck
117+
func (d *baseDatabase) Close() error { return ch.FreeDatabase(d.db) } //nolint: wrapcheck
119118

120119
// Version identify this release version.
121120
//

chimera/compile.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,22 @@ func (b *DatabaseBuilder) Build() (Database, error) {
144144

145145
db, err := ch.CompileExtMulti(b.Patterns, b.Mode, platform, b.MatchLimit, b.MatchLimitRecursion)
146146
if err != nil {
147-
return nil, err // nolint: wrapcheck
147+
return nil, err //nolint: wrapcheck
148148
}
149149

150150
return newBlockDatabase(db), nil
151151
}
152152

153153
// NewBlockDatabase compile expressions into a pattern database.
154-
func NewBlockDatabase(patterns ...*Pattern) (BlockDatabase, error) {
155-
db, err := Patterns(patterns).Build(Groups)
154+
func NewBlockDatabase(patterns ...*Pattern) (bdb BlockDatabase, err error) {
155+
var db Database
156+
db, err = Patterns(patterns).Build(Groups)
156157
if err != nil {
157158
return nil, err
158159
}
159160

160-
return db.(BlockDatabase), err
161+
bdb, _ = db.(*blockDatabase)
162+
return
161163
}
162164

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

187189
return newBlockDatabase(db), nil

chimera/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717
type Capture = ch.Capture
1818

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

2222
const (
2323
// PCRE hits its match limit and reports PCRE_ERROR_MATCHLIMIT.

chimera/runtime_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var blockDatabaseConstructors = map[string]BlockDatabaseConstructor{
2020
func TestBlockScanner(t *testing.T) {
2121
for dbType, dbConstructor := range blockDatabaseConstructors {
2222
Convey("Given a "+dbType+" block database", t, func() {
23-
bdb, err := dbConstructor(chimera.NewPattern(`\d+`, 0)) // nolint: scopelint
23+
bdb, err := dbConstructor(chimera.NewPattern(`\d+`, 0)) //nolint: scopelint
2424

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

5353
So(err, ShouldBeNil)
5454
So(bdb, ShouldNotBeNil)

chimera/scratch.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Scratch struct {
1717
func NewScratch(db Database) (*Scratch, error) {
1818
s, err := ch.AllocScratch(db.(database).c())
1919
if err != nil {
20-
return nil, err // nolint: wrapcheck
20+
return nil, err //nolint: wrapcheck
2121
}
2222

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

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

4444
// Realloc reallocate the scratch for another database.
4545
func (s *Scratch) Realloc(db Database) error {
46-
return ch.ReallocScratch(db.(database).c(), &s.s) // nolint: wrapcheck
46+
r, _ := db.(database)
47+
48+
return ch.ReallocScratch(r.c(), &s.s) //nolint: wrapcheck
4749
}
4850

4951
// Clone allocate a scratch space that is a clone of an existing scratch space.
5052
func (s *Scratch) Clone() (*Scratch, error) {
5153
cloned, err := ch.CloneScratch(s.s)
5254
if err != nil {
53-
return nil, err // nolint: wrapcheck
55+
return nil, err //nolint: wrapcheck
5456
}
5557

5658
return &Scratch{cloned}, nil
5759
}
5860

5961
// Free a scratch block previously allocated.
60-
func (s *Scratch) Free() error { return ch.FreeScratch(s.s) } // nolint: wrapcheck
62+
func (s *Scratch) Free() error { return ch.FreeScratch(s.s) } //nolint: wrapcheck

hyperscan/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type Database interface {
5757
Marshal() ([]byte, error)
5858

5959
// Reconstruct a pattern database from a stream of bytes at a given memory location.
60-
Unmarshal([]byte) error
60+
Unmarshal(b []byte) error
6161
}
6262

6363
// DbInfo identify the version and platform information for the supplied database.

hyperscan/pattern.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func ParseExprExt(s string) (ext *ExprExt, err error) {
147147
var n int
148148

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

153153
switch key {

0 commit comments

Comments
 (0)