Skip to content

Commit 5e8ad7a

Browse files
authored
Merge pull request #79 from clash-lang/formatter
Add fourmolu as a formatter
2 parents 0f387ab + 5968f44 commit 5e8ad7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5448
-4263
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8eb89807b15f622e70b25f0eb18f8de6404dac23

.github/workflows/ci.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Setup Stack / GHC
2323
uses: haskell-actions/setup@v2
2424
with:
25-
ghc-version: '8.10.7'
25+
ghc-version: '9.4.8'
2626
cabal-version: '3.10.2.1'
2727
enable-stack: true
2828
stack-version: 'latest'
@@ -54,21 +54,14 @@ jobs:
5454
matrix:
5555
os: [ubuntu-latest]
5656
clash:
57-
- "1.6.1"
5857
- "1.8.1"
5958
cabal:
6059
- "3.10"
6160
ghc:
62-
- "8.10.7"
6361
- "9.0.2"
6462
- "9.2.8"
6563
- "9.4.8"
6664
- "9.6.4"
67-
exclude:
68-
# Clash 1.6 doesn't support latest GHCs
69-
- {clash: "1.6.1", ghc: "9.2.8"}
70-
- {clash: "1.6.1", ghc: "9.4.8"}
71-
- {clash: "1.6.1", ghc: "9.6.4"}
7265

7366
env:
7467
clash_version: ${{ matrix.clash }}
@@ -115,6 +108,19 @@ jobs:
115108
run: |
116109
.ci/build_docs.sh
117110
111+
fourmolu:
112+
runs-on: ubuntu-latest
113+
steps:
114+
# Note that you must checkout your code before running haskell-actions/run-fourmolu
115+
- uses: actions/checkout@v3
116+
- uses: haskell-actions/run-fourmolu@v9
117+
with:
118+
version: "0.14.0.0"
119+
pattern: |
120+
src/**/*.hs
121+
tests/**/*.hs
122+
!src/Protocols/Cpp.hs
123+
118124
linting:
119125
name: Source code linting
120126
runs-on: ubuntu-latest

Setup.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Prelude
21
import Distribution.Extra.Doctest (defaultMainWithDoctests)
2+
import Prelude
33

44
main :: IO ()
55
main = defaultMainWithDoctests "doctests"

clash-protocols.cabal

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,11 @@ common common-options
9191

9292
default-language: Haskell2010
9393
build-depends:
94-
-- GHC >= 8.10
95-
base >= 4.14.0.0,
94+
-- GHC >= 9.0
95+
base >= 4.15.0.0,
9696
Cabal,
9797

98-
-- clash-prelude will set suitable version bounds for the plugins
99-
clash-prelude >= 1.4.0 && < 1.10,
98+
clash-prelude >= 1.8.1 && < 1.10,
10099
ghc-typelits-natnormalise,
101100
ghc-typelits-extra,
102101
ghc-typelits-knownnat

default.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{ nixpkgs ? import ./nix/nixpkgs.nix {} }:
2+
3+
with nixpkgs.pkgs;
4+
with gitignore;
5+
6+
haskellPackages.callCabal2nix "clash-protocols" (gitignoreSource ./.) {}

format.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Help message
5+
show_help() {
6+
local script_name
7+
script_name=$(basename "$0")
8+
echo "Fourmolu formatting Script.
9+
10+
Usage:
11+
$script_name diff Format the current git diff.
12+
$script_name full Format all source files.
13+
$script_name check Check the formatting of the source files.
14+
$script_name (-h | --help)
15+
16+
Options:
17+
-h --help Show this screen."
18+
}
19+
20+
# Main script logic
21+
if [[ "$#" -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then
22+
show_help
23+
exit 0
24+
fi
25+
26+
exclude_files=(
27+
"src/Protocols/Cpp.hs"
28+
)
29+
30+
# Make sure it doesn't matter from where this script is executed
31+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
32+
cd $DIR
33+
34+
if [ $1 == "diff" ] ; then
35+
src_files=$(git diff --cached --name-only --diff-filter=ACMR -- '*.hs')
36+
else
37+
src_files=$(find Setup.hs src tests -type f -name "*.hs")
38+
fi
39+
40+
src_files_str=$(printf "%s\n" "${src_files[@]}" | sed 's| |\\ |g')
41+
exclude_files_str=$(printf "%s\n" "${exclude_files[@]}" | sed 's| |\\ |g')
42+
src_files=$(echo "$src_files_str" | grep -vwE "$exclude_files_str")
43+
44+
if [ -z "$src_files" ]; then
45+
exit 0;
46+
fi
47+
48+
if [[ "$1" == "diff" || "$1" == "full" ]] ; then
49+
fourmolu --mode inplace $src_files
50+
elif [[ "$1" == "check" ]] ; then
51+
fourmolu --mode check $src_files
52+
else
53+
echo "Expected a single argument, \"full\", \"diff\", \"check\" or \"--help\"" >&2
54+
exit 3
55+
fi

fourmolu.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
indentation: 2
2+
column-limit: 90

nix/nixpkgs.nix

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{ sources ? import ./sources.nix }:
2+
3+
let
4+
overlay = _: pkgs: {
5+
6+
# Nix tooling
7+
niv = (import sources.niv {}).niv;
8+
gitignore = import sources.gitignore { inherit (pkgs) lib; };
9+
10+
# Haskell overrides
11+
haskellPackages = pkgs.haskellPackages.override {
12+
overrides = self: super: {
13+
# Add overrides here
14+
circuit-notation =
15+
self.callCabal2nix "circuit-notation" sources.circuit-notation {};
16+
doctest-parallel =
17+
self.callCabal2nix "doctest-parallel" sources.doctest-parallel {};
18+
clash-prelude =
19+
pkgs.haskell.lib.dontCheck (self.callCabal2nix "clash-prelude" (sources.clash-compiler + "/clash-prelude") {});
20+
clash-lib =
21+
self.callCabal2nix "clash-lib" (sources.clash-compiler + "/clash-lib") {};
22+
clash-ghc =
23+
self.callCabal2nix "clash-ghc" (sources.clash-compiler + "/clash-ghc") {};
24+
clash-prelude-hedgehog =
25+
self.callCabal2nix "clash-prelude" (sources.clash-compiler + "/clash-prelude-hedgehog") {};
26+
tasty-hedgehog =
27+
self.callCabal2nix "tasty-hedgehog" sources.tasty-hedgehog {};
28+
hedgehog =
29+
self.callCabal2nix "hedgehog" (sources.haskell-hedgehog + "/hedgehog") {};
30+
};
31+
};
32+
};
33+
34+
in import sources.nixpkgs { overlays = [ overlay ]; }

nix/sources.json

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"clash-compiler": {
3+
"branch": "1.8",
4+
"description": "Haskell to VHDL/Verilog/SystemVerilog compiler",
5+
"homepage": "https://clash-lang.org/",
6+
"owner": "clash-lang",
7+
"repo": "clash-compiler",
8+
"rev": "3f5dc67c0e526e43a4dd88eb3902e39ed512c166",
9+
"sha256": "022rwif8xkaabw0j3arhyj0hswmh3vq2nx1bbz8rbkp05jm4psgg",
10+
"type": "tarball",
11+
"url": "https://github.com/clash-lang/clash-compiler/archive/3f5dc67c0e526e43a4dd88eb3902e39ed512c166.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
13+
"version": "1.8.1"
14+
},
15+
"doctest-parallel": {
16+
"branch": "main",
17+
"description": "Test interactive Haskell examples",
18+
"homepage": null,
19+
"owner": "martijnbastiaan",
20+
"repo": "doctest-parallel",
21+
"rev": "d73df0a2fd58b0b6aba438eb40aa56d30724e42a",
22+
"sha256": "1k88bkwz2crvb6dafcf6y5y6wm0m2qvds57f3b0rx4id7la4qv89",
23+
"type": "tarball",
24+
"url": "https://github.com/martijnbastiaan/doctest-parallel/archive/d73df0a2fd58b0b6aba438eb40aa56d30724e42a.tar.gz",
25+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
26+
"version": "0.3.1"
27+
},
28+
"gitignore": {
29+
"branch": "master",
30+
"description": "Nix function for filtering local git sources",
31+
"homepage": "",
32+
"owner": "hercules-ci",
33+
"repo": "gitignore",
34+
"rev": "bff2832ec341cf30acb3a4d3e2e7f1f7b590116a",
35+
"sha256": "0va0janxvmilm67nbl81gdbpppal4aprxzb25gp9pqvf76ahxsci",
36+
"type": "tarball",
37+
"url": "https://github.com/hercules-ci/gitignore/archive/bff2832ec341cf30acb3a4d3e2e7f1f7b590116a.tar.gz",
38+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
39+
},
40+
"haskell-hedgehog": {
41+
"branch": "master",
42+
"description": "Release with confidence, state-of-the-art property testing for Haskell.",
43+
"homepage": "",
44+
"owner": "hedgehogqa",
45+
"repo": "haskell-hedgehog",
46+
"rev": "52c35cabe24de2a1c03e72dde9d04b64f81d1f44",
47+
"sha256": "1f9znljkmrdd4nlfmjfi8kx0fgcysp328rz27099n7bygchpgjr6",
48+
"type": "tarball",
49+
"url": "https://github.com/hedgehogqa/haskell-hedgehog/archive/52c35cabe24de2a1c03e72dde9d04b64f81d1f44.tar.gz",
50+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
51+
"version": "1.4"
52+
},
53+
"circuit-notation": {
54+
"branch": "master",
55+
"description": "A plugin for circuit notation",
56+
"homepage": null,
57+
"owner": "cchalmers",
58+
"repo": "circuit-notation",
59+
"rev": "19b386c4aa3ff690758ae089c7754303f3500cc9",
60+
"sha256": "0qz2w6akxj51kq50rbl88bnjyxzd2798a9sn9jj1z2kak7a6kqbg",
61+
"type": "tarball",
62+
"url": "https://github.com/cchalmers/circuit-notation/archive/19b386c4aa3ff690758ae089c7754303f3500cc9.tar.gz",
63+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
64+
},
65+
"niv": {
66+
"branch": "master",
67+
"description": "Easy dependency management for Nix projects",
68+
"homepage": "https://github.com/nmattia/niv",
69+
"owner": "nmattia",
70+
"repo": "niv",
71+
"rev": "723f0eeb969a730db3c30f977c2b66b9dce9fe4a",
72+
"sha256": "0016l7230gd2kdh0g2w573r9a2krqb7x4ifcjhhsn4h1bwap7qr0",
73+
"type": "tarball",
74+
"url": "https://github.com/nmattia/niv/archive/723f0eeb969a730db3c30f977c2b66b9dce9fe4a.tar.gz",
75+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
76+
},
77+
"nixpkgs": {
78+
"branch": "nixpkgs-unstable",
79+
"description": "Nix Packages collection",
80+
"homepage": "",
81+
"owner": "NixOS",
82+
"repo": "nixpkgs",
83+
"rev": "e2dd4e18cc1c7314e24154331bae07df76eb582f",
84+
"sha256": "19zbxf7rb787jvyrfhl4z9sn3aisd6xvx6ikybbi75ym9sy39jds",
85+
"type": "tarball",
86+
"url": "https://github.com/NixOS/nixpkgs/archive/e2dd4e18cc1c7314e24154331bae07df76eb582f.tar.gz",
87+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
88+
},
89+
"tasty-hedgehog": {
90+
"branch": "master",
91+
"description": "Tasty integration for the Hedgehog property testing library",
92+
"homepage": "",
93+
"owner": "qfpl",
94+
"repo": "tasty-hedgehog",
95+
"rev": "ed07ecef3f6a01572b577b450ba6d58108173125",
96+
"sha256": "1b8y5ibg1ihgf44nyym4g45lwmabymfcjb2nigv93s2fmng9zp6r",
97+
"type": "tarball",
98+
"url": "https://github.com/qfpl/tasty-hedgehog/archive/ed07ecef3f6a01572b577b450ba6d58108173125.tar.gz",
99+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
100+
"version": "1.4.0.2"
101+
}
102+
}

0 commit comments

Comments
 (0)