From b099b0cb350633ff2c5b9cc0aaff47bafdaf7b54 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Tue, 2 Aug 2022 08:02:11 +0000 Subject: [PATCH] [IMP] web: tooling: abort commit if tooling is outdated Currently, if your tooling is not up to date, the pre-commit hook will happily just format your code with the outdated config. This is undesirable because the next person to touch the file with an up-to-date config will introduce a bunch of linting noice in their commit. This commit adds some basic checking by comparing the config files and aborting the commit if they are out of date, and suggesting a refresh when the eslint/prettier config files have changed or a full reload if the package.json has changed. closes odoo/odoo#97286 Signed-off-by: Simon Genin (ges@odoo) --- addons/web/tooling/hooks/pre-commit | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/web/tooling/hooks/pre-commit b/addons/web/tooling/hooks/pre-commit index b6f58d2cbde..92791d94e30 100755 --- a/addons/web/tooling/hooks/pre-commit +++ b/addons/web/tooling/hooks/pre-commit @@ -1,5 +1,18 @@ #!/bin/bash # run tooling only on branches that start with master to avoid linting noise in stable if [[ $(git branch --show-current) == master* ]]; then + if ! cmp -s -- addons/web/tooling/_package.json package.json; then + echo "Your package.json is out of date, reload the tooling using the reload script" + exit 1 + fi + if + ! cmp -s -- addons/web/tooling/_eslintignore .eslintignore || + ! cmp -s -- addons/web/tooling/_prettierignore .prettierignore || + ! cmp -s -- addons/web/tooling/_eslintrc.json .eslintrc.json || + ! cmp -s -- addons/web/tooling/_prettierrc.json .prettierrc.json + then + echo "Some of your eslint/prettier config files are out of date, refresh them using the refresh script" + exit 1 + fi npm run format-staged fi