taplo icon indicating copy to clipboard operation
taplo copied to clipboard

reorder_arrays = false is ignored if the key is set to the array.

Open Kladki opened this issue 1 year ago • 3 comments

I have the following taplo.toml file:

include = ["**/*.toml"]
[formatting]
reorder_arrays = true

[[rule]]
include = ["bar.toml"]
keys = ["baz"]

[rule.formatting]
reorder_arrays = false

I would assume that the rule listed would prevent the array baz from being re-ordered, but still allow for all other arrays to be sorted.

This is my bar.toml file:

baz = ["foo", "bar", "baz"]

sort_me = ["z", "a"]

However, when running taplo fmt, bar.toml ends up like this:

baz = ["bar", "baz", "foo"]

sort_me = ["a", "z"]

As you can see, all arrays were sorted. When omitting keys, nothing gets formatted, which is not what I want.

Kladki avatar May 06 '24 18:05 Kladki

I have a similar rule-based formatting issue. The rule works until I add the include property and then it stops being applied. It will work as expected if I use the Taplo cli.

andrewweston avatar May 18 '24 04:05 andrewweston

It looks like keys is matching table names, not keys within a table. A rust-toolchain.toml of

[toolchain]
targets = ["zz", "x86_64-unknown-linux-gnu"]

gets targets sorted with

[[rule]]
include = ["rust-toolchain.toml"]
keys = ["toolchain"]

[rule.formatting]
reorder_arrays = true

but not with

keys = ["components", "targets"]

or

keys = ["toolchain.components", "toolchain.targets"]

tv42 avatar Sep 13 '24 21:09 tv42

Of course, one table might have both a key I want array sorted and a key I don't, so I feel like Taplo must support tablename.keyname there.

tv42 avatar Sep 13 '24 21:09 tv42