jcberquist / commandbox-cfformat

A CommandBox module for formatting CFML component files.
MIT License
22 stars 10 forks source link

Support for concatenated method calls #76

Closed lmajano closed 4 years ago

lmajano commented 4 years ago

I would like to propose a setting to control the way chaining is done with functions.

getInstance( "entityService:Task" )
  .list()
  .reduce( ( result, row ) => result.append( row ), [] );

When using our standard formatting rules, it flatens it to one row:

variables.aProjectTasks = getInstance( "entityService:Task" ).list().reduce( ( result, row ) => result.append( row ), [] );

Is there a way to control this?

jcberquist commented 4 years ago

Have you looked at this setting: "method_call.chain.multiline". The default is 3 so your example above will get put on one line (only two method calls). If you set it to 2, it will get printed on multiple lines.

lmajano commented 4 years ago

That worked, but I can say that having that to 2 really messes up other chain calls. Maybe what would be best is a width measurement. Since in reality you can have two calls that are long, like I have, which obviously look a lot better in different lines than just one. THoughts?

jcberquist commented 4 years ago

Yes, that makes sense. I actually thought it was currently doing that, but I took a look, and it isn't.

jcberquist commented 4 years ago

v0.15.1 is out. In this version the inline rendered method chain will be checked against the max_columns setting. If it exceeds it, the chain will be rendered over multiple lines.

lmajano commented 4 years ago

sweetnes!