taplo icon indicating copy to clipboard operation
taplo copied to clipboard

Feature request: sorting arrays

Open gilescope opened this issue 3 years ago • 4 comments

Sorting arrays would be cool for cargo features to be sorted. I guess somewhere there must be a toml array where the order matters but I've not yet encountered any... Wonders how we turn it on just for cargo features (is that what the schema part is for?)

gilescope avatar Aug 31 '21 09:08 gilescope

This could be a formatter feature along with reordering inline table keys.

We should be careful with arrays, and this feature should be disabled by default if added, as changing array order no longer just changes the format but also the data as well.

As for scoping the behaviour, path-specific rules could be used in .taplo.toml (https://taplo.tamasfe.dev/configuration/#rules), so that the sorting of arrays is enabled for e.g dependencies.*.features, I wouldn't bake this in anywhere either but leave up to the users if they want to configure it for their projects.

tamasfe avatar Aug 31 '21 19:08 tamasfe

Some additional implementation details at https://github.com/tamasfe/taplo/issues/338#issuecomment-1289489987, posting here for the sake of completeness.

tamasfe avatar Oct 27 '22 10:10 tamasfe

It looks like this can be closed..?

jayvdb avatar Feb 05 '23 01:02 jayvdb

It looks like this can be closed..?

Looks like it, but the website would need to be updated to document the new feature. In particular this file should mention reorder_arrays.

ia0 avatar Feb 24 '23 16:02 ia0