From 2fef13f21f4e109faa1114b17deb38166162bc33 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Fri, 29 Apr 2022 10:40:54 +0200 Subject: [PATCH] Added yaml tl;dr and yamllint notes to the kb --- knowledge base/yaml.md | 21 ++++++++++++++ knowledge base/yamllint.md | 59 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 knowledge base/yamllint.md diff --git a/knowledge base/yaml.md b/knowledge base/yaml.md index e0d290b..339f4da 100644 --- a/knowledge base/yaml.md +++ b/knowledge base/yaml.md @@ -1,7 +1,28 @@ # YAML +## TL;DR + +```yaml +--- +# This is a comment +string: this is a string +number: 0 +truthy: true +list: + - element + - element +object: + key: value + nested: + can: do + lists: + - too +``` + ## Further readings - [yaml-multiline.info] +- [yamllint] [yaml-multiline.info]: https://yaml-multiline.info +[yamllint]: yamllint.md diff --git a/knowledge base/yamllint.md b/knowledge base/yamllint.md new file mode 100644 index 0000000..671d11e --- /dev/null +++ b/knowledge base/yamllint.md @@ -0,0 +1,59 @@ +# Yamllint + +A linter for YAML files written in Python and compatible with Python 3 only. + +## TL;DR + +```shell +# Use a specific configuration file. +yamllint -c /path/to/config file.yaml + +# Pass custom configuration options on the CLI. +yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" file.yaml +``` + +## Configuration + +`yamllint` uses a set of [rules] to check YAML files for problems. Each rule is independent from the others, and can be enabled, disabled or tweaked. All these settings can be gathered in a configuration file. + +To use a custom configuration file, use the `-c` option: + +```shell +yamllint -c /path/to/config file.yaml +``` + +If no such option is provided, `yamllint` will look for a configuration file in the following locations (by order of preference): + +- `.yamllint`, `.yamllint.yaml` or `.yamllint.yml` in the current working directory +- the file referenced by `$YAMLLINT_CONFIG_FILE`, if set +- `$XDG_CONFIG_HOME/yamllint/config` +- `~/.config/yamllint/config` + +Finally, if no config file is found the default configuration is applied. + +You can avoid the need to redefine every rule when writing a custom configuration file `extend`ing the default one or any other already-existing configuration file: + +```yaml +extends: default +rules: + comments-indentation: disable # don't bother me at all with this rule +``` + +```yaml +extends: relaxed + line-length: # just warn if a line is longer than 120 chars, instead of failing at 81 + max: 120 + level: warning + indentation: # loosen up on block sequences indentation + indent-sequences: whatever +``` + +## Further readings + +- [GitHub] page +- Yamllint's [documentation] +- [Rules] + +[documentation]: https://yamllint.readthedocs.io/en/stable +[github]: https://github.com/adrienverge/yamllint +[rules]: https://yamllint.readthedocs.io/en/stable/rules.html