Better Code Quality with ESLint

Linters go through your code and look for mistakes such as undefined variables or reassigned constants. They are more powerful though when combined with a style guide - a preset which dictates how code should be written (spacing, use of semicolons etc.). ESLint is a linter which uses the JavaScript standard style guide.


Setting up ESLint with Visual Studio Code:
  • open a Terminal and enter the following:
    npm install -g eslint
  • open VS Code, click the Extensions icon
  • in the search box, enter ESLint and click Install and then click Reload
  • add an .eslintrc file to the project root with the following contents:
    {"extends": "airbnb-base"}
  • in the terminal for JavaScript without React:
    (export PKG=eslint-config-airbnb-base;npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest")
    JavaScript with React:
    (export PKG=eslint-config-airbnb;npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest")
Standard JS - https://standardjs.com/index.html
Visual Studio Code - https://code.visualstudio.com/docs/languages/javascript#_linters
Why you should always use a Linter - https://medium.com/dailyjs/why-you-should-always-use-a-linter-and-or-pretty-formatter-bb5471115a76

Popular posts from this blog

Week 9 to 12 - Learning with MCR Codes

Week 9 - Session 1 - The Internet, the Web, HTTP