Lint YAML

As part of our build process we have some YAML files, I would like to validate these files and ideally Lint them.

 

What would be the best way to go about this please ?

There are no lint cmdlets that are native to PowerShell.

You’d have to leverage C/C++ to get such things and use PowerShell Add-Type cmdlet to bring such DLL’s in to your script for use.
I personally don’t use YAML, so, I’ve had no reason to look at it to date or look up any API / DLL needed to interact with it.

There are request in the PowerShell GitHub to have cmdlets for YAML, but that is not linting.

ConvertFrom-Yaml, ConvertTo-Yaml https://github.com/PowerShell/PowerShell/issues/3607

However, a quick web search for ‘powershell yaml lint’ turns up several hits you can leverage.

Example:

YAML in powershell powershell doesn't have native support for yaml. Solution: PSYAML and powershell-yaml http://dbadailystuff.com/yaml-in-powershell

PSYaml: PowerShell does YAML - Simple Talk
https://www.red-gate.com/simple-talk/blogs/psyaml-powershell-yaml

GitHub - cloudbase/powershell-yaml: PowerShell CmdLets for
https://github.com/cloudbase/powershell-yaml

on GitHub: https://github.com/scottmuc/PowerYaml
…which is a wrapper for the YamlDotNet library: https://github.com/aaubry/YamlDotNet

uses in YAML in PSDeploy
http://ramblingcookiemonster.github.io/PSDeploy/

There are Linter if you are using VSCode as your editor. It’s part of the extension library, but none are PS specific.

you can use yamllint , but it has no relation with PowerShell and cannot run on windows by default. As @postanote mentioned, VSCode yamllint plug-in is the best way to achieve this in Windows.

Thanks for the replies. I was hoping I had over looked an obvious YAML Linter that I could implement into our build process. This doesn’t look to be the case.