Closed Daemach closed 2 years ago
I will have to look into this. I think it should be possible to special case single string arguments to allow keeping the quotes on the same line as the parentheses.
That would be great. Thanks!
Just checking up on this again. I will be doing code reviews soon and have to manually fix these after running cfformat:
queryExecute(
"
declare @total float = (select sum(market_val) from veritiadmin.idx.constituents where benchmarkID = '#benchmark.id#')
update veritiadmin.idx.constituents set
pct_wt = (market_val/@total) * 100
where benchmarkID = '#benchmark.id#'
"
)
would look better as
queryExecute( "
declare @total float = (select sum(market_val) from veritiadmin.idx.constituents where benchmarkID = '#benchmark.id#')
update veritiadmin.idx.constituents set
pct_wt = (market_val/@total) * 100
where benchmarkID = '#benchmark.id#'
" )
Thanks for the nudge, I have added some special case single string argument formatting in v0.17.4
- I would appreciate you trying it out. I tried to copy how prettier does this with JavaScript and you can see the new behavior illustrated with the current test files here:
tests/data/functionCallSingleString/source.cfc
tests/data/functionCallSingleString/formatted.txt
I like the first case the best.
On a side note, what would it take to work this into vscode as a formatter for cfml files? I might be willing to sponsor the effort.
I could have been clearer, the test cases match the behavior of Prettier with JavaScript, if you look through the source and then compare with the output, you will see that if you have a string argument (a string containing newlines) and the source starts the string on the same line as the opening parentheses, then the output will preserve that, and if the string starts on the next line, the output will preserve that. So it is source dependent what happens.
With regard to VSCode, I don't use it day to day, so I am not aware of how formatters work in it. I think it supports terminals running within it, so maybe one could get CommandBox running and then watch files to format on save, or even send a format command to the terminal immediately when a save happens? I am not sure what the options are.
In the formatted code below, what setting do I have to change to remove the CR between the parentheses and the double quotes? I want it to look like the second example, not the first:
This would be acceptable too: