Skip to content

Commit a924253

Browse files
authored
Merge pull request #3605 from nspcc-dev/fix-linter
Enable linter for every module
2 parents 8ed3ab8 + 8bdb8af commit a924253

File tree

19 files changed

+100
-60
lines changed

19 files changed

+100
-60
lines changed

.github/workflows/tests.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,33 @@ on:
1414

1515
jobs:
1616
lint:
17-
name: Lint
17+
name: 'Lint: NeoGo'
1818
uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master
19+
20+
lint_examples:
21+
name: 'Lint: examples (${{ matrix.contract }})'
22+
uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master
23+
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
contract: [ 'engine', 'events', 'iterator', 'nft-d', 'nft-nd', 'nft-nd-nns', 'oracle',
28+
'runtime', 'storage', 'timer', 'token', 'zkp/cubic_circuit', 'zkp/xor_compat']
29+
with:
30+
workdir: examples/${{ matrix.contract }}
31+
32+
lint_scripts:
33+
name: 'Lint: scripts'
34+
uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master
35+
with:
36+
workdir: scripts
37+
38+
lint_interops:
39+
name: 'Lint: interop'
40+
uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master
41+
with:
42+
workdir: pkg/interop
43+
1944
gomodcheck:
2045
name: Check internal dependencies
2146
runs-on: ubuntu-latest

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ IMAGE_REPO=nspccdev/neo-go
2424

2525
DISABLE_NEOTEST_COVER=1
2626

27+
ROOT_DIR:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
28+
GOMODDIRS=$(dir $(shell find $(ROOT_DIR) -name go.mod))
29+
2730
# All of the targets are phony here because we don't really use make dependency
2831
# tracking for files
2932
.PHONY: build $(BINARY) deps image docker/$(BINARY) image-latest image-push image-push-latest clean-cluster \
@@ -113,7 +116,9 @@ vet:
113116
curl -L -o $@ https://github.com/nspcc-dev/.github/raw/master/.golangci.yml
114117

115118
lint: .golangci.yml
116-
@golangci-lint run
119+
@for dir in $(GOMODDIRS); do \
120+
(cd "$$dir" && golangci-lint run --config $(ROOT_DIR)/$< | sed -r "s,^,$$dir," | sed -r "s,^$(ROOT_DIR),,") \
121+
done
117122

118123
fmt:
119124
@gofmt -l -w -s $$(find . -type f -name '*.go'| grep -v "/vendor/")

examples/engine/engine.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ import (
44
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
55
)
66

7-
// NotifyScriptContainer sends runtime notification with script container hash
7+
// NotifyScriptContainer sends runtime notification with script container hash.
88
func NotifyScriptContainer() {
99
tx := runtime.GetScriptContainer()
1010
runtime.Notify("Tx", tx.Hash)
1111
}
1212

13-
// NotifyCallingScriptHash sends runtime notification with calling script hash
13+
// NotifyCallingScriptHash sends runtime notification with calling script hash.
1414
func NotifyCallingScriptHash() {
1515
callingScriptHash := runtime.GetCallingScriptHash()
1616
runtime.Notify("Calling", callingScriptHash)
1717
}
1818

19-
// NotifyExecutingScriptHash sends runtime notification about executing script hash
19+
// NotifyExecutingScriptHash sends runtime notification about executing script hash.
2020
func NotifyExecutingScriptHash() {
2121
execScriptHash := runtime.GetExecutingScriptHash()
2222
runtime.Notify("Executing", execScriptHash)
2323
}
2424

25-
// NotifyEntryScriptHash sends notification about entry script hash
25+
// NotifyEntryScriptHash sends notification about entry script hash.
2626
func NotifyEntryScriptHash() {
2727
entryScriptHash := runtime.GetEntryScriptHash()
2828
runtime.Notify("Entry", entryScriptHash)

examples/iterator/iterator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
// _deploy primes contract's storage with some data to be used later.
10-
func _deploy(_ any, _ bool) {
10+
func _deploy(_ any, _ bool) { // nolint: unused
1111
ctx := storage.GetContext() // RW context.
1212
storage.Put(ctx, "foo1", "1")
1313
storage.Put(ctx, "foo2", "2")

examples/nft-nd-nns/nns.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const (
6060
// Other constants.
6161
const (
6262
// defaultRegisterPrice is the default price for new domain registration.
63-
defaultRegisterPrice = 10_0000_0000
63+
defaultRegisterPrice = 10_0000_0000 // nolint: unused
6464
// millisecondsInYear is amount of milliseconds per year.
6565
millisecondsInYear = 365 * 24 * 3600 * 1000
6666
)
@@ -79,7 +79,7 @@ func Update(nef []byte, manifest string) {
7979
}
8080

8181
// _deploy initializes defaults (total supply and registration price) on contract deploy.
82-
func _deploy(data any, isUpdate bool) {
82+
func _deploy(data any, isUpdate bool) { // nolint: unused
8383
if isUpdate {
8484
return
8585
}
@@ -491,7 +491,7 @@ func getRecordKey(tokenId []byte, name string, typ RecordType) []byte {
491491

492492
// isValid returns true if the provided address is a valid Uint160.
493493
func isValid(address interop.Hash160) bool {
494-
return address != nil && len(address) == 20
494+
return address != nil && len(address) == 20 // nolint: gosimple
495495
}
496496

497497
// checkCommittee panics if the script container is not signed by the committee.
@@ -555,7 +555,7 @@ func splitAndCheck(name string, allowMultipleFragments bool) []string {
555555
if l > 2 && !allowMultipleFragments {
556556
return nil
557557
}
558-
for i := 0; i < l; i++ {
558+
for i := range fragments {
559559
if !checkFragment(fragments[i], i == l-1) {
560560
return nil
561561
}

examples/nft-nd-nns/nns_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,9 @@ func testTokensOf(t *testing.T, c *neotest.ContractInvoker, result [][]byte, arg
418418
}
419419
require.NoError(t, err)
420420
iter := s.Pop().Interop().Value().(*storage.Iterator)
421-
arr := make([]stackitem.Item, 0, len(result))
422421
for i := range result {
423422
require.True(t, iter.Next())
424423
require.Equal(t, result[i], iter.Value().Value())
425-
arr = append(arr, stackitem.Make(result[i]))
426424
}
427425
require.False(t, iter.Next())
428426
}

examples/nft-nd/nft.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
totalSupplyPrefix = "s"
2727
// balancePrefix contains map from addresses to balances.
2828
balancePrefix = "b"
29-
// accountPrefix contains map from address + token id to tokens
29+
// accountPrefix contains map from address + token id to tokens.
3030
accountPrefix = "a"
3131
// tokenPrefix contains map from token id to it's owner.
3232
tokenPrefix = "t"

examples/runtime/runtime.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
var (
10-
// Check if the invoker of the contract is the specified owner
10+
// Check if the invoker of the contract is the specified owner.
1111
owner = address.ToHash160("NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB")
1212
)
1313

@@ -22,7 +22,7 @@ func init() {
2222

2323
// _deploy is called after contract deployment or update, it'll be called
2424
// in deployment transaction and if call update method of this contract.
25-
func _deploy(_ any, isUpdate bool) {
25+
func _deploy(_ any, isUpdate bool) { // nolint: unused
2626
if isUpdate {
2727
Log("_deploy method called after contract update")
2828
return

examples/storage/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import (
55
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
66
)
77

8-
// ctx holds storage context for contract methods
8+
// ctx holds storage context for contract methods.
99
var ctx storage.Context
1010

1111
// defaultKey represents the default key.
1212
var defaultKey = []byte("default")
1313

14-
// init inits storage context before any other contract method is called
14+
// init inits storage context before any other contract method is called.
1515
func init() {
1616
ctx = storage.GetContext()
1717
}

examples/timer/timer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ import (
99
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
1010
)
1111

12-
const defaultTicks = 3
12+
const defaultTicks = 3 // nolint: unused
1313
const mgmtKey = "mgmt"
1414

1515
var (
16-
// ctx holds storage context for contract methods
16+
// ctx holds storage context for contract methods.
1717
ctx storage.Context
18-
// Check if the invoker of the contract is the specified owner
18+
// Check if the invoker of the contract is the specified owner.
1919
owner = address.ToHash160("NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB")
20-
// ticksKey is a storage key for ticks counter
20+
// ticksKey is a storage key for ticks counter.
2121
ticksKey = []byte("ticks")
2222
)
2323

2424
func init() {
2525
ctx = storage.GetContext()
2626
}
2727

28-
func _deploy(_ any, isUpdate bool) {
28+
func _deploy(_ any, isUpdate bool) { // nolint: unused
2929
if isUpdate {
3030
ticksLeft := storage.Get(ctx, ticksKey).(int) + 1
3131
storage.Put(ctx, ticksKey, ticksLeft)

0 commit comments

Comments
 (0)