-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use stylua_lib::{format_code, BraceSpacing, Config, OutputVerification}; | ||
|
||
fn format(brace_spacing: BraceSpacing, input: &str) -> String { | ||
format_code( | ||
input, | ||
Config::default().with_brace_spacing(brace_spacing), | ||
None, | ||
OutputVerification::None, | ||
) | ||
.unwrap() | ||
} | ||
|
||
#[test] | ||
fn test_table_oneline_with_internal_spaces() { | ||
insta::assert_snapshot!( | ||
format(BraceSpacing::Always, | ||
r###" | ||
local foo = { "content" } | ||
"### | ||
), | ||
@r###" | ||
local foo = { "content" } | ||
"### | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_table_oneline_without_internal_spaces() { | ||
insta::assert_snapshot!( | ||
format(BraceSpacing::Never, | ||
r###" | ||
local foo = { "content" } | ||
"### | ||
), | ||
@r###" | ||
local foo = {"content"} | ||
"### | ||
); | ||
} |