JavaScript - HealthTeacher/style-guide GitHub Wiki
Much of this was inspired by idiomatic-js. Please add to this guide if you find any particular patterns or styles that we've adopted internally.
Table of Contents
General
- We lint all our JavaScript with StandardJS.
Naming
- JavaScript hooks should follow the
js-myJsHook
pattern. - Testing hooks should follow the
qa-myTestHook
pattern. - Do NOT apply styles to
js-
orqa-
prefixed classes.
Marionette
- Label
View
s withclassName
exclusively, notid
. - Order view properties/methods as follows:
- View properties (alphabetically)
- Child view properties (alphabetically)
- Marionette methods (by lifecycle of the view)
- Custom methods (alphabetically)
React
- Use
static propTypes
andstatic defaultProps
at the top of React classes. (This does not work in the teacher app currently)
class MyComponent extends React.Component {
static propTypes = {
...
};
static defaultProps = {
...
};
render() {
...
}
}