Yamllint
Use an online validator like https://www.yamllint.com/ or https://jsonformatter.org/yaml-validator
Of course, you should have one in your local tools and CI pipeline to ensure that your Yaml is always correct.
Manually fix errors
Unfortunately, yamllint does not fix your file for you. There could be ambiguities about the proper fix, so you need to do the fix(es) yourself.
Many linters
You can't just use "one" solution either[1]. The leading GPL linter is based on Python, so depending on your code repo, you may instead want to use a JavaScript or PHP implementation. Thus, tools like wp:Grunt (software) may be used to automate JSHint linting in JavaScript projects[2].
Source, Docs and Reading
- https://github.com/adrienverge/yamllint
- https://yamllint.readthedocs.io/en/stable/
- https://www.redhat.com/sysadmin/check-yaml-yamllint