microsoft / PSRule

Validate infrastructure as code (IaC) and objects using PowerShell rules.
https://microsoft.github.io/PSRule/v2/
MIT License
400 stars 52 forks source link

Add option to sort Yaml/Json object keys #819

Open ArmaanMcleod opened 3 years ago

ArmaanMcleod commented 3 years ago

Add an output option to sort object keys.

Currently all JSON/YAML keys are sorted when serialized. In most cases this is ideal, but we should have an option like output.sortObjectKeys which allows the user to disable auto key sorting.

For example:

Sort object keys (default to true)

output:
  sortObjectKeys: true

Disable sorting of object keys

output:
  sortObjectKeys: false

Related to https://github.com/microsoft/PSRule/issues/817#issuecomment-933126658

ArmaanMcleod commented 3 years ago

Will come back to this one. I think its not worth implementing given YAML serialization already exists for baselines which always output the same sorted order of keys. Having an option like this would give inconsistent results between resources.

I also don't really see a reason why someone would wan't to turn this off, except maybe for a performance increase of not sorting keys by default with OrderBy() in the contract resolvers/type inspectors.

It would probably be more useful to allow the user to override the ordering of properties via an output option, but that is another issue 😄

BernieWhite commented 3 years ago

@ArmaanMcleod Sure. Let's park it for now.