From 0a8284f1ed8695a759fc565bd6077fcbc2c65323 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 14 May 2019 12:42:56 +0200 Subject: [PATCH 1/4] 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..d09baa9 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": "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..ee94818 --- /dev/null +++ b/scripts/git-hooks/install @@ -0,0 +1,2 @@ +#!/bin/sh +cp 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 -- 2.25.1 From a028db07186fd8bd571badba228a78c93233b863 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 14 May 2019 12:46:44 +0200 Subject: [PATCH 2/4] Document hook setup in README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 45126f7..468d73e 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ Each of the aragon apps are separate packages: You can use `npm run install-all` to install all app dependencies at once. +We also recommend using our git hooks for linting staged files and other +convenient helpers. You can install them via: + + $ npm run setup + ### Local development chain For local development it is recommended to use -- 2.25.1 From 698741ec09ac2ce56af7a09ec06a5287a382fd3a Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 22 May 2019 10:38:10 +0200 Subject: [PATCH 3/4] Turn git-hook setup into post-install script 1. Don't have to think about them 2. Updates hooks autonmatically --- README.md | 5 ----- package.json | 4 ++-- scripts/git-hooks/install | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 468d73e..45126f7 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,6 @@ Each of the aragon apps are separate packages: You can use `npm run install-all` to install all app dependencies at once. -We also recommend using our git hooks for linting staged files and other -convenient helpers. You can install them via: - - $ npm run setup - ### Local development chain For local development it is recommended to use diff --git a/package.json b/package.json index d09baa9..9a33d4a 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "scripts": { "install-all": "./scripts/every-app.sh \"npm install\"", + "postinstall": "sh scripts/git-hooks/install", "build-json": "npm run compile-contracts && node ./scripts/build-json.js", "repl": "truffle exec scripts/repl.js", "seeds": "truffle exec scripts/seeds.js", @@ -23,8 +24,7 @@ "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", - "setup": "sh scripts/git-hooks/install" + "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", diff --git a/scripts/git-hooks/install b/scripts/git-hooks/install index ee94818..0bdcb14 100644 --- a/scripts/git-hooks/install +++ b/scripts/git-hooks/install @@ -1,2 +1,2 @@ #!/bin/sh -cp scripts/git-hooks/pre-commit .git/hooks +cp -f scripts/git-hooks/pre-commit .git/hooks -- 2.25.1 From 068984481388cefbc8bdbdfcf654abcc99f89fd5 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 9 Jun 2019 13:32:23 +0200 Subject: [PATCH 4/4] Rename setup hook again --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9a33d4a..66569fa 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ }, "scripts": { "install-all": "./scripts/every-app.sh \"npm install\"", - "postinstall": "sh scripts/git-hooks/install", "build-json": "npm run compile-contracts && node ./scripts/build-json.js", "repl": "truffle exec scripts/repl.js", "seeds": "truffle exec scripts/seeds.js", @@ -24,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", -- 2.25.1