Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fourmolu as formatter #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .ci/gitlab/branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ nix-build:
tags:
- local

fourmolu:
extends: .common-local
needs: []
stage: test
script:
- cabal v2-update
# Install the same version as Nix OS manages, 0.14.0.0.
# Installation failure should not make the job fail. This can happen if
# fourmolu was already in PATH for example.
- cabal v2-install --overwrite-policy=always fourmolu-0.14.0.0 || true
- export PATH="$HOME/.cabal/bin:$PATH"
- ./format.sh check

haddock:
extends: .common-local
needs: []
Expand Down
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d3d5a48394c28232c9d84e7a4d8e504dc0d2d0ad
1 change: 1 addition & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import Distribution.Simple

main = defaultMain
60 changes: 60 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -euo pipefail

# Help message
show_help() {
local script_name
script_name=$(basename "$0")
echo "Fourmolu formatting Script.

Usage:
$script_name diff Format the current git diff.
$script_name full Format all source files.
$script_name check Check the formatting of the source files.
$script_name (-h | --help)

Options:
-h --help Show this screen."
}

# Main script logic
if [[ "$#" -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then
show_help
exit 0
fi

# Certain files have CPP annotations which cannot be parsed by fourmolu.
# These files need to be manually formatted.
# Moreover, we also ignore build files in dist-newstyle.
exclude_files=(
"dist-newstyle"
"hdl-tests"
"src/Clash/Cores/UART.hs"
)

# Make sure it doesn't matter from where this script is executed
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR

if [ $1 == "diff" ] ; then
src_files=$(git diff --cached --name-only --diff-filter=ACMR -- '*.hs')
else
src_files=$(find -type f -name "*.hs")
fi

src_files_str=$(printf "%s\n" "${src_files[@]}" | sed 's| |\\ |g')
exclude_files_str=$(printf "%s\n" "${exclude_files[@]}" | sed 's| |\\ |g')
src_files=$(echo "$src_files_str" | grep -vwE "$exclude_files_str")

if [ -z "$src_files" ]; then
exit 0;
fi

if [[ "$1" == "diff" || "$1" == "full" ]] ; then
fourmolu --mode inplace $src_files
elif [[ "$1" == "check" ]] ; then
fourmolu --mode check $src_files
else
echo "Expected a single argument, \"full\", \"diff\", \"check\" or \"--help\"" >&2
exit 3
fi
3 changes: 3 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
indentation: 2
column-limit: 90

1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pkgs.stdenv.mkDerivation {
name = "shell";
buildInputs = project.env.nativeBuildInputs ++ [
haskellPackages.cabal-install
haskellPackages.fourmolu
haskellPackages.haskell-language-server
];
LC_ALL = "C.UTF-8";
Expand Down
34 changes: 17 additions & 17 deletions src/Clash/Cores/Crc.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-|
{- |
Copyright : (C) 2024, Rowan Goemans <[email protected]>
License : BSD2 (see the file LICENSE)
Maintainer : QBayLogic B.V. <[email protected]>
Expand Down Expand Up @@ -75,25 +75,25 @@ indicates how many @BitVector 8@ are valid inside the @Vec@. 0 means 1 is valid.
True

Notice that the 'crcEngine' has a latency of one clock cycle.

-}
module Clash.Cores.Crc (
CrcParams (..),
KnownCrc (..),

module Clash.Cores.Crc
( CrcParams(..)
, KnownCrc(..)
-- ** Software
, SoftwareCrc
, mkSoftwareCrc
, reset
, feed
, digest
, rawResidue
, residue
SoftwareCrc,
mkSoftwareCrc,
reset,
feed,
digest,
rawResidue,
residue,

-- ** Hardware
, HardwareCrc
, deriveHardwareCrc
, crcEngine
, crcValidator
) where
HardwareCrc,
deriveHardwareCrc,
crcEngine,
crcValidator,
) where

import Clash.Cores.Crc.Internal
Loading