1#!/bin/sh
2#
3# SPDX-FileCopyrightText: 2023,2025 Sören Tempel <soeren+git@soeren-tempel.net>
4#
5# SPDX-License-Identifier: GPL-3.0-only
6
7staged_files() {
8 git diff --diff-filter=MA --cached --name-only |
9 awk '/..*\.hs/'
10}
11
12if command -v hlint 1>/dev/null && [ ${SKIP_HLINT:-0} -ne 1 ]; then
13 files=$(staged_files | \
14 xargs -r hlint 2>&1 | \
15 awk '/[a-zA-Z.\/][a-zA-Z.\/]*\.hs/')
16
17 if [ -n "${files}" ]; then
18 printf "hlint found the following hints:\n\n" 1>&2
19 printf "%s\n" "${files}" | sed 's/^/\t/' 1>&2
20 exit 1
21 fi
22fi
23
24########################################################################
25
26if ! command -v ormolu 1>/dev/null; then
27 echo "error: ormolu is not installed" 1>&2
28 exit 1
29fi
30
31# TODO: Add an option to ormolu to only print file names.
32files=$(staged_files | \
33 xargs -r ormolu --mode check 2>&1 | \
34 awk '/[a-zA-Z.\/][a-zA-Z.\/]*\.hs/')
35
36if [ -n "${files}" ]; then
37 printf "The following files need to be formated with 'ormolu':\n\n" 1>&2
38 printf "%s\n" "${files}" | sed 's/^/\t/' 1>&2
39 exit 1
40fi
41
42########################################################################
43
44if command -v reuse 1>/dev/null; then
45 reuse lint --quiet
46 if [ $? -ne 0 ]; then
47 echo "reuse-lint failed, run it to figure out why." 1>&2
48 exit 1
49 fi
50else
51 echo "WARNING: reuse-lint is not installed!" 1>&2
52fi