git-hooks.nix icon indicating copy to clipboard operation
git-hooks.nix copied to clipboard

Fourmolu hook does not read the cabal files for default-extensions

Open lf- opened this issue 3 years ago • 4 comments

I have to set ormolu.defaultExtensions in flake.nix to use ImportQualifiedPost in my files, even though invoking Fourmolu manually does not require such since it reads the Cabal files.

This seems like pre-commit-hooks.nix is doing something funny that is causing fourmolu to not be able to read these.

commit 60cad1a326df17a8c6cf2bb23436609fdd83024e

lf- avatar Oct 03 '22 22:10 lf-

There's an example in the README, did you follow that?

domenkozar avatar Nov 04 '22 13:11 domenkozar

pre-commit = {
   settings = {
       hooks = {
            fourmolu.enable = true;
        };
         settings.ormolu.cabalDefaultExtensions = true;
        };
      };
    };

I have this pre-commit config and OverloadedRecordDot in default-extensions in .cabal. But fourmolu formats a.b into a . b.

I don't get it: is the ormolu setting supposed to influence fourmolu? What's the status of this issue? Fixed with this trick above, but strangely doesn't work for some other reason on my side? Fourmolu doesn't support this? Or pre-commit doesn't?

zmrocze avatar May 07 '23 14:05 zmrocze

From my experience fourmolu when run from pre-commit.nix:

  • doesn't understand cabal's default extensions
  • neither does it support OverloadedRecordDot

because setting the OverloadedRecordDot option directly in the source file results in a fail:

  The GHC parser (in Haddock mode) failed:
  Unsupported extension: OverloadedRecordDot

but setting it just in cabal, doesn't fail, but formats the source not respecting the option

zmrocze avatar May 07 '23 14:05 zmrocze

From CHANGELOG it looks like the support for this extensions lands in version 5, while nixpkgs.haskellPackages.fourmolu is 4.

zmrocze avatar May 07 '23 14:05 zmrocze