Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

b00ris
Copy link
Contributor

@b00ris b00ris commented Oct 9, 2017

This PR fixes gometalinter warnings ( #281) except dubl linter.

@divan
Copy link
Contributor

divan commented Oct 9, 2017

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..

@divan divan changed the title fix linters except dupl Fix linters' warnings Oct 9, 2017
@@ -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{
Copy link
Contributor

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?

Copy link
Contributor Author

@b00ris b00ris Oct 9, 2017

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@tiabc
Copy link
Contributor

tiabc commented Oct 9, 2017

Setting #371 as a blocker to merge it after it.

@b00ris
Copy link
Contributor Author

b00ris commented Oct 9, 2017

@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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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??)
Copy link
Contributor

@tiabc tiabc Oct 9, 2017

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//nolint: errcheck?

Copy link
Contributor Author

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() {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

Copy link
Contributor

@tiabc tiabc left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so long?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i could fix it after #383 and #375

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@tiabc
Copy link
Contributor

tiabc commented Oct 11, 2017

Please, resolve conflicts and let's merge it.

@b00ris
Copy link
Contributor Author

b00ris commented Oct 12, 2017

@tiabc I'm going to do it after deploying faucet for rinkeby at #383

@b00ris b00ris mentioned this pull request Oct 19, 2017
@b00ris
Copy link
Contributor Author

b00ris commented Oct 19, 2017

Made separated #417 PR from local repository.
My miss. I've done it from my fork.

@b00ris b00ris closed this Oct 19, 2017
tiabc pushed a commit that referenced this pull request Oct 20, 2017
fixed make lint warnings
cleared linter_exclude_list.txt
removed some commented code
fixed comments from #388
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants