In some pipelines or when a project build, we want to check if some files are build correctly like our YAML files!
So here is YamlLint!
You can find on their website all that you will need to use it, but here is a quick look!
Depending your project/machine, you can :
- install it directly on your machine if you are on Linux
sudo apt-get install yamllint
- install it with brew
brew install yamllint
- add it in your Python project
python setup.py sdist pip install --user dist/yamllint-*.tar.gz
Then you can use it directly with the default configs, or override it with your configs.
To do it, create a .yamllint file at the top level of your project. Then, in this file, you can enable/disable rules or override rules ...
--- yaml-files: - '*.yaml' - '*.yml' - '.yamllint' rules: braces: level: warning max-spaces-inside: 1 brackets: enable colons: enable commas: enable comments: level: warning comments-indentation: level: warning document-end: disable document-start: level: warning empty-lines: enable empty-values: disable hyphens: enable indentation: enable key-duplicates: enable key-ordering: disable line-length: enable new-line-at-end-of-file: enable new-lines: enable octal-values: disable quoted-strings: disable trailing-spaces: enable truthy: level: warning
Then, you can run the yaml lint to test it!
When you want to check some files
yamllint file.yml other-file.yaml
When you want to check all the files in the folder
If you are working with a Maven project, maybe you want to check it during your build! In this case you can use this library:
YAML lint written in Java
Its main purpose is to provide an API and scripts to analyze YAML documents
The YAML documents are syntactically checked as well as against rules. To get the list of rules, please refer to the classes
com.github.sbaudoin.yamllint.rules package. Among
other, we have a rule to check the presence of the start and end YAML document marker, the correct and consistent indentation, etc.
<dependency> <groupId>com.github.sbaudoin</groupId> <artifactId>yamllint</artifactId> <version>1.4.0</version> </dependency>
For use, please refer to the JavaDoc.
The class that will mostly interest you is
com.github.sbaudoin.yamllint.Linter: it contains static methods
that can be used to analyze a YAML string or a file.
3 errors levels have been defined: info, warning and error.
The linter can return only one syntax error per file (once a syntax error has been met we cannot expect a lot from the rest of…
- YAML Lint : https://yamllint.readthedocs.io/en/stable/
- GitHub Java YamlLint : https://github.com/sbaudoin/yamllint
I hope it will help you!
Please don't hesitate to give me a feedback about this post to improuve my writing skills. Thanks!