diff --git a/ssf/defaults.yaml b/ssf/defaults.yaml index d0ddc9c0..9e54d264 100644 --- a/ssf/defaults.yaml +++ b/ssf/defaults.yaml @@ -15,8 +15,8 @@ ssf_node_anchors: # An alternative method could be to use: # `git describe --abbrev=0 --tags` # yamllint disable-line rule:line-length - title: 'chore: use standard test pillar path' - body: '* Semi-automated using https://github.com/myii/ssf-formula/pull/28' + title: 'ci(yamllint): add rule `empty-values` & use new `yaml-files` setting' + body: '* Automated using https://github.com/myii/ssf-formula/pull/27' github: owner: saltstack-formulas repo: '' @@ -115,14 +115,22 @@ ssf_node_anchors: use_cirrus_ci: false use_tofs: false yamllint: - check_files: + extends: default + ignore: default: - - . - - .yamllint - - pillar.example + - 'node_modules/' + additional_ssf: + - 'test/**/states/**/*.sls' + additional: [] + yaml-files: + default: + - '*.yaml' + - '*.yml' + - '.yamllint' + additional_ssf: + - '*.example' + - 'test/**/*.sls' additional: [] - extends: default - ignore: [] rules: # yamllint disable rule:comments-indentation # Commenting out all of the rules that haven't been implemented yet @@ -135,7 +143,9 @@ ssf_node_anchors: # document-end: {} # document-start: {} # empty-lines: {} - # empty-values: {} + empty-values: + forbid-in-block-mappings: 'true' + forbid-in-flow-mappings: 'true' # hyphens: {} # indentation: {} key-duplicates: {} diff --git a/ssf/files/default/.travis.yml b/ssf/files/default/.travis.yml index 7243eb3d..8dde02db 100644 --- a/ssf/files/default/.travis.yml +++ b/ssf/files/default/.travis.yml @@ -58,20 +58,6 @@ script: {%- endfor %} {%- endif %} -{%- set yamllint_files = yamllint.check_files.default + yamllint.check_files.additional %} -{#- Don't need to do this in index order but maintaining consistency with `kitchen.yml` #} -{%- for index in range(0, inspec_suites_kitchen | length) %} -{%- set suite = inspec_suites_kitchen[index] %} -{%- set pillars_from_files = suite.provisioner.pillars_from_files %} -{%- for pff in pillars_from_files %} -{%- for k, v in pff.items() %} -{%- if v not in yamllint_files %} -{%- do yamllint_files.append(v) %} -{%- endif %} -{%- endfor %} -{%- endfor %} -{%- endfor %} - jobs: include: # Define the `lint` stage (runs `yamllint` and `commitlint`) @@ -81,9 +67,9 @@ jobs: before_install: skip script: # Install and run `yamllint` - - pip install --user yamllint - # yamllint disable-line rule:line-length - - yamllint -s {{ yamllint_files | join(' ') }} + # Need at least `v1.17.0` for the `yaml-files` setting + - pip install --user yamllint>=1.17.0 + - yamllint -s . # Install and run `commitlint` - npm install @commitlint/config-conventional -D - npm install @commitlint/travis-cli -D diff --git a/ssf/files/default/.yamllint b/ssf/files/default/.yamllint index 92d38f67..fd31879c 100644 --- a/ssf/files/default/.yamllint +++ b/ssf/files/default/.yamllint @@ -1,13 +1,10 @@ # -*- coding: utf-8 -*- # vim: ft=yaml --- -{%- macro format_ignore(ignore_parent, first_ignores=[], width=4) %} +{%- macro format_ignore(ignore_parent, width=4) %} {%- filter indent(width) %} {%- if ignore_parent.ignore is defined %} ignore: | - {%- for first_ignore in first_ignores %} - {{ first_ignore }} - {%- endfor %} {%- for file in ignore_parent.ignore %} {{ file }} {%- endfor %} @@ -19,15 +16,34 @@ extends: {{ yamllint.extends }} # Files to ignore completely # 1. All YAML files under directory `node_modules/`, introduced during the Travis run +# 2. Any SLS files under directory `test/`, which are actually state files {%- if semrel_formula == 'ssf' %} -# 2. All Jinja templates under `ssf/files/` (result in `yamllint` syntax errors) +# 3. All Jinja templates under `ssf/files/` (result in `yamllint` syntax errors) # Not disabling via. `*.yml` since we may end up with non-Jinja YAML files here {%- elif semrel_formula == 'mysql' %} -# 2. Any YAML files using Jinja (result in `yamllint` syntax errors) +# 3. Any YAML files using Jinja (result in `yamllint` syntax errors) {%- elif semrel_formula == 'postgres' %} -# 2. All YAML files heavily reliant on Jinja; these can be tackled in a subsequent PR +# 3. All YAML files heavily reliant on Jinja; these can be tackled in a subsequent PR +{%- endif %} +{%- set yl_ignores = {'ignore': + yamllint.ignore.default + + yamllint.ignore.additional_ssf + + yamllint.ignore.additional +} %} +{{- format_ignore(yl_ignores, width=0) }} + +yaml-files: +{%- set yl_yf = yamllint.get('yaml-files') %} +{%- filter indent(2) %} +# Default settings +{{ yl_yf.default | yaml(False) }} +# SaltStack Formulas additional settings +{{ yl_yf.additional_ssf | yaml(False) }} +{%- if yl_yf.additional %} +# Formula-specific additional settings +{{ yl_yf.additional | yaml(False) }} {%- endif %} -{{- format_ignore(yamllint, first_ignores=['node_modules/'], width=0) }} +{%- endfilter %} rules: {%- if yamllint.rules.get('commas') %} @@ -45,6 +61,13 @@ rules: {{- format_ignore(yl_ci) }} {%- endif %} + {#- Don't need the `if` here since we're always providing a `empty-values` setting #} + empty-values: + {%- set yl_ev = yamllint.rules.get('empty-values') %} + {{- format_ignore(yl_ev) }} + forbid-in-block-mappings: {{ yamllint.rules.get('empty-values').get('forbid-in-block-mappings') }} + forbid-in-flow-mappings: {{ yamllint.rules.get('empty-values').get('forbid-in-flow-mappings') }} + {%- if yamllint.rules.get('key-duplicates') %} key-duplicates: {%- set yl_kd = yamllint.rules.get('key-duplicates') %} diff --git a/ssf/formulas.yaml b/ssf/formulas.yaml index 47119a51..889acba0 100644 --- a/ssf/formulas.yaml +++ b/ssf/formulas.yaml @@ -143,6 +143,10 @@ ssf_node_anchors: rule: ignore_pillar_example: &ignore_pillar_example - pillar.example + # yamllint disable-line rule:line-length + ignore_pillar_example_and_with_views_example: &ignore_pillar_example_and_with_views_example + - pillar.example + - pillar-with-views.example semrel_files: &semrel_files_default bin/kitchen: &file__bin__kitchen <<: *file_default @@ -260,11 +264,11 @@ ssf: yamllint: rules: comments-indentation: - ignore: *ignore_pillar_example + ignore: *ignore_pillar_example_and_with_views_example key-duplicates: ignore: *ignore_pillar_example line-length: - ignore: *ignore_pillar_example + ignore: *ignore_pillar_example_and_with_views_example semrel_files: *semrel_files_default cert: context: @@ -674,7 +678,8 @@ ssf: - [debian , 8 , 2017.7, 2, default] yamllint: ignore: - - mysql/supported_sections.yaml + additional: + - mysql/supported_sections.yaml semrel_files: *semrel_files_default nginx: context: @@ -850,12 +855,13 @@ ssf: use_tofs: true yamllint: ignore: - - pillar.example - - postgres/codenamemap.yaml - - postgres/osfamilymap.yaml - - postgres/osmap.yaml - - postgres/repo.yaml - - test/salt/pillar/postgres.sls + additional: + - pillar.example + - postgres/codenamemap.yaml + - postgres/osfamilymap.yaml + - postgres/osmap.yaml + - postgres/repo.yaml + - test/salt/pillar/postgres.sls semrel_files: *semrel_files_default prometheus: context: @@ -931,11 +937,12 @@ ssf: use_tofs: true yamllint: ignore: - - ssf/files/default/.cirrus.yml - - ssf/files/default/.travis.yml - - ssf/files/default/.yamllint - - ssf/files/default/kitchen.yml - - ssf/files/default/inspec/inspec.yml + additional: + - ssf/files/default/.cirrus.yml + - ssf/files/default/.travis.yml + - ssf/files/default/.yamllint + - ssf/files/default/kitchen.yml + - ssf/files/default/inspec/inspec.yml rules: commas: ignore: @@ -1048,10 +1055,6 @@ ssf: - [debian , 9 , 2018.3, 2, default] # - [ubuntu , 16.04, 2017.7, 2, default] use_cirrus_ci: true - yamllint: - check_files: - additional: - - pillar.debian.example semrel_files: <<: *semrel_files_default inspec/inspec.yml: