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!
Quick look
Setup
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.
Overiding 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 ...
example
---
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
Documentation links
Run
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
yamllint .
Alternatives
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
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
of the 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.
API usage
Maven dependency:
<dependency>
<groupId>com.github.sbaudoin</groupId>
<artifactId>yamllint</artifactId>
<version>1.6.1</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…
Links
- 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!
Top comments (0)