Skip to content

Commit

Permalink
Merge pull request #36 from jonathangreen/bugfix/indexError
Browse files Browse the repository at this point in the history
Fix indexError exception
  • Loading branch information
pappasam committed Dec 31, 2022
2 parents 48da498 + e02f9c3 commit 38d6058
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/examples/inline.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[b]
z = []
q = {}
blist=[ 'c', 'a', 'b'] # Comment
alist = [
'g',
Expand Down
2 changes: 2 additions & 0 deletions tests/examples/sorted/inline-default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ test = [
]

[b]
z = []
q = {}
blist = ['c', 'a', 'b'] # Comment
alist = [
'g',
Expand Down
2 changes: 2 additions & 0 deletions tests/examples/sorted/inline-no-comments-no-table-sort.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ alist = [
'w',
]
blist = ['a', 'b', 'c']
q = {}
z = []

[a]
test = [
Expand Down
2 changes: 2 additions & 0 deletions tests/examples/sorted/inline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ alist = [
'w' # Comment inline
]
blist = ['a', 'b', 'c'] # Comment
q = {}
z = []
4 changes: 3 additions & 1 deletion toml_sort/tomlsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ def sort_array(self, array: Array, indent_depth: int = 0) -> Array:
new_array_value.extend(comments)
new_array_value.append(array_item)

if not (multiline and self.format_config.trailing_comma_inline_array):
if len(new_array_value) != 0 and not (
multiline and self.format_config.trailing_comma_inline_array
):
new_array_value[-1].comma = Whitespace("")

if multiline:
Expand Down

0 comments on commit 38d6058

Please sign in to comment.