From 09118348913252d118a46be9e077a0e9867e65ac Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Wed, 10 May 2023 09:41:30 +1000 Subject: [PATCH] Chore: Add pre-commit hooks, yamllint update tox - 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 Change-Id: Iae948bbb8abf611ee308bdd4bdf96591125b71fa --- .pre-commit-config.yaml | 38 ++++++++++++++++++++++++++++++++++++++ .yamllint | 11 +++++++++++ tox.ini | 40 +++++++++++++++++++++++++++++----------- 3 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 .yamllint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..ea2aa9f6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 index 00000000..d21ceb68 --- /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 5ff30f8b..56241b11 100644 --- 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. -- 2.16.6