HookyQR / VSCodeBeautify

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

Optional-chaining / null coalescing #368

Open bluefangs opened 3 years ago

bluefangs commented 3 years ago

VS Code settings:

"beautify.config": {
        "indent_size": 4,
        "indent_char": "\t",
    },
"beautify.language": {
        "js": {
            "type": [
                "javascript",
                "json",
                "jsonc"
            ],
            "filename": [
                ".jshintrc",
                ".jsbeautifyrc"
            ]
        },
        "css": [
            "css",
            "less",
            "scss"
        ],
        "html": [
            "htm",
            "html"
        ]
    }

Expected results

When there is chaining or nullish coalescing involved, do not put spaces inbetween '?'

let a = {
    b: {
        c: 1
    }
};
var d = a?.b?.c || 0;

Actual results

Space is added inbetween the '?' causing syntax error.

let a = {
    b: {
        c: 1
    }
};
var d = a ? .b ? .c || 0;

Similar issue : https://github.com/beautify-web/js-beautify/issues/1530

Thanks.

yume-chan commented 3 years ago

I see beautify-web/js-beautify#1779 and beautify-web/js-beautify#1794 both have been merged, and released in js-beautify 1.11.0

Does it mean this extension need to upgrade its dependency and do a release?

l246804 commented 3 years ago

Has the problem been solved?

moscoso commented 3 years ago

I see that this is closed but 'm still dealing with this issue. When I run the beautify command on a file all of my optional chaining expressesions add a space before and after the ? question mark causing syntax errors

toferj commented 3 years ago

I am also having this problem using Beautify 1.5.0 in VSCode... How can I fix this other than disabling Beautify?

moscoso commented 3 years ago

I am also having this problem using Beautify 1.5.0 in VSCode... How can I fix this other than disabling Beautify?

what i had to do was navigate to the folder where the extension is and run npm update Google what directory vs code is in and then look for a subdirectory of extensions/hookyqr.beautify

moscoso commented 3 years ago

The fix to this is just HookyQR updating the beautify-js dependency to a newer version that fixed this issue .... it takes less then 30 seconds

toferj commented 3 years ago

I appreciate the suggestion, but it's too much trouble. I just bailed on Beautify and switched to Prettier. Seems like maybe Beautify doesn't have it's stuff together. Idk.

filozof595 commented 3 years ago

I'm still heaving this issue. I run the npm update as suggested but id didn't solve the issue. Does anyone know how to stop Beautify to add space in JS Nullish Coalescing (?? -> ? ?) ?

alexgritton commented 3 years ago

@moscoso 's solution worked perfectly. I did have to reload vscode for it to work though.

jasonkneen commented 2 years ago

@moscoso 's solution worked perfectly. I did have to reload vscode for it to work though.

Yep, just drop into ~/.vscode/extensions/hookyqr.beautify-1.5.0, update package.json and run npm update -- I relaunched VScode to be sure and worked perfectly.

GibranValle commented 2 years ago

@jasonkneen Hey man, thank you, Great Solution!