diff --git a/.gitignore b/.gitignore index cfbf1c0511..80d4fa3c76 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ test/testdata/**/hie.yaml # shake build folder (used in benchmark suite) .shake/ + +# pre-commit-hook.nix +.pre-commit-config.yaml diff --git a/.stylish-haskell.yaml b/.stylish-haskell.yaml new file mode 100644 index 0000000000..d41f5ccb5a --- /dev/null +++ b/.stylish-haskell.yaml @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f9a88b47da..6bc27da912 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/ghcide/.stylish-haskell.yaml b/ghcide/.stylish-haskell.yaml new file mode 100644 index 0000000000..a1c72461b9 --- /dev/null +++ b/ghcide/.stylish-haskell.yaml @@ -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 diff --git a/hls-plugin-api/.stylish-haskell.yaml b/hls-plugin-api/.stylish-haskell.yaml new file mode 100644 index 0000000000..08eda7297c --- /dev/null +++ b/hls-plugin-api/.stylish-haskell.yaml @@ -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 diff --git a/nix/default.nix b/nix/default.nix index 360f1f15da..f80bc6354c 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -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/*" ]; + }; + }; + } diff --git a/shell.nix b/shell.nix index a851b48c49..d3ac9b4967 100644 --- a/shell.nix +++ b/shell.nix @@ -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} ''; }