I use React and VSCode, I wanna setup self-closing when code is saved but I don't know how...
What I wanna do is
<Hello></Hello>
after I save code
<Hello />
Where can I setup self closing?
Thank you.
If you have the ESLint extension installed you can use CTRL+SHIFT+P to open the Command Palette. Then search for ESLint: Fix all auto-fixable Problems and press ENTER (or RETURN ).
Open the terminal in your project root folder and install eslint as a dev dependency. We also need to enable the eslint and prettier extension for the VSCode. So visit the extensions section of VSCode (ctrl + shift + x) and search for Eslint and Prettier — Code formatter and install it.
Configure VSCode Settings to use ESLint for Formatting Click that tiny icon in the top-right that looks like a piece of paper with a little arrow. The first one turns on ESLint for formatting, and the next 3 make it do the formatting when you hit save. That should do it! Save the settings file and close it, we're done.
Prettier runs as a plugin of ESLint and thanks to the special configuration it won't conflict with it.
You need to enable the related rule and make sure VSCode
is integrated to fix lint warnings/errors on saving.
react/self-closing-comp
rule:// eslint config file (package.json / eslintrc / settings.json etc.)
{
...
"rules": {
"react/self-closing-comp": "error"
}
}
settings.json
at VSCode
make sure you got auto-fix enabled (for example with vscode-eslint extension, it may be any other lint extension related): // settings.json @ VSCode
{
...
"eslint.autoFixOnSave": true,
"eslint.run": "onSave",
}
Refer to eslint-plugin for vscode for integration.
Note that eslint-config-airbnb
enables it by default (I suggest using any config).
Add this ti vscode config:
vscode settings.json:
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
If 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