HookyQR / VSCodeBeautify

Enable js-beautify (https://github.com/beautify-web/js-beautify) in VS Code
MIT License
607 stars 178 forks source link

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

Open jagadeeshgade008 opened 3 years ago

jagadeeshgade008 commented 3 years ago

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 }

TyronNIKO commented 3 years ago

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');
sbubaron commented 3 years ago

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 commented 3 years ago

@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.