cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Could we use a formatter for `.cabal` files in this project?

Open philderbeast opened this issue 1 year ago • 6 comments

Could we use a formatter for .cabal files such as cabal-fmt? Nothing fancy, just a CI check to see that the .cabal files have been formated (by formatting again and checking for diffs).

I notice leading commas in cabal-install-solver.cabal and trailing commas in cabal-install.cabal.

https://github.com/haskell/cabal/blob/03d7b42a3f08bc1e6aa85118ca365277d8d83334/cabal-install-solver/cabal-install-solver.cabal#L101-L113

https://github.com/haskell/cabal/blob/03d7b42a3f08bc1e6aa85118ca365277d8d83334/cabal-install/cabal-install.cabal#L214-L245

philderbeast avatar Jan 30 '24 23:01 philderbeast

I'm mildly supportive. We learned the downsides of auto formatting all too well with fourmolu: backports become very painful, contributor's life becomes harder. But cabal files are a tiny part of the code, so maybe these downsides don't quite apply.

ulysses4ever avatar Jan 31 '24 00:01 ulysses4ever

Small gain with an increase of stuff that can break CI, not a fan.

ffaf1 avatar Jan 31 '24 01:01 ffaf1

FWIW I don't like the auto formatting. Having yet another one would be another hoop to jump through before being able to submit a patch that isn't add odds with CI for little gain.

alt-romes avatar Jan 31 '24 17:01 alt-romes

I used cabal-fmt in production CI and found it pretty effortless to use. Before commiting, grab the relative path to the .cabal file in question and run $ cabal-fmt <paste> --inplace.

As for backporting, would that be easier if we ran cabal-fmt on the branch we're porting to first?

Disregarding cabal-fmt for the moment, won't we adopt automatic formatting when the exact printer, #7544, is ready?

philderbeast avatar Jan 31 '24 17:01 philderbeast

There's now cabal-gild that can format .cabal and .project files.

I don't like having to hand-crank my editor to line up with the existing ad-hoc formatting, like this snippet that tries but fails to do column aligned version constraints;

https://github.com/haskell/cabal/blob/fe82d9bceddac028ad54569b7eb73f214e1ed525/Cabal-syntax/Cabal-syntax.cabal#L30-L46

philderbeast avatar Feb 17 '24 17:02 philderbeast

Take cabal-testsuite, it has leading commas and trailing commas, sort of sorted and really unsorted lists of dependencies.

https://github.com/haskell/cabal/blob/2ee79c375aff334e98f807481c5f7cd0e7a5b4e4/cabal-testsuite/cabal-testsuite.cabal#L126-L136

https://github.com/haskell/cabal/blob/2ee79c375aff334e98f807481c5f7cd0e7a5b4e4/cabal-testsuite/cabal-testsuite.cabal#L60-L66

philderbeast avatar Mar 29 '24 16:03 philderbeast