From 48b8324578286c332756d4887a3fe384dab4f02b Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 8 Apr 2021 18:00:26 +0100 Subject: [PATCH] Ignore templated files (#1524) Avoid using file extensions from files under templates/ folders as they are unlikely to validate using their extension type. For example .yaml files from these are likely jinja2 templated. Fixes: #1511 --- .pre-commit-config.yaml | 1 + examples/playbooks/templates/not-valid.yaml | 2 ++ src/ansiblelint/config.py | 1 + 3 files changed, 4 insertions(+) create mode 100644 examples/playbooks/templates/not-valid.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b50d65211f..878de08e48 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -48,6 +48,7 @@ repos: - id: yamllint exclude: > (?x)^( + examples/playbooks/templates/.*| examples/other/some.j2.yaml )$ files: \.(yaml|yml)$ diff --git a/examples/playbooks/templates/not-valid.yaml b/examples/playbooks/templates/not-valid.yaml new file mode 100644 index 0000000000..5d34f55281 --- /dev/null +++ b/examples/playbooks/templates/not-valid.yaml @@ -0,0 +1,2 @@ +# Used to validate that a templated YAML file does not confuse the linter +{% include 'port.j2' %} diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py index 0a3394cc9e..32cef06815 100644 --- a/src/ansiblelint/config.py +++ b/src/ansiblelint/config.py @@ -46,6 +46,7 @@ "text/jinja2": "**/*.j2" }, # jinja2 templates are not always parsable as something else {"text/jinja2": "**/*.j2.*"}, + {"text": "**/templates/**/*.*"}, # templates are likely not validable {"text/json": "**/*.json"}, # standardized {"text/markdown": "**/*.md"}, # https://tools.ietf.org/html/rfc7763 {"text/rst": "**/*.rst"}, # https://en.wikipedia.org/wiki/ReStructuredText