-
Notifications
You must be signed in to change notification settings - Fork 41
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
Allow cuddling an assignment and a variable declaration #82
Comments
Thanks for the report! I don't think I agree that they are they are the same. Not in the AST and not aesthetically either. Since there are two different ways to assign (or declare) I think they should be grouped by that way and not the fact that both might result in an assignment (which is not the case in your example). I know this is super opinionated but one of the nice benefits with the var (
x = 12345
someLonger = 55
andString = "stringy"
) Instead of this: x := 12345
someLonger := 55
andString := "stringy" If I want to separate declarations and assignments, that's possible in the var block like this, even though that is the kind of separation that you're against. var (
err error
x int64
assigned = 12345
someLonger = 55
) Personally I think it makes it clear and visually appealing to pick either or. Also, you have to imagine this in a bigger context. If we allow your example, this is also allowed: var (
err error
x int64
)
var foo = 10
bar := 1234
var (
fooErr error
assigned = 12345
)
biz := 123
notBizOrBaz := "x"
var bizErr error To me that's a mess and not really in line with this linters philosophy. So to sum it up, if you want all your assignments done with var err error
x := 12345 If you still want to use this linter and are using it with |
I didn't want to ignore the error as I feared that I would ignore more cases than I want. So you say I can ignore the error as it is really only about this specific case? As for your messy example...yeah, sure, looks strange. But consider this: first of all, no sane person would do that. If so, no linter can save them. Second, this is already allowed with var (
err error
x int64
)
var foo = 10
var (
fooErr error
assigned = 12345
)
var bizErr error How less bad that truly is? :D I personally use err := error(nil)
x := 12345
var err = error(nil)
var x = 12345 So all personal feelings about prefered syntax...is my example really different, so that it should be treated separately? var err error
x := 12345 Anyway, if you disagree, I accept that. If I can solve my issue by ignoring the error (and by that not ignoring something else), I'm fine with that :) |
Just to clarify/simplify even more: as you wrote in the second issue, I simply consider both |
Thanks for a great response and some good comments about the situation. I think we could land somewhere in the middle but since I don't think two wrongs make a right I don't want to just abandon the current behaviour without thinking it through. I see tow alternative ways forward here:
Other than that I'm not sure how to address this specific issue. At least I don't think I want to do some kind of limitation on assignments and declarations if there are less than X in a row etc. |
Sure, I'll let you decide how to move forward with this, as you know the linter better than anyone and also I can sign under the statement I'll ignore the error for now and wait for what you come up with :) Thanks for your time! Much appreciated |
I'll close this in favour of #83 since that's the preferred solution with some more details about how to implement it. |
I consider these two basically the same, and it's annoying that I have to split them. It makes the code look weird at some places. It's also weird when you realize that this is a perfectly fine way to do the same thing, just more verbose:
The text was updated successfully, but these errors were encountered: