diff --git a/tests/examples/from-toml-lang.toml b/tests/examples/from-toml-lang.toml index 7d3de9b..91b1524 100644 --- a/tests/examples/from-toml-lang.toml +++ b/tests/examples/from-toml-lang.toml @@ -45,3 +45,7 @@ hosts = [ name = "Nail" sku = 284758393 color = "gray" + +[inline] +# Test "first" sorting for inline tables +c = { limit="<3.12", version ="4.12.2"} \ No newline at end of file diff --git a/tests/examples/sorted/from-toml-lang-first.toml b/tests/examples/sorted/from-toml-lang-first.toml index 94d9394..d7bea04 100644 --- a/tests/examples/sorted/from-toml-lang-first.toml +++ b/tests/examples/sorted/from-toml-lang-first.toml @@ -37,6 +37,10 @@ connection_max = 5000 enabled = true # Comment after a boolean server = "192.168.1.1" +[inline] +# Test "first" sorting for inline tables +c = {version = "4.12.2", limit = "<3.12"} + [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00Z # First class dates? Why not? diff --git a/tests/examples/sorted/from-toml-lang-overrides.toml b/tests/examples/sorted/from-toml-lang-overrides.toml index c93d813..7e40666 100644 --- a/tests/examples/sorted/from-toml-lang-overrides.toml +++ b/tests/examples/sorted/from-toml-lang-overrides.toml @@ -16,6 +16,10 @@ enabled = true # Comment after a boolean ports = [8001, 8001, 8002] server = "192.168.1.1" +[inline] +# Test "first" sorting for inline tables +c = {limit = "<3.12", version = "4.12.2"} + [owner] bio = "GitHub Cofounder & CEO\nLikes tater tots and beer." dob = 1979-05-27T07:32:00Z # First class dates? Why not? diff --git a/tests/examples/sorted/from-toml-lang.toml b/tests/examples/sorted/from-toml-lang.toml index f341d0d..ac43b43 100644 --- a/tests/examples/sorted/from-toml-lang.toml +++ b/tests/examples/sorted/from-toml-lang.toml @@ -16,6 +16,10 @@ ports = [8001, 8001, 8002] connection_max = 5000 enabled = true # Comment after a boolean +[inline] +# Test "first" sorting for inline tables +c = {limit = "<3.12", version = "4.12.2"} + [owner] name = "Tom Preston-Werner" organization = "GitHub" diff --git a/tests/test_toml_sort.py b/tests/test_toml_sort.py index 39b948e..fde13f0 100644 --- a/tests/test_toml_sort.py +++ b/tests/test_toml_sort.py @@ -111,6 +111,7 @@ def test_sort_toml_is_str() -> None: "sort_config_overrides": { "database": SortOverrideConfiguration(first=["ports"]), "owner": SortOverrideConfiguration(first=["name", "dob"]), + "inline.c": SortOverrideConfiguration(first=["version"]), }, }, ), diff --git a/toml_sort/tomlsort.py b/toml_sort/tomlsort.py index 3c66927..25a0339 100644 --- a/toml_sort/tomlsort.py +++ b/toml_sort/tomlsort.py @@ -430,8 +430,9 @@ def sort_keys( """ def sort_first(item: TomlSortItem) -> int: - if item.keys.base in sort_config.first: - return sort_config.first.index(item.keys.base.as_string()) + for index, value in enumerate(sort_config.first): + if value == item.keys.base.key: + return index return len(sort_config.first) items = sorted(items, key=self.key_sort_func)