Chore: Add pre-commit hooks, yamllint update tox 66/11066/2
authorAnil Belur <abelur@linuxfoundation.org>
Tue, 9 May 2023 23:41:30 +0000 (09:41 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Wed, 10 May 2023 00:46:29 +0000 (10:46 +1000)
- Add pre-commit hooks to check for tailing whitespaces
  linting, prettier.
- Update tox to invoke pre-commit and remove outdated deps.
- Add .yamllint conf file.

Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
Change-Id: Iae948bbb8abf611ee308bdd4bdf96591125b71fa

.pre-commit-config.yaml [new file with mode: 0644]
.yamllint [new file with mode: 0644]
tox.ini

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644 (file)
index 0000000..ea2aa9f
--- /dev/null
@@ -0,0 +1,38 @@
+---
+default_language_version:
+  python: python3
+  node: "14.13.0"
+repos:
+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v4.2.0
+    hooks:
+      - id: check-json
+      - id: trailing-whitespace
+
+  - repo: https://github.com/pre-commit/mirrors-prettier
+    rev: v2.6.2
+    hooks:
+      - id: prettier
+        stages: [commit]
+
+  - repo: https://github.com/jorisroovers/gitlint
+    rev: v0.17.0
+    hooks:
+      - id: gitlint
+        stages: [commit-msg]
+
+  - repo: https://github.com/jumanjihouse/pre-commit-hooks
+    rev: 2.1.6
+    hooks:
+      - id: shellcheck
+        exclude: >
+          (?x)^(
+              jjb/global-jjb/.*|
+              packer/common-packer/.*|
+              jenkins-config/.*
+          )$
+
+  - repo: https://github.com/adrienverge/yamllint
+    rev: v1.26.3
+    hooks:
+      - id: yamllint
diff --git a/.yamllint b/.yamllint
new file mode 100644 (file)
index 0000000..d21ceb6
--- /dev/null
+++ b/.yamllint
@@ -0,0 +1,11 @@
+extends: default
+
+rules:
+  braces:
+    max-spaces-inside: 1
+  empty-lines:
+    max-end: 1
+  line-length:
+    max: 120
+    ignore: |
+      packer
diff --git a/tox.ini b/tox.ini
index 5ff30f8..56241b1 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -1,17 +1,35 @@
 [tox]
 minversion = 1.6
-envlist = coala
+envlist = pre-commit
 skipsdist = true
 
-[testenv:coala]
-basepython = python3
+[testenv:jenkins-jobs]
 deps =
-    coala==0.11
-    coala-bears==0.11
-    pygments~=2.3.1
-    nodeenv~=1.3.0
+    jenkins-job-builder=={env:JJB_VERSION:5.0.2}
+commands =
+    jenkins-jobs {posargs:--help}
+
+[testenv:pre-commit-install]
+basepython = python3
+deps = pre-commit
+commands =
+    pre-commit install
+    pre-commit install --hook-type commit-msg
+
+[testenv:pre-commit-uninstall]
+basepython = python3
+deps = pre-commit
+commands =
+    pre-commit uninstall
+    pre-commit uninstall --hook-type commit-msg
+
+[testenv:pre-commit]
+basepython = python3
+deps = pre-commit
+passenv = HOME
 commands =
-    nodeenv -p
-    npm install --global write-good
-    python3 -m nltk.downloader punkt maxent_treebank_pos_tagger averaged_perceptron_tagger
-    coala --non-interactive
+    pre-commit run --all-files --show-diff-on-failure
+    pre-commit run gitlint --hook-stage commit-msg --commit-msg-filename .git/COMMIT_EDITMSG
+    # Gitlint only proposes a pre-commit configuration for the commit-msg stage but none for the commit stage.
+    # Its default arguments --passed and --msg-filename are different from CI recommandations.
+    # As a result, the line above is always skipped in jenkins CI since there cannot be a .git/COMMIT_EDITMSG file.