eslint-config-sky
ESLint config for Sky JavaScript projects. Aside from linting rules, this also enforces the use of ES6 either via Node or transpilation (probably via Babel).
Purpose
- Provide strict eslint configuration
- Codification of consistency and best practices
- Increased stylistic consistency in JavaScript projects at Sky
- Less time spent debating stylistic issues in code reviews
- Perform error checking prior to execution
Contributing
For information on the process of contributing to this library, please read the contributing guide.
Getting started
1. Install:
To install eslint-config-sky
and all required peerDependencies at the correct versions:
npm info "@sky-uk/eslint-config-sky" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-exact --save-dev "@sky-uk/eslint-config-sky"
When installing or updating the version of eslint-config-sky
you should also make sure the versions of the other libraries are at a minimum the versions specific in the peer dependencies of this package.
You should always point to a specific version of eslint-config-sky
as referencing the latest will break your CI when new rules are introduced.
2. Create or extend your .eslintrc
:
{
"extends": ["@sky-uk/eslint-config-sky"],
"env": {
"browser": true/false,
"node": true/false
}
}
See here for more environment options.
3. NPM scripts
It is recommended to create npm scripts to run your linting through. To do so, add the following to the scripts object in your package.json
.
{
"scripts": {
"lint": "eslint .",
"format": "npm run lint -- --fix"
}
}
4. Automatically fix problems
You can use npm run format
to automatically fix most errors.
If, after running format you still find you have a lot of linting issues you can set those rules to warn
for the time being until you have time to work through them. You can do this by adding a rules section to your .eslintrc
.
{
"rules": {
"import/no-named-as-default": "warn"
}
}
5. Check linting in your CI
You can add the npm run lint
command to your CI to make sure that no linting problems are introduced.
Extensions
If you use a specific library, then you can install the extension for it in addition to the base Sky config.
If you do not use these, you will get peer dependency warnings on npm install
but they can be ignored.
react
Install:
npm install --save-dev eslint-plugin-react
Extend your .eslintrc
:
{
"extends": [
...
"@sky-uk/eslint-config-sky/react"
]
}
mocha
Install:
npm install --save-dev eslint-plugin-mocha
Extend your .eslintrc
:
{
"extends": [
...
"@sky-uk/eslint-config-sky/mocha"
]
}
Examples: