Last active
March 1, 2019 07:25
-
-
Save mikeplus64/3bf4d6dfa3412e5485dceb71686c0630 to your computer and use it in GitHub Desktop.
apply stylish-haskell to only module preamble+imports, if stylish-haskell fails on entire module first
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
INPUT="$(cat)" | |
IFS='' | |
ERRORS="$(mktemp)" | |
EXIT_OK=true | |
if ! (echo "$INPUT" | stylish-haskell 2>>"$ERRORS") ; then | |
PREAMBLE="$(echo "$INPUT" | grep -B100000 '^import')" | |
LEFTOVERS="$(echo "$INPUT" | tail -n +$((1 + $(echo "$PREAMBLE" | wc -l))))" | |
if echo "$PREAMBLE" | stylish-haskell 2>>"$ERRORS"; then | |
echo "$LEFTOVERS" | |
else | |
cat "$ERRORS" 1>&2 | |
EXIT_OK=false | |
fi | |
fi | |
rm "$ERRORS" | |
$EXIT_OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment