Skip to content

Commit c95b076

Browse files
authored
Add a pre commit hook for code formatting (#1384)
* Add pre-commit-hook * Update CONTRIBUTING.md * Reduce stylish-haskell configs
1 parent 240f793 commit c95b076

File tree

7 files changed

+255
-2
lines changed

7 files changed

+255
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ test/testdata/**/hie.yaml
3030

3131
# shake build folder (used in benchmark suite)
3232
.shake/
33+
34+
# pre-commit-hook.nix
35+
.pre-commit-config.yaml

.stylish-haskell.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# See https://github.com/jaspervdj/stylish-haskell/blob/main/data/stylish-haskell.yaml
2+
# for reference.
3+
4+
steps:
5+
# - unicode_syntax:
6+
# add_language_pragma: true
7+
8+
# - module_header:
9+
# indent: 4
10+
# sort: true
11+
# separate_lists: true
12+
13+
# - records:
14+
# equals: "indent 2"
15+
# first_field: "indent 2"
16+
# field_comment: 2
17+
# deriving: 2
18+
# via: "indent 2"
19+
# sort_deriving: true
20+
# break_enums: false
21+
# break_single_constructors: true
22+
# curried_context: false
23+
24+
- simple_align:
25+
cases: always
26+
top_level_patterns: always
27+
records: always
28+
multi_way_if: always
29+
30+
- imports:
31+
align: global
32+
list_align: after_alias
33+
pad_module_names: true
34+
long_list_align: inline
35+
empty_list_align: inherit
36+
list_padding: 4
37+
separate_lists: true
38+
space_surround: false
39+
ghc_lib_parser: false
40+
41+
- language_pragmas:
42+
style: vertical
43+
align: true
44+
remove_redundant: true
45+
language_prefix: LANGUAGE
46+
47+
# - tabs:
48+
# spaces: 8
49+
50+
- trailing_whitespace: {}
51+
52+
# - squash: {}
53+
54+
columns: 80
55+
56+
newline: native
57+
58+
language_extensions:
59+
- DataKinds
60+
- OverloadedStrings
61+
- TypeOperators
62+
63+
cabal: true

CONTRIBUTING.md

+35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# Contributors Guide
22

3+
## Pre-commit hook
4+
We are using [pre-commit-hook.nix](https://github.com/cachix/pre-commit-hooks.nix) to configure git pre-commit hook for formatting. Although it is possible to run formatting manually, we recommend you to use it to set pre-commit hook as our CI checks pre-commit hook is applied or not.
5+
6+
You can configure the pre-commit-hook by running
7+
8+
``` bash
9+
nix-shell
10+
```
11+
12+
If you don't want to use [nix](https://nixos.org/guides/install-nix.html), you can instead use [pre-commit](https://pre-commit.com) with the following config.
13+
14+
```json
15+
{
16+
"repos": [
17+
{
18+
"hooks": [
19+
{
20+
"entry": "stylish-haskell -i ",
21+
"exclude": "(/test/testdata/*)",
22+
"files": "\\.l?hs$",
23+
"id": "stylish-haskell",
24+
"language": "system",
25+
"name": "stylish-haskell",
26+
"pass_filenames": true,
27+
"types": [
28+
"file"
29+
]
30+
}
31+
],
32+
"repo": "local"
33+
}
34+
]
35+
}
36+
```
37+
338
## Testing
439

540
The tests make use of the [Tasty](https://github.com/feuerbach/tasty) test framework.

ghcide/.stylish-haskell.yaml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# See https://github.com/jaspervdj/stylish-haskell/blob/main/data/stylish-haskell.yaml
2+
# for reference.
3+
4+
steps:
5+
# - unicode_syntax:
6+
# add_language_pragma: true
7+
8+
# - module_header:
9+
# indent: 4
10+
# sort: true
11+
# separate_lists: true
12+
13+
# - records:
14+
# equals: "indent 2"
15+
# first_field: "indent 2"
16+
# field_comment: 2
17+
# deriving: 2
18+
# via: "indent 2"
19+
# sort_deriving: true
20+
# break_enums: false
21+
# break_single_constructors: true
22+
# curried_context: false
23+
24+
- simple_align:
25+
cases: always
26+
top_level_patterns: always
27+
records: always
28+
multi_way_if: always
29+
30+
- imports:
31+
align: global
32+
list_align: after_alias
33+
pad_module_names: true
34+
long_list_align: inline
35+
empty_list_align: inherit
36+
list_padding: 4
37+
separate_lists: true
38+
space_surround: false
39+
ghc_lib_parser: false
40+
41+
- language_pragmas:
42+
style: vertical
43+
align: true
44+
remove_redundant: true
45+
language_prefix: LANGUAGE
46+
47+
# - tabs:
48+
# spaces: 8
49+
50+
- trailing_whitespace: {}
51+
52+
# - squash: {}
53+
54+
columns: 80
55+
56+
newline: native
57+
58+
language_extensions:
59+
- BangPatterns
60+
- DeriveFunctor
61+
- DeriveGeneric
62+
- FlexibleContexts
63+
- GeneralizedNewtypeDeriving
64+
- LambdaCase
65+
- NamedFieldPuns
66+
- OverloadedStrings
67+
- RecordWildCards
68+
- ScopedTypeVariables
69+
- StandaloneDeriving
70+
- TupleSections
71+
- TypeApplications
72+
- ViewPatterns
73+
74+
cabal: true

hls-plugin-api/.stylish-haskell.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# See https://github.com/jaspervdj/stylish-haskell/blob/main/data/stylish-haskell.yaml
2+
# for reference.
3+
4+
steps:
5+
# - unicode_syntax:
6+
# add_language_pragma: true
7+
8+
# - module_header:
9+
# indent: 4
10+
# sort: true
11+
# separate_lists: true
12+
13+
# - records:
14+
# equals: "indent 2"
15+
# first_field: "indent 2"
16+
# field_comment: 2
17+
# deriving: 2
18+
# via: "indent 2"
19+
# sort_deriving: true
20+
# break_enums: false
21+
# break_single_constructors: true
22+
# curried_context: false
23+
24+
- simple_align:
25+
cases: always
26+
top_level_patterns: always
27+
records: always
28+
multi_way_if: always
29+
30+
- imports:
31+
align: global
32+
list_align: after_alias
33+
pad_module_names: true
34+
long_list_align: inline
35+
empty_list_align: inherit
36+
list_padding: 4
37+
separate_lists: true
38+
space_surround: false
39+
ghc_lib_parser: false
40+
41+
- language_pragmas:
42+
style: vertical
43+
align: true
44+
remove_redundant: true
45+
language_prefix: LANGUAGE
46+
47+
# - tabs:
48+
# spaces: 8
49+
50+
- trailing_whitespace: {}
51+
52+
# - squash: {}
53+
54+
columns: 80
55+
56+
newline: native
57+
58+
language_extensions:
59+
- DataKinds
60+
- KindSignatures
61+
- TypeOperators
62+
63+
cabal: true

nix/default.nix

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{ sources ? import ./sources.nix }:
22
let
3+
nix-pre-commit-hooks = import (builtins.fetchTarball "https://github.com/cachix/pre-commit-hooks.nix/tarball/master");
34
overlay = _self: pkgs:
45
let sharedOverrides = {
56
overrides = _self: super: {
@@ -42,5 +43,18 @@ let
4243
};
4344
};
4445

45-
in import sources.nixpkgs
46-
{ overlays = [ overlay ] ; config = {allowBroken = true;}; }
46+
in (import sources.nixpkgs
47+
{
48+
overlays = [ overlay ];
49+
config = {allowBroken = true;};
50+
}) // {
51+
pre-commit-check = nix-pre-commit-hooks.run {
52+
src = ./.;
53+
# If your hooks are intrusive, avoid running on each commit with a default_states like this:
54+
# default_stages = ["manual" "push"];
55+
hooks = {
56+
stylish-haskell.enable = true;
57+
stylish-haskell.excludes = [ "/test/testdata/*" "/hie-compat/*" ];
58+
};
59+
};
60+
}

shell.nix

+1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ haskellPackagesForProject.shellFor {
6464
export LD_LIBRARY_PATH=${gmp}/lib:${zlib}/lib:${ncurses}/lib:${capstone}/lib
6565
export DYLD_LIBRARY_PATH=${gmp}/lib:${zlib}/lib:${ncurses}/lib:${capstone}/lib
6666
export PATH=$PATH:$HOME/.local/bin
67+
${pre-commit-check.shellHook}
6768
'';
6869
}

0 commit comments

Comments
 (0)