Add ability to reformat specific tables with different options enabled
Specifically regarding reorder_keys and reorder_arrays, it can be that part of the toml file can have these reorders, and other parts should not.
The typical case I run into is Cargo.toml, where the rust tools have a preferred order of the keys in the package table, but it is desirable to reorder the keys in all of the other tables such as features, dependencies, etc. https://github.com/Electron100/butane/pull/40 is an example of using reorder_keys on Cargo.toml files.
IMO it would be great if the fmt command CLI allows patterns like the get command, to specific which part of the file to apply the formatting to.
You can use rules for that:
[formatting]
reorder_keys = true
# Do not reorder keys within a package or a dependency.
[[rule]]
formatting = { reorder_keys = false }
keys = ["dependencies.*", "package"]
My question would be: Is it possible to define a non-alphabetical ordering? And should this be part of a schema? The concrete example would be that within the package table, I would like to use the following ordering:
-
nameis required and first -
versionis required and second -
authorsis required (and next) -
licenseis required (etc) -
editionis required -
rust-versionis optional (and next) -
publishis optional (etc) -
keywordsis optional -
categoriesis optional -
readmeis optional - etc