diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..696fabf4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +# 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-merge-conflict + - id: mixed-line-ending + - id: check-added-large-files + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 1.11.0 + 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: + # - id: forbid-crlf + - id: remove-crlf 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 diff --git a/.travis.yml b/.travis.yml index 12d5e15e..535709c4 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: + pre-commit run --files `cat clean_files.txt`; + - <<: *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/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). diff --git a/clean_files.txt b/clean_files.txt new file mode 100644 index 00000000..e69de29b 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