js-beautify icon indicating copy to clipboard operation
js-beautify copied to clipboard

Add support for unifying quote style (single- vs. double-quotes) of string literals

Open akloeber opened this issue 11 years ago • 6 comments

When pasting code from documentation, tutorials, stackoverflow, etc. I often have to manually unify the quote style (single-quotes vs. double-quotes) of string literals. It would be super cool if js-beautify had an option for that.

akloeber avatar Jun 21 '14 08:06 akloeber

This is the sort of thing that needs parsed AST (#200), which is unfortunately hard to do with our current algorithm (not to mention Python and JS platform requirements). In the meantime, esprima (via escodegen) demonstrates one way to do this particular kind of transform.

evocateur avatar Jun 25 '14 16:06 evocateur

is there any progress with this?

AndrewEastwood avatar Sep 16 '14 10:09 AndrewEastwood

No, there is not progress on this and there is unlikely to be any for sometime. The beautifier is designed to modify only the whitespace of javascript input. This scenario is one that we specifically avoid at this time due to the limitations mentioned above. Also as noted above, there are other projects that might serve you better in this scenario.

We're leaving this open as a possible future enhancement along with other code folding feature requests.

bitwiseman avatar Sep 16 '14 21:09 bitwiseman

+1 :+1:

florrain avatar Jun 26 '15 17:06 florrain

I was able to make some changes to the javascript version to change single quotes to double quotes (or vice versa). It might not work in all cases. See https://gist.github.com/nmalaguti/576d191c4547cdf7e0cb lines 18-21 and 114-119 for the code changes.

nmalaguti avatar Aug 13 '15 14:08 nmalaguti

@bitwiseman I understand that Javascript requires something like #200, but what about HTML support or CSS? Any hope of them being tackled separately (and sooner? 😁)

wgordon17 avatar Jan 13 '25 12:01 wgordon17