Skip to content

Commit 473f3ca

Browse files
committed
nix(hlint): add option to apply inplace hlint suggestions
`postgrest-lint` now supports an optional argument `--apply-hlint-suggestions` which applies Hlint suggestions inplace to the input haskell file. Hlint supports this via another package `apply-refact` which is marked broken in nixpkgs because it doesn't build with GHC 9.10, so we are using the GHC 9.12 pinned version. Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
1 parent 3a38cf9 commit 473f3ca

2 files changed

Lines changed: 37 additions & 16 deletions

File tree

default.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ rec {
126126
inherit (pkgs.haskell.packages."${compiler}") ghcWithPackages;
127127
};
128128

129+
# The "apply-refact" package is marked broken in nixpkgs because it
130+
# doesn't build with GHC 9.10, so we are using the GHC 9.12 pinned version.
131+
# https://github.com/mpickering/apply-refact#ghc-version-compatibility
132+
apply-refact = pkgs.haskell.packages.ghc912.apply-refact;
133+
129134
# Used by CI on MacOS
130135
inherit (pkgs) nix-build-uncached;
131136

@@ -163,7 +168,9 @@ rec {
163168

164169
# Linting and styling tools.
165170
style =
166-
pkgs.callPackage nix/tools/style.nix { inherit hsie; };
171+
pkgs.callPackage nix/tools/style.nix {
172+
inherit hsie apply-refact;
173+
};
167174

168175
# Scripts for running tests.
169176
tests =

nix/tools/style.nix

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{ actionlint
2+
, apply-refact
23
, black
34
, buildToolbox
45
, checkedShellScript
@@ -71,29 +72,42 @@ let
7172
{
7273
name = "postgrest-lint";
7374
docs = "Lint all Haskell files, bash scripts and github workflows.";
75+
args = [
76+
"ARG_OPTIONAL_SINGLE([apply-hlint-suggestions], [], [Filename to apply hlint suggestions on], [])"
77+
];
7478
workingDir = "/";
7579
}
7680
''
77-
echo "Linting workflows..."
78-
${actionlint}/bin/actionlint
81+
if [ -z "$_arg_apply_hlint_suggestions" ]; then
7982
80-
echo "Scanning nix files for unused code..."
81-
${deadnix}/bin/deadnix -f
83+
echo "Linting workflows..."
84+
${actionlint}/bin/actionlint
8285
83-
# ruff has gaps in scanning for unused code, so we use vulture
84-
echo "Scanning python files for unused code..."
85-
${fd}/bin/fd '\.l?py$' \
86-
| xargs ${python3Packages.vulture}/bin/vulture --exclude docs/conf.py --min-confidence 80
86+
echo "Scanning nix files for unused code..."
87+
${deadnix}/bin/deadnix -f
8788
88-
echo "Linting python files..."
89-
${ruff}/bin/ruff check .
89+
# ruff has gaps in scanning for unused code, so we use vulture
90+
echo "Scanning python files for unused code..."
91+
${fd}/bin/fd '\.l?py$' \
92+
| xargs ${python3Packages.vulture}/bin/vulture --exclude docs/conf.py --min-confidence 80
9093
91-
echo "Checking consistency of import aliases in Haskell code..."
92-
${hsie} check-aliases src/library src/executable
94+
echo "Linting python files..."
95+
${ruff}/bin/ruff check .
9396
94-
echo "Linting Haskell files..."
95-
${fd}/bin/fd '\.l?hs$' \
96-
| xargs ${hlint}/bin/hlint --hint=${hlintConfig}
97+
echo "Checking consistency of import aliases in Haskell code..."
98+
${hsie} check-aliases src/library src/executable
99+
100+
echo "Linting Haskell files..."
101+
${fd}/bin/fd '\.l?hs$' \
102+
| xargs ${hlint}/bin/hlint --hint=${hlintConfig}
103+
104+
else
105+
106+
echo "Applying Hlint suggestions..."
107+
export PATH="${apply-refact}/bin:$PATH"
108+
${hlint}/bin/hlint --hint=${hlintConfig} --refactor --refactor-options="--inplace" "$_arg_apply_hlint_suggestions"
109+
110+
fi
97111
'';
98112

99113
in

0 commit comments

Comments
 (0)