1

I would like more control and customisation regarding where Fantomas inserts or remove a line break in the code that's formatted by Fantomas. For instance, the following function is formatted in one line but I would prefer having a line break.

module Xxx =
    // Actual
    let private emptyOrTrimmed (code: string) = if code = null then "" else code.Trim()

    // Expected
    let private emptyOrTrimmed (code: string) =
        if code = null then "" else code.Trim()

How is it possible, preferably without touching the .editorconfig file (given below) ? Can we add some comment in the code to disable one rule like it exists for eslint ?

// .editorconfig file
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

[*.fs]
end_of_line = lf
max_line_length = 210
fsharp_semicolon_at_end_of_line = false
fsharp_space_before_parameter = true
fsharp_space_before_lowercase_invocation = true
fsharp_space_before_uppercase_invocation = false
fsharp_space_before_class_constructor = false
fsharp_space_before_member = false
fsharp_space_before_colon = false
fsharp_space_after_comma = true
fsharp_space_before_semicolon = false
fsharp_space_after_semicolon = true
fsharp_indent_on_try_with = false
fsharp_space_around_delimiter = true
fsharp_max_if_then_else_short_width = 40
fsharp_max_infix_operator_expression = 50
fsharp_max_newline_infix_operator_expression_number_of_items = 1
fsharp_multiline_infix_multiline_formatter = character_width
fsharp_max_record_width = 40
fsharp_max_record_number_of_items = 1
fsharp_record_multiline_formatter = character_width
fsharp_max_array_or_list_width = 40
fsharp_max_array_or_list_number_of_items = 1
fsharp_array_or_list_multiline_formatter = character_width
fsharp_max_value_binding_width = 40
fsharp_max_function_binding_width = 40
fsharp_max_dot_get_expression_width = 50
fsharp_multiline_block_brackets_on_same_column = false
fsharp_newline_between_type_definition_and_members = false
fsharp_keep_if_then_in_same_line = true
fsharp_max_elmish_width = 10
fsharp_single_argument_web_mode = false
fsharp_align_function_signature_to_indentation = false
fsharp_alternative_long_member_definitions = true
fsharp_disable_elmish_syntax = false
fsharp_strict_mode = false
Romain Deneau
  • 2,841
  • 12
  • 24

2 Answers2

1

Just change this setting to assign it to zero:

fsharp_max_function_binding_width=0
knocte
  • 16,941
  • 11
  • 79
  • 125
  • I tried this setting with 0 and -1. In both cases, I've got other existing files reformatted in order to force every function to have a line break. It's not what I want. I want to override the setting for some functions to force either the line break or the one line declaration. – Romain Deneau Mar 07 '22 at 08:48
  • you didn't specify what would be the reason for the line being split or not being split? anyway, regardless of the reason, I don't think it would be possible with the current version of fantomas, unless you propose a PR to fantomas that implements it – knocte Mar 07 '22 at 09:07
  • PS: each line in .editorconfig is a setting, not a rule, they cannot be applied independently, can't be disabled or enabled – knocte Mar 07 '22 at 09:10
0

Currently, I've managed to "force a line break" where I want, just by putting a comment in the code. In order to be explicit, the comment is // force-line-break, which looks like a "configuration comment" (e.g. for ESLint) but the comment can be anything.

But I still have no way to do the opposite: forcing no line break, which is occurring very often with record object.

Note: for me the most annoying thing with this code formatting is to have several blocks of code doing something similar but not formatted the same way regarding line breaks, which is breaking the symmetry and is penalizing the code scanning (meaning fast reading, where visual similarities help).

Romain Deneau
  • 2,841
  • 12
  • 24