From: guillaume.lambert <guillaume.lambert@orange.com>
Date: Thu, 7 Jul 2022 17:59:38 +0000 (+0200)
Subject: Use pre-commit in CI to fix trailing blanks & tabs
X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=43823bba039100d09a0820c820cd725e1d14b69e;p=functest.git

Use pre-commit in CI to fix trailing blanks & tabs

Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: I7e2d918ced690624df44ef8a84df865aa8505b40
(cherry picked from commit beaf6055d77b00dc4ff90165512d2877afc7b79d)
---

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 000000000..323386c88
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,16 @@
+---
+repos:
+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v4.4.0
+    hooks:
+      - id: trailing-whitespace
+        exclude: '.patch$'
+        # trailing blanks shall not preferably be fixed in patch files
+
+  - repo: https://github.com/Lucas-C/pre-commit-hooks
+    rev: v1.4.2
+    hooks:
+      - id: remove-tabs
+        stages: [commit]
+        exclude: '^(.git/|docs/make.bat|docs/Makefile|)'
+
diff --git a/test-requirements.txt b/test-requirements.txt
index a552f60f2..5fdfd2948 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -15,3 +15,4 @@ doc8 # Apache-2.0
 bashate # Apache-2.0
 bandit
 sphinxcontrib-spelling
+pre-commit
diff --git a/tox.ini b/tox.ini
index a04067d80..f9c99247e 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = docs,pep8,pylint,yamllint,bashate,bandit,py310,cover,perm
+envlist = docs,pep8,pylint,yamllint,bashate,bandit,py310,cover,perm,pre-commit
 
 [testenv]
 pip_version = pip==20.2.4
@@ -92,3 +92,8 @@ commands =
     -exec ls -l \{\} + | grep '.' && exit 1 || exit 0"
   sh -c "\
     find {[testenv:perm]path} -exec file \{\} + | grep CRLF && exit 1 || exit 0"
+
+[testenv:pre-commit]
+basepython = python3.10
+commands =
+    pre-commit run --all-files --show-diff-on-failure
diff --git a/upper-constraints.txt b/upper-constraints.txt
index ef6679936..833c7986e 100644
--- a/upper-constraints.txt
+++ b/upper-constraints.txt
@@ -21,3 +21,4 @@ ruamel.yaml===0.17.17
 sphinxcontrib-spelling===4.3.0
 ansible-lint===5.2.1
 setuptools_scm===6.3.2
+pre-commit===3.1.1