From f639e3aa196d5c422e0fededfd1c9899a6c59f82 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 9 Jun 2019 13:53:40 +0200 Subject: [PATCH] Add pre-commit hook and setup script (#129) Add pre-commit hook and setup script Runs the appropriate linter on staged files before committing. --- package.json | 3 ++- scripts/git-hooks/install | 2 ++ scripts/git-hooks/pre-commit | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 scripts/git-hooks/install create mode 100755 scripts/git-hooks/pre-commit diff --git a/package.json b/package.json index 61a1ab8..66569fa 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "lint:contracts": "solhint \"contracts/**/*.sol\" \"apps/*/contracts/**/*.sol\"", "lint:contract-tests": "eslint apps/*/test", "lint:wrapper": "eslint lib/", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "setup-git-hooks": "sh scripts/git-hooks/install" }, "repository": { "type": "git", diff --git a/scripts/git-hooks/install b/scripts/git-hooks/install new file mode 100644 index 0000000..0bdcb14 --- /dev/null +++ b/scripts/git-hooks/install @@ -0,0 +1,2 @@ +#!/bin/sh +cp -f scripts/git-hooks/pre-commit .git/hooks diff --git a/scripts/git-hooks/pre-commit b/scripts/git-hooks/pre-commit new file mode 100755 index 0000000..1055313 --- /dev/null +++ b/scripts/git-hooks/pre-commit @@ -0,0 +1,17 @@ +#!/bin/sh +# +# Run appropriate linter against staged files +# +if [ $(git diff --name-only --cached lib/ | wc -l) != 0 ]; then + ./node_modules/.bin/eslint lib/ + if [ $? != 0 ]; then + exit 1 + fi +fi +# TODO master not linted yet, uncomment this when ready +# if [ $(git diff --name-only --cached contracts/ | wc -l) != 0 ]; then +# solhint contracts/**/*.sol && apps/*/contracts/**/*.sol +# if [ $? != 0 ]; then +# exit 1 +# fi +# fi