taplo icon indicating copy to clipboard operation
taplo copied to clipboard

Add ability to reformat specific tables with different options enabled

Open jayvdb opened this issue 3 years ago • 3 comments

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.

jayvdb avatar Feb 05 '23 01:02 jayvdb

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:

  • name is required and first
  • version is required and second
  • authors is required (and next)
  • license is required (etc)
  • edition is required
  • rust-version is optional (and next)
  • publish is optional (etc)
  • keywords is optional
  • categories is optional
  • readme is optional
  • etc

ia0 avatar Feb 24 '23 16:02 ia0