Skip to content

Commit

Permalink
Merge pull request #125 from hhefesto/pre-commit-hook
Browse files Browse the repository at this point in the history
Pre commit hook
  • Loading branch information
sfultong authored Aug 27, 2024
2 parents 9925d16 + 3cf3a6c commit 79987f3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,50 @@ This project is in active development. Do expect bugs and general trouble, and p
## Quick Start

1. Clone this repository and change directory to it:
```
```sh
$ git clone https://github.com/Stand-In-Language/stand-in-language.git
$ cd stand-in-language
```
2. [Install Nix](https://nixos.org/nix/download.html):
```
```sh
$ curl https://nixos.org/nix/install | sh
```
3. Optional (reduces build time by using telomare's cache):
```
```sh
# Install cachix with nix-env or adding `cachix` to your `/etc/nixos/configuration.nix`'s' `environment.systemPackages` if in NixOS.
$ nix-env -iA cachix -f https://cachix.org/api/v1/install
$ cachix use telomare
```
4. Enter a Nix shell. This will setup an environment where all external dependencies will be available (such as `cabal` for building):
```
$ nix-shell shell.nix
```sh
$ nix develop # or nix develop -c zsh
```
5. Build the project:
```
$ cabal new-build
```sh
$ cabal build # or nix build
```
6. Run the tictactoe example and start playing with a friend (or run your own telomare file):
```
$ cabal new-run telomare -- tictactoe.tel
```sh
$ cabal run telomare -- tictactoe.tel # or nix run . -- tictactoe.tel
```
7. Profit!

## Running `cabal new-repl`

There is a known issue (#7) for getting a repl.

To get around it, you should copy `libgc.so.1` (provided by the `bohem` garbage collector) into your repository (telomare/lib is a good choice) and rename it to `libgc.so`. You will also need to reference it on `telomare.cabal` under the `library` stanza. Be sure to use the complete path for `libgc.so` on `telomare.cabal` (a commented version on `telomare.cabal` is provided as an example).

## Telomare REPL
1. Run:
```
```sh
$ cd <your/local/proyect/location>/telomare
$ nix-shell shell.nix
$ cabal new-build
$ cabal new-run telomare-repl -- --haskell
$ nix develop -c zsh
$ cabal run telomare-repl -- --haskell # or nix run .#repl
```
2. Profit!

## Git Hooks

You can setup your git configuration to automatically format and look for lint suggestions. Just run:

``` sh
$ git config core.hooksPath hooks
```

## Contributing
If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

Expand Down
27 changes: 27 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

echo "Formatting:"
# Formatting
nix develop -c stylish-haskell -irv .
output=$(git diff)
if [ "$output" = "" ]; then
echo "Success! No formatting suggestions applied."
else
echo "These stylish-haskell formatting changes will be made for your commit:"
echo "$output"
fi
echo "Finished formatting"

# Linting
# TODO: The --refactor flag does not work even after adding `apply-refactor` to the devShell
echo "Linting:"
output=$(nix develop -c hlint . --no-exit-code)
if [ "$output" = "No hints" ]; then
echo "Success! No Hlint suggestions."
else
echo "Failure: Hlint has some suggestions for your commit"
echo "$output"
echo "Please fix or add an exception to the .hlint.yaml file"
exit 1
fi
echo "Finished linting"

0 comments on commit 79987f3

Please sign in to comment.