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 .eslintrc in this repository.
For an explanation of these rules please refer to the ESLint documentation.
Here is a brief description of the rules:
"no-underscore-dangle": 0
Allow variables beginning with_
."curly": [2, "multi-line"]
Force curly braces except on single line statements."camelcase": [2, {"properties": "never"}]
Force camel case variables except on object properties."space-before-blocks": [2, "always"]
Force spaces before starting a block."no-extra-parens": [2, "always"]
Don't allow extra redundant brackets in expressions."block-scoped-var": 2
Don't allow variables to be defined in a block but used outside of one."no-else-return": 2
Don't allow else statements to return."no-self-compare": 2
Don't allow a variable to be compared to itself."radix": 2
Enforce the specification of the base to use with theparseInt()
function."comma-style": [2, "last"]
Force multi line lists to have the separating comma after each item."indent": [2, 2]
Force two space indentation."quotes": [2, "single", "avoid-escape"]
Force use of single quotes for strings, except when you need to escape characters."linebreak-style": [2, "unix"]
Force UNIX line endings."brace-style": [2, "1tbs"]
Force theone true brace style
."no-new-object": 2
Don't allownew Object()
, use shortened syntax instead."no-nested-ternary": 2
Don't allow nested ternary expressions."no-unneeded-ternary": 2
Don't allow ternary expressions for just coverting to a boolean."object-curly-spacing": [2, "always"]
Force spaces inside curly braces."space-after-keywords": [2, "always"]
Force spaces after keywords (if, for, etc)."space-before-function-paren": [2, "never"]
Don't allow spaces after function keyword."valid-jsdoc": 2
Check if JSDoc blocks are valid if used.
Rules which are not in the above list are taken from the eslint recommended rules as of version 0.22.1 (latest at time of conception).
In general the format of the rules specified are:
- A rule name, these may be prefixed with
no-
to not allow something if enabled, otherwise turning on a rule sets a requirement on the code, such as "must use single quotes etc." - A rule ID, this enable (2) or disables (0) a rule and also sets a warning (1). If a rule is enabled and the code is not compliant eslint with exit with an error.
- Rule options, these vary from rule to rule but generally allow fine tuning of a rule.
The rule set is compatible with ESLint.
The rule set is the basis of the config for eslint, but in each version the config used may differ due to new rules being available or defaults changing.
To do comparison between two rule sets and/or eslint versions follow the steps below:
- Download the original ruleset as
/tmp/original_rules
- Alter the ruleset and save as
/tmp/new_rules
- Checkout the
make-up
repo and change into it - Run
script/calculate_eslint_config.js /tmp/original_rules > /tmp/old
- Change eslint versions if required
npm install [email protected]
- Run
script/calculate_eslint_config.js /tmp/new_rules > /tmp/new
- Run
diff /tmp/old /tmp/new
to see actual config changes
Rather than adding the ruleset from this repo into your own project, please use make-up to add the checks to your project as follows:
npm install make-up --save-dev
Then add a call to node_modules/.bin/make-up dir1 dir2 ... dirN
in your npm script to perform the checks.
If adding linting to an existing project, it would be advisable to add one directory at a time and resolve errors as they arise.
For more information on this tool please see the make-up documentation.
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 tech team.