4 ms·
I can wholeheartedly recommend Black for Python, gofmt for Go, and terraform fmt for Terraform. What are some other great formatters out there?
by philwelch 6y ago
I can wholeheartedly recommend Black for Python, gofmt for Go, and terraform fmt for Terraform.
What are some other great formatters out there?
- kevinastone 6y agoThe previously mentioned prettier[0] along with swift-format[1] and rustfmt[2]. [0]: https://prettier.io https://prettier.io [1]: https://github.com/apple/swift-format https://github.com/apple/swift-format [2]: https://github.com/rust-lang/rustfmt https://github.com/rust-lang/rustfmt
- wenc 6y agoAnother recommendation for Black. I use 'black -l 120' because the default PEP recommended 80 chars per line is too restrictive.
- minimaxir 6y agoBlack uses a 88 char per line limit. In the course of normal Python coding I rarely hit it. For public code I do not recommend changing the defaults since it may make PRs a mess.
- philwelch 6y agoThe 88 character limit is just a best effort thing anyway. I find the double-quote coercion more disruptive.
- wenc 6y agoI started programming in the 80s, so I'm used to double-quoting anyway. Apostrophes occur so often in English that it makes it easier to type strings like "I'm a dog". With single quoting you have to go 'I\'m a dog'. If I hit double quotes in a string, I just triple-quote. """He said "hah" sarcastically""". I know Guido (van Rossum) prefers single quotes -- I'm not sure why exactly -- so it's become a default Python style. I tried to adopting it but always ended up reverting to double quotes.
- _bohm 6y agoI use single quotes simply because I'm lazy and tapping the quote key with my pinky is marginally easier than shift-quote :p
- a1369209993 6y ago> I'm not sure why exactly Might be ease of typing? Eg: `foo = 'bar'` doesn't require any shift chords, whereas `foo = "bar"` requires two. Though then I'd expect similar preference for kebab-case in identifies, for similar reason.
- wenc 6y agoYes, that must be right, although to me the trade-off is escaped strings which lack good aesthetics. 'The class of \'72 didn\'t think much of Sam\'s speech' vs "The class of '72 didn't think much of Sam's speech" To me, the shift chord is an almost negligible price to pay for more aesthetically pleasing strings, especially since on a QWERTY keyboard, the shift key is literally right next to the ' key. For emacs users who are used to complex key chords, it's even more negligible. I do use single quotes for strings frequently in interpolated f-strings though: f"The date is {result['year']}"
- chrismorgan 6y agoUnless I mean straight quotes, I type curly quotes as a matter of course. Love my Compose key. :)
- mintplant 6y agoI maintain Lavender as a Black alternative with single-quote support. https://github.com/spinda/lavender https://github.com/spinda/lavender
- leadingthenet 6y agoBut the double quotes are exactly what I like about Black haha.
- minimaxir 6y agoThat, I've gotten surprisingly used to. (atleast Black is smart about using single-quotes instead if you use double-quotes in a string)
- Guillaume86 6y agoI wish there was good C# one (and ideally a standard one like go). When switching between typescript with prettier and C# the first thing I notice is the lack of autoformating. edit: seems https://github.com/dotnet/format https://github.com/dotnet/format is the closest thing
- sethreno 6y agoI wish their was a standard c# formatter too. dotnet-format doesn't support wrapping long lines which is one of the more important features in my opinion. Resharper has a free command line tool that supports wrapping long lines. https://www.jetbrains.com/help/resharper/CleanupCode.html https://www.jetbrains.com/help/resharper/CleanupCode.html I made a wrapper for it to try and make it easier to use. https://github.com/sethreno/ReGitLint#regitlint https://github.com/sethreno/ReGitLint#regitlint
- Guillaume86 6y agoThanks I will check it out
- Merad 6y agoReSharper's formatter is pretty good, but you do have to pay to use it in the VS IDE and it's kind of slow. The service I'm working on at present is fairly small (20k LOC) and formatting the entire solution takes about 5 minutes in the IDE or 30 minutes in CI. :/
- sethreno 6y agoIs your service open source? I'd be interested in testing it. Also, you could speed up formatting in CI by only formatting files that changed.
- Merad 6y agoNah, this is from my day job so it's a proprietary closed source thing. Supposedly the CI speed issues are because the CI has to start with cold caches every run (we use Gitlab pipelines that run in docker containers) whereas the IDE has the caches on hand. Something about the way our devops has set up the Gitlab runners makes enabling shared cache much hard than it should be so I haven't had the chance to test that. I don't think I ever tried limiting it to only changed files, that's worth a shot.
- The_rationalist 6y agoWe use klint at work (Kotlin) https://github.com/pinterest/ktlint https://github.com/pinterest/ktlint It's take inspiration from standardjs and gofmt
- ScoutOrgo 6y agoI really want one for sql, but haven't found any good ones available.
- reledi 6y agomix format for Elixir rubyfmt for Ruby
- koreth1 6y agoGoogle-java-format for Java and ktfmt for Kotlin. https://github.com/google/google-java-format https://github.com/google/google-java-format https://github.com/facebookincubator/ktfmt https://github.com/facebookincubator/ktfmt