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

Shebang directives get removed from scripts #2367

Closed
2 of 3 tasks
mataha opened this issue Jul 16, 2022 · 3 comments · Fixed by #2387
Closed
2 of 3 tasks

Shebang directives get removed from scripts #2367

mataha opened this issue Jul 16, 2022 · 3 comments · Fixed by #2387

Comments

@mataha
Copy link
Contributor

mataha commented Jul 16, 2022

Issue created from fantomas-online

Code

#!/usr/bin/env -S dotnet fsi --warn:5 --warnon:1182 --warnaserror+

open System
// ...

Result

open System
// ...

Problem description

See fsharp/fslang-design#683.

Extra information

  • The formatted result breaks my code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas master branch at 2022-07-15T14:30:45Z - 87cd212

    { config with
                MaxIfThenElseShortWidth = 40
                MaxInfixOperatorExpression = 50
                MaxArrayOrListWidth = 40
                MaxDotGetExpressionWidth = 50
                NewlineBetweenTypeDefinitionAndMembers = false }

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

@nojaf
Copy link
Contributor

nojaf commented Jul 18, 2022

Hello, thank you for raising this. The shebang is currently captured as a code comment but is not restored correctly. This is due to an assumption that all non-block code comments start with //.

| CommentTrivia.LineComment r ->
let content = source.GetContentAt r
let line = source.GetLineString(r.StartLine - 1)
let item =
Comment(
if line.TrimStart(' ', ';').StartsWith("//") then
CommentOnSingleLine content
else
LineCommentAfterSourceCode content
)
{ Item = item; Range = r })

would need to be something like

        | CommentTrivia.LineComment r ->
            let content = source.GetContentAt r

            let line = source.GetLineString(r.StartLine - 1)

            let item =
                let trimmedLine = line.TrimStart(' ', ';')
                Comment(
                    if trimmedLine.StartsWith("//") || trimmedLine.StartsWith("#!") then
                        CommentOnSingleLine content
                    else
                        LineCommentAfterSourceCode content
                )

            { Item = item; Range = r })

Are you interested in submitting a PR for this one?

@mataha
Copy link
Contributor Author

mataha commented Jul 18, 2022

Sure; in fact I was writing a comment asking where to start, as I'd imagine starting with modifying hash regex wouldn't cut it.

@nojaf
Copy link
Contributor

nojaf commented Jul 26, 2022

We probably even no longer need that hash regex.
Let me know if you need any help. Our Contribution Guidelines are a good place to start.

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

Successfully merging a pull request may close this issue.

2 participants