Skip to content

Commit 5f3f28d

Browse files
authored
Merge pull request #27 from myii/feat/add-rule_empty-values_to-yamllint
feat(yamllint): add rule `empty-values` & use new `yaml-files` setting
2 parents 7b11026 + 534b0eb commit 5f3f28d

File tree

4 files changed

+74
-52
lines changed

4 files changed

+74
-52
lines changed

ssf/defaults.yaml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ ssf_node_anchors:
1515
# An alternative method could be to use:
1616
# `git describe --abbrev=0 --tags`
1717
# yamllint disable-line rule:line-length
18-
title: 'chore: use standard test pillar path'
19-
body: '* Semi-automated using https://github.com/myii/ssf-formula/pull/28'
18+
title: 'ci(yamllint): add rule `empty-values` & use new `yaml-files` setting'
19+
body: '* Automated using https://github.com/myii/ssf-formula/pull/27'
2020
github:
2121
owner: saltstack-formulas
2222
repo: ''
@@ -115,14 +115,22 @@ ssf_node_anchors:
115115
use_cirrus_ci: false
116116
use_tofs: false
117117
yamllint:
118-
check_files:
118+
extends: default
119+
ignore:
119120
default:
120-
- .
121-
- .yamllint
122-
- pillar.example
121+
- 'node_modules/'
122+
additional_ssf:
123+
- 'test/**/states/**/*.sls'
124+
additional: []
125+
yaml-files:
126+
default:
127+
- '*.yaml'
128+
- '*.yml'
129+
- '.yamllint'
130+
additional_ssf:
131+
- '*.example'
132+
- 'test/**/*.sls'
123133
additional: []
124-
extends: default
125-
ignore: []
126134
rules:
127135
# yamllint disable rule:comments-indentation
128136
# Commenting out all of the rules that haven't been implemented yet
@@ -135,7 +143,9 @@ ssf_node_anchors:
135143
# document-end: {}
136144
# document-start: {}
137145
# empty-lines: {}
138-
# empty-values: {}
146+
empty-values:
147+
forbid-in-block-mappings: 'true'
148+
forbid-in-flow-mappings: 'true'
139149
# hyphens: {}
140150
# indentation: {}
141151
key-duplicates: {}

ssf/files/default/.travis.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,6 @@ script:
5858
{%- endfor %}
5959
{%- endif %}
6060

61-
{%- set yamllint_files = yamllint.check_files.default + yamllint.check_files.additional %}
62-
{#- Don't need to do this in index order but maintaining consistency with `kitchen.yml` #}
63-
{%- for index in range(0, inspec_suites_kitchen | length) %}
64-
{%- set suite = inspec_suites_kitchen[index] %}
65-
{%- set pillars_from_files = suite.provisioner.pillars_from_files %}
66-
{%- for pff in pillars_from_files %}
67-
{%- for k, v in pff.items() %}
68-
{%- if v not in yamllint_files %}
69-
{%- do yamllint_files.append(v) %}
70-
{%- endif %}
71-
{%- endfor %}
72-
{%- endfor %}
73-
{%- endfor %}
74-
7561
jobs:
7662
include:
7763
# Define the `lint` stage (runs `yamllint` and `commitlint`)
@@ -81,9 +67,9 @@ jobs:
8167
before_install: skip
8268
script:
8369
# Install and run `yamllint`
84-
- pip install --user yamllint
85-
# yamllint disable-line rule:line-length
86-
- yamllint -s {{ yamllint_files | join(' ') }}
70+
# Need at least `v1.17.0` for the `yaml-files` setting
71+
- pip install --user yamllint>=1.17.0
72+
- yamllint -s .
8773
# Install and run `commitlint`
8874
- npm install @commitlint/config-conventional -D
8975
- npm install @commitlint/travis-cli -D

ssf/files/default/.yamllint

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# -*- coding: utf-8 -*-
22
# vim: ft=yaml
33
---
4-
{%- macro format_ignore(ignore_parent, first_ignores=[], width=4) %}
4+
{%- macro format_ignore(ignore_parent, width=4) %}
55
{%- filter indent(width) %}
66
{%- if ignore_parent.ignore is defined %}
77
ignore: |
8-
{%- for first_ignore in first_ignores %}
9-
{{ first_ignore }}
10-
{%- endfor %}
118
{%- for file in ignore_parent.ignore %}
129
{{ file }}
1310
{%- endfor %}
@@ -19,15 +16,34 @@ extends: {{ yamllint.extends }}
1916

2017
# Files to ignore completely
2118
# 1. All YAML files under directory `node_modules/`, introduced during the Travis run
19+
# 2. Any SLS files under directory `test/`, which are actually state files
2220
{%- if semrel_formula == 'ssf' %}
23-
# 2. All Jinja templates under `ssf/files/` (result in `yamllint` syntax errors)
21+
# 3. All Jinja templates under `ssf/files/` (result in `yamllint` syntax errors)
2422
# Not disabling via. `*.yml` since we may end up with non-Jinja YAML files here
2523
{%- elif semrel_formula == 'mysql' %}
26-
# 2. Any YAML files using Jinja (result in `yamllint` syntax errors)
24+
# 3. Any YAML files using Jinja (result in `yamllint` syntax errors)
2725
{%- elif semrel_formula == 'postgres' %}
28-
# 2. All YAML files heavily reliant on Jinja; these can be tackled in a subsequent PR
26+
# 3. All YAML files heavily reliant on Jinja; these can be tackled in a subsequent PR
27+
{%- endif %}
28+
{%- set yl_ignores = {'ignore':
29+
yamllint.ignore.default +
30+
yamllint.ignore.additional_ssf +
31+
yamllint.ignore.additional
32+
} %}
33+
{{- format_ignore(yl_ignores, width=0) }}
34+
35+
yaml-files:
36+
{%- set yl_yf = yamllint.get('yaml-files') %}
37+
{%- filter indent(2) %}
38+
# Default settings
39+
{{ yl_yf.default | yaml(False) }}
40+
# SaltStack Formulas additional settings
41+
{{ yl_yf.additional_ssf | yaml(False) }}
42+
{%- if yl_yf.additional %}
43+
# Formula-specific additional settings
44+
{{ yl_yf.additional | yaml(False) }}
2945
{%- endif %}
30-
{{- format_ignore(yamllint, first_ignores=['node_modules/'], width=0) }}
46+
{%- endfilter %}
3147

3248
rules:
3349
{%- if yamllint.rules.get('commas') %}
@@ -45,6 +61,13 @@ rules:
4561
{{- format_ignore(yl_ci) }}
4662
{%- endif %}
4763

64+
{#- Don't need the `if` here since we're always providing a `empty-values` setting #}
65+
empty-values:
66+
{%- set yl_ev = yamllint.rules.get('empty-values') %}
67+
{{- format_ignore(yl_ev) }}
68+
forbid-in-block-mappings: {{ yamllint.rules.get('empty-values').get('forbid-in-block-mappings') }}
69+
forbid-in-flow-mappings: {{ yamllint.rules.get('empty-values').get('forbid-in-flow-mappings') }}
70+
4871
{%- if yamllint.rules.get('key-duplicates') %}
4972
key-duplicates:
5073
{%- set yl_kd = yamllint.rules.get('key-duplicates') %}

ssf/formulas.yaml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ ssf_node_anchors:
143143
rule:
144144
ignore_pillar_example: &ignore_pillar_example
145145
- pillar.example
146+
# yamllint disable-line rule:line-length
147+
ignore_pillar_example_and_with_views_example: &ignore_pillar_example_and_with_views_example
148+
- pillar.example
149+
- pillar-with-views.example
146150
semrel_files: &semrel_files_default
147151
bin/kitchen: &file__bin__kitchen
148152
<<: *file_default
@@ -260,11 +264,11 @@ ssf:
260264
yamllint:
261265
rules:
262266
comments-indentation:
263-
ignore: *ignore_pillar_example
267+
ignore: *ignore_pillar_example_and_with_views_example
264268
key-duplicates:
265269
ignore: *ignore_pillar_example
266270
line-length:
267-
ignore: *ignore_pillar_example
271+
ignore: *ignore_pillar_example_and_with_views_example
268272
semrel_files: *semrel_files_default
269273
cert:
270274
context:
@@ -674,7 +678,8 @@ ssf:
674678
- [debian , 8 , 2017.7, 2, default]
675679
yamllint:
676680
ignore:
677-
- mysql/supported_sections.yaml
681+
additional:
682+
- mysql/supported_sections.yaml
678683
semrel_files: *semrel_files_default
679684
nginx:
680685
context:
@@ -850,12 +855,13 @@ ssf:
850855
use_tofs: true
851856
yamllint:
852857
ignore:
853-
- pillar.example
854-
- postgres/codenamemap.yaml
855-
- postgres/osfamilymap.yaml
856-
- postgres/osmap.yaml
857-
- postgres/repo.yaml
858-
- test/salt/pillar/postgres.sls
858+
additional:
859+
- pillar.example
860+
- postgres/codenamemap.yaml
861+
- postgres/osfamilymap.yaml
862+
- postgres/osmap.yaml
863+
- postgres/repo.yaml
864+
- test/salt/pillar/postgres.sls
859865
semrel_files: *semrel_files_default
860866
prometheus:
861867
context:
@@ -931,11 +937,12 @@ ssf:
931937
use_tofs: true
932938
yamllint:
933939
ignore:
934-
- ssf/files/default/.cirrus.yml
935-
- ssf/files/default/.travis.yml
936-
- ssf/files/default/.yamllint
937-
- ssf/files/default/kitchen.yml
938-
- ssf/files/default/inspec/inspec.yml
940+
additional:
941+
- ssf/files/default/.cirrus.yml
942+
- ssf/files/default/.travis.yml
943+
- ssf/files/default/.yamllint
944+
- ssf/files/default/kitchen.yml
945+
- ssf/files/default/inspec/inspec.yml
939946
rules:
940947
commas:
941948
ignore:
@@ -1048,10 +1055,6 @@ ssf:
10481055
- [debian , 9 , 2018.3, 2, default]
10491056
# - [ubuntu , 16.04, 2017.7, 2, default]
10501057
use_cirrus_ci: true
1051-
yamllint:
1052-
check_files:
1053-
additional:
1054-
- pillar.debian.example
10551058
semrel_files:
10561059
<<: *semrel_files_default
10571060
inspec/inspec.yml:

0 commit comments

Comments
 (0)