-
Notifications
You must be signed in to change notification settings - Fork 398
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
vscode: do not autoformat markdown or toml files #1994
Conversation
Summary: This caught me several times and several instances of autoformatting have slipped by in some of my commits; generally this is a PITA when you're doing something like modifying markdown files and Visual Studio Code "helpfully" autoformats the entire document for a 1-byte change, creating a 100+ line diff out of thin air. This is of course a function of the specified users autosave configuration and enabled extensions. I can't possibly account for everyone's integrations or workflows, but at least for me, I think, it's OK to turn off autoformatting here because we aren't enforcing a consistent one anyway. I do think that adding autoformatting for some of these things *may* be a good idea. But in the mean time I think this is just a helpful safeguard. As an example of this problem, I've included a small diff to remove a bunch of redundant whitespace from the top-level Cargo workspace file; this is exactly the kind of autoformatting that I think isn't good unless everyone agrees on it and it only serves to bloat diffs if someone changes it later (and no, there isn't really a standardized format for Cargo.toml yet from what I can tell — though, tellingly, the related style guides for Cargo.toml in the manual don't seem to recommend things like "add 60 characters of whitespace for no reason to align comments to column 80".) Signed-off-by: Austin Seipp <[email protected]> Change-Id: Iea17b611d58e65135fdc702f7b59f46c
Works for me 🤷 |
Does the project have a .editorconfig file? |
I actually checked (While I like |
I'm not a huge fan of this: if somebody set up autoformatting on save that actually works for them, why shouldn't it work in our repo? If somebody set up autoformatting on save that doesn't work for them, why should we prevent them from learning that they don't like their config? Either way, since this config doesn't make autoformatting work perfectly for our repo, I don't think it's worth making somebody's editor behave differently in our repo compared to another repo. My worry is that this will cause as much confusion as benefit. But this might be a wrong prediction and it is not a hill I'd die on; if this really makes people's lives more convenient, I'm OK with it. For TOML, formatting-on-save seems less important, so my feelings are less strong either way. As an aside, we'd benefit from a good Markdown auto-formatter; I'd rather standardize on some plugin (is "Prettier" good? I think it would work in other editors), set up a presubmit check, and use BTW, I set up formatting on save for |
Well, the same reason it happened to me: because it makes patches more annoying to write! If the autoformatter accidentally causes something to be committed, then undoing it is often an annoying dance of rigamarole, to either turn off those features, use another editor, etc. But also, I do want those autoformatters on my own projects. I just don't think they're appropriate here since, in lieu of a chosen style, it mostly will make patches more annoying to review. So I guess you could make an argument I should add my own
I'd also be really happy with this, but I'll be honest, part of the reason I submitted this instead of that is because formatting discussions can get into wonderfully long bikesheds. :) And I'm not sure that, unlike Rust or Go, there are clear standards in this area. But I actually would be 100% happy to have some standards here, if it looks like we can get something working for everyone.
Yeah, I also use rewrap actually. The |
I personally care much more that we have some standardized formatting than exactly what it looks like. |
I agree. I think the major issue is probably we don't want to tie someone to vscode, right? I haven't taken a poll, but I'd be little surprised if literally 100% of the active devs used it? (Or maybe we do, thanks to |
Ah, I thought you meant bikeshedding the details of how to format. I agree that don't require a particular editor. |
I looked into Markdown formatting a bit. I might try formatting the jj repo with the two options I found when I get a moment. I also don't want to create any barriers for first-time contributors that want to help us with documentation. Unfortunately, there seems to be no option that's trivial to install in the Rust ecosystem. So, I think any presubmit checks for Markdown formatting would have to be optional. PrettierPrettier seems to be pretty bad, at a glance. It converts As a pro, it's very well integrated in different editors. It can also be run with https://pre-commit.com/ (see below). MdformatThere's https://github.com/executablebooks/mdformat. (This is different than an internal Google tool of the same name). It claims to be better than Prettier, but doesn't have any editor integrations I could find. It only integrates with https://pre-commit.com/.
Since jj doesn't support pre-commit hooks, we'd probably have to run it with https://pre-commit.com/ manually ( Aside on pre-commit hooksI'm not sure whether pre-commit hooks designed for After writing this section, I realized there's #405 tracking this. I think it came to a similar conclusion. Update: MarkdownlintThere's a third option I haven't really explored, "markdownlint". It's a library and has a VS Code plugin. I'm not sure which CLI is best for use with markdownlint has a whole bunch of options. Aside on ChromiumFWIW, the Chromium project seems to have given up on formatting markdown. |
You can take a look at my first attempt at auto-formatting: ilyagr@mdformat and ilyagr@prettier. Clearly, we'd need to exclude some files from overly aggressive formatting (Update: Actually, changing some options helped a bit here), but this can give a taste of what it looks like. Also, you can try the Prettier also formats a bunch of non-md files. Pre-commit should be able to prevent that, I think. Prettier actually does pretty well. I'm worried a bit about prettier/prettier#11828, but it's theoretical for now. I guess I'd have to live with OTOH, we can also add a TOML formatter to the pre-commit hooks. Fortunately, neither of the tools has many options, so there's a limited space for arguing about the style if we use either of them. Update 2: I updated the configs to make them wrap text in ~similar way. Another thing that annoys me with prettier is that it changes code blocks defined with
into codeblocks defined with 4 spaces. Generally, I prefer the former. |
I found another interesting Markdown formatter: https://github.com/dprint/dprint. It's used by the |
While working on #2273 I was once again bitten by vscode "helpfully" doing autoformatting due to my settings using it by default, so to stop the diff from bloating, I had to snip out the relevant parts, put it in another file, Regardless of what we choose, I realize I'm not sure what kind of editor integration it will end up having, so I'd still like to see this merged. For example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I only skimmed the Conversion tab but I didn't see any objections from anyone else either.
It might have worked to use |
// then, such a feature tends to make diffs much worse and various people's | ||
// editors config may have some "helpful" plugins that autoformat these | ||
// filetypes, so this disables a footgun for everyone. | ||
"[markdown]": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very happy about this. For one, this is incompatible with somebody having another per-workspace config for their jj
repo.
I wonder whether VSCode provides some sort of "suggested config", so this'd work similarly to the envrc.recommended
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, BTW, whether this problem is theoretical or practical: do people often use .vscode/settings.json
for something else? So, if this matters to you enough (and the sort-of-solution from my other comment doesn't work), we could still go with it.
"[toml]": { | ||
"editor.formatOnSave": false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preferred (but imperfect) solution to such a usecase would be to have you put .vscode into a global gitignore or .git/exclude and have your own vscode config.
On problem I see with this is that finding the per-repo .git/exclude
with jj is tricky with non-colocated repos (I'm not even sure it's supported).
A version of this idea (which is currently hard to do) would be to provide a script that creates that setup.
Closing this for now, as there's division on this and it can be worked around locally for me in various ways. |
Summary: This caught me several times and several instances of autoformatting have slipped by in some of my commits; generally this is a PITA when you're doing something like modifying markdown files and Visual Studio Code "helpfully" autoformats the entire document for a 1-byte change, creating a 100+ line diff out of thin air.
This is of course a function of the specified users autosave configuration and enabled extensions. I can't possibly account for everyone's integrations or workflows, but at least for me, I think, it's OK to turn off autoformatting here because we aren't enforcing a consistent one anyway.
I do think that adding autoformatting for some of these things may be a good idea. But in the mean time I think this is just a helpful safeguard.
As an example of this problem, I've included a small diff to remove a bunch of redundant whitespace from the top-level Cargo workspace file; this is exactly the kind of autoformatting that I think isn't good unless everyone agrees on it and it only serves to bloat diffs if someone changes it later (and no, there isn't really a standardized format for Cargo.toml yet from what I can tell — though, tellingly, the related style guides for Cargo.toml in the manual don't seem to recommend things like "add 60 characters of whitespace for no reason to align comments to column 80".)
Change-Id: Iea17b611d58e65135fdc702f7b59f46c
Checklist
If applicable:
CHANGELOG.md