Comments (5)
Agreed that the rules should be simple.
I'll go ahead with leaving const and import groups alone, most likely pushing the commit tomorrow. I'll reopen this issue to remind myself.
Thanks again for the helpful feedback - it was useful to help me make a good decision!
from gofumpt.
Perhaps a simple way to stop annoying developers is to not simplify declaration groups (parentheses) if there is a comment attached to the whole group. I agree that the docs can be broken very easily in this case.
Would that make the rule less painful for you?
from gofumpt.
It would certainly make it less painful, as there'd be fewer cases where a block of mine got destroyed.
However, in a common case where I write a const (…)
block but fail to preemptively add a doc comment, I'd still get the scope destroyed. Knowing my habits, I'd save (and therefore run gofumpt) before putting the doc comment. Then I'd need to add a doc comment (possibly only to disable the block destruction) and put the parentheses back in. I'd grumble about it the entire time, and that's with me knowing the "doc comments disable const (…)
flattening" rule. If I didn't know about doc comments, I'd have to search Stack Overflow for an explanation, as gofmt doesn't do anything like that AFAIK.
Furthermore, if I were left with an iota at file scope (as in my example above) I'd be outright confused by what the intent of the code was. I'd be quadruply confused if I had two separate iotas at file scope, lifted there out of two separate const blocks.
from gofumpt.
Thanks for the extra information. The original issue was about the buggy comment behavior, so I've closed the issue as fixed for now.
Knowing my habits, I'd save (and therefore run gofumpt) before putting the doc comment.
I tend to run gofmt/gofumpt manually myself; perhaps this is why I don't see the pain as often.
The point about iotas is a good one. We could skip the rule if the declaration group contains an iota
identifier, though.
Aside from the comment and iota points, I'd still like to keep the rule around; I don't think people should commit unnecessary declaration groups to branches. Do you have any more ideas to reduce the annoyance, aside from removing the rule entirely?
For example, perhaps the rule could be relaxed to only work on var declarations. Top level imports and consts tend to grow over time, but top-level vars don't tend to as much. And I think most of the real cases I've seen in the wild have involved vars, and not consts/imports. I'm not bothered by unnecessary groups in imports, actually, but I only included them for consistency.
from gofumpt.
Do you have any more ideas to reduce the annoyance, aside from removing the rule entirely?
Nothing comes to mind. Plus, having a long list of exceptions makes it hard for a user to understand when gofumpt will change the code he's working on. When a user can't predict what a tool will do, that makes it effectively nondeterministic to him. This unpredictability is its own source of annoyance.
Generally, when I see a one-item const block, I think "this too shall pass", figuring that more constants will be added later. The one-item const block won't be an eyesore for all that long, relative to the time the codebase will last.
from gofumpt.
Related Issues (20)
- Multiline blocks allow newline before closing brace HOT 1
- Enforce some consistency with newlines at the start and end of parameter lists HOT 3
- Unnecessary newline in arguments when putting type parameters on a separate line
- Document WHEN generated code is touched and how to mitigate it HOT 2
- gofumpt badge HOT 1
- Fails to install with Go 1.20.3 HOT 1
- Panic on formatting of multiple files
- Don't group variables when //go:embed is present. HOT 2
- No empty lines before a simple error check not working HOT 2
- gofumpt conflicts with goimports-reviser based import formatting. HOT 1
- Feature suggestion: Distinguishing between ex-repo, intra-repo, and internal packages HOT 3
- Using rewrite rules with gofumpt HOT 3
- Fail to install HOT 4
- different output for stdin vs passing in filename HOT 1
- Feature: Handling of closing parenthesis on function calls HOT 2
- make breaking long lines manually easier by reading off of trailing commas
- Tracking issue: go release tag fails semver version check HOT 2
- Members of struct after Pass-through type inside struct's formatting is ignored HOT 2
- install as a CLI HOT 2
- Remove empty lines in if and for similar to functions HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gofumpt.