-
Notifications
You must be signed in to change notification settings - Fork 100
chore: remove duplicate imports. #3306
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
Conversation
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.
So where is the script? 😁 Could it be added to CI?
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/bitsurance" | ||
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc" | ||
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin" | ||
coinpkg "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin" |
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 in case of dups, you should keep the named one and remove the unnamed one. The reason for naming these imports is to avoid clashes or generic names. func foo(coin coin.Coin)
is no good 😅
Not sure what the idiomatic way is, as I assume renaming imports is not very idiomatic. I am afraid it might be one letter var name like func foo(c coin.Coin)
, but I hate short names with a passion.
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 in case of dups, you should keep the named one and remove the unnamed one. The reason for naming these imports is to avoid clashes or generic names.
func foo(coin coin.Coin)
is no good 😅
Not sure what the idiomatic way is, as I assume renaming imports is not very idiomatic.
Exactly, according to this: https://google.github.io/styleguide/go/decisions#import-renaming imports shouldn't be renamed unless there are good reasons
The reason for naming these imports is to avoid clashes or generic names.
func foo(coin coin.Coin)
is no good 😅
I don't think this is solved by renaming the package import:
func foo (coin coinpkg.Coin)
doesn't look much better imho. In general having a type Coin
in a package coin
will inevitably leads us to situations like these.
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.
func foo (coin coinpkg.Coin)
doesn't look much better imho
I should have been more specific. It's not the optics, it's about the name shadowing. Inside the foo
function you can't use the coin
package anymore b/c it's shadowed by the coin
argument. It's a bit silly that vars and packages live in the same namespace in Go, but since it is, we should not shadow.
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'd personally argue that it is better to rename the argument rather than the package (smaller scope, and it's easier to find a more meaningful name for an arg rather than a pkg) but I will not fight over it :D I'll make the changes!
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 not a fight 😄 I think your point makes sense and I'm okay with it too.
Well there's the script:
It can probably be added to the CI but I would rather write something non in bash :) easier to test and maintain |
c0b95f6
to
c8fe216
Compare
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.
@benma this is ready for review again. I changed it so that in case of duplicate imports, the unnamed one is removed and the aliased one is kept.
Let me know if you want me to write a proper linter/script that detects duplicate imports; I have some free cycles to work on it but I'd prefer to have it in a proper programming language :)
backend/accounts.go
Outdated
@@ -969,7 +967,7 @@ type scriptTypeWithKeypath struct { | |||
keypath signing.AbsoluteKeypath | |||
} | |||
|
|||
// adds a combined BTC account with the given script types. | |||
// adds a combined BTC account with the given script accountsTypes. |
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.
wrong search&replace
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.
whoops!
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.
Fixed together with a few others, thanks for catching it!
c8fe216
to
91fa2b6
Compare
Inspired by #3298, I had ChatGPT come up with an ugly but working bash script that finds all duplicate imports. It looks like golangci doesn't have a linter for this specific.
Before asking for reviews, here is a check list of the most common things you might need to consider: