Use pre-commit instead of coala 34/81434/4
authorThanh Ha <zxiiro@gmail.com>
Mon, 8 Apr 2019 02:37:55 +0000 (10:37 +0800)
committerDaniel Farrell <dfarrell@redhat.com>
Tue, 9 Apr 2019 08:37:56 +0000 (04:37 -0400)
Idea here is to replace slow coala linter with the much faster
pre-commit tool for linting. Pre-commit hooks run only against
the files that changed rather than running against every single
file in the repo. Additionally after installing pre-commit it
will automatically run on every local commit so linting happens
without the developer even having to think about it. Pre-commit
will also automatically make the changes for you when it detects
failed lint issues.

Install can be performed via the following method:

1.a) Install pre-commit from your package manager, like pip:

    pip install pre-commit --user

1.b) Install the commit hook:

    pre-commit install --hook-type commit-msg

2) Install via tox & run tests using the tox pre-commit env:

    tox -e pre-commit

Option 2 is an all in 1 environment and is method most folks will want
to use and only needs to be run once for initial configuration. Once
installed pre-commit will automatically run on every `git commit` call
automatically.

Change-Id: I0a583905d026a60250c395b364a80bf73c5b46ab
Signed-off-by: Thanh Ha <zxiiro@gmail.com>
.coafile [deleted file]
.pre-commit-config.yaml [new file with mode: 0644]
tox.ini

diff --git a/.coafile b/.coafile
deleted file mode 100644 (file)
index 1d15dde..0000000
--- a/.coafile
+++ /dev/null
@@ -1,31 +0,0 @@
-[Default]
-use_spaces = True
-enforce_newline_at_EOF = False
-default_actions = SpaceConsistencyBear: ApplyPatchAction
-
-[Git]
-bears = GitCommitBear
-ignore_length_regex = Signed-off-by,
-    Also-by,
-    Co-authored-by,
-    http://,
-    https://
-
-[Markdown]
-bears = MarkdownBear,SpaceConsistencyBear
-files = **.md
-ignore = .**,
-    docs/submodules/**
-max_line_length = 120
-
-[reStructuredText]
-bears = SpaceConsistencyBear
-files = **.rst
-ignore = .**,
-    docs/developer-guide/**,
-    docs/documentation.rst,
-    docs/getting-started-guide/**,
-    docs/opendaylight-with-openstack/**,
-    docs/release-notes/projects/**,
-    docs/templates/template-user-guide.rst,
-    docs/user-guide/**
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644 (file)
index 0000000..650ccd7
--- /dev/null
@@ -0,0 +1,22 @@
+---
+repos:
+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v1.3.0
+    hooks:
+      - id: trailing-whitespace
+
+  - repo: https://github.com/jorisroovers/gitlint
+    rev: v0.11.0
+    hooks:
+      - id: gitlint
+
+  - repo: https://github.com/Lucas-C/pre-commit-hooks
+    sha: v1.1.6
+    hooks:
+      - id: remove-tabs
+        exclude: >
+            (?x)^(
+                .git/COMMIT_EDITMSG|
+                docs/make.bat|
+                docs/Makefile
+            )$
diff --git a/tox.ini b/tox.ini
index ddfad28cd5c93384f9c12ecbad3cf31c2b8698c1..7987050ef04a868704cca16d1258f074bec4da87 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -1,21 +1,8 @@
 [tox]
 minversion = 1.6
-envlist = coala,docs
+envlist = pre-commit,docs
 skipsdist = true
 
-[testenv:coala]
-basepython = python3
-deps =
-    coala==0.11
-    coala-bears==0.11
-    # Requests 2.16 breaks coala dependency on chardet
-    requests<2.16
-    nodeenv==1.1.2
-commands =
-    nodeenv -p
-    npm install --global remark-cli remark-lint
-    coala --non-interactive
-
 [testenv:docs]
 deps = -rdocs/requirements.txt
 commands =
@@ -24,3 +11,10 @@ commands =
 [testenv:docs-linkcheck]
 deps = -rdocs/requirements.txt
 commands = sphinx-build -j auto -W -b linkcheck -d {envtmpdir}/doctrees ./docs/ {toxinidir}/docs/_build/linkcheck
+
+[testenv:pre-commit]
+deps = pre-commit
+commands =
+    pre-commit install
+    pre-commit install --hook-type commit-msg
+    pre-commit run --all-files