Skip to content

Commit abdc230

Browse files
authored
ci(ffi): add linter (#893)
1 parent 30819e7 commit abdc230

File tree

8 files changed

+269
-91
lines changed

8 files changed

+269
-91
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ jobs:
127127
with:
128128
go-version-file: "ffi/go.mod"
129129
cache-dependency-path: "ffi/go.sum"
130+
- name: Run golanci-lint
131+
uses: golangci/golangci-lint-action@v3
132+
with:
133+
version: latest
134+
working-directory: ffi
130135
- name: Test Go FFI bindings
131136
working-directory: ffi
132137
# cgocheck2 is expensive but provides complete pointer checks

ffi/.golangci.yaml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# https://golangci-lint.run/usage/configuration/
2+
run:
3+
timeout: 10m
4+
5+
# If set we pass it to "go list -mod={option}". From "go help modules":
6+
# If invoked with -mod=readonly, the go command is disallowed from the implicit
7+
# automatic updating of go.mod described above. Instead, it fails when any changes
8+
# to go.mod are needed. This setting is most useful to check that go.mod does
9+
# not need updates, such as in a continuous integration and testing system.
10+
# If invoked with -mod=vendor, the go command assumes that the vendor
11+
# directory holds the correct copies of dependencies and ignores
12+
# the dependency descriptions in go.mod.
13+
#
14+
# Allowed values: readonly|vendor|mod
15+
# By default, it isn't set.
16+
modules-download-mode: readonly
17+
18+
issues:
19+
# Make issues output unique by line.
20+
# Default: true
21+
uniq-by-line: false
22+
23+
# Maximum issues count per one linter.
24+
# Set to 0 to disable.
25+
# Default: 50
26+
max-issues-per-linter: 0
27+
28+
# Maximum count of issues with the same text.
29+
# Set to 0 to disable.
30+
# Default: 3
31+
max-same-issues: 0
32+
33+
# Enables skipping of directories:
34+
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
35+
# Default: true
36+
exclude-dirs-use-default: false
37+
38+
linters:
39+
disable-all: true
40+
enable:
41+
- asciicheck
42+
- bodyclose
43+
- copyloopvar
44+
- depguard
45+
- dupword
46+
- dupl
47+
- errcheck
48+
- errname
49+
- errorlint
50+
- forbidigo
51+
- gci
52+
- goconst
53+
- gocritic
54+
# - err113 - encourages wrapping static errors
55+
- gofmt
56+
- gofumpt
57+
# - mnd - unnecessary magic numbers
58+
- goprintffuncname
59+
- gosec
60+
- gosimple
61+
- govet
62+
- importas
63+
- ineffassign
64+
# - lll line length linter
65+
- misspell
66+
- nakedret
67+
- nilerr
68+
- noctx
69+
- nolintlint
70+
- perfsprint
71+
- prealloc
72+
- predeclared
73+
- revive
74+
- spancheck
75+
- staticcheck
76+
- stylecheck
77+
- tagalign
78+
- testifylint
79+
- typecheck
80+
- unconvert
81+
- unparam
82+
- unused
83+
- usestdlibvars
84+
- whitespace
85+
86+
linters-settings:
87+
depguard:
88+
rules:
89+
packages:
90+
deny:
91+
- pkg: "github.com/golang/mock/gomock"
92+
desc: go.uber.org/mock/gomock should be used instead.
93+
- pkg: "github.com/stretchr/testify/assert"
94+
desc: github.com/stretchr/testify/require should be used instead.
95+
- pkg: "io/ioutil"
96+
desc: io/ioutil is deprecated. Use package io or os instead.
97+
errorlint:
98+
# Check for plain type assertions and type switches.
99+
asserts: false
100+
# Check for plain error comparisons.
101+
comparison: false
102+
forbidigo:
103+
# Forbid the following identifiers (list of regexp).
104+
forbid:
105+
- 'require\.Error$(# ErrorIs should be used instead)?'
106+
- 'require\.ErrorContains$(# ErrorIs should be used instead)?'
107+
- 'require\.EqualValues$(# Equal should be used instead)?'
108+
- 'require\.NotEqualValues$(# NotEqual should be used instead)?'
109+
- '^(t|b|tb|f)\.(Fatal|Fatalf|Error|Errorf)$(# the require library should be used instead)?'
110+
revive:
111+
rules:
112+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr
113+
- name: bool-literal-in-expr
114+
disabled: false
115+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return
116+
- name: early-return
117+
disabled: false
118+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
119+
- name: empty-lines
120+
disabled: false
121+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format
122+
- name: string-format
123+
disabled: false
124+
arguments:
125+
- ["b.Logf[0]", "/.*%.*/", "no format directive, use b.Log instead"]
126+
- ["fmt.Errorf[0]", "/.*%.*/", "no format directive, use errors.New instead"]
127+
- ["fmt.Fprintf[1]", "/.*%.*/", "no format directive, use fmt.Fprint instead"]
128+
- ["fmt.Printf[0]", "/.*%.*/", "no format directive, use fmt.Print instead"]
129+
- ["fmt.Sprintf[0]", "/.*%.*/", "no format directive, use fmt.Sprint instead"]
130+
- ["log.Fatalf[0]", "/.*%.*/", "no format directive, use log.Fatal instead"]
131+
- ["log.Printf[0]", "/.*%.*/", "no format directive, use log.Print instead"]
132+
- ["t.Logf[0]", "/.*%.*/", "no format directive, use t.Log instead"]
133+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag
134+
- name: struct-tag
135+
disabled: false
136+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-naming
137+
- name: unexported-naming
138+
disabled: false
139+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error
140+
- name: unhandled-error
141+
# prefer the errcheck linter since it can be disabled directly with nolint directive
142+
# but revive's disable directive (e.g. //revive:disable:unhandled-error) is not
143+
# supported when run under golangci_lint
144+
disabled: true
145+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
146+
- name: unused-parameter
147+
disabled: false
148+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
149+
- name: unused-receiver
150+
disabled: false
151+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break
152+
- name: useless-break
153+
disabled: false
154+
tagalign:
155+
align: true
156+
sort: true
157+
strict: true
158+
order:
159+
- serialize
160+
testifylint:
161+
# Enable all checkers (https://github.com/Antonboom/testifylint#checkers).
162+
# Default: false
163+
enable-all: true
164+
# Disable checkers by name
165+
# (in addition to default
166+
# suite-thelper
167+
# ).
168+
disable:
169+
- go-require
170+
- float-compare

ffi/firewood.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
keyNotFound = "key not found"
3434
)
3535

36-
var errDbClosed = errors.New("firewood database already closed")
36+
var errDBClosed = errors.New("firewood database already closed")
3737

3838
// A Database is a handle to a Firewood database.
3939
// It is not safe to call these methods with a nil handle.
@@ -138,14 +138,14 @@ func (db *Database) Batch(ops []KeyValue) ([]byte, error) {
138138
hash := C.fwd_batch(
139139
db.handle,
140140
C.size_t(len(ffiOps)),
141-
(*C.struct_KeyValue)(unsafe.SliceData(ffiOps)), // implicitly pinned
141+
unsafe.SliceData(ffiOps), // implicitly pinned
142142
)
143143
return extractBytesThenFree(&hash)
144144
}
145145

146146
func (db *Database) Propose(keys, vals [][]byte) (*Proposal, error) {
147147
if db.handle == nil {
148-
return nil, errDbClosed
148+
return nil, errDBClosed
149149
}
150150

151151
values, cleanup := newValueFactory()
@@ -158,13 +158,12 @@ func (db *Database) Propose(keys, vals [][]byte) (*Proposal, error) {
158158
value: values.from(vals[i]),
159159
}
160160
}
161-
id_or_err := C.fwd_propose_on_db(
161+
idOrErr := C.fwd_propose_on_db(
162162
db.handle,
163163
C.size_t(len(ffiOps)),
164-
(*C.struct_KeyValue)(unsafe.SliceData(ffiOps)), // implicitly pinned
164+
unsafe.SliceData(ffiOps), // implicitly pinned
165165
)
166-
id, err := extractIdThenFree(&id_or_err)
167-
166+
id, err := extractUintThenFree(&idOrErr)
168167
if err != nil {
169168
return nil, err
170169
}
@@ -180,7 +179,7 @@ func (db *Database) Propose(keys, vals [][]byte) (*Proposal, error) {
180179
// If the key is not found, the return value will be (nil, nil).
181180
func (db *Database) Get(key []byte) ([]byte, error) {
182181
if db.handle == nil {
183-
return nil, errDbClosed
182+
return nil, errDBClosed
184183
}
185184

186185
values, cleanup := newValueFactory()
@@ -200,7 +199,7 @@ func (db *Database) Get(key []byte) ([]byte, error) {
200199
// Empty trie must return common.Hash{}.
201200
func (db *Database) Root() ([]byte, error) {
202201
if db.handle == nil {
203-
return nil, errDbClosed
202+
return nil, errDBClosed
204203
}
205204
hash := C.fwd_root_hash(db.handle)
206205
bytes, err := extractBytesThenFree(&hash)
@@ -222,7 +221,7 @@ func (db *Database) Revision(root []byte) (*Revision, error) {
222221
// Returns an error if already closed.
223222
func (db *Database) Close() error {
224223
if db.handle == nil {
225-
return errDbClosed
224+
return errDBClosed
226225
}
227226
C.fwd_close_db(db.handle)
228227
db.handle = nil

0 commit comments

Comments
 (0)