-
Notifications
You must be signed in to change notification settings - Fork 148
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
Elm fragments get turned into Elm modules named Main #744
Comments
The internals sort of support this, and it's partially used for formatting Elm code fragments that are in markdown code blocks within documentation comments. But there's not currently a way to invoke this directly. A safe workaround for the moment would be to format as you have, and then remove lines starting with / I think a command line argument to specify what type of thing is being input would be worth adding. I think the things that make sense to format are:
This issue is also related: #65 |
I see this as simpler, and I kinda don't think this even needs to/should be a command line argument? The spec in my mind is "an autoformatter turns a valid file into an 'equivalent-whatever-that-means' file, or raise an error." A list of declarations in a file is accepted by the elm compiler (yesterday-I-learned!!!), and I'd ask elm-format to output a semantically 'equivalent-whatever-that-means' list of declarations, rather than a module, which doesn't seem equivalent to me. At first I assumed a list of declarations wouldn't be accepted by the elm compiler! If that had been the case I would have argued elm-format should raise an error on a fragment without a module declaration. That state of the world would be preferable all around to me but I will acknowledge that (Context: for us, this happened because elm-format got run on a fragmentary elm file it actually shouldn't have and broke some stuff... we do the "remove |
If
blah.txt
contains the following contents:elm-format
(version 0.8.5) will change the file to one that has different semantics:If
blah.txt
is an elm fragment that was later going to be merged into a larger piece of code, then the addition ofmodule Main exposing (whatever)
violates expected behavior for an autoformatter, which is to never change the meaning of file, by turning something that's not broken into something that is.Elm does support fragmentary files that don't start as
module
; wouldn't it be more consistent to leave those files fragmentary when they're autoformatted?The text was updated successfully, but these errors were encountered: