eslint javascript code example

Example 1: eslint npm install

$ npm install eslint --save-dev
$ ./node_modules/.bin/eslint --init

Example 2: node eslint

// package.json
"devDependencies": {
    "eslint": "^7.2.0",
	"eslint-plugin-node": "^11.1.0"
}

// .eslintrc.json
{
   "extends": [
      "eslint:recommended",
      "plugin:node/recommended"
   ],
   "parserOptions": {
      // Only ESLint 6.2.0 and later support ES2020.
      "ecmaVersion": 2020
   },
   "rules": {
      "node/exports-style": ["error", "module.exports"],
      "node/file-extension-in-import": ["error", "always"],
      "node/prefer-global/buffer": ["error", "always"],
      "node/prefer-global/console": ["error", "always"],
      "node/prefer-global/process": ["error", "always"],
      "node/prefer-global/url-search-params": ["error", "always"],
      "node/prefer-global/url": ["error", "always"],
      "node/prefer-promises/dns": "error",
      "node/prefer-promises/fs": "error"
   }
}

Example 3: javascript linting

// alternative linting for javascript developer using standard zero configuration follow this step by step
 
1.install standard to development mode - npm i standard -D or install standard to global - npm i standard -g
2.install standard extension for vscode
3.add this configuration to vscode json config
  "standard.enable": true,
  "standard.run": "onSave",
  "standard.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
  "standard.autoFixOnSave": true,
  "standard.engine": "standard",
4. enjoy linting is active