Skip to content

Latest commit

 

History

History
105 lines (73 loc) · 2.21 KB

javascript-linting-rules.md

File metadata and controls

105 lines (73 loc) · 2.21 KB

⬅ Back to Coding Culture

Javascript Linting Rules

The following rules should be applied to all of our javascript projects.

If a rule is absent from rule set below, please adhere to the conventions used in the current project.

A project may use additional rules to ones listed here, but these would not be part of the current standard and such rules are subject to change in the future.

Current Rules

These are stored in the linters folder in this repository.

For an explanation of these rules please refer to the JSHint documentation.

Implementation

Adding to your project

Add the .editorconfig, .jshintrc & .jshintrcignore files from the linters folder to the root of your project.

Then run the following commands to add jshint to your package.json file:

Node Linting

npm install jshint --save-dev
npm install jshint-stylish --save-dev

Then you can run the following command to test linting:

./node_modules/jshint/bin/jshint --reporter=node_modules/jshint-stylish ./path/to/js

You can then add it to your package.json file like so:

{
  "scripts": {
    "lint": "./node_modules/jshint/bin/jshint --reporter=node_modules/jshint-stylish" ./path/to/js
  }
}

which will allow you to run:

npm run lint

Grunt Linting

npm install grunt-contrib-jshint --save-dev
npm install jshint-stylish --save-dev

you could have a grunt command that looks like this:

module.exports = {
	dist: [
		'www/src/js/*.js',
		'www/src/js/**/*.js',
		'test/*.js'
	],
	options: {
		jshintrc: '.jshintrc',
		reporter: require('jshint-stylish')
	}
};

Then you can run the following command to test linting:

grunt jshint:dist

You can then add it to your package.json file like so:

{
  "scripts": {
    "lint": "grunt jshint:dist"
  }
}

which will allow you to run:

npm run lint

Expanding current rules

In order for a rule to be added to the above list it requires the following:

  1. A valid reason for adoption the rule.
  2. Agreement from the Lead Software Engineer