fantomas icon indicating copy to clipboard operation
fantomas copied to clipboard

[Feature request] Split into multiple lines if a line including comments exceed the maximum width

Open lulunac27a opened this issue 1 year ago • 4 comments

I propose we ... add a feature that formats a statement into a line including comments that don't exceed the maximum width.

The existing way of Fantomas deals with this problem is ... When I format the code, the line of code including the comments sometimes exceeds the maximum width, but the line of code without comments doesn't exceed the maximum width.

Pros and Cons

The advantages of making this adjustment to Fantomas are ... Easier to read

The disadvantages of making this adjustment to Fantomas are ... None

Examples

Please provide multiple examples (before and after scenarios) and explain what rules did apply to achieve the outcome. Input:

let complex_function first second third fourth last = first + second + third + fourth + last // complex function

Actual Output:

let complex_function first second third fourth last = first + second + third + fourth + last // complex function

Expected Output:

let complex_function first second third fourth last =
    first + second + third + fourth + last // complex function

Input:

let very_complex_function first second third fourth fifth last = first + second + third + fourth + fifth + last // very complex function

Actual Output:

let very_complex_function first second third fourth fifth last =
    first + second + third + fourth + fifth + last // very complex function

Expected Output:

let very_complex_function first second third fourth fifth last =
    first + second + third + fourth + fifth + last // very complex function

Affidavit (please submit!)

Please tick this by placing a cross in the box:

Please tick all that apply:

  • [x] This is not a breaking change to Fantomas
  • [ ] I or my company would be willing to help implement and/or test this
  • [ ] This suggestion is part of the Microsoft style guide (please add a link to section if so)
  • [ ] This suggestion is part of the G-Research style guide (please add a link to section if so)

lulunac27a avatar Nov 12 '24 21:11 lulunac27a

Hello, thank you for your interest. At first glance, I don't think this is deemed problematic by the current userbase. (As it was never brought up until now)

Could you provide some more examples where you are bumping into this use-case? Please use the online tool where possible.

nojaf avatar Nov 13 '24 07:11 nojaf

These examples are repetitive, and they don't broaden the scope of your expectations. The technical details surrounding this situation are quite unclear, particularly regarding the predefined rules and what changes would be necessary to achieve it. How significant would the impact be?

nojaf avatar Nov 13 '24 14:11 nojaf

The above code is formatted based on the line length of the code excluding comments, instead of the line length of the code including comments. So the above code is formatted and the line length of code excluding comments always doesn't exceed the maximum line width, sometimes the line length of code can exceed the maximum line width.

lulunac27a avatar Nov 13 '24 16:11 lulunac27a