Add scripts for linting and styling with all dependencies managed by Nix (#1501)

* Integrate the style and lint dependencies with Nix

* Add documentation on the nix styling scripts.
This commit is contained in:
Remo
2020-04-27 15:04:50 -05:00
committed by GitHub
parent ad92c207f2
commit dbc3aa28c4
5 changed files with 71 additions and 0 deletions
+14
View File
@@ -61,6 +61,20 @@ nix-shell --run postgrest-test-spec-postgresql-9.5.21
```
## Linting and styling code
The nix-shell also contains scripts for linting and styling the PostgREST
source code:
```bash
# Linting
nix-shell --run postgrest-lint
# Styling / auto-formatting code
nix-shell --run postgrest-style
```
## Tour
The following is not required for working on PostgREST with Nix, but it will
+12
View File
@@ -0,0 +1,12 @@
{ writeShellScriptBin, git, silver-searcher, hlint }:
writeShellScriptBin "postgrest-lint"
''
set -euo pipefail
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
# Lint Haskell files
${silver-searcher}/bin/ag -l -g '\.l?hs$' "$rootdir" \
| xargs ${hlint}/bin/hlint -X QuasiQuotes -X NoPatternSynonyms
''
+37
View File
@@ -0,0 +1,37 @@
{ writeShellScriptBin
, git
, nixpkgs-fmt
, silver-searcher
, stylish-haskell
, buildEnv
}:
let
style =
writeShellScriptBin "postgrest-style"
''
set -euo pipefail
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
# Format Nix files
${nixpkgs-fmt}/bin/nixpkgs-fmt "$rootdir" > /dev/null 2> /dev/null
# Format Haskell files
${silver-searcher}/bin/ag -l -g '\.l?hs$' "$rootdir" \
| xargs ${stylish-haskell}/bin/stylish-haskell -i
'';
check =
writeShellScriptBin "postgrest-style-check"
''
set -euo pipefail
${style}/bin/${style.name}
${git}/bin/git diff-index --exit-code HEAD -- '*.hs' '*.lhs' '*.nix'
'';
in
buildEnv {
name = "postgrest-style";
paths = [ style check ];
}