Standard format for common charm files


@sed-i opened this issue in Charmcraft’s tracker requesting a new command in the tool that would apply a set of opinionated formatting choices in several charm files.

The idea is to be able to offer “aesthetic consistency” across charms, without making any semantic/functional changes.

The new charmcraft format command would rewrite several files in the charms’ project, applying the needed changes. Of course this will be totally optional, and the user may not want to use this command at all (in other words, this will not happen automatically on pack, for example)

So far we collected these actions on what such command would do:

  • sort metadata.yaml sections in a particular order; from metadata v2 reference:
    • name
    • summary
    • description
    • maintainers
    • terms
    • min-juju-version
    • series
    • assumes
    • tags
    • categories
    • subordinate
    • provides
    • requires
    • peers
    • extra-bindings
    • storage
    • devices
    • containers
    • deployment
    • resources
  • sort actions.yaml and config.yaml entries alphabetically
  • sort charmcraft.yaml sections in a particular order:
    • type
    • charmhub
    • analysis
    • bases
    • parts, and here inside try to sort them by order of business (need to check if that is possible)
  • in all those .yaml files: one line gap between each main section and no gaps anywhere else
  • in config.yaml options and in actions.yaml keys and their params items: change names to be in kebab case (“foo-bar”)

Please comment below what other actions this command could have, thanks!!

1 Like

Such a change will break charm code. Perhaps charmcraft analyze is a better place for kebabization?