These are OpenNebula settings for ESLint and Prettier
- Lints JavaScript based on the latest standards
- Fixes issues and formatting errors with Prettier
It's usually best to install this locally once per project, that way you can have project specific settings as well as sync those settings with others working on your project via git.
-
If you don't already have a
package.json
file, create one withnpm init
. -
Then we need to install everything needed by the config:
npm install --save-dev eslint eslint-config-opennebula
- Create a
.eslintrc
file in the root of your project's directory (it should live where package.json does). Your.eslintrc
file should look like this:
{
"extends": [ "opennebula" ]
}
Tip: You can alternatively put this object in your package.json
under the property "eslintConfig":
. This makes one less file in your project.
- You can add two scripts to your package.json to lint and/or fix:
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
- Now you can manually lint your code by running
npm run lint
and fix all fixable issues withnpm run lint:fix
.
You probably want your editor to do this though.
- Install the ESLint package
- Now we need to setup some VS Code settings via
Code/File
→Preferences
→Settings
. It's easier to enter these settings while editing thesettings.json
file, so click the Open (Open Settings) icon in the top right corner:
"editor.formatOnSave": true,
// turn it off for JS and JSX, we will do this via eslint
"[javascript]": {
"editor.formatOnSave": false
},
"[javascriptreact]": {
"editor.formatOnSave": false
},
// show eslint icon at bottom toolbar
"eslint.alwaysShowStatus": true,
// tell the ESLint plugin to run on save
"editor.codeActionsOnSave": {
"source.fixAll": true
}
Finally you'll usually need to restart VS code.