tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
958 stars 83 forks source link

Convenient default options #519

Closed sir4ur0n closed 3 years ago

sir4ur0n commented 4 years ago

Hi,

Is there some way to configure the default GHC options (like extensions) not enabled by default, like XTypeApplications? We really don't want to repeat the pragma in each of our file...

For the moment what we do in my team is:

# shell.nix
let
  # Wrap Ormolu to add our default extensions that are not enabled by default in Ormolu
  # Run 'ormolu --manual-exts' to find out which extensions are not enabled by default
  # Inspired by https://nixos.wiki/wiki/Nix_Cookbook
  # If for whatever reason you want to reformat the whole code base, run:
  # for f in ./**/*.hs; do
  #   ormolu --mode inplace "$f"
  # done
  ormolu-wrapped = symlinkJoin {
    name = "ormolu";
    paths = [ ormolu ];
    buildInputs = [ pkgs.makeWrapper ];
    postBuild = ''
     wrapProgram $out/bin/ormolu \
       --add-flags "\
         --ghc-opt -XBangPatterns \
         --ghc-opt -XTypeApplications \
       "
    '';
  };
in
  mkShell {
    buildInputs = [
        ormolu-wrapped
        # Other build inputs
    ];

  # Other conf, like env vars
  }

However:

I feel like supporting an Ormolu configuration file at the root of the project would be an improvement for such a use case.

I am aware of:

Thank you for Ormolu and cheers!

seagreen commented 4 years ago

I'm not sure this exists, but if there was something like https://editorconfig.org/ that allowed you to choose what executable + arguments to use to format any given file type that would be a nice general solution.

seagreen commented 4 years ago

Also see: https://github.com/tweag/ormolu/issues/452