jcberquist / commandbox-cfformat

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

split long lines by operator #90

Closed chapmandu closed 3 years ago

chapmandu commented 3 years ago

I'm not sure how to categorise this, but would it be possible to split long lines by operators rather than function arguments.

input

if (!StructKeyExists(variables.wheels.class.mapping, local.propertyName) || !StructKeyExists(variables.wheels.class.mapping[local.propertyName], "label")
  // ...
)

actual

if (
  !StructKeyExists(variables.wheels.class.mapping, local.propertyName) || !StructKeyExists(
    variables.wheels.class.mapping[local.propertyName],
    "label"
  )
  // ...
)

wanted

if (
  !StructKeyExists(variables.wheels.class.mapping, local.propertyName) ||
  !StructKeyExists(variables.wheels.class.mapping[local.propertyName], "label"
)
  // ...
)
jcberquist commented 3 years ago

I agree that this would be great. In my opinion the lack of it is the current shortcoming of cfformat. Unfortunately, the way cfformat currently works (no AST), it can't tell ahead of time that it is looking at a compound expression and split on the operator. The best it can do is respect the line breaks you put in, so if you put your "wanted" version in place yourself, it should be preserved. Absent a significant rework of cfformat internals, this is going to be the best it can do. Sorry!

chapmandu commented 3 years ago

Never mind.. On the upside, the fact that writing the desired format is not overwritten is a great feature in itself.

Thanks again!