jcberquist / commandbox-cfformat

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

Not switching quotes around quotes #62

Closed elpete closed 4 years ago

elpete commented 4 years ago

This one might not be possible and may need the ignore pragmas, but consider this use case:

// this is a double quote inside single quotes.
// (the opposite can apply as well.)
var someStringWithQuotesInside = '"';

If I format this with "strings.quote":"double" then I get this output:

var someStringWithQuotesInside = """"; // four double quotes in a row

Not as readable, in my opinion.

It would be awesome if the setting was something like preferDouble so it would not escape if it didn't have to.

I realize this can get confusing with multiple levels of quotes, and I understand if you would suggest to just use the pragma to ignore these uncommon situations.

jcberquist commented 4 years ago

I have thought about this in the past - I do think it is doable, but I am not sure if it will be consistent with people's expectations? So, as you suggest, another setting is probably needed. I would think it would need to go both ways so maybe something like strings.avoidEscapes?

Supposing you started with:

var someStringWithQuotesInside = """";

Would you want.expect that formatted to be formatted to (even with the quote setting being double)

var someStringWithQuotesInside = '"';

or just avoid the conversion when starting with '"'?

elpete commented 4 years ago

I think I’d leave alone any quotes with quotes inside in each direction.

jcberquist commented 4 years ago

I have added a setting "strings.convertNestedQuotes": true (open to better naming ideas). You can set this to false to avoid the quote conversion when the string contains quotes.