Skip to content

Commit

Permalink
Add a pre commit hook for code formatting (#1384)
Browse files Browse the repository at this point in the history
* Add pre-commit-hook

* Update CONTRIBUTING.md

* Reduce stylish-haskell configs
Ailrun authored Feb 18, 2021

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
1 parent 240f793 commit c95b076
Showing 7 changed files with 255 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -30,3 +30,6 @@ test/testdata/**/hie.yaml

# shake build folder (used in benchmark suite)
.shake/

# pre-commit-hook.nix
.pre-commit-config.yaml
63 changes: 63 additions & 0 deletions .stylish-haskell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# See https://github.com/jaspervdj/stylish-haskell/blob/main/data/stylish-haskell.yaml
# for reference.

steps:
# - unicode_syntax:
# add_language_pragma: true

# - module_header:
# indent: 4
# sort: true
# separate_lists: true

# - records:
# equals: "indent 2"
# first_field: "indent 2"
# field_comment: 2
# deriving: 2
# via: "indent 2"
# sort_deriving: true
# break_enums: false
# break_single_constructors: true
# curried_context: false

- simple_align:
cases: always
top_level_patterns: always
records: always
multi_way_if: always

- imports:
align: global
list_align: after_alias
pad_module_names: true
long_list_align: inline
empty_list_align: inherit
list_padding: 4
separate_lists: true
space_surround: false
ghc_lib_parser: false

- language_pragmas:
style: vertical
align: true
remove_redundant: true
language_prefix: LANGUAGE

# - tabs:
# spaces: 8

- trailing_whitespace: {}

# - squash: {}

columns: 80

newline: native

language_extensions:
- DataKinds
- OverloadedStrings
- TypeOperators

cabal: true
35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# Contributors Guide

## Pre-commit hook
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.

You can configure the pre-commit-hook by running

``` bash
nix-shell
```

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.

```json
{
"repos": [
{
"hooks": [
{
"entry": "stylish-haskell -i ",
"exclude": "(/test/testdata/*)",
"files": "\\.l?hs$",
"id": "stylish-haskell",
"language": "system",
"name": "stylish-haskell",
"pass_filenames": true,
"types": [
"file"
]
}
],
"repo": "local"
}
]
}
```

## Testing

The tests make use of the [Tasty](https://github.com/feuerbach/tasty) test framework.
74 changes: 74 additions & 0 deletions ghcide/.stylish-haskell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# See https://github.com/jaspervdj/stylish-haskell/blob/main/data/stylish-haskell.yaml
# for reference.

steps:
# - unicode_syntax:
# add_language_pragma: true

# - module_header:
# indent: 4
# sort: true
# separate_lists: true

# - records:
# equals: "indent 2"
# first_field: "indent 2"
# field_comment: 2
# deriving: 2
# via: "indent 2"
# sort_deriving: true
# break_enums: false
# break_single_constructors: true
# curried_context: false

- simple_align:
cases: always
top_level_patterns: always
records: always
multi_way_if: always

- imports:
align: global
list_align: after_alias
pad_module_names: true
long_list_align: inline
empty_list_align: inherit
list_padding: 4
separate_lists: true
space_surround: false
ghc_lib_parser: false

- language_pragmas:
style: vertical
align: true
remove_redundant: true
language_prefix: LANGUAGE

# - tabs:
# spaces: 8

- trailing_whitespace: {}

# - squash: {}

columns: 80

newline: native

language_extensions:
- BangPatterns
- DeriveFunctor
- DeriveGeneric
- FlexibleContexts
- GeneralizedNewtypeDeriving
- LambdaCase
- NamedFieldPuns
- OverloadedStrings
- RecordWildCards
- ScopedTypeVariables
- StandaloneDeriving
- TupleSections
- TypeApplications
- ViewPatterns

cabal: true
63 changes: 63 additions & 0 deletions hls-plugin-api/.stylish-haskell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# See https://github.com/jaspervdj/stylish-haskell/blob/main/data/stylish-haskell.yaml
# for reference.

steps:
# - unicode_syntax:
# add_language_pragma: true

# - module_header:
# indent: 4
# sort: true
# separate_lists: true

# - records:
# equals: "indent 2"
# first_field: "indent 2"
# field_comment: 2
# deriving: 2
# via: "indent 2"
# sort_deriving: true
# break_enums: false
# break_single_constructors: true
# curried_context: false

- simple_align:
cases: always
top_level_patterns: always
records: always
multi_way_if: always

- imports:
align: global
list_align: after_alias
pad_module_names: true
long_list_align: inline
empty_list_align: inherit
list_padding: 4
separate_lists: true
space_surround: false
ghc_lib_parser: false

- language_pragmas:
style: vertical
align: true
remove_redundant: true
language_prefix: LANGUAGE

# - tabs:
# spaces: 8

- trailing_whitespace: {}

# - squash: {}

columns: 80

newline: native

language_extensions:
- DataKinds
- KindSignatures
- TypeOperators

cabal: true
18 changes: 16 additions & 2 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ sources ? import ./sources.nix }:
let
nix-pre-commit-hooks = import (builtins.fetchTarball "https://github.com/cachix/pre-commit-hooks.nix/tarball/master");
overlay = _self: pkgs:
let sharedOverrides = {
overrides = _self: super: {
@@ -42,5 +43,18 @@ let
};
};

in import sources.nixpkgs
{ overlays = [ overlay ] ; config = {allowBroken = true;}; }
in (import sources.nixpkgs
{
overlays = [ overlay ];
config = {allowBroken = true;};
}) // {
pre-commit-check = nix-pre-commit-hooks.run {
src = ./.;
# If your hooks are intrusive, avoid running on each commit with a default_states like this:
# default_stages = ["manual" "push"];
hooks = {
stylish-haskell.enable = true;
stylish-haskell.excludes = [ "/test/testdata/*" "/hie-compat/*" ];
};
};
}
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -64,5 +64,6 @@ haskellPackagesForProject.shellFor {
export LD_LIBRARY_PATH=${gmp}/lib:${zlib}/lib:${ncurses}/lib:${capstone}/lib
export DYLD_LIBRARY_PATH=${gmp}/lib:${zlib}/lib:${ncurses}/lib:${capstone}/lib
export PATH=$PATH:$HOME/.local/bin
${pre-commit-check.shellHook}
'';
}

0 comments on commit c95b076

Please sign in to comment.