2.0.2 • Published 1 year ago

eslint-config-opennebula v2.0.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

OpenNebula Eslint and Prettier Setup

These are OpenNebula settings for ESLint and Prettier

What it does

  • Lints JavaScript based on the latest standards
  • Fixes issues and formatting errors with Prettier

Installing

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.

  1. If you don't already have a package.json file, create one with npm init.

  2. Then we need to install everything needed by the config:

npm install --save-dev eslint eslint-config-opennebula
  1. 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.

  1. You can add two scripts to your package.json to lint and/or fix:
"scripts": {
  "lint": "eslint .",
  "lint:fix": "eslint . --fix"
},
  1. Now you can manually lint your code by running npm run lint and fix all fixable issues with npm run lint:fix.

With VS Code

You probably want your editor to do this though.

  1. Install the ESLint package
  2. Now we need to setup some VS Code settings via Code/FilePreferencesSettings. It's easier to enter these settings while editing the settings.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.