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

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

Open
philderbeast opened this issue Jan 30, 2024 · 6 comments
Open

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

philderbeast opened this issue Jan 30, 2024 · 6 comments

Comments

@philderbeast
Copy link
Collaborator

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.

build-depends:
, array >=0.4 && <0.6
, base >=4.10 && <4.20
, bytestring >=0.10.6.0 && <0.13
, Cabal ^>=3.11
, Cabal-syntax ^>=3.11
, containers >=0.5.6.2 && <0.8
, edit-distance ^>= 0.2.2
, filepath ^>=1.4.0.0 || ^>=1.5.0.0
, mtl >=2.0 && <2.4
, pretty ^>=1.1
, transformers >=0.4.2.0 && <0.7
, text (>= 1.2.3.0 && < 1.3) || (>= 2.0 && < 2.2)

build-depends:
async >= 2.0 && < 2.3,
array >= 0.4 && < 0.6,
base16-bytestring >= 0.1.1 && < 1.1.0.0,
binary >= 0.7.3 && < 0.9,
bytestring >= 0.10.6.0 && < 0.13,
containers >= 0.5.6.2 && < 0.8,
cryptohash-sha256 >= 0.11 && < 0.12,
directory >= 1.3.7.0 && < 1.4,
echo >= 0.1.3 && < 0.2,
edit-distance >= 0.2.2 && < 0.3,
exceptions >= 0.10.4 && < 0.11,
filepath >= 1.4.0.0 && < 1.6,
hashable >= 1.0 && < 1.5,
HTTP >= 4000.1.5 && < 4000.5,
mtl >= 2.0 && < 2.4,
network-uri >= 2.6.0.2 && < 2.7,
pretty >= 1.1 && < 1.2,
process >= 1.2.3.0 && < 1.7,
random >= 1.2 && < 1.3,
stm >= 2.0 && < 2.6,
tar >= 0.5.0.3 && < 0.7,
time >= 1.5.0.1 && < 1.13,
zlib >= 0.5.3 && < 0.7,
hackage-security >= 0.6.2.0 && < 0.7,
text >= 1.2.3 && < 1.3 || >= 2.0 && < 2.2,
parsec >= 3.1.13.0 && < 3.2,
open-browser >= 0.2.1.0 && < 0.3,
regex-base >= 0.94.0.0 && <0.95,
regex-posix >= 0.96.0.0 && <0.97,
safe-exceptions >= 0.1.7.0 && < 0.2,
semaphore-compat >= 1.0.0 && < 1.1

@ulysses4ever
Copy link
Collaborator

ulysses4ever commented Jan 31, 2024

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.

@ffaf1
Copy link
Collaborator

ffaf1 commented Jan 31, 2024

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

@alt-romes
Copy link
Collaborator

alt-romes commented Jan 31, 2024

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.

@philderbeast
Copy link
Collaborator Author

philderbeast commented Jan 31, 2024

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
Copy link
Collaborator Author

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;

build-depends:
array >= 0.4.0.1 && < 0.6,
base >= 4.9 && < 5,
binary >= 0.7 && < 0.9,
bytestring >= 0.10.0.0 && < 0.13,
containers >= 0.5.0.0 && < 0.8,
deepseq >= 1.3.0.1 && < 1.6,
directory >= 1.2 && < 1.4,
filepath >= 1.3.0.1 && < 1.6,
mtl >= 2.1 && < 2.4,
parsec >= 3.1.13.0 && < 3.2,
pretty >= 1.1.1 && < 1.2,
text (>= 1.2.3.0 && < 1.3) || (>= 2.0 && < 2.2),
time >= 1.4.0.1 && < 1.13,
-- transformers-0.4.0.0 doesn't have record syntax e.g. for Identity
-- See also https://github.com/ekmett/transformers-compat/issues/35
transformers (>= 0.3 && < 0.4) || (>=0.4.1.0 && <0.7)

@philderbeast
Copy link
Collaborator Author

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

build-depends: cabal-testsuite,
base,
directory,
Cabal,
Cabal-syntax,
filepath,
transformers,
bytestring,
time,
process,
exceptions

build-depends:
, aeson ^>= 1.4.2.0 || ^>=1.5.0.0 || ^>= 2.0.0.0 || ^>= 2.1.0.0 || ^>= 2.2.1.0
, async ^>= 2.2.1
, attoparsec ^>= 0.13.2.2 || ^>=0.14.1
, base16-bytestring ^>= 0.1.1.5 || ^>= 1.0
, bytestring ^>= 0.10.0.2 || ^>= 0.11.0.0 || ^>= 0.12.0.0
, containers ^>= 0.5.0.0 || ^>= 0.6.0.1 || ^>= 0.7

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

No branches or pull requests

4 participants