Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .cabal or cabal.project to discover which files to format #348

Open
turion opened this issue Jul 11, 2023 · 2 comments
Open

Use .cabal or cabal.project to discover which files to format #348

turion opened this issue Jul 11, 2023 · 2 comments

Comments

@turion
Copy link

turion commented Jul 11, 2023

It would be great if, instead of having to specify files to format via a directory or a complicated call to git, fourmolu would simply detect the files to format in the same way cabal does. Basically, if the command cabal build all --enable-tests --enable-benchmarks would read a particular Haskell source file, then fourmolu -i should format that file.

Why the current situation is not good enough

For any particular project, I can somehow adapt the fourmolu call. But when I want to automatize (e.g. to write a good git alias, or a github action), I want to be able to deal with any sort of Haskell repo.

Specifying a directory

The docs recommend e.g. fourmolu -i src. This doesn't work for projects that have several folders (e.g. test, benchmark, app) generically because a project might have any sort of folders. Also, it doesn't work when you have a cabal.project structure.

git ls-files

The docs recommend fourmolu --mode inplace $(git ls-files '*.hs'), but this doesn't work in general because there might be other files like *.lhs, *.md. Also, it doesn't work if there is no git repository (e.g. downloading a tarball).

What would be the most straightforward way

Like cabal, fourmolu should automatically discover whether there is a *.cabal file, and then format all of the Haskell source files specified in it, or if there is a cabal.project file, format all the source files found from all the cabal projects in there. Advantages:

  • Single point of definition what is part of the project and what is not
  • No additional assumptions about directory structure or available tooling
@brandonchinn178
Copy link
Collaborator

This would be great, perhaps behind an --all-files flag! Can you file an issue with ormolu? It would be great if this could be implemented in ormolu and we'd get it for free after. If ormolu rejects it, we can implement it ourselves

@turion
Copy link
Author

turion commented Jul 12, 2023

Can you file an issue with ormolu?

Good point :) See tweag/ormolu#1054

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants