Closed mataha closed 1 year ago
@nojaf fyi, might be interesting for you
If the lexer/parser can capture this in the syntax tree, Fantomas can restore it.
This can be captured, yes, we should treat this as an FCS/ fantomas bug
What's the next step then? Do I file a bug report in Fantomas, then try to fix it before v5 hits?
The next step would be to raise a PR to dotnet/fsharp
that adds the shebang as ParsedHashDirective (I think).
You can open an issue in Fantomas, but you would get the same reply there. This doesn't hinder the v5 release, we would accept a fix at any time for this.
Actually, after taking another look at this, it can be solved quite easily on Fantomas' side without any compiler changes.
Looking at the AST, the shebang is parsed as a line comment. There is a bug in Fantomas that doesn't recognize this as a line comment on a single line because it does not start with //
.
@mataha, please report an issue on Fantomas' side. You can do this using the online tool.
@dsyme this was implemented in Fantomas a while ago, do we still need to do anything here?
This can be closed as completed.
Writing F# scripts is a great way of, among other things, creating project tooling to improve the development and build processes, by e.g. managing git hooks or setting up CI. Saying that, the preferable, cross-platform way of invoking a F# script is to prepend it with a shebang directive (in this case
#!/usr/bin/env -S dotnet fsi
) and make it executable in order to run it on Linux distros, macOS, WSL et al.However, this is not mentioned at all in the de-facto F# code formatting guidelines and, as a consequence, formatters implementing the coding conventions of F# remove it entirely. I believe this should not be done for F# scripts (
.fsx
), while code and signature files should be fine as they currently are.Using e.g. Fantomas, the following:
Is rewritten as:
That should not be the case.