From 9ac6a6ab964d4f77356376042138fc08d206b5f0 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 15 Oct 2019 14:34:32 +0300 Subject: [PATCH 1/8] Enforce some coding standards for the contributers --- .pre-commit-config.yaml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..2443753a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +--- +# fail_fast: true +minimum_pre_commit_version: 1.18.1 +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-docstring-first + - id: check-merge-conflict + - id: requirements-txt-fixer + - id: double-quote-string-fixer + - id: forbid-new-submodules + - id: mixed-line-ending + - id: check-added-large-files + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 1.11.0 + hooks: + - id: forbid-binary + - id: git-check # Configure in .gitattributes + - id: git-dirty # Configure in .gitignore + - id: markdownlint # Configure in .mdlrc + - id: shellcheck + - id: shfmt + - repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.1.7 + hooks: + # - id: forbid-crlf + - id: remove-crlf + # - id: forbid-tabs + - id: remove-tabs + args: [--whitespaces-count, '2'] # defaults to: 4 From 250bd2bbd8d74885427e19e2bcff407a589809b2 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 15 Oct 2019 15:05:52 +0300 Subject: [PATCH 2/8] Add a note on how to use the pre-commit yaml. --- DEVELOPMENT.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index e2fc7bd5..2f7941cb 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -64,3 +64,11 @@ These items are subject to change. When making changes to the internal functiona Plugins can define a function that will be called when the plugin is being disabled. The callback name should be `{PLUGIN_NAME}_on_disable`, you can see `gitstatus` for usage example. + +## Using the pre-commit hook + +Note the file .pre-commit-config.yaml at the top of the repo. +This file configures the behavior of the a pre-commit hook based on [the Pre-Commit framework](https://pre-commit.com/). Please see the site about +installing it (with pip, brew or other tools) then run `pre-commit install` in the repo's root to activate the hook. +For the full use of the tool, you may need to install also other third-party tools, such as +[shellcheck](https://github.com/koalaman/shellcheck/) and [shfmt](https://github.com/mvdan/sh). From d986261f98c25a259b593feba290cfa9ab9156fc Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 15 Oct 2019 16:17:16 +0300 Subject: [PATCH 3/8] another round of refinements after PR #1434 --- .pre-commit-config.yaml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2443753a..4fa61012 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,20 +9,13 @@ repos: hooks: - id: trailing-whitespace - id: end-of-file-fixer - - id: check-docstring-first - id: check-merge-conflict - - id: requirements-txt-fixer - - id: double-quote-string-fixer - - id: forbid-new-submodules - id: mixed-line-ending - id: check-added-large-files - repo: https://github.com/jumanjihouse/pre-commit-hooks rev: 1.11.0 hooks: - - id: forbid-binary - id: git-check # Configure in .gitattributes - - id: git-dirty # Configure in .gitignore - - id: markdownlint # Configure in .mdlrc - id: shellcheck - id: shfmt - repo: https://github.com/Lucas-C/pre-commit-hooks @@ -33,3 +26,4 @@ repos: # - id: forbid-tabs - id: remove-tabs args: [--whitespaces-count, '2'] # defaults to: 4 + exclude: .gitmodules From 5045867b2c3c0940da5d4ad9241facadd2a30d71 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 10 Mar 2020 10:09:32 +0200 Subject: [PATCH 4/8] Don't touch tab indentations, they are there for a good reason --- .pre-commit-config.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4fa61012..51e4318d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,3 @@ repos: hooks: # - id: forbid-crlf - id: remove-crlf - # - id: forbid-tabs - - id: remove-tabs - args: [--whitespaces-count, '2'] # defaults to: 4 - exclude: .gitmodules From b14a38fec953e3d1558b6f095c9f588c1c5c1012 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 21 Jun 2020 16:01:05 +0300 Subject: [PATCH 5/8] ci: Add pre-commit run and remove trailling spaces --- .travis.yml | 26 +++++++++++++++++++++++--- test/lint-requirements.txt | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/lint-requirements.txt diff --git a/.travis.yml b/.travis.yml index 12d5e15e..68624bc8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,19 +12,39 @@ os: linux dist: xenial +cache: + directories: + - "${HOME}/.cache/pip" + - "${HOME}/.cache/pre-commit" + - "${HOME}/.pre-commit-venv" + - "${HOME}/bin" + - /usr/lib/python3.8 + jobs: + include: + - language: go + go: "1.14" + name: Ubuntu 18.04 + dist: bionic + sudo: required + before_script: + GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt; + curl https://pre-commit.com/install-local.py | python3 - + script: + SKIP=shellcheck pre-commit run --all-files; + - <<: *native_job name: Ubuntu 16.04 - + - <<: *native_job name: Ubuntu 18.04 dist: bionic - + - <<: *native_job name: MacOS xcode9.4 os: osx osx_image: xcode9.4 # Default xcode on Travis. - + - <<: *native_job name: MacOS xcode11.5 os: osx diff --git a/test/lint-requirements.txt b/test/lint-requirements.txt new file mode 100644 index 00000000..72224bf8 --- /dev/null +++ b/test/lint-requirements.txt @@ -0,0 +1 @@ +pre-commit==2.3.0 From 45d076567a13635f5a266261fca384801d5af22d Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 21 Jun 2020 21:32:46 +0300 Subject: [PATCH 6/8] Add simple shellcheckrc --- .shellcheckrc | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .shellcheckrc diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 00000000..6418bd8f --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,6 @@ +# We use colors and not assigned +disable=SC2154 +# Hard to fix +disable=SC2155 +# shellcheck is wrong on some +disable=SC2034 From 2acf26b7b3c1b976e7f9ecac9dd2793f67836f55 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 13 Oct 2020 17:20:11 +0300 Subject: [PATCH 7/8] pre-commit: Do not run shfmt/shellcheck on .bats files --- .pre-commit-config.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 51e4318d..696fabf4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,9 @@ repos: hooks: - id: git-check # Configure in .gitattributes - id: shellcheck + exclude: ".bats$" - id: shfmt + exclude: ".bats$" - repo: https://github.com/Lucas-C/pre-commit-hooks rev: v1.1.7 hooks: From d150fc6ec18ef8b81fd781ef9bc75646675ce4a5 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Thu, 15 Oct 2020 23:49:52 +0300 Subject: [PATCH 8/8] ci: Run pre-commit only on whitelisted files --- .travis.yml | 2 +- clean_files.txt | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 clean_files.txt diff --git a/.travis.yml b/.travis.yml index 68624bc8..535709c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ jobs: GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt; curl https://pre-commit.com/install-local.py | python3 - script: - SKIP=shellcheck pre-commit run --all-files; + pre-commit run --files `cat clean_files.txt`; - <<: *native_job name: Ubuntu 16.04 diff --git a/clean_files.txt b/clean_files.txt new file mode 100644 index 00000000..e69de29b