-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add linter pairedbrackets #3225
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
This kind of linter already exists inside golangci-lint. |
What linter does the same? I haven't seen it. |
At least: gofumpt |
As I noted in readme, For example it isn't complain about following (all of them are good for
|
🤔 Your example: fmt.Printf("%s, %s!",
"Hello", "world") is not bad from my point of view, it's common when the pattern is long or to improve readability. I evaluate the other example as more bad than good: fmt.Printf(
"%s, %s!", "Hello", "world",
) Otherwise, I'm checking the other linters. |
I understand you, and I'm sure you are not alone. There are a lot of opinionated linters in golangci-lint. |
yes there are opinionated linters but here I see more false-positive than opinion. A lot of people (I think the majority) enable all linters and try to follow them. So the default behavior of linter must be something that we can recommend. |
Just to be clear, I'm just chatting. |
@bombsimon what is your opinion? |
👌
I've run the linter on our code base and found false positives only in tests:
I can add a config to ignore all function calls by default. |
I think the "ignore function calls" is not a good option, because I don't want to ignore rules with some functions, I just want to ignore some recommendations. Also, I don't understand the default exclusion of the testify functions. |
There are also some problems with the other elements, for example with Composite literal: if I want to have a slice with values organized by pair (like with the |
I didn't get your point about composite literals. Following is a good format according to strings.NewReplacer([]string{
"a", "A",
"b", "B",
}...) It doesn't expect items to be formatted in one column. It just checks opening and closing brackets. |
I think this linter makes sense and as someone that in general appreciate consistent styling I would probably even use this myself (although that doesn't really matter). I think the reasoning around the linter, the link to the article and the clear examples is more than enough to argue for its use case. It's absolutely opinionated but like you both stated that goes for a lot of the linters in I agree I think I agree with all cases the linter enforces except the one that @ldez pointed out. To me, this is "balanced" and paired (left parenthesis and first argument on same line, last argument and parenthesis on same line). Maybe an option to allow this? fmt.Sprintf("This is too long for one line but ok for two %s: %d",
someString, someInt) Regarding |
I think we need data about that because we are just expressing opinions 😸.
I do that too, but I have seen different behavior with the handle of a new linter:
This is why for me the default behavior is really important. |
You are right! 👍
Makes sense and I agree. With that in mind maybe a default "relaxed" mode would be nice with the option to be more strict if desired. From my point of view the only needed change would be to allow the above example by default and optionally disallow it for those who don't agree and care to read the docs. All the others, including the ones in the readme, makes sense and is easy to understand why they're there in my opinion. I guess such a relax mode would do the same for functions and composite literals as well although that makes way less sense to me personally. 😄 func Foo(a int,
b string, c bool) {
...
}
func Foo() (int,
error) {
...
}
foo := []int{1,
2, 3} |
Google published their style guide recently. Looks like they use "relaxed" version of linter's rules (link1, link2):
Will you accept the linter to be a part of golangci-lint, if I change it?
|
Yes if your linter handles the cases we talked about. |
@maratori |
I will close this PR because:
Feel free to open a new PR, when the linter and the implementation inside golangci-lint will be updated. |
pairedbrackets
is a linter that checks formatting of paired brackets.https://github.com/maratori/pairedbrackets