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.
These are stored in the linters folder in this repository.
For an explanation of these rules please refer to the JSHint documentation.
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:
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
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
In order for a rule to be added to the above list it requires the following:
- A valid reason for adoption the rule.
- Agreement from the Lead Software Engineer