-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Golint: fix golint warnings in merkledag submodule #4665
Conversation
License: MIT Signed-off-by: Hector Sanjuan <[email protected]>
f0b163e
to
2d138b0
Compare
merkledag/merkledag.go
Outdated
// NewDAGService constructs a new DAGService (using the default implementation). | ||
func NewDAGService(bs bserv.BlockService) *dagService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does golint really complain about this?
I actually prefer to return concrete types whenever possible. It helps to deal with multiple potentially fulfilled interfaces. For example, if *dagService
implements X
which is a superset of DAGService
, I can pass NewDAGService
to something that wants an X
without extra type assertions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want me to export dagService
instead?
merkledag/merkledag_test.go
Outdated
@@ -241,9 +242,10 @@ func TestFetchGraph(t *testing.T) { | |||
// create an offline dagstore and ensure all blocks were fetched | |||
bs := bserv.New(bsis[1].Blockstore(), offline.Exchange(bsis[1].Blockstore())) | |||
|
|||
offline_ds := NewDAGService(bs) | |||
// we know the default dagService implements LinkGetter | |||
offlineDS := NewDAGService(bs).(ipld.LinkGetter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly the case for having NewDAGService
return the concrete type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it is a case only used in tests (and tests in the same module). From an external user's point of view, it's not possible to know what *dagService can do because it's unexported.
Thank you!! Everything except the DAGService return type LGTM... If golint really complains about that it makes me a tad bit sad. |
I agree and I want to emphasis that we don't have to follow all off golints suggestions. If this will cause codeclimate to complain we should add exception. |
It does this for a (possibly debatable) reason. The lint disallows returning unexported types because they can't be named outside the package. |
License: MIT Signed-off-by: Hector Sanjuan <[email protected]>
Ok, I have reverted to what it was before and get the expected:
If it is valuable that this is used as a |
merkledag/errservice.go
Outdated
@@ -14,28 +14,34 @@ type ErrorService struct { | |||
|
|||
var _ ipld.DAGService = (*ErrorService)(nil) | |||
|
|||
// Add returns an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this description confusing, rather than say "an error" something like "returns ErrorService.Err" or maybe just "returns the error" rather than "an error".
merkledag/errservice.go
Outdated
func (cs *ErrorService) Add(ctx context.Context, nd ipld.Node) error { | ||
return cs.Err | ||
} | ||
|
||
// AddMany returns an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
merkledag/errservice.go
Outdated
func (cs *ErrorService) AddMany(ctx context.Context, nds []ipld.Node) error { | ||
return cs.Err | ||
} | ||
|
||
// Get returns an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Etc.
@@ -23,7 +23,13 @@ func init() { | |||
ipld.Register(cid.DagCBOR, ipldcbor.DecodeBlock) | |||
} | |||
|
|||
// contextKey is a type to use as value for the ProgressTracker contexts. | |||
type contextKey string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would export this type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has no use outside. If someone ever has a use, it can be exported then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, your right. Sorry.
Per @kevina's comments License: MIT Signed-off-by: Hector Sanjuan <[email protected]>
FYI,
In general, users shouldn't care if something is a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One import nit. Otherwise, LGTM. ❤️
merkledag/merkledag_test.go
Outdated
@@ -13,6 +13,8 @@ import ( | |||
"testing" | |||
"time" | |||
|
|||
blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be grouped with cid
, u
, etc. (we group by standard, in-repo, then out-of-repo).
License: MIT Signed-off-by: Hector Sanjuan <[email protected]>
opps. fixed @Stebalien |
This fixes all golint warnings in merkledag (except in protobuf generated code).
Main change of note is that
NewDAGService
returns anipld.DAGService
and not a non-exporteddagService
.