vscode
is my favorite editor, I have a code formatting problem with it. Here is my jsx
code:
return <div className={panelHeadingClassName}> <h3 className={style.panelTitle}> <i className={iconStyle[iconClass]}></i> {title} <small className={style.panelSubTitle}>{subTitle}</small> </h3> </div>
when I use option + shift + F to format it, it gives me this:
return <div className = { panelHeadingClassName } > < h3 className = { style.panelTitle } > < i className = { iconStyle[iconClass] } > < /i> { title } < small className = { style.panelSubTitle } > { subTitle } < /small> < /h3> < /div>
Obviously, it's not correct.
vscode
version - v1.10.2
, and not install any code formatting extension.
So, I don't want to install any code formatting extension, is there any config for vscode
to doing this correctly?
-- update --
Sorry about that. I check my extensions installed, found Beautify
extension. But why the i use vscode code formatting, it use Beautify
?
You can use hot key Ctrl+M (Command+M) to beautify your JSX file.
JSX stands for JavaScript XML. It is simply a syntax extension of JavaScript. It allows us to directly write HTML in React (within JavaScript code). It is easy to create a template using JSX in React, but it is not a simple template language instead it comes with the full power of JavaScript.
The code formatting is available in Visual Studio Code through the following shortcuts: On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.
Embedding Expressions in JSX const name = 'Josh Perez';const element = <h1>Hello, {name}</h1>; You can put any valid JavaScript expression inside the curly braces in JSX. For example, 2 + 2 , user. firstName , or formatName(user) are all valid JavaScript expressions.
As you note, the Beautify extension is the root cause here (see this issue). That extension provides a document formatter that VSCode will run when you run the format command
A few options:
js
entry from the "beautify.language"
settingjavascriptreact
. I believe this will prevent Beautify from running on the fileIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With