JavaScript
Type with flow
Style with prettier (see section below)
Lint with eslint and use
eslint:recommended
at a minimumTest with jest and enzyme
2 spaces (instead of tabs)
Promises (not callbacks)
No decorators
No mobx
Place tests alongside the file(s) it tests (not in a separate directory)
End test files with
.test.js
React/Redux
Lint with
tslint-react
or eslint’splugin:react/recommended
at a minimum.No unnecessary and empty
<div>
’sIf
this.props.<variable name>
is used more than once, dereference it at the top ofrender
.Extract variables used in
render()
to the top ofrender()
API calls should lie in a testable file outside of components.
Components should not wait for promises to resolve, instead listen on props via redux’
mapStateToProps()
.Declare and export components in separate places (otherwise the web inspector cannot name components properly)
Flowtype
Any types used in more than one file should be placed in
src/types.js
Add flow linting via eslint-plugin-flowtype
Disallow “
any
” with eslint no-weak-types (use “Obect
” and “Function
” to cover complicated use-cases)In components which use
mapStateToProps
, separateOwnProps
fromConnectedProps
into separate types. Join them withtype Props = OwnProps & ConnectedProps
. In addition, if usingmapDispatchToProps
, create a typeDispatchProps
and join that withProps
.
𝓣𝓢 TypeScript 𝓣𝓢
Lint with
tslint:recommended
at a minimum.No implicit any (type everything that’s not inferable)
Any variable declared without an initial value should be typed
Prettier
Add the following to package.json
:
"prettier": {
"overrides": [
{
"files": ["*.js", "*.scss", "*.css", "*.pcss"],
"options": {
"singleQuote": true,
"trailingComma": "all"
}
}
]
}
The following information about prettier is better described on the prettier documentation here. Use lint-staged
to auto-call prettier in a precommit
“script
”:
"lint-staged": {
"src/**/*.scss": ["prettier --parser scss --write", "git add"],
"src/**/*.{js,css}": ["prettier --parser flow --write", "git add"],
"nightwatch/**/*.js": ["prettier --write", "git add"]
}
Npm
- Support the following
script
’s in your rootpackage.json
:
“watch”
: Starts the dev server“build”
: Builds static assets (if they exist) “/src
” -> “/build
”“test”
: Runs all tests (linting first, then unit tests)