Add setup for YAML/JSON files linting 93/102593/3
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Fri, 28 Feb 2020 13:09:43 +0000 (14:09 +0100)
committerMorgan Richomme <morgan.richomme@orange.com>
Mon, 2 Mar 2020 14:20:42 +0000 (14:20 +0000)
Tox based setup for running linters on YAML and
JSON files. It can be run manually to verify local
changes in _commited_ files.

Relevant CI job (created at Change-Id:
I4f130f6c68222d53dcf022f3fd4a2b41765eaf45) triggered
by change to any of yaml/json files leverages this
setup to run verify tasks.

Change-Id: I07845e3771c0246847184217a96dc90764595f17
Issue-ID: INT-1427
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
.coafile [new file with mode: 0644]
.yamllint [new file with mode: 0644]
tox.ini [new file with mode: 0644]

diff --git a/.coafile b/.coafile
new file mode 100644 (file)
index 0000000..a22c086
--- /dev/null
+++ b/.coafile
@@ -0,0 +1,18 @@
+[yaml]
+bears = YAMLLintBear
+yamllint_config = .yamllint
+ignore =
+  .tox/**,
+  # Doesn't look like a valid YAML although it pretends one
+  deployment/heat/onap-rke/parts/onap-oom-2.yaml
+
+[json]
+bears = JSONFormatBear
+json_sort = False
+indent_size = 2
+ignore =
+  .tox/**,
+  # This one ought to be broken
+  test/mocks/pnfsimulator/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/invalidJsonStructureEvent.json,
+  # This one is empty
+  test/mocks/datafilecollector-testharness/simulator-group/consul/consul_config.json
diff --git a/.yamllint b/.yamllint
new file mode 100644 (file)
index 0000000..ab5bdc3
--- /dev/null
+++ b/.yamllint
@@ -0,0 +1,16 @@
+---
+
+extends: default
+
+rules:
+  line-length: disable
+  truthy: disable
+  braces:
+    max-spaces-inside: 1
+  brackets:
+    max-spaces-inside: 1
+  comments-indentation: disable
+  comments: disable
+  document-start: disable
+  indentation:
+    indent-sequences: whatever
diff --git a/tox.ini b/tox.ini
new file mode 100644 (file)
index 0000000..0d17113
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,29 @@
+[tox]
+minversion = 3.2.0
+envlist = json,yaml
+skipsdist = true
+requires = pip >= 8
+
+[testenv]
+basepython = python3
+whitelist_externals =
+  git
+  bash
+deps =
+  coala-bears
+
+[testenv:json]
+commands_pre =
+    /bin/sh -c "git --no-pager diff HEAD HEAD^ --name-only '*.json' > /tmp/.coalist_json"
+commands =
+# '\ ' at the end of command is needed for a case where above command returns empty list (it adds empty file
+# parameter to '--files' opt
+    /bin/bash -c "coala --non-interactive --disable-caching --no-autoapply-warn json --files $(</tmp/.coalist_json) \ "
+
+[testenv:yaml]
+commands_pre =
+    /bin/sh -c "git --no-pager diff HEAD HEAD^ --name-only '*.yaml' '*.yml' > /tmp/.coalist_yaml"
+commands =
+# '\ ' at the end of command is needed for a case where above command returns empty list (it adds empty file
+# parameter to '--files' opt
+    /bin/bash -c "coala --non-interactive --disable-caching --no-autoapply-warn yaml --files $(</tmp/.coalist_yaml) \ "