To fix the issue we could manually introduce the space. The next warnings concentrates on comments, missing starting space in comment which means the comment token # and the actual comment string after it are not separated by a space. ![]() To fix this issue, we can replace the empty line with “-” (without the quote). The first two issues indicates that the some_file.yaml does not starts with “-” but with an empty line. Let’s take the following example: yamllint some_file.yamlġ:1 error too many blank lines (1 > 0) (empty-lines)Ģ:1 warning missing document start "-" (document-start)Ģ6:14 warning missing starting space in comment (comments)Ģ6:13 warning missing starting space in comment (comments)Ģ8:14 warning comment not indented like content (comments-indentation)Ģ77:81 error line too long (90 > 80 characters) (line-length)Ģ99:27 error no new line character at the end of file (new-line-at-end-of-file) The output of yamllint can be used to direct manual formatting. In fact I use this technique as part of my test-suite to ensure yaml files in a project are passing linting tests for example. It is also important to mention that yamllint can be imported as a python package and can be used programmatically to lint yaml files. I you are into automation like me, you would want to know that yamllint exits with 0 when no errors nor warnings have been found and exists with non-zero otherwise. Integrating yamllint with pre-commit is detailed here. It can be used to enforce code formatting styles. ![]() is a wonderful tool that I encourage all developers to use to ensure simple mistakes, and bugs are not introduced accidentally to the code. One way to do that is to integrate yamllint with pre-commit a took that magically add git pre-commit hooks to any project. To use yamllint consistently, it is recommended to add a git hook that invokes yamllint before committing the code to the git repository. The tool is well maintained and well documented, and the docs can be found under. The output would look like the following example depending on the content of the file: yamllint some_file.yamlĢ4:81 error line too long (152 > 80 characters) (line-length)Ģ6:81 error line too long (156 > 80 characters) (line-length)ģ9:30 warning truthy value should be one of (truthy)ĥ2:81 error line too long (144 > 80 characters) (line-length) The tool checks for the validity of syntax, additionally it also highlights multiple usage of the same key, as well as non-breaking formatting issues such as lines’ width, trailing spaces, indentation, spaces before the comments. Once installed, the tool can be invoked directly from the command line with: yamllint some_file.yaml You can install it using pip with: pip install -user yamllint Yamllint is an open-source command line tool written by Adrien Vergé in python and hosted on github under. I cover the issue of handling long strings thoroughly in another blog post titled: YAML Files – Formatting Long Strings. Luckily there are many tools available that helps with “linting” and formatting yaml file, I will introduce two of those tools in this blog post. ![]() ![]() Not only it improves code readability but also helps avoiding misunderstanding and bugs. Keep the Yaml files in your project tidy is useful.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |