StandardJS

Javascript Coding Standards

So that code is easier to read and understand, developers will naturally develop their own style of formatting coding. This is fine when you are the sole developer on a project, but becomes an issue where there are multiple developers. StandardJS to the rescue.

Installation

npm install -g standard

To check your project, do:

$ standard

To set some global variables, you can specify that with the CLI, or via a key/value pair in package.json. e.g.

{
 	"name": "sc-customer-timeline",
 	"version": "1.0.0",
 	"description": "Customer Hub Timeline component",
 	"main": "index.js",
 	"author": "Craig",
 	"license": "ISC",
 	"standard": {
 		"globals": ["describe", "it"]
 	}
 }

Alternatively, you can specify your globals in an .eslintrc config file.

You can also ignore files by placing them in a "ignore" key and then pass an array of paths or files. Refer to https://github.com/feross/standard#how-do-i-ignore-files

Per File Overrides

Instead of defining globals in package.json, you could do it in each file. The first line of the file will be a comment taking the form:

 	/* global $ */
 	/* eslint-env mocha */

Refer to the ESLint doco for more options.

Automatic Formatting

You will need to install standard-format

$ npm install -g standard-format

Then to do a dry-run of the automatic formatting just issue

$ standard-format

To do it for real add the -w flag. i.e. $ standard-format -w

To automatically do it on save (in Sublime Text), you will need to install a few Sublime packages. See the next section.

Linting and Automatic Formatting in Sublime Text

First make sure you have `Package Control`, a nearly mandatory install for all users of Sublime Text, and then use it to install:

Those two package will then get you real-time linting.

Next, if you want automatic formatting on save, install (again, via Package Control) StandardFormat.

Overriding Standard

Standard is built on top of ESlint, so you could install that and then just import the StandardJS Config file and then tweak it.