This VS Code extension exposes the possibility to sort, format and validate YAML files.
This extension contributes the following settings:
vscode-yaml-sort.indent: Indentation width in spaces.
vscode-yaml-sort.lineWidth: Maximum line width for YAML files. Defaults to 500.
vscode-yaml-sort.noArrayIndent: When true, will not add an indentation level to array elements. Defaults to false.
vscode-yaml-sort.useLeadingDashes: When true, sorted YAML files begin with leading dashes. Defaults to true.
vscode-yaml-sort.useQuotesForSpecialKeywords: When false, will not add quotes for keywords with special characters e.g. 'text::text': will result in text::text:. Defaults to true.
vscode-yaml-sort.customSortKeywords_1: List of keywords for Custom Sort 1. Defaults to ["apiVersion", "kind", "metadata", "spec", "data"].
vscode-yaml-sort.customSortKeywords_2: List of keywords for Custom Sort 2.
vscode-yaml-sort.customSortKeywords_3: List of keywords for Custom Sort 3.
This extension contributes the following commands:
Sort YAML: Sorts a given YAML. You can either sort the whole YAML document or sort only a selection of the text.
Validate YAML: Validates a given YAML.
Format YAML: Formats a given YAML without sorting it.
Custom Sort 1: This command will sort a given YAML with custom order. If some of the keys of customSortKeywords_1 will be found at the top level of the YAML, these will be put at the beginning of the YAML file (in the given order). You can use this e. g. to sort Kubernetes configmaps.
Custom Sort 2: Same as Custom Sort 1.
Custom Sort 3: Same as Custom Sort 1.
Be careful with anchors and references, these don't work very well in this extension.
If you like this extension, please feel free to rate it on the marketplace.
If you miss something or found a bug, please let me know and open an issue on this project on GitHub.