tweag / ormolu

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

Add `-R, --recursive` option for implying `--mode inplace ` and all `*.hs` file under given directory #1086

Closed evan0greenup closed 5 months ago

evan0greenup commented 6 months ago

Is your feature request related to a problem? Please describe.

For modern Haskell usage, reformatting a whole haskell project is certainly more often then single file. according to the README.md, ormolu --mode inplace $(find . -name '*.hs') or ormolu --mode inplace $(git ls-files '*.hs') is too long and inconvenient for user to input.

Describe the solution you'd like A -R or --recursive option would works. It implies --mode inplace and the path on the end will be the directory to make recursive reformatting.

Unlike ormolu --mode inplace $(find . -name '*.hs'), -R can identify scm repository. If the path is located inside Git workspace or Mercurial workspace. It can automatically ignore the files which is ignored by .gitignore spec.

Describe alternatives you've considered It would be good to referencing black for python https://github.com/psf/black

Additional context The final functionality should like this

$ cd haskell-sample-project/
$ ormolu -R .
totally 150 *.hs files found, 23 *.hs file reformated!!!
amesgen commented 6 months ago

See #691, #697, #910 for prior discussions on this topic, and #1054 for a related discussion.

mrkkrp commented 5 months ago

Closing as a duplicate of #691. I'm not sure how exactly ormolu --mode inplace $(git ls-files '*.hs') is too long or inconvenient. It is already a one-liner, and it can be further shortened if you create a bash alias. Personally, I made this little function in Nushell:

# Format all Haskell files in the current git repository.
def "ormolu all" [] {
    ormolu -i (git ls-files '*.hs' '*.hs-boot' | lines)
}

I do see that there has been multiple requests like this, but the correct implementation here would need to

Otherwise there is a host of extra settings we would need to think about, such as what to do with symbolic links when we traverse a directory tree.

I prefer to avoid dealing with this complexity in an already pretty complex project.