Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 2d1afad

Browse files
committed
[CDEC-383] Add stylish-haskell to nix and CI
1 parent 1a27109 commit 2d1afad

File tree

7 files changed

+117
-2
lines changed

7 files changed

+117
-2
lines changed

.buildkite/pipeline.yml

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ steps:
44
agents:
55
system: x86_64-linux
66

7+
- label: 'stylish-haskell'
8+
command: 'scripts/ci/nix-shell.sh --run scripts/check-stylish.sh'
9+
agents:
10+
system: x86_64-linux
11+
712
- label: 'stack2nix'
813
command: 'scripts/ci/nix-shell.sh -p cabal2nix stack cabal-install ghc moreutils expect -Q -j 4 --run scripts/check-stack2nix.sh'
914
agents:

.stylish-haskell.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ steps:
6363
# > (concat, foldl, foldr, head, init, last, length)
6464
#
6565
# Default: after_alias
66-
list_align: after_alias
66+
list_align: with_module_name
6767

6868
# Right-pad the module names to align imports in a group:
6969
#
@@ -198,7 +198,7 @@ steps:
198198
# Note: we tend to write code which fits into 80 characters, in some cases
199199
# 100 is acceptable. For imports we always permit 100 characters because it
200200
# decreases verbosity of diffs and makes merging easier.
201-
columns: 100
201+
columns: 80
202202

203203
# By default, line endings are converted according to the OS. You can override
204204
# preferred format here.

pkgs/default.nix

+69
Original file line numberDiff line numberDiff line change
@@ -75842,6 +75842,75 @@ homepage = "http://github.com/ekmett/structs/";
7584275842
description = "Strict GC'd imperative object-oriented programming with cheap pointers";
7584375843
license = stdenv.lib.licenses.bsd3;
7584475844

75845+
}) {};
75846+
"stylish-haskell" = callPackage
75847+
({
75848+
mkDerivation
75849+
, aeson
75850+
, base
75851+
, bytestring
75852+
, containers
75853+
, directory
75854+
, fetchgit
75855+
, file-embed
75856+
, filepath
75857+
, haskell-src-exts
75858+
, mtl
75859+
, optparse-applicative
75860+
, semigroups
75861+
, stdenv
75862+
, strict
75863+
, syb
75864+
, yaml
75865+
}:
75866+
mkDerivation {
75867+
75868+
pname = "stylish-haskell";
75869+
version = "0.9.2.0";
75870+
src = fetchgit {
75871+
75872+
url = "https://github.com/input-output-hk/stylish-haskell.git";
75873+
sha256 = "0d6ylb07gxv050fpzc6siwxj8c7j1pkcry5zyzimv0xwn1wf6rfy";
75874+
rev = "ecfd3b307d8d13a6d12aff03055f25a39a17e182";
75875+
75876+
};
75877+
isLibrary = true;
75878+
isExecutable = true;
75879+
libraryHaskellDepends = [
75880+
aeson
75881+
base
75882+
bytestring
75883+
containers
75884+
directory
75885+
file-embed
75886+
filepath
75887+
haskell-src-exts
75888+
mtl
75889+
semigroups
75890+
syb
75891+
yaml
75892+
];
75893+
executableHaskellDepends = [
75894+
aeson
75895+
base
75896+
bytestring
75897+
containers
75898+
directory
75899+
file-embed
75900+
filepath
75901+
haskell-src-exts
75902+
mtl
75903+
optparse-applicative
75904+
strict
75905+
syb
75906+
yaml
75907+
];
75908+
doHaddock = false;
75909+
doCheck = false;
75910+
homepage = "https://github.com/jaspervdj/stylish-haskell";
75911+
description = "Haskell code prettifier";
75912+
license = stdenv.lib.licenses.bsd3;
75913+
7584575914
}) {};
7584675915
"sum-type-boilerplate" = callPackage
7584775916
({

scripts/check-stylish.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# check and warn if commits don't conform to stylish-haskell
4+
5+
set -xe
6+
7+
fail_stylish_check() {
8+
# The '-w' option for 'git diff' is used because in some builds
9+
# (i.e. https://buildkite.com/input-output-hk/cardano-sl/builds/976#0fb162df-8f9b-42d7-9ca7-608a9ea06d4d)
10+
# the patch to 'default.nix' only suggests that whitespaces be added
11+
# (see https://gist.github.com/anonymous/f52dbb040db16034d303e27056a0a48e), without
12+
# which the build fails in the 'stack2nix' step.
13+
git diff -w --text > /tmp/stylish.patch
14+
buildkite-agent artifact upload /tmp/stylish.patch --job "$BUILDKITE_JOB_ID"
15+
echo "ERROR: you need to (run ./scripts/haskell/stylish-last-10.sh or apply the patch in the buildkite artifact) and commit the changes" >&2
16+
exit 1
17+
}
18+
19+
# Get relative path to script directory
20+
haskellScriptDir=$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")/haskell/
21+
22+
# shellcheck source=/dev/null
23+
source "${haskellScriptDir}stylish-last-10.sh"
24+
25+
26+
git diff -w --text --exit-code || fail_stylish_check
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let
2+
cardanoPkgs = import ../../. {};
3+
pkgs = import ((import ../../lib.nix).fetchNixPkgs) { };
4+
in pkgs.runCommand "name" { buildInputs = [ cardanoPkgs.stylish-haskell ]; } ""

scripts/haskell/stylish-last-10.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
nix-shell ${haskellScriptDir}shell-with-stylish.nix --run "\
2+
git diff --diff-filter=AMR --name-only -r HEAD~10 |\
3+
grep '.hs$' |\
4+
xargs -I '{}' realpath --relative-to=. $(git rev-parse --show-toplevel)/'{}' |\
5+
xargs -L 1 stylish-haskell -i"

stack.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ packages:
141141
commit: e4e879abca99d0d56015765859fb37af59a81dbb
142142
extra-dep: true
143143

144+
# Add custom stylish-haskell while waiting for PR upstream: https://github.com/jaspervdj/stylish-haskell/pull/214
145+
- location:
146+
git: https://github.com/input-output-hk/stylish-haskell.git
147+
commit: ecfd3b307d8d13a6d12aff03055f25a39a17e182
148+
extra-dep: true
149+
144150
nix:
145151
shell-file: shell.nix
146152

0 commit comments

Comments
 (0)