-
Notifications
You must be signed in to change notification settings - Fork 72
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
Add brace_spacing
option
#628
base: main
Are you sure you want to change the base?
Conversation
To be honest, I have mixed feelings about adding options to formatters (maintainability, fragmentation of the community). Even if this is rejected, I hope it will shed some light on #620. Regardless, I will definitely use this tool so thank you for it! Also, I found it very easy to modify. |
An interesting thing that prettier does, is that it doesn't have spaces around array braces, but does in object braces (to be fair, maybe because they are 2 different syntax constructs in JS/TS, but not in Lua). I wonder if that would be an interesting middle ground? Regardless, for all options I tend to not make them boolean but instead enums, so that they can be extended later (and also makes it slightly easier to understand what the option does) No promises on whether this will be merged or not, but just some thoughts! |
Braces, used for table construction, are typically used with spaces inside them: ```lua t = { "content-0" } ``` There can be another style, however, which consists in sticking the braces to the content: ```lua t = {"content-0"} ``` This work adds a configuration parameter `brace_spacing: BraceSpacing` (`Always`, `Never`) to control the spacing inside table constructors and enable the use of the second style. This is similar to [Prettier's bracket spacing option](https://prettier.io/docs/en/options.html#bracket-spacing). Which style is better is debatable, of course. In my quick research, I listed what the formatters I know do: - rustfmt (Rust): space - OCamlFormat (OCaml): space, configurable - Prettier (JavaScript, TypeScript): space, configurable - Black (Python): no space - Clang-Format (C, C++): no space, configurable
e62246a
to
256e5e0
Compare
I'm not sure because in Lua you can mix the two forms in the same literal: table = {"x", "y", a = "z"}
-- or
table = { "x", "y", a = "z" } Lua is pretty wild. :)
Done! I also added the |
Just came here to say that I've been pretty happy with StyLua so far except for this one missing feature. Please consider merging! I'll note too that while Roblox (and I realize this is not just about Roblox, but they do constitute a significant group of Lua(u) developers) doesn't take an official stand on it in their style guide, most documentation examples follow the form of having no outer edge spacing, so that is likely to be the form that many developers on the platform learn and use. As for fragmenting the community or causing divides by adding options, I wouldn't worry about that. StyLua is presented as an opinionated code formatter, and I don't see why we can't use it to implement our own opinionated formatting. Customization options seem to only be beneficial to me. We are also already given options for different parts like quote formatting, so this is entirely appropriate imo. |
Agreed!
Agreed as well. If anything, allowing for more configuration should have the opposite effect of fragmentation, by allowing people with different opinions to use the same tool, as long as the configuration is agreed upon at the project level. |
I will voice my support for this, it's the one thing in stylua that I don't like. We have very deeply nested table definitions and the extra spaces waste a lot of line length. |
just a note: editorconfig proposes: It's mentioned in the section: |
Braces, used for table construction, are typically used with spaces inside them:
There can be another style, however, which consists in sticking the braces to the content:
This work adds a configuration parameter
brace_spacing: BraceSpacing
(Always
,Never
) to control the spacing inside table constructors and enable the use of the second style. This is similar to Prettier's bracket spacing option.Which style is better is debatable, of course, and so is the configurability. In my quick research, I listed what the formatters I know do:
Closes #313