From 9866603dbe0e9dacc40158220e9bc07bc12fe722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A4tzel?= Date: Tue, 22 Oct 2019 16:42:16 +0200 Subject: [PATCH] Add pre-commit hook that enforces ormolu formatting --- pre-commit | 17 +++++++++++++++++ src/Main.hs | 8 ++++---- src/Pretty.hs | 3 --- src/Seminar.hs | 2 +- src/Test.hs | 2 +- 5 files changed, 23 insertions(+), 9 deletions(-) create mode 100755 pre-commit diff --git a/pre-commit b/pre-commit new file mode 100755 index 0000000..c7ff367 --- /dev/null +++ b/pre-commit @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + + +tmp=$(mktemp) + + +find src/ -type f | while read f; do + if ! ormolu --mode check "$f"; then + echo "$f is not properly formatted" + echo 1 > "$tmp" + fi +done + + +if test "X1" = "X$(cat "$tmp")"; then + exit 1 +fi diff --git a/src/Main.hs b/src/Main.hs index 5e045a4..fd53534 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -2,11 +2,11 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} -import Protolude hiding (for) -import Pretty -import WS19 import Pipes +import Pretty +import Protolude hiding (for) import System.IO +import WS19 mkPop = population 100 (I prios []) @@ -16,7 +16,7 @@ main = do let t = fromMaybe 100 $ headMay args >>= readMaybe hSetBuffering stdout NoBuffering pop <- mkPop - pop' <- runEffect $ for (run 2 1 (5/100) pop (steps t)) log + pop' <- runEffect $ for (run 2 1 (5 / 100) pop (steps t)) log (res, _) <- bests 5 pop' sequence_ $ format <$> res where diff --git a/src/Pretty.hs b/src/Pretty.hs index 109109b..a46cdcd 100644 --- a/src/Pretty.hs +++ b/src/Pretty.hs @@ -1,11 +1,8 @@ {-# LANGUAGE NoImplicitPrelude #-} - module Pretty where - import Protolude - class Pretty a where pretty :: a -> Text diff --git a/src/Seminar.hs b/src/Seminar.hs index c72bc1c..1f0fa84 100644 --- a/src/Seminar.hs +++ b/src/Seminar.hs @@ -28,7 +28,7 @@ instance Pretty (Maybe Topic) where pretty (Just t) = t pretty Nothing = "Kein Thema" -newtype Priorities = P { unP :: [(Student, [(Topic, Int)])] } +newtype Priorities = P {unP :: [(Student, [(Topic, Int)])]} deriving (Eq, Show) instance Arbitrary Priorities where diff --git a/src/Test.hs b/src/Test.hs index c320594..e0a921d 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -2,9 +2,9 @@ module Main where +import qualified GA import Protolude import qualified Seminar -import qualified GA main :: IO () main = do