Bad indentation in list comprehension
Issue created from fantomas-online
Code
[ for x in [] do yield 1 ]
Result
[ for x in [] do
yield 1 ]
Problem description
Getting two excessive spaces added before yield - there are six instead of four.
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.
- [ ] I would like a release if this problem is solved.
Options
Fantomas main branch at 1/8/2025
Default Fantomas configuration
There are four spaces in regards to the for keyword.
I'm pretty sure this is a can of worms if we want to respect this from the opening [.
For your small example there is no problem, but for larger expressions I can imagine it can lead to indentation problems.
Are you interested to send a PR to investigate this?
@nojaf Sorry, I am not a professional developer. What does your last question mean?
Do you want me to investigate the scale of this problem? Not sure I can help with it because I just don't understand what should I do. But I actually had a large expression with two nested list comprehensions where such indents were a real trouble.
Or you want me to propose the changes to Fantomas source code? If so I think I can participate - I did similar things a couple of times in other open source projects.
I cannot definitively say whether it is safe to preserve indentation relative to the [ for each expression. My assumption is that we currently do so to ensure formatted code remains valid.
A developer should investigate by changing the code and running the test suite to observe the effects; each test verifies whether the formatted code is still valid.
If this proves not to be a problem, we should raise the matter with the style-guide maintainers to determine whether the behavior can be formalized.
Do you want to do some digging?
ok, will do
Thank you! Comprehensive documentation is available at https://fsprojects.github.io/fantomas/docs/contributors/Getting%20Started.html. Please do not hesitate to ask if you have any questions.