Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an init script of precommit hook with scalafmt. #177

Merged
merged 4 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Development

To work on the Scala API, run sbt using `sbt -DdevMode` (the devMode
To work on the Scala API, run sbt using `sbt -DdevMode=true` (the devMode
option allows to skip webpack execution to speed up execution). You can
use `~compile` or `~test` on the root project or focus on a specific
project using `~timeseries/test`.
Expand Down Expand Up @@ -33,15 +33,23 @@ Use `yarn format` to format the Javascript files.

### Scalafmt

We use Scalafmt to enforce style. The minimal config is found in the
We use Scalafmt to enforce style. The minimal config is found in the
.scalafmt.conf file (you probably won't make any friends if you change
this).

To use you can install the [IntelliJ
Several ways to use it:

1. We provide a `git-init-scalafmt-precommit-hook.sh` that **replaces you git precommit hook** by a Scalafmt check.

__Note__:
- It works only in UNIX like systems with bash installed.
- [You need a Scalafmt installed in your PATH in CLI mode](http://scalameta.org/scalafmt/#CLI).

2. You can install the [IntelliJ
plugin](http://scalameta.org/scalafmt/#IntelliJ) and use the familiar
shift-ctrl-L shortcut.

You can also use the sbt plugin:
3. You can also use the sbt plugin:
```
$> sbt "scalafmt -i"
```
Expand Down
18 changes: 18 additions & 0 deletions git-init-scalafmt-precommit-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# This script creates a pre-commit git hook that run scalafmt before each commit
# http://scalameta.org/scalafmt/
# Need scalafmt installed in CLI mode.
# Tested in Ubuntu's bash.
[ -d .git/hooks/ ] || (echo "It's not a git directory";exit 1)
[ -d .git/hooks/ ] && echo '#!/usr/bin/env bash
echo -e "\e[0;33m Scalafmt RUNNING \e[0m"
scalafmt --git true --diff-branch $(git branch | grep \* | cut -d " " -f2)
RESULT=$?
if [ ${RESULT} -ne 0 ]; then
echo -e "\e[0;31m Scalafmt FAILED \e[0m"
exit ${RESULT}
fi
echo -e "\e[0;32m Scalafmt SUCCEEDED \e[0m"
exit 0
' > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit