Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: yamllint rule #2450

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 29 additions & 15 deletions src/ansiblelint/rules/yaml.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
# yaml

Our linter also includes violations reported by [yamllint](https://github.com/adrienverge/yamllint)
but it uses a slightly different default configuration. We will still load
custom yamllint configuration files, but the defaults come from
ansible-lint, not from yamllint.
This rule checks YAML syntax and is an implementation of `yamllint`.

You can fully disable all yamllint violations by adding `yaml` to the `skip_list`.
You can disable YAML syntax violations by adding `yaml` to the `skip_list`
in your Ansible-lint configuration as follows:

Specific tag identifiers that are printed at the end of the rule name,
like `yaml[trailing-spaces]` or `yaml[indentation]` can also be skipped, allowing
you to have more control.
```yaml
skip_list:
- yaml
```

For more fine-grained control, disable violations for specific rules using tag
identifiers in the `yaml[yamllint_rule]` format as follows:

```yaml
skip_list:
- yaml[trailing-spaces]
- yaml[indentation]
```

If you want Ansible-lint to report YAML syntax violations as warnings, and not
fatal errors, add tag identifiers to the `warn_list` in your configuration, for example:

```yaml
warn_list:
- yaml[document-start]
```

Keep in mind that `ansible-lint` does not take into consideration the warning level
of yamllint; we treat all yamllint matches as errors. So, if you want to treat
some of these as warnings, add them to `warn_list`.
See the [list of yamllint rules](https://yamllint.readthedocs.io/en/stable/rules.html) for more information.

## Problematic code

```yaml
# missing document-start
# Missing YAML document start.
foo: ...
foo: ... # <-- key-duplicates
bar: ... # <-- wrong comment indentation
foo: ... # <-- Duplicate key.
bar: ... # <-- Incorrect comment indentation
```

## Correct code

```yaml
---
foo: ...
bar: ... # comment
bar: ... # Correct comment indentation.
```