@financial-times/eslint-config-reliability-engineering
v6.2.7
Published
Shared eslint config for reliability-engineering projects
Downloads
53
Maintainers
Keywords
Readme
eslint-config-reliability-engineering
This is an ESLint configuration which aims to ensure all reliability-engineering applications' source code is consistent in style.
This config extends airbnbs base config along with extra rules provided by eslint-plugin-unicorn, and language/framework specific config
Usage
Install this package together with your application:
npm install --save-dev @financial-times/eslint-config-reliability-engineering
It's recommended to avoid global installs where possible, as eslint in particular can be volatile with dependency locations.
Extend the config using an eslint config file. For example in an .eslintrc.js
file:
// .eslintrc.js
const config = require('@financial-times/reliability-engineering')({
prettier: true, // use prettier, defaults to true
esModules: true, // use esModules, defaults to false
});
module.exports = Object.assign({}, config, {
rules: Object.assign({}, config.rules, {
// Override any settings from the "parent" extended configuration
}),
});
This root export detects your dependencies from package.json
and loads the relevant eslint
configs that follow in this list, including prettier.
This is configured using JS to allow for options to be passed in (prettier/esModules) for hard to detect features - esModules can vary per file, and prettier is often installed as a subdependency rather than a direct dependency.
The following configs are also exposed, which allow more granular configuration depending on your choice of tooling, these can be consumed using the standard eslint extends
syntax:
// .eslintrc.js
module.exports = {
extends: ['@financial-times/reliability-engineering/base'],
rules: {
// override any rules
},
};
@financial-times/reliability-engineering/base
- base (non-react) configuration. Extends the main airbnb rules@financial-times/reliability-engineering/cypress
- cypress configuration@financial-times/reliability-engineering/mocha
- mocha configuration@financial-times/reliability-engineering/jest
- jest configuration. Also readspackage.json
to determine whether to override file extension rules@financial-times/reliability-engineering/react
- react configuration. Extends the main airbnb rules@financial-times/reliability-engineering/prettier
- enables formatting with prettier
Dependencies
This package requires certain dependencies as peerDependencies
. This is a decision consistent with eslint (see https://github.com/eslint/eslint/issues/2518, https://github.com/eslint/eslint/issues/3458). There is an RFC to address this and allow a package to ship its dependencies: https://github.com/eslint/rfcs/pull/5. This means they should be installed wherever this package is consumed, with matching version ranges:
- eslint
- eslint-plugin-import
- eslint-plugin-mocha (only required when using mocha config)
- eslint-plugin-cypress (only required when using cypress config)
- eslint-plugin-jest (only required when using jest config)
- eslint-plugin-react (only required when using react config, can otherwise be ignored)
- eslint-plugin-react-hooks (only required when using react config, can otherwise be ignored)
- eslint-plugin-jsx-a11y (only required when using react config, can otherwise be ignored)
- eslint-plugin-prettier (only required when using prettier config)
- eslint-config-prettier (only required when using prettier config)
It's possible to automatically install these by adapting the steps from eslint-config-airbnb-base, e.g. for Linux/OSX:
(
export PKG=@financial-times/eslint-config-reliability-engineering;
npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
)