Skip to content

use blank identifier for interface compliance #1493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fi
# by default, "./scripts/lint.sh" runs all lint tests
# to run only "license_header" test
# TESTS='license_header' ./scripts/lint.sh
TESTS=${TESTS:-"golangci_lint license_header require_error_is_no_funcs_as_params single_import"}
TESTS=${TESTS:-"golangci_lint license_header require_error_is_no_funcs_as_params single_import interface_compliance_nil"}

function test_golangci_lint {
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2
Expand Down Expand Up @@ -57,6 +57,17 @@ function test_require_error_is_no_funcs_as_params {
fi
}

# Ref: https://go.dev/doc/effective_go#blank_implements
function test_interface_compliance_nil {
if grep -R -o -P '_ .+? = &.+?\{\}' .; then
echo ""
echo "Interface compliance checks need to be of the form:"
echo " var _ json.Marshaler = (*RawMessage)(nil)"
echo ""
return 1
fi
}

function run {
local test="${1}"
shift 1
Expand Down
2 changes: 1 addition & 1 deletion vms/avm/txs/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
)

var (
_ Mempool = &mempool{}
_ Mempool = (*mempool)(nil)

errDuplicateTx = errors.New("duplicate tx")
errTxTooLarge = errors.New("tx too large")
Expand Down
2 changes: 1 addition & 1 deletion vms/rpcchainvm/gruntime/runtime_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
pb "github.com/ava-labs/avalanchego/proto/pb/vm/runtime"
)

var _ pb.RuntimeServer = &Server{}
var _ pb.RuntimeServer = (*Server)(nil)

// Server is a VM runtime initializer controlled by RPC.
type Server struct {
Expand Down
2 changes: 1 addition & 1 deletion x/merkledb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package merkledb

import "github.com/ava-labs/avalanchego/database"

var _ database.Batch = &batch{}
var _ database.Batch = (*batch)(nil)

// batch is a write-only database that commits changes to its host database
// when Write is called.
Expand Down
4 changes: 2 additions & 2 deletions x/merkledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const (
)

var (
_ TrieView = &Database{}
_ database.Database = &Database{}
_ TrieView = (*Database)(nil)
_ database.Database = (*Database)(nil)

Codec, Version = newCodec()

Expand Down
2 changes: 1 addition & 1 deletion x/merkledb/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package merkledb

import "github.com/ava-labs/avalanchego/database"

var _ database.Iterator = &iterator{}
var _ database.Iterator = (*iterator)(nil)

type iterator struct {
db *Database
Expand Down
4 changes: 2 additions & 2 deletions x/merkledb/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

var (
_ merkleMetrics = &mockMetrics{}
_ merkleMetrics = &metrics{}
_ merkleMetrics = (*mockMetrics)(nil)
_ merkleMetrics = (*metrics)(nil)
)

type merkleMetrics interface {
Expand Down
4 changes: 2 additions & 2 deletions x/merkledb/trieview.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
const defaultPreallocationSize = 100

var (
_ TrieView = (*trieView)(nil)

ErrCommitted = errors.New("view has been committed")
ErrInvalid = errors.New("the trie this view was based on has changed, rendering this view invalid")
ErrOddLengthWithValue = errors.New(
Expand All @@ -36,8 +38,6 @@ var (
ErrViewIsNotAChild = errors.New("passed in view is required to be a child of the current view")
ErrNoValidRoot = errors.New("a valid root was not provided to the trieView constructor")

_ TrieView = &trieView{}

numCPU = runtime.NumCPU()
)

Expand Down
2 changes: 1 addition & 1 deletion x/sync/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
)

var (
_ Client = &client{}
_ Client = (*client)(nil)

errInvalidRangeProof = errors.New("failed to verify range proof")
errTooManyKeys = errors.New("response contains more than requested keys")
Expand Down
4 changes: 2 additions & 2 deletions x/sync/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

var (
_ SyncMetrics = &mockMetrics{}
_ SyncMetrics = &metrics{}
_ SyncMetrics = (*mockMetrics)(nil)
_ SyncMetrics = (*metrics)(nil)
)

type SyncMetrics interface {
Expand Down
2 changes: 1 addition & 1 deletion x/sync/network_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
const minRequestHandlingDuration = 100 * time.Millisecond

var (
_ NetworkClient = &networkClient{}
_ NetworkClient = (*networkClient)(nil)

ErrAcquiringSemaphore = errors.New("error acquiring semaphore")
ErrRequestFailed = errors.New("request failed")
Expand Down
2 changes: 1 addition & 1 deletion x/sync/response_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package sync
// Look into making a struct to handle requests/responses that uses a sync pool
// to avoid allocations.

var _ ResponseHandler = &responseHandler{}
var _ ResponseHandler = (*responseHandler)(nil)

// Handles responses/failure notifications for a sent request.
// Exactly one of OnResponse or OnFailure is eventually called.
Expand Down
2 changes: 1 addition & 1 deletion x/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
syncpb "github.com/ava-labs/avalanchego/proto/pb/sync"
)

var _ Client = &mockClient{}
var _ Client = (*mockClient)(nil)

func newNoopTracer() trace.Tracer {
tracer, _ := trace.New(trace.Config{Enabled: false})
Expand Down
2 changes: 1 addition & 1 deletion x/sync/syncworkheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/google/btree"
)

var _ heap.Interface = &syncWorkHeap{}
var _ heap.Interface = (*syncWorkHeap)(nil)

type heapItem struct {
workItem *syncWorkItem
Expand Down