-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
SemicolonAtEndOfLine causes syntax error #1342
Comments
Here’s another case. This time, the “blank line” workaround does not help :( Issue created from fantomas-online Codemodule ViewBuilder =
let rec private buildNode (isHtml : bool) (sb : StringBuilder) (node : XmlNode) : unit =
let buildElement closingBracket (elemName, attributes : XmlAttribute array) =
match attributes with
| [||] -> do sb += "<" += elemName +! closingBracket
| _ ->
do sb += "<" +! elemName
attributes
|> Array.iter
(fun attr ->
match attr with
| KeyValue (k, v) -> do sb += " " += k += "=\"" += v +! "\""
| Boolean k -> do sb += " " +! k)
do sb +! closingBracket
let inline buildParentNode
(elemName, attributes : XmlAttribute array)
(nodes : XmlNode list)
=
do buildElement ">" (elemName, attributes)
for node in nodes do
buildNode isHtml sb node
do sb += "</" += elemName +! ">"
match node with
| Text text -> do sb +! text
| ParentNode (e, nodes) -> do buildParentNode e nodes
| VoidElement e -> do buildElement (selfClosingBracket isHtml) e ErrorFantomas was able to format the code but the result appears to be invalid F# code.
Please open an issue.
Formatted result:
module ViewBuilder =
let rec private buildNode (isHtml: bool) (sb: StringBuilder) (node: XmlNode): unit =
let buildElement closingBracket (elemName, attributes: XmlAttribute array) =
match attributes with
| [||] -> do sb += "<" += elemName +! closingBracket
| _ ->
do sb += "<" +! elemName
attributes
|> Array.iter
(fun attr ->
match attr with
| KeyValue (k, v) -> do sb += " " += k += "=\"" += v +! "\""
| Boolean k -> do sb += " " +! k)
;
do sb +! closingBracket
let inline buildParentNode (elemName, attributes: XmlAttribute array) (nodes: XmlNode list) =
do buildElement ">" (elemName, attributes)
for node in nodes do
buildNode isHtml sb node
;
do sb += "</" += elemName +! ">"
match node with
| Text text -> do sb +! text
| ParentNode (e, nodes) -> do buildParentNode e nodes
| VoidElement e -> do buildElement (selfClosingBracket isHtml) e
OptionsFantomas Master at 12/26/2020 15:00:23 - 76fa31e { config with
SemicolonAtEndOfLine = true } WorkaroundI finally came up with this workaround: let buildElement closingBracket (elemName, attributes : XmlAttribute array) =
match attributes with
| [||] -> do sb += "<" += elemName +! closingBracket
| _ ->
do sb += "<" +! elemName
let fantomasWorkaround =
function
| KeyValue (k, v) -> do sb += " " += k += "=\"" += v +! "\""
| Boolean k -> do sb += " " +! k
Array.iter fantomasWorkaround attributes
do sb +! closingBracket
let inline buildParentNode
(elemName, attributes : XmlAttribute array)
(nodes : XmlNode list)
=
do buildElement ">" (elemName, attributes)
let fantomasWorkaround () =
for node in nodes do
buildNode isHtml sb node
fantomasWorkaround ()
do sb += "</" += elemName +! ">" |
Hey @lydell, thank you for reporting this issue. I'm afraid I don't have a lot of incentive this look into this. Perhaps we should sunset this feature in the next major and replace it with something that better covers your need. |
@nojaf There is an easier solution!
So I suggest making I could try making a PR that solves both issues at the same time in the upcoming months. |
That would change the overall behavior of the current setting, this is something we cannot do at any given point in time. |
It’s been over a year, and I still haven’t made a PR. At work we are going away from using this option now. So I’m leaning more towards removing this now:
|
This option was deprecated in #2250. |
Issue created from fantomas-online
Code
Error
Problem description
Workaround: Add a blank line between the two statements – then Fantomas won’t add any semicolons at all.
I found this when upgrading from Fantomas 4.0 to 4.3 at work.
Extra information
The reason we use
SemicolonAtEndOfLine = true
is because we love it in lists and records, but we don’t care about semicolons at the end of statements.Options
Fantomas Master at 12/26/2020 15:00:23 - 76fa31e
Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?
The text was updated successfully, but these errors were encountered: