-
Notifications
You must be signed in to change notification settings - Fork 246
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
Fix linters' warnings #388
Conversation
I think this PR should not touch tests, until #375 is merged. Probably would be hard to resolve the conflicts after the huge changes and file movements in mentioned PR. LGTM otherwise.. |
@@ -835,7 +837,7 @@ func testCompleteMultipleQueuedTransactions(t *testing.T) bool { | |||
|
|||
// this call blocks, and should return when DiscardQueuedTransaction() for a given tx id is called | |||
sendTx := func() { | |||
txHashCheck, err := statusAPI.SendTransaction(nil, common.SendTxArgs{ | |||
txHashCheck, err := statusAPI.SendTransaction(context.TODO(), common.SendTxArgs{ |
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.
Good catch! By the way, why TODO
instead of Background
?
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.
@tiabc Both of them are empty context.
context.Background
- need empty context.
context.TODO
- it's unclear which Context to use.
It helps us to find all unclear context usage later.
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 here we have a test. Do we want context.TODO
to draw our attention here? I guess context.Background
is perfectly fine or let's use context.WithTimeout
to prevent from running forever.
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.
Scope of this issue could grow fast. I use it, because the issue is fix linters warnings. I think Adding context.WithTimeout to tests
is separated issue and we could do it, if we need.
Setting #371 as a blocker to merge it after it. |
@divan most of the affected files are related to tests =( |
@@ -218,7 +218,8 @@ func (m *Manager) SelectAccount(address, password string) error { | |||
return err | |||
} | |||
|
|||
if err := whisperService.SelectKeyPair(accountKey.PrivateKey); err != nil { | |||
err = whisperService.SelectKeyPair(accountKey.PrivateKey) | |||
if err != nil { |
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.
Please, refrain from refactoring in regular issues in the future. Even if you don't like the code. We only do refactoring in refactoring issues to ease merging.
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.
There is no refactoring. I've fixed variable shadowing
@@ -195,6 +195,7 @@ func (api *StatusAPI) JailBaseJS(js string) { | |||
api.b.jailManager.BaseJS(js) | |||
} | |||
|
|||
// Notify (push notification and mailbox??) |
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.
Notify sends a push notification to the device with the given token.
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.
Got it.
@@ -123,5 +123,5 @@ func (s *APITestSuite) TestRaceConditions() { | |||
} | |||
|
|||
time.Sleep(2 * time.Second) // so that we see some logs | |||
s.api.StopNode() // just in case we have a node running | |||
_ = s.api.StopNode() // just in case we have a node running |
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.
Well, this is a test and not of s.api.StopNode
and we don't really care.
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's only fixing errcheck linter warning.
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.
//nolint: errcheck
?
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's another way, but i've changed it to nolint. It's more faster way to find all nolint tags.
return err | ||
} | ||
|
||
return nil | ||
_, err = t.cb.Call(otto.NullValue(), arguments...) | ||
return err | ||
} | ||
|
||
func (t *fetchTask) Cancel() { |
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.
Hasn't golint blamed this line?
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.
No
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.
First of all, outstanding execution!
Please, resolve written comments and re-file the PR from the local repo. Also, the branch name should be bugfix/fix-linters-warnings-387
.
I'll revisit the PR after I merge #375 and you resolve appeared conflicts, if any.
} | ||
|
||
err = vm.Set("clearImmediate", clearTimeout) | ||
return err |
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.
Just return vm.Set...
as you've already done in other places?
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.
In that case it's more clear for me. A lot of errchecks.
@@ -88,7 +90,7 @@ func (s *PromiseSuite) SetupTest() { | |||
s.vm = vm.New(o) | |||
s.loop = loop.New(s.vm) | |||
|
|||
go s.loop.Run() | |||
go s.loop.Run(context.TODO()) //nolint: errcheck |
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.
New argument? How did it work before?
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 was not working after merge.
@@ -441,7 +441,7 @@ func (s *ManagerTestSuite) TestNodeStartCrash() { | |||
require.NoError(err) | |||
|
|||
// start node outside the manager (on the same port), so that manager node.Start() method fails | |||
outsideNode, err := node.MakeNode(nodeConfig) | |||
outsideNode, _ := node.MakeNode(nodeConfig) |
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.
Why?
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.
Nice catch! Fixed.
@@ -137,9 +137,9 @@ func (s *TxQueueTestSuite) TestCompleteTransactionMultipleTimes() { | |||
wg.Add(1) | |||
go func() { | |||
defer wg.Done() | |||
_, err := txQueueManager.CompleteTransaction(tx.ID, TestConfig.Account1.Password) | |||
_, errCompleteTransaction := txQueueManager.CompleteTransaction(tx.ID, TestConfig.Account1.Password) |
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.
Why so long?
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.
Why not? It's obvious name.
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.
Yes but why so long? Why not just e
? Usually, the longer a variable name, the broader its scope.
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 could be e. But.. Why not?) In that case what should be next name of error after e? ee?
errCompleteTransaction is obvious name. It's simple. You don't need to comment it.
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.
There won't be another case. If there's, the name will be just longer. Anyway, it's just a matter or taste, I prefer longer variables for broader scope and shorter for narrower. Following and knowing this rule just makes you understand existing code faster.
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.
Is this rule fixed in our docs? Should we check "a matter or taste" on code review?
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.
Sorry?
Docs is not what's doled out to us, this is what we ourselves create during open discussions. If there's something you follow which makes code better, why shouldn't you share it?
I'm not asking to fix that based on my matter of taste, by that I'm saying my comment isn't relevant any more as the matter isn't worth the efforts discussing it.
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'll try to describe better my point.
As far as i know we are going to make oun community. If so we need strict CR rules on which all major contributors agreed. If we all agred that "less scope = shorter name", this should be fixed in doc to be project standard for core developers and all new contributers.
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 agree but your question was strange given that we don't have such a document yet at all and I never asked to fix anything due to just my taste.
And not all comments are major, some of them are just for discussion like this one and written along with major comments. Or they're just some questions.
comment on exported function StopCPUProfiling should be of the form "StopCPUProfiling ..." (golint) | ||
comment on exported function WriteHeapProfile should be of the form "WriteHeapProfile ..." (golint) | ||
comment on exported function Notify should be of the form "Notify ..." (golint) | ||
type name will be used as node.NodeManager by other packages, and that stutters; consider calling this Manager (golint) |
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 think it's more reasonable to refactor this. Can you delete this line and add a note to #200?
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 fully support this. I'll add note to #200.
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.
done.
@@ -95,47 +95,47 @@ lint-cur: | |||
|
|||
lint: ##@tests Run meta linter on code |
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 wonder if we can replace all these lines with:
gometalinter $(LINT_EXCLUDE) --disable-all --enable=vet --enabled=gofmt --enable=goimports [--enable=...] cmd/... geth/...
And I guess this linter_exclude_list.txt
can be removed as we can use // nolint: golint
for individual functions?
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.
Yes, we could call gometalinter as you offered, but for me it's less convinient to use.
About linter_exclude_list.txt i fully agree with you. I had to switch to #383 and push as is.
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.
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.
done
Please, resolve conflicts and let's merge it. |
Made separated #417 PR from local repository. |
fixed make lint warnings cleared linter_exclude_list.txt removed some commented code fixed comments from #388
This PR fixes gometalinter warnings ( #281) except dubl linter.