StandardJS for JavaScript/NodeJS

Disable default JavaScript validation in VS Code so standard can take that role. Go to menu File/Preferences/Settings or just press CTRL+, and add to settings.json following line:

"javascript.validate.enable": false

Open a terminal and install standard with the command:

$ npm i -g --dev-save standard

If you want to ignore specific files you can do that like in the following example where we added ignore for checking and formatting Angular2 bundle files. Add the following to package.json:

"standard": {
"ignore": [
"*.bundle.js"
]
}

Restart VS Code

Now you probably have a lot of unformatted code in a project, you can fix it by typing following command. After that, all .js files will be fixed against the standard you will need some parts to fix manually since this will fix the only indentation and remove semicolons.

To fix existing files to follow standard rules you need to install global tslint and typescript:

$ npm i -g tslint typescript

And after that to run the command:

$ tslint -c tslint.json assets/**/*.ts

Known issues

TypeScript constructor keyword doesn’t have space before opening brackets after code formating, which will report error by standard. Workaround is to put above constructor following line:

// tslint:disable-next-line:space-before-function-paren

Automatic Imports with light bulp or CTRL+. will not follow standard rules. It will import with double quotes and semicolon at the end. Don’t know workaround for this if someone find solution please add it to comments.