Skip to content
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 inner spacing to inline objects (non-empty) - BREAKING #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions tests/examples/sorted/inline-default.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[a]
test = [
{x = [
"foo",
"bar"
], a = [
""
]},
{y = [
"foo",
"baz"
]}
{ x = [
"foo",
"bar"
], a = [
""
] },
{ y = [
"foo",
"baz"
] }
]

[b]
Expand All @@ -24,18 +24,18 @@ alist = [
# Second attached comment
'a'
]
'aalist' = {c = "test", a = "another test"} # list comment
'aalist' = { c = "test", a = "another test" } # list comment
# Multilevel inline array
aaalist = [
[
{name = "Homer Simpson", town = "Springfield"}
{ name = "Homer Simpson", town = "Springfield" }
],
[
{name = "Bart Simpson", town = "Springfield"}
{ name = "Bart Simpson", town = "Springfield" }
],
# Weird block comment
[
# Another weird block comment
{name = "Lisa Simpson", town = "Springfield", a-test = "Did this sort?"} # Should get sorted
{ name = "Lisa Simpson", town = "Springfield", a-test = "Did this sort?" } # Should get sorted
]
]
28 changes: 14 additions & 14 deletions tests/examples/sorted/inline-no-comments-no-table-sort.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[b]
aaalist = [
[
{a-test = "Did this sort?", name = "Lisa Simpson", town = "Springfield"},
{ a-test = "Did this sort?", name = "Lisa Simpson", town = "Springfield" },
],
[
{name = "Bart Simpson", town = "Springfield"},
{ name = "Bart Simpson", town = "Springfield" },
],
[
{name = "Homer Simpson", town = "Springfield"},
{ name = "Homer Simpson", town = "Springfield" },
],
]
'aalist' = {a = "another test", c = "test"}
'aalist' = { a = "another test", c = "test" }
alist = [
'a',
'g',
Expand All @@ -22,14 +22,14 @@ z = []

[a]
test = [
{a = [
"",
], x = [
"bar",
"foo",
]},
{y = [
"baz",
"foo",
]},
{ a = [
"",
], x = [
"bar",
"foo",
] },
{ y = [
"baz",
"foo",
] },
]
28 changes: 14 additions & 14 deletions tests/examples/sorted/inline.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[a]
test = [
{a = [
""
], x = [
"bar",
"foo"
]},
{y = [
"baz",
"foo"
]}
{ a = [
""
], x = [
"bar",
"foo"
] },
{ y = [
"baz",
"foo"
] }
]

[b]
Expand All @@ -18,16 +18,16 @@ aaalist = [
# Weird block comment
[
# Another weird block comment
{a-test = "Did this sort?", name = "Lisa Simpson", town = "Springfield"} # Should get sorted
{ a-test = "Did this sort?", name = "Lisa Simpson", town = "Springfield" } # Should get sorted
],
[
{name = "Bart Simpson", town = "Springfield"}
{ name = "Bart Simpson", town = "Springfield" }
],
[
{name = "Homer Simpson", town = "Springfield"}
{ name = "Homer Simpson", town = "Springfield" }
]
]
'aalist' = {a = "another test", c = "test"} # list comment
'aalist' = { a = "another test", c = "test" } # list comment
alist = [
# Multiline
# Second attached comment
Expand Down
8 changes: 7 additions & 1 deletion toml_sort/tomlsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ def sort_inline_table(
tomlsort_items = [
TomlSortItem(
keys=keys + k,
value=self.sort_item(keys + k, v, indent_depth=indent_depth),
value=self.sort_item(
keys + k, v, indent_depth=indent_depth + 1
),
)
for k, v in item.value.body
if not isinstance(v, Whitespace) and k is not None
Expand All @@ -482,11 +484,15 @@ def sort_inline_table(
new_table = InlineTable(
Container(parsed=True), trivia=item.trivia, new=True
)
if tomlsort_items:
new_table.append(None, Whitespace(" "))
for tomlsort_item in tomlsort_items:
normalize_trivia(tomlsort_item.value, include_comments=False)
new_table.append(
self.format_key(tomlsort_item.keys.base), tomlsort_item.value
)
if tomlsort_items:
new_table.append(None, Whitespace(" "))
new_table = normalize_trivia(
new_table,
include_comments=self.comment_config.inline,
Expand Down