Linters are great ways to keep your team on the same page.
This document will walk through how to setup eslint to check your project using the following linting libraries:
- standard
- promise
- fp
- funfp
Standard supplies basic JavaScript standard rules, promise focuses on promise linting rules, fp focuses on core functional programming techniques, and funfp is more opinionated to focus on restricting patterns that can cause errors if null or undefined exist.
npm install eslint eslint-plugin-standard eslint-config-standard eslint-plugin-promise eslint-plugin-fp eslint-plugin-funfp -D
module.exports = {
"extends": [
"standard",
"plugin:fp/recommended",
"plugin:funfp/recommended"
],
"rules": {
"fp/no-nil": "off",
"fp/no-mutation": ["error", {
"commonjs": true,
"allowThis": true,
"exceptions": [
{"object": "foo", "property": "bar"}
]
}],
"promise/always-return": "error",
"promise/no-return-wrap": "error",
"promise/param-names": "error",
"promise/catch-or-return": "error",
"promise/no-native": "off",
"promise/no-nesting": "warn",
"promise/no-promise-in-callback": "warn",
"promise/no-callback-in-promise": "warn",
"promise/avoid-new": "warn"
},
"plugins": [
"standard",
"promise",
"fp",
"funfp"
]
}
These are the rules I have enabled for my project, but you can turn on/off any rules you like.
"lint": "eslint [files]"
You can use file paths like src/**/*.js
"test": "npm run lint & faucet src/**/**/*test.js"
try https://www.npmjs.com/package/pre-push
Linting can be a great constraint to guide your team to a common path, don't be afraid to adjust the rules as they best work for your team.
// eslint-disable-next-line [rule name optional]
or
dosomething() // eslint-disable-line [rule name optional]