mirror of
https://github.com/haskell/haskell-language-server.git
synced 2024-09-11 08:45:35 +03:00
Add a pre commit hook for code formatting (#1384)
* Add pre-commit-hook * Update CONTRIBUTING.md * Reduce stylish-haskell configs
This commit is contained in:
parent
240f793bc2
commit
c95b0766fe
3
.gitignore
vendored
3
.gitignore
vendored
@ -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
.stylish-haskell.yaml
Normal file
63
.stylish-haskell.yaml
Normal file
@ -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
|
@ -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
ghcide/.stylish-haskell.yaml
Normal file
74
ghcide/.stylish-haskell.yaml
Normal file
@ -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
hls-plugin-api/.stylish-haskell.yaml
Normal file
63
hls-plugin-api/.stylish-haskell.yaml
Normal file
@ -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
|
@ -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/*" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -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}
|
||||
'';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user