Code Linting - TorinitTechnologies/Torinit-Coding-Guidelines GitHub Wiki

Linting is a way to correct bad patterns and reduce errors in code by using a tool either on the command line or in your IDE or text editor.

The tool we are using is ESLint, which is primarily for JavaScript, but has many plugins for other languages, and for various IDEs.

General Installation

ESLint requires Node.js (>=6.14), and npm version 3+.

Global

First, you should install ESLint globally, so that it is available to your tools across all projects. This should be done by all developers.

$ npm install -g eslint

Then, you should find and install a plugin to enable ESLint in your IDE.

Local

ESLint also needs to be installed locally in every project, along with the plugin package. This only needs to be done once, at the start of each project, by the lead developer. Note: There must be a package.json file present in the directory. If one is not generated by the project framework (e.g. Angular), you must run npm init first.

$ npm install eslint eslint-plugin-import --save-dev

The next step is to set up the configuration file:

$ eslint init

The lead deveolper should follow the prompts to select the settings appropriate for the project. This process will create an .eslintrc file in the root directory. The developer should review this file, and make any necessary changes based on project requirements, as outlined below.

JavaScript

Default

For JavaScript, we are starting with a default configuration provided by AirBnB. [These settings may be overridden over time, if necessary. Developers can discuss desired changes by raising an issue.]

After installing ESLint as described above, install the AirBnB Base Configuration plugin. With npm 5+*, run:

npx install-peerdeps --dev eslint-config-airbnb-base

* For more installation instructions, see the package details on npm.

Next, open the .eslintrc rile and add airbnb as a value for extends:

"extends": "airbnb"

With React

TBD. Suggest using AirBnB React, or find appropriate config for React Native and update this wiki.

With React Native

TBD. Suggest using AirBnB React, or find appropriate config for React Native and update this wiki.

With Angular

TBD. Suggest using default option, or find appropriate config for Angular and update this wiki.