haskell-actions / run-fourmolu

Fourmolu GitHub Action
https://github.com/marketplace/actions/run-fourmolu
Other
9 stars 8 forks source link

Support hpack by running hpack before ormolu #10

Open codygman opened 1 year ago

codygman commented 1 year ago

Otherwise the cabal files aren't there.

cdepillabout commented 1 year ago

That doesn't sound too unreasonable.

Some reservations I would have are:

  1. I guess you'd need some logic to recurse over the repo and run hpack on any package.yaml files you find. I'm not sure what sort of problems you'd encounter with this, but it'd be really nice to have some tests that this is actually working as promised.
  2. I think committing .cabal files is now seen as good practice: https://www.fpcomplete.com/blog/storing-generated-cabal-files/. This feature wouldn't be necessary if you committed cabal files.
  3. In theory it would be more helpful if you had a separate action for recursively running hpack. That way, you could pair that hpack-action with either this repo or the ormolu GitHub Action. Or any other Haskell-related GitHub Action that requires .cabal files to be present.
wraithm commented 1 year ago

IMHO, this is an upstream problem. Fourmolu should just support hpack/package.yaml. It could even run hpack in memory and then use the exact cabal file logic.

cdepillabout commented 1 year ago

Oh, also, this fourmolu-action should currently be working even if you don't check-in the .cabal files.

In our repo at work, we don't check in .cabal files and this action still works for us. fourmolu will still output a line like:

Could not find a .cabal file for /home/runner/work/our-org/our-repo/package-foo/src/FooBar.hs

But fourmolu still runs on this file and correctly checks the formatting, although it is not able to figure out default language extensions or fixities for dependencies' operators: https://github.com/fourmolu/fourmolu#language-extensions-dependencies-and-fixities

brandonchinn178 commented 1 year ago

IMHO, this is an upstream problem. Fourmolu should just support hpack/package.yaml. It could even run hpack in memory and then use the exact cabal file logic.

I don't think Fourmolu (or Ormolu) should be responsible for generating cabal files. If you're using stack, why not run a short stack path (or some other trivial stack command to run hpack) before running the action? It seems like a lot of overhead for Fourmolu (e.g. adding hpack as a dependency) when there's such a simple workaround before