wsl
wsl copied to clipboard
Check when spaces are not needed
I enabled this tool for my pipeline but now I'm seeing more spaces than needed like:
a := 1
if a == 1 {
...
}
Thanks for the report!
What do you mean? The tool currently does not add spaces, but warns about the lack of them. You should be able to cuddle the code above without a warning like this:
a := 1
if a == 1 {
...
}
If you have more assignments than a
on the line above the if statement, the reasoning behind that can be found e.g. in #71 and #33 and also described in the rules. Either separate all of them or separate a
from the rest of them. Or, assign multiple variables on the same line.
If you don't have any other assignments above a
that would be a bug.
Ninja edit: Oh, do you mean the linter should warn about the newlinew between the assignment and the if statement? If so, I think that would be a major job to define a rule set where empty lines should be removed other than in the beginning or end of blocks. If this is what you meant, do you have any thoughts about how to define such rule set?
yes your edit is right, some devs are adding extra spaces after the assignment when it's not needed (and doesn't look good)
I think this will be very hard to achieve, we don't know why someone adds empty lines and since it's something that's encouraged by this linter I don't want to limit that. Consider this:
carName := "Volvo"
carModel := "XC90"
carYear := 2020
bikeName := "Scott"
bikeModel := "Spark RC"
bikeYear := 2023
If we blindly remove empty lines when they're not needed we would group that together which I don't think is the right approach. I agree with your example but I think that's about the only example; a single statement before a block where the variable is immediately used.
I'm tempted to close this as a wontfix but before I do that I want to ask if you had some kind of ruleset in mind that would be a subset of all the rules where we can guarantee this will always make sense?