rabbah commented on a change in pull request #2650: Apply standard scala 
formatting.
URL: 
https://github.com/apache/incubator-openwhisk/pull/2650#discussion_r136810654
 
 

 ##########
 File path: docs/dev/hooks.md
 ##########
 @@ -0,0 +1,23 @@
+# Git pre-commit hooks
+
+To minimize review overhead OpenWhisk uses tools to enforce our coding 
standards. This is a set of git pre-commit hooks which will automatically check 
for formatting errors, so you don't need to wait for a CI build to fail to find 
those.
+
+## Scala
+
+Scala is formatted using [scalafmt](http://scalameta.org/scalafmt/). It's 
configuration can be found [here](../.scalafmt.conf). To automatically reformat 
**changed** Scala files upon commit, add the following to your `pre-commit` 
hook.
+
+```bash
+#!/bin/sh
+
+# determine openwhisk base directory
+root="$(git rev-parse --show-toplevel)"
+
+git diff --name-only --cached | grep '\.scala'
+if [ "$?" -eq 0 ]; then
+    # reformat scala code iff a scala file changed
+    $root/gradlew scalafmtAll
+fi
+
+# readd all staged files
+git add "$(git diff --name-only --cached)"
+```
 
 Review comment:
   should we mention scan code also (and link to that commit hook)?
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to