Skip to content

Add a pre commit hook for code formatting #1384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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: {
Expand Down Expand Up @@ -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
Expand Up @@ -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}
'';
}