From e4eca4d0cc144b01aa4f13cea7618343c60a14dd Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Sat, 24 Aug 2024 11:08:30 -0400 Subject: [PATCH] chore: add pre-commit git hooks to run linters --- .githooks/pre-commit | 19 +++++++++++++++++++ CHANGELOG.md | 1 + docs/developers/developers-setup.md | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..863bca5 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +txtred='\e[0;31m' +txtbld='\e[1m' +txtrst='\e[0m' + +if ! flake8 src/ po/ +then + echo -e "${txtred}${txtbld}Linter error(s) from flake8${txtrst}" + exit 1 +fi + +if ! mypy src/ po/ +then + echo -e "${txtred}${txtbld}Linter error(s) from mypy${txtrst}" + exit 1 +fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 71337fb..0ef98a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Translation: update Portuguese translation (@hugok79) - Translation: add 'nl' in LINGUAS (@hugok79) - Update pypi packages (@MightyCreak) +- Add pre-commit git hooks to run linters (@MightyCreak) ## 0.9.0 - 2024-01-13 diff --git a/docs/developers/developers-setup.md b/docs/developers/developers-setup.md index 16b52cc..fa694f3 100644 --- a/docs/developers/developers-setup.md +++ b/docs/developers/developers-setup.md @@ -10,6 +10,16 @@ Diffuse depends on these projects: * Meson * Flatpak and Flatpak builder (Linux only) +### Install git hooks (optional) + +There is a pre-commit git hook that runs some linters on the source code before committing. + +To install the git hooks (for the repository only), run this command: + +```sh +git config --local core.hooksPath ./.githooks +``` + ## Install the dependencies ### Install the system dependencies