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
RFC: Create cabal fix
command
#5741
Comments
@m-renaud see my comment on the other ticket. I think the amount of work here could profitably be put into resolving more issues with |
@m-renaud very thoughtful proposal. I generally also love the idea to have the formatter for such purposes. But probably I would need more from that, like alphabetic order for build-depends or modules, Details question: I don't really get why one could need But overall I like the idea, and would be happy to see at least light version of it here. |
I want to raise the attention for a recently released formatting tool What How can ormolu be integrated into cabal? Identified requirements to date are:
|
This is issue is about formatting *.cabal files, not *.hs sources. My opinion is that Or to say it directly: we won't hard code any formatters, why |
Thanks for the idea! |
Ormolu is build-system independent. It depends on GHC but it won't depend on Cabal. There won't be anything that goes beyond single-file processing, in particular there won't be anything that will have anything to do with Cabal files (parsing them, etc.). It is outside of the scope of the tool.
Sure. The way to do is to have some sort of plugin system for this. |
There's impedance mismatch in what tool writers want from build tools, e.g. Please, if you want discuss Haskell code formatters, open a new issue. This issue is formatting I'm locking the discussion until tomorrow. |
As now (b101f2d),
|
A useful and common (see for example |
Overview
So, it became clear in #5734 that the purpose of
cabal format
is not, in fact, to format your cabal files, which I was sad to hear because I was looking for a tool to do that for a while. The main reason appears to be because it operates on aGenericPackageDescription
which doesn't maintain source file location (or things likecommon
stanzas).I propose that we create a
cabal fix
command with the following behaviour:Don't let great be the enemy of good
Yes, it would be possibly to build a full parser like exists for
GPD
, and also store source file locations, how things were populated, etc., but we could get a pretty long way with a much simpler and dumber formatter. Simple things like: remove trailing whitespace, always leave 1 space after the:
, two blank lines between stanzas, always hang "repeated fields" and put one per line (build-depends
,exposed-modules
, etc). Maybe it can't handle everything from the beginning, but if it can successfully format the majority of folks cabal files then I think that's a win.High Level Flow
cabal check
to return different error code on parse failure vs. warning.cabal fix
, which makes sure the file parses first (viacabal check
)Simplified Package Description
Since the majority of what we need to do doesn't care what an individual field or stanza represents, all we need to know is if the field is a single values field, a repeated field with optional commas, or a repeated field with required. This means we can use a much simpler package description and keep a list of which fields require different parsers/pretty printers. This should simplify the development greatly.
Support undo/redo
In case the formatter messes something up, there should be an easy way to revert it. One simple scheme is described below:
cabal fix --undo
This will replace cabal-file.cabal with
.cabal-fix/cabal-file.cabal.bak.n
and move the current cabal file to.cabal-fix/cabal-file.cabal.redo.n
cabal fix --redo
This will replace
cabal-file.cabal
with.cabal-fix/cabal-file.cabal.redo.n
Sample Formatted File
Prior Art
http://hackage.haskell.org/package/stylish-cabal (just found this, will check it out)
Edit: This looks like a good start, I'm personally not a fan of the indentation style, but I'll start by poking around in the code there and see what I can do.
Implementation
I've been looking for little side project to write in Haskell for a while so I'd be willing to implement this.
/cc @phadej @vrom911
The text was updated successfully, but these errors were encountered: