Skip to content

Commit

Permalink
fix: golangci-lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: D4ryl00 <[email protected]>
  • Loading branch information
D4ryl00 committed Aug 7, 2024
1 parent 3a83c66 commit c0ab509
Show file tree
Hide file tree
Showing 49 changed files with 189 additions and 181 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup asdf
uses: asdf-vm/actions/setup@v1
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-

- name: Avoid triggering make generate
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-

- name: Check go.mod and go.sum
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:
uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-

- name: Check go.mod and go.sum
Expand Down Expand Up @@ -235,7 +235,7 @@ jobs:
uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-

- name: Check go.mod and go.sum
Expand Down
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
run:
deadline: 1m
tests: false
skip-files:
issues:
exclude-files:
- ".*\\.pb\\.go$"
- ".*\\.pb\\.gw\\.go$"
- ".*\\.gen\\.go$"
Expand Down Expand Up @@ -29,7 +30,7 @@ linters:
enable:
- asciicheck
- bodyclose
- depguard
#- depguard
- dogsled
- errcheck
#- exhaustive # nice to have
Expand Down Expand Up @@ -62,4 +63,3 @@ linters:
- unparam
- unused
- whitespace
- unused
11 changes: 2 additions & 9 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@ golang 1.22.5

#-----
# This is simply the most recent golangci-lint version available to date.
#
# @TODO(gfanton): check if we still have this issue
# The current version of golangci-lint also has a problem displaying logs on
# Github actions, see: https://github.com/golangci/golangci-lint-action/issues/119
#
# It would be good to update it (when possible) to a version that fixes this log
# issue and to update the golangci-lint Github Actions step accordingly.
#-----
golangci-lint 1.51.2
#-----
golangci-lint 1.59.1

#-----
# This is simply the most recent jq version available to date.
Expand Down
2 changes: 1 addition & 1 deletion api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *service) ServiceExportData(_ *protocoltypes.ServiceExportData_Request,
return nil
}

func (s *service) ServiceGetConfiguration(ctx context.Context, req *protocoltypes.ServiceGetConfiguration_Request) (*protocoltypes.ServiceGetConfiguration_Reply, error) {
func (s *service) ServiceGetConfiguration(ctx context.Context, _ *protocoltypes.ServiceGetConfiguration_Request) (*protocoltypes.ServiceGetConfiguration_Reply, error) {
key, err := s.ipfsCoreAPI.Key().Self(ctx)
if err != nil {
return nil, errcode.ErrCode_TODO.Wrap(err)
Expand Down
6 changes: 3 additions & 3 deletions api_contactrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// ContactRequestReference retrieves the necessary information to create a contact link
func (s *service) ContactRequestReference(ctx context.Context, _ *protocoltypes.ContactRequestReference_Request) (*protocoltypes.ContactRequestReference_Reply, error) {
func (s *service) ContactRequestReference(context.Context, *protocoltypes.ContactRequestReference_Request) (*protocoltypes.ContactRequestReference_Reply, error) {
accountGroup := s.getAccountGroup()
if accountGroup == nil {
return nil, errcode.ErrCode_ErrGroupMissing
Expand Down Expand Up @@ -180,7 +180,7 @@ func (s *service) ContactRequestDiscard(ctx context.Context, req *protocoltypes.
// ShareContact uses ContactRequestReference to get the contact information for the current account and
// returns the Protobuf encoding which you can further encode and share. If needed, his will reset the
// contact request reference and enable contact requests.
func (s *service) ShareContact(ctx context.Context, req *protocoltypes.ShareContact_Request) (_ *protocoltypes.ShareContact_Reply, err error) {
func (s *service) ShareContact(ctx context.Context, _ *protocoltypes.ShareContact_Request) (_ *protocoltypes.ShareContact_Reply, err error) {
accountGroup := s.getAccountGroup()
if accountGroup == nil {
return nil, errcode.ErrCode_ErrGroupMissing
Expand Down Expand Up @@ -232,7 +232,7 @@ func (s *service) ShareContact(ctx context.Context, req *protocoltypes.ShareCont
}

// DecodeContact decodes the Protobuf encoding of a shareable contact which was returned by ShareContact.
func (s *service) DecodeContact(ctx context.Context, req *protocoltypes.DecodeContact_Request) (_ *protocoltypes.DecodeContact_Reply, err error) {
func (s *service) DecodeContact(_ context.Context, req *protocoltypes.DecodeContact_Request) (_ *protocoltypes.DecodeContact_Reply, err error) {
contact := &protocoltypes.ShareableContact{}
if err := proto.Unmarshal(req.EncodedContact, contact); err != nil {
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions api_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"berty.tech/weshnet/pkg/protocoltypes"
)

func (s *service) DebugListGroups(req *protocoltypes.DebugListGroups_Request, srv protocoltypes.ProtocolService_DebugListGroupsServer) error {
func (s *service) DebugListGroups(_ *protocoltypes.DebugListGroups_Request, srv protocoltypes.ProtocolService_DebugListGroupsServer) error {
accountGroup := s.getAccountGroup()
if accountGroup == nil {
return errcode.ErrCode_ErrGroupMissing
Expand Down Expand Up @@ -176,7 +176,7 @@ func (s *service) DebugGroup(ctx context.Context, request *protocoltypes.DebugGr
return rep, nil
}

func (s *service) SystemInfo(ctx context.Context, request *protocoltypes.SystemInfo_Request) (*protocoltypes.SystemInfo_Reply, error) {
func (s *service) SystemInfo(ctx context.Context, _ *protocoltypes.SystemInfo_Request) (*protocoltypes.SystemInfo_Reply, error) {
reply := protocoltypes.SystemInfo_Reply{}

// process
Expand Down Expand Up @@ -232,7 +232,7 @@ func (s *service) SystemInfo(ctx context.Context, request *protocoltypes.SystemI
return &reply, nil
}

func (s *service) PeerList(ctx context.Context, request *protocoltypes.PeerList_Request) (*protocoltypes.PeerList_Reply, error) {
func (s *service) PeerList(ctx context.Context, _ *protocoltypes.PeerList_Request) (*protocoltypes.PeerList_Reply, error) {
reply := protocoltypes.PeerList_Reply{}
api := s.IpfsCoreAPI()
if api == nil {
Expand Down
24 changes: 12 additions & 12 deletions api_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *service) GroupMetadataList(req *protocoltypes.GroupMetadataList_Request
if req.UntilId == nil && !req.UntilNow {
sub, err := cg.MetadataStore().EventBus().Subscribe([]interface{}{
// new(stores.EventReplicated),
new(protocoltypes.GroupMetadataEvent),
new(*protocoltypes.GroupMetadataEvent),
}, eventbus.Name("weshnet/api/group-metadata-list"), eventbus.BufSize(32))
if err != nil {
return fmt.Errorf("unable to subscribe to new events")
Expand All @@ -63,7 +63,7 @@ func (s *service) GroupMetadataList(req *protocoltypes.GroupMetadataList_Request
}

// Subscribe to previous metadata events and stream them if requested
previousEvents := make(chan protocoltypes.GroupMetadataEvent)
previousEvents := make(chan *protocoltypes.GroupMetadataEvent)
if !req.SinceNow {
pevt, err := cg.MetadataStore().ListEvents(ctx, req.SinceId, req.UntilId, req.ReverseOrder)
if err != nil {
Expand All @@ -84,15 +84,15 @@ func (s *service) GroupMetadataList(req *protocoltypes.GroupMetadataList_Request
if req.UntilNow {
cancel()
} else {
previousEvents <- protocoltypes.GroupMetadataEvent{EventContext: nil}
previousEvents <- &protocoltypes.GroupMetadataEvent{EventContext: nil}
}

cg.logger.Debug("GroupMetadataList: previous events stream ended")

return
}

previousEvents <- *evt
previousEvents <- evt
}
}()
}
Expand All @@ -107,12 +107,12 @@ func (s *service) GroupMetadataList(req *protocoltypes.GroupMetadataList_Request
case event = <-newEvents:
}

msg := event.(protocoltypes.GroupMetadataEvent)
msg := event.(*protocoltypes.GroupMetadataEvent)
if msg.EventContext == nil {
continue
}

if err := sub.Send(&msg); err != nil {
if err := sub.Send(msg); err != nil {
return err
}

Expand Down Expand Up @@ -140,7 +140,7 @@ func (s *service) GroupMessageList(req *protocoltypes.GroupMessageList_Request,
var newEvents <-chan interface{}
if req.UntilId == nil && !req.UntilNow {
messageStoreSub, err := cg.MessageStore().EventBus().Subscribe([]interface{}{
new(protocoltypes.GroupMessageEvent),
new(*protocoltypes.GroupMessageEvent),
}, eventbus.Name("weshnet/api/group-message-list"))
if err != nil {
return fmt.Errorf("unable to subscribe to new events")
Expand All @@ -150,7 +150,7 @@ func (s *service) GroupMessageList(req *protocoltypes.GroupMessageList_Request,
}

// Subscribe to previous message events and stream them if requested
previousEvents := make(chan protocoltypes.GroupMessageEvent)
previousEvents := make(chan *protocoltypes.GroupMessageEvent)
if !req.SinceNow {
pevt, err := cg.MessageStore().ListEvents(ctx, req.SinceId, req.UntilId, req.ReverseOrder)
if err != nil {
Expand All @@ -171,15 +171,15 @@ func (s *service) GroupMessageList(req *protocoltypes.GroupMessageList_Request,
if req.UntilNow {
cancel()
} else {
previousEvents <- protocoltypes.GroupMessageEvent{EventContext: nil}
previousEvents <- &protocoltypes.GroupMessageEvent{EventContext: nil}
}

cg.logger.Debug("GroupMessageList: previous events stream ended")

return
}

previousEvents <- *evt
previousEvents <- evt
}
}()
}
Expand All @@ -195,12 +195,12 @@ func (s *service) GroupMessageList(req *protocoltypes.GroupMessageList_Request,
case event = <-newEvents:
}

msg := event.(protocoltypes.GroupMessageEvent)
msg := event.(*protocoltypes.GroupMessageEvent)
if msg.EventContext == nil {
continue
}

if err := sub.Send(&msg); err != nil {
if err := sub.Send(msg); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions api_multimember.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// MultiMemberGroupCreate creates a new MultiMember group
func (s *service) MultiMemberGroupCreate(ctx context.Context, req *protocoltypes.MultiMemberGroupCreate_Request) (_ *protocoltypes.MultiMemberGroupCreate_Reply, err error) {
func (s *service) MultiMemberGroupCreate(ctx context.Context, _ *protocoltypes.MultiMemberGroupCreate_Request) (_ *protocoltypes.MultiMemberGroupCreate_Reply, err error) {
ctx, _, endSection := tyber.Section(ctx, s.logger, "Creating MultiMember group")
defer func() { endSection(err, "") }()

Expand Down Expand Up @@ -120,7 +120,7 @@ func (s *service) MultiMemberGroupAdminRoleGrant(context.Context, *protocoltypes
}

// MultiMemberGroupInvitationCreate creates a group invitation
func (s *service) MultiMemberGroupInvitationCreate(ctx context.Context, req *protocoltypes.MultiMemberGroupInvitationCreate_Request) (*protocoltypes.MultiMemberGroupInvitationCreate_Reply, error) {
func (s *service) MultiMemberGroupInvitationCreate(_ context.Context, req *protocoltypes.MultiMemberGroupInvitationCreate_Request) (*protocoltypes.MultiMemberGroupInvitationCreate_Reply, error) {
cg, err := s.GetContextGroupForID(req.GroupPk)
if err != nil {
return nil, errcode.ErrCode_ErrGroupMemberUnknownGroupID.Wrap(err)
Expand Down
2 changes: 1 addition & 1 deletion api_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *service) ReplicationServiceRegisterGroup(ctx context.Context, request *
gopts = append(gopts, grpc.WithTransportCredentials(tlsconfig))
}

cc, err := grpc.DialContext(context.Background(), request.ReplicationServer, gopts...)
cc, err := grpc.NewClient("passthrough://"+request.ReplicationServer, gopts...)
if err != nil {
return nil, errcode.ErrCode_ErrStreamWrite.Wrap(err)
}
Expand Down
10 changes: 5 additions & 5 deletions contact_request_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *contactRequestsManager) metadataWatcher(ctx context.Context) {
}

// subscribe to new event
sub, err := c.metadataStore.EventBus().Subscribe(new(protocoltypes.GroupMetadataEvent),
sub, err := c.metadataStore.EventBus().Subscribe(new(*protocoltypes.GroupMetadataEvent),
eventbus.Name("weshnet/rqmngr/metadata-watcher"))
if err != nil {
c.logger.Warn("unable to subscribe to group metadata event", zap.Error(err))
Expand Down Expand Up @@ -153,15 +153,15 @@ func (c *contactRequestsManager) metadataWatcher(ctx context.Context) {
}

// handle new events
e := evt.(protocoltypes.GroupMetadataEvent)
e := evt.(*protocoltypes.GroupMetadataEvent)
typ := e.GetMetadata().GetEventType()
hctx, _, endSection := tyber.Section(ctx, c.logger, fmt.Sprintf("handling event - %s", typ.String()))

c.muManager.Lock()

var err error
if handler, ok := handlers[typ]; ok {
if err = handler(hctx, &e); err != nil {
if err = handler(hctx, e); err != nil {
c.logger.Error("metadata store event handler", zap.String("event", typ.String()), zap.Error(err))
}
}
Expand Down Expand Up @@ -421,7 +421,7 @@ func (c *contactRequestsManager) SendContactRequest(ctx context.Context, to *pro
_, own := c.metadataStore.GetIncomingContactRequestsStatus()
if own == nil {
err = fmt.Errorf("unable to retrieve own contact information")
return
return err
}

// get own metadata for contact
Expand All @@ -438,7 +438,7 @@ func (c *contactRequestsManager) SendContactRequest(ctx context.Context, to *pro
}

// create a new stream with the remote peer
stream, err := c.ipfs.NewStream(network.WithUseTransient(ctx, "req_mngr"), peer.ID, contactRequestV1)
stream, err := c.ipfs.NewStream(network.WithAllowLimitedConn(ctx, "req_mngr"), peer.ID, contactRequestV1)
if err != nil {
return fmt.Errorf("unable to open stream: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions events_sig_checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type sigChecker func(g *protocoltypes.Group, metadata *protocoltypes.GroupMetadata, message proto.Message) error

func sigCheckerGroupSigned(g *protocoltypes.Group, metadata *protocoltypes.GroupMetadata, message proto.Message) error {
func sigCheckerGroupSigned(g *protocoltypes.Group, metadata *protocoltypes.GroupMetadata, _ proto.Message) error {
pk, err := g.GetPubKey()
if err != nil {
return err
Expand All @@ -33,7 +33,7 @@ type eventDeviceSigned interface {
GetDevicePk() []byte
}

func sigCheckerDeviceSigned(g *protocoltypes.Group, metadata *protocoltypes.GroupMetadata, message proto.Message) error {
func sigCheckerDeviceSigned(_ *protocoltypes.Group, metadata *protocoltypes.GroupMetadata, message proto.Message) error {
msg, ok := message.(eventDeviceSigned)
if !ok {
return errcode.ErrCode_ErrDeserialization
Expand Down
6 changes: 3 additions & 3 deletions group_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (gc *GroupContext) ActivateGroupContext(contactPK crypto.PubKey) (err error
// chainkey of new members.
{
m := gc.MetadataStore()
sub, err := m.EventBus().Subscribe(new(protocoltypes.GroupMetadataEvent))
sub, err := m.EventBus().Subscribe(new(*protocoltypes.GroupMetadataEvent))
if err != nil {
return fmt.Errorf("unable to subscribe to group metadata event: %w", err)
}
Expand All @@ -132,9 +132,9 @@ func (gc *GroupContext) ActivateGroupContext(contactPK crypto.PubKey) (err error
}

// @TODO(gfanton): should we handle this in a sub gorouting ?
e := evt.(protocoltypes.GroupMetadataEvent)
e := evt.(*protocoltypes.GroupMetadataEvent)
// start := time.Now()
if err := gc.handleGroupMetadataEvent(&e); err != nil {
if err := gc.handleGroupMetadataEvent(e); err != nil {
gc.logger.Error("unable to handle EventTypeGroupDeviceSecretAdded", zap.Error(err))
}

Expand Down
5 changes: 4 additions & 1 deletion internal/queue/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ var _ MetricsTracer[any] = (*noopTracer[any])(nil)

type noopTracer[T any] struct{}

// nolint:revive
func (*noopTracer[T]) ItemQueued(name string, item T) {}
func (*noopTracer[T]) ItemPop(name string, item T) {}

// nolint:revive
func (*noopTracer[T]) ItemPop(name string, item T) {}
2 changes: 2 additions & 0 deletions orbitdb_datastore_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type datastoreCache struct {
ds datastore.Batching
}

//nolint:revive
func (d *datastoreCache) Load(directory string, dbAddress address.Address) (datastore.Datastore, error) {
return datastoreutil.NewNamespacedDatastore(d.ds, datastore.NewKey(dbAddress.String())), nil
}
Expand All @@ -23,6 +24,7 @@ func (d *datastoreCache) Close() error {
return nil
}

//nolint:revive
func (d *datastoreCache) Destroy(directory string, dbAddress address.Address) error {
keys, err := datastoreutil.NewNamespacedDatastore(d.ds, datastore.NewKey(dbAddress.String())).Query(context.TODO(), query.Query{KeysOnly: true})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion orbitdb_many_adds_berty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func testAddBerty(ctx context.Context, t *testing.T, node ipfsutil.CoreAPIMock,
amountCurrentlyFound++
}

sub, err := gc.MessageStore().EventBus().Subscribe(new(protocoltypes.GroupMessageEvent))
sub, err := gc.MessageStore().EventBus().Subscribe(new(*protocoltypes.GroupMessageEvent))
require.NoError(t, err)
defer sub.Close()

Expand Down
Loading

0 comments on commit c0ab509

Please sign in to comment.