VSCodeBeautify icon indicating copy to clipboard operation
VSCodeBeautify copied to clipboard

Adding space before and after "?" when we are using it for checking if key existing

Open jagadeeshgade008 opened this issue 5 years ago • 3 comments

let obj = { "key" : { "key1" : "value" } }

if(obj.key?.key1?){ //when i format it. It is converted to obj.key ? .key1 ? ) which is not valid. //do something }

jagadeeshgade008 avatar Feb 15 '21 07:02 jagadeeshgade008

You doing it wrong...

let obj = {
    "key": {
        "key1": "value"
    }
}
if (obj.key.key1) {
    //do something
    console.log('true');
}else{
    console.log('false');
}
/*OR*/
obj.key.key1 ? console.log('true') : console.log('false');

TyronNIKO avatar Feb 17 '21 15:02 TyronNIKO

having same issue, @jagadeeshgade008 syntax is fine, the included version of beautifier is messing it up.

https://github.com/beautify-web/js-beautify/issues/1727

sbubaron avatar Feb 20 '21 21:02 sbubaron

@jagadeeshgade008 update the bundled version of js-beautifer: https://github.com/HookyQR/VSCodeBeautify/issues/346

After doing this, I had to restart VS Code and reload the plugin.

sbubaron avatar Feb 20 '21 21:02 sbubaron