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

Surround return type annotations with white space [F# style guide] #1420

Closed
3 tasks
cmeeren opened this issue Jan 30, 2021 · 6 comments · Fixed by #1432
Closed
3 tasks

Surround return type annotations with white space [F# style guide] #1420

cmeeren opened this issue Jan 30, 2021 · 6 comments · Fixed by #1432

Comments

@cmeeren
Copy link
Contributor

cmeeren commented Jan 30, 2021

Issue created from fantomas-online

Code

let expensiveToCompute : int = 0
let myFun (a: decimal) b c : decimal = a + b + c

Result

let expensiveToCompute: int = 0
let myFun (a: decimal) b c: decimal = a + b + c

Problem description

F# style guide:

In a let-bound function or value type annotation (return type in the case of a function), use white space before and after the : symbol:

// OK
let expensiveToCompute : int = 0 // Type annotation for let-bound value
let myFun (a: decimal) b c : decimal = a + b + c // Type annotation for the return type of a function
// Bad
let expensiveToComputeBad1:int = 1
let expensiveToComputeBad2 :int = 2
let myFunBad (a: decimal) b c:decimal = a + b + c 

Extra information

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

Options

Fantomas Master at 01/29/2021 10:31:35 - c1a4fe6

Default Fantomas configuration

@cmeeren cmeeren changed the title Surround return type annotations with white space [F# Style guide] Surround return type annotations with white space Jan 30, 2021
@cmeeren cmeeren changed the title [F# Style guide] Surround return type annotations with white space Surround return type annotations with white space [F# style guide] Jan 30, 2021
@nojaf
Copy link
Contributor

nojaf commented Feb 4, 2021

Please try and set fsharp_space_before_colon to true.

@cmeeren
Copy link
Contributor Author

cmeeren commented Feb 4, 2021

No dice, that produces this:

let expensiveToCompute : int = 0
let myFun (a : decimal) b c : decimal = a + b + c

While the return type and let annotation are correct, a : decimal is not. This is also a violation of the F# style guide, which says a: decimal.

@nojaf
Copy link
Contributor

nojaf commented Feb 4, 2021

I see, thanks for clarifying this.

@knocte
Copy link
Contributor

knocte commented Feb 8, 2021

@nojaf This will basically change all the type declarations of all code, will fsharp_space_before_colon=false override this new behaviour?

@nojaf
Copy link
Contributor

nojaf commented Feb 8, 2021

No it won't. Both style guides dictate that the return type colon needs a space before it so it is outside the control of a setting.

@knocte
Copy link
Contributor

knocte commented Feb 8, 2021

Mmm I see, then the setting should probably be renamed to fsharp_always_space_before_colon 🤔

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.

3 participants