shell: add editorconfig hook
This commit is contained in:
parent
46a7e7d4ce
commit
c4699ed682
1 changed files with 19 additions and 7 deletions
|
@ -59,6 +59,8 @@ pkgs.devshell.mkShell {
|
||||||
git.hooks = with pkgs; {
|
git.hooks = with pkgs; {
|
||||||
enable = true;
|
enable = true;
|
||||||
pre-commit.text = ''
|
pre-commit.text = ''
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
if ${git}/bin/git rev-parse --verify HEAD >/dev/null 2>&1
|
if ${git}/bin/git rev-parse --verify HEAD >/dev/null 2>&1
|
||||||
then
|
then
|
||||||
against=HEAD
|
against=HEAD
|
||||||
|
@ -66,15 +68,25 @@ pkgs.devshell.mkShell {
|
||||||
# Initial commit: diff against an empty tree object
|
# Initial commit: diff against an empty tree object
|
||||||
against=$(${git}/bin/git hash-object -t tree /dev/null)
|
against=$(${git}/bin/git hash-object -t tree /dev/null)
|
||||||
fi
|
fi
|
||||||
# Redirect output to stderr.
|
|
||||||
exec 1>&2
|
diff="${git}/bin/git diff-index --name-only --cached $against --diff-filter d"
|
||||||
|
|
||||||
|
nix_files=($($diff -- '*.nix'))
|
||||||
|
|
||||||
|
all_files=($($diff))
|
||||||
|
|
||||||
# Format staged nix files.
|
# Format staged nix files.
|
||||||
exec ${nixpkgs-fmt}/bin/nixpkgs-fmt \
|
${nixpkgs-fmt}/bin/nixpkgs-fmt "${"\${nix_files[@]}"}"
|
||||||
$(
|
|
||||||
${git}/bin/git diff-index --name-only --cached $against --diff-filter d -- \
|
# check editorconfig
|
||||||
| ${ripgrep}/bin/rg '\.nix$'
|
${editorconfig-checker}/bin/editorconfig-checker -- "${"\${all_files[@]}"}"
|
||||||
)
|
if [[ $? != '0' ]]; then
|
||||||
|
{
|
||||||
|
echo -e "\nCode is not aligned with .editorconfig"
|
||||||
|
echo "Review the output and commit your fixes"
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue