Repository navigation
Add gocondense formatter #6860
Replies: 4 comments 4 replies
|
Notes on the checklist, since it's written for linters:
The integration is implemented and tested on a branch of my fork: https://github.com/abemedia/golangci-lint/tree/feat/gocondense |
|
This is a style that decreases readability. Examples: - args: []string{
- "--my-custom-flag",
- },
+ args: []string{"--my-custom-flag"},- cmd := foobar.NewBuilder(t).
- WithPath(path).
- WithArgs(args...).
+ cmd := foobar.NewBuilder(t).WithPath(path).WithArgs(args...).IMHO readability is more important than the number of lines, so clearly not my style, or a style I would recommend. Also, I think there is no configuration that can be added to make the formatter more relevant. But this is a possible opinion: readability < LOC. |
|
This kinda addresses segmentio/golines#98 (also tracked in golangci/golines#2), but with a bunch of extra rules as well. I think for me ideally this would be a feature there, but I understand this is a completely different implementation. I think there are several examples in the readme that feel relevant to me such as collapsing empty blocks, removing redundant parens/identifiers, trimming blank lines and empty functions and more. I also think condensing function signatures makes sense, especially together with golines, which would automatically handle them just like I think I don't see much of a problem with the examples above either, but maybe something like this is something I'd keep for readability: func fn() {
+ a := []string{"foo", "bar", "baz"}
- a := []string{
- "foo",
- "bar",
- "baz",
- }
}Less config is good, but in this case maybe opting in or out of specific parts would tailor it to broader usage? Alternatively or additionally for the case above an option for the number of struct or slice members for it to condense. I agree with the statement that readability is more important than LOC, but I also think readability ties together with consistent code and having a uniform way to both wrap and unwrap lines would be ideal to me, that means all code will always look the same no matter how long a line is. |
|
Thanks for reviewing @ldez & @bombsimon. I really like the simplicity of Prettier where there are no options to control whether or not to condense arrays & chains. I will however concede that Prettier has a heuristic to only condense arrays and chains that are considered trivial e.g. strings, numbers etc. Another option would be something similar to rustfmt which defaults to only condensing arrays & chains that are under 60% of the If I had to choose I personally would prefer the former. Right now arrays & chains are always condensed if the entire expression fits within |
Uh oh!
There was an error while loading. Please reload this page.
Repository URL
https://github.com/abemedia/gocondense
Analyzer Requirements
go/analysis.go.mod<= 1.26.0.Analyzer Goal
Style
Analyzer Description
A gofmt-compatible formatter that condenses multi-line constructs (calls, literals, signatures, expressions) onto single lines where they fit within a configurable line length.
Analyzer License
MIT
Analyzer License Checks
LICENSE(capitalized).Analyzer Details
init().panic().log.Fatal().os.Exit().Repository Details
v1.0.0,v0.1.0(0.0.xare not valid).Repository Recommendations
.gitignore(IDE files, binaries, OS files, etc. should not be committed).mainas the default branch name.Pull Request
All reactions