Skip to content

Commit

Permalink
Merge pull request #27 from myii/feat/add-rule_empty-values_to-yamllint
Browse files Browse the repository at this point in the history
feat(yamllint): add rule `empty-values` & use new `yaml-files` setting
  • Loading branch information
myii authored Sep 12, 2019
2 parents 7b11026 + 534b0eb commit 5f3f28d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 52 deletions.
28 changes: 19 additions & 9 deletions ssf/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down Expand Up @@ -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
Expand All @@ -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: {}
Expand Down
20 changes: 3 additions & 17 deletions ssf/files/default/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand All @@ -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
Expand Down
39 changes: 31 additions & 8 deletions ssf/files/default/.yamllint
Original file line number Diff line number Diff line change
@@ -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 %}
Expand All @@ -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') %}
Expand All @@ -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') %}
Expand Down
39 changes: 21 additions & 18 deletions ssf/formulas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 5f3f28d

Please sign in to comment.