-
Notifications
You must be signed in to change notification settings - Fork 1
Project Style Guide
| Version | Date | Description | Responsable |
|---|---|---|---|
| 0.1 | 22/03/2017 | Document creation and adaptation | Luiz Guilherme |
| 0.2 | 22/03/2017 | Adding React Topics | Gustavo Braz |
-
This is an adapted guide based on the coding standard used by Airbnb and Google Style Guide. It's utilization was adapted for utilization in the project found here. This guide can be used openly, even if is this version, an adaptation of the project cited above.
-
The reading and consult of this guide can be somewhat confusing for users that are not acquainted with Java, Javascript, ReactJS, JSX and HTML/CSS. It is recommended that you study them before utilizing this guide.
-
It's also recommended the utilization of the Eclipse IDE for Java development during the process of development and for ReactJS development it's recommended a text editor like Atom, Sublime or Webstorm because it is more intuitive, easy to use and well documented. As a web browser, we recommend Google Chrome.
-
If you have any doubts in relation of a code pattern, utilize the search function from your browser(CTRL+F on Google Chrome) before start coding!
-
Alterations can be made without previous warning.
- Only include one React component per file.
- However, multiple Stateless, or Pure, Components are allowed per file. eslint: react/no-multi-comp.
- Always use JSX syntax.
- Do not use React.createElement unless you're initializing the app from a file that is not JSX.
- Do not use displayName for naming components. Instead, name the component by reference.
// bad
export default React.createClass({
displayName: 'ReservationCard',
// stuff goes here
});
// good
export default class ReservationCard extends React.Component {
}- Ordering for class extends React.Component:
- optional static methods
- constructor
- getChildContext
- componentWillMount
- componentDidMount
- componentWillReceiveProps
- shouldComponentUpdate
- componentWillUpdate
- componentDidUpdate
- componentWillUnmount
- clickHandlers or eventHandlers like onClickSubmit() or onChangeDescription()
- getter methods for render like getSelectReason() or getFooterContent()
- optional render methods like renderNavigation() or renderProfilePicture()
- render
- How to define propTypes, defaultProps, contextTypes, etc...
import React, { PropTypes } from 'react';
const propTypes = {
id: PropTypes.number.isRequired,
url: PropTypes.string.isRequired,
text: PropTypes.string,
};
const defaultProps = {
text: 'Hello World',
};
class Link extends React.Component {
static methodsAreOk() {
return true;
}
render() {
return <a href={this.props.url} data-id={this.props.id}>{this.props.text}</a>
}
}
Link.propTypes = propTypes;
Link.defaultProps = defaultProps;
export default Link;- Ordering for React.createClass: eslint: react/sort-comp :
- displayName
- propTypes
- contextTypes
- childContextTypes
- mixins
- statics
- defaultProps
- getDefaultProps
- getInitialState
- getChildContext
- componentWillMount
- componentDidMount
- componentWillReceiveProps
- shouldComponentUpdate
- componentWillUpdate
- componentDidUpdate
- componentWillUnmount
- clickHandlers or eventHandlers like onClickSubmit() or onChangeDescription()
- getter methods for render like getSelectReason() or getFooterContent()
- optional render methods like renderNavigation() or renderProfilePicture()
- render
- Always use camelCase for prop names.
// bad
<Foo
UserName="hello"
phone_number={12345678}
/>
// good
<Foo
userName="hello"
phoneNumber={12345678}
/>- Omit the value of the prop when it is explicitly true. eslint: react/jsx-boolean-value
// bad
<Foo
hidden={true}
/>
// good
<Foo
hidden
/>- Always include an alt prop on
tags. If the image is presentational, alt can be an empty string or the
must have role="presentation". eslint: jsx-a11y/img-has-alt
// bad
<img src="hello.jpg" />
// good
<img src="hello.jpg" alt="Me waving hello" />
// good
<img src="hello.jpg" alt="" />
// good
<img src="hello.jpg" role="presentation" />- Do not use words like "image", "photo", or "picture" in
alt props. eslint: jsx-a11y/img-redundant-alt
Why? Screenreaders already announce img elements as images, so there is no need to include this information in the alt text.
// bad
<img src="hello.jpg" alt="Picture of me waving hello" />
// good
<img src="hello.jpg" alt="Me waving hello" />- Use only valid, non-abstract ARIA roles. eslint: jsx-a11y/aria-role
// bad - not an ARIA role
<div role="datepicker" />
// bad - abstract ARIA role
<div role="range" />
// good
<div role="button" />- Do not use accessKey on elements. eslint: jsx-a11y/no-access-key
Why? Inconsistencies between keyboard shortcuts and keyboard commands used by people using screenreaders and keyboards complicate accessibility.
// bad
<div accessKey="h" />
// good
<div />- Avoid using an array index as key prop, prefer a unique ID. (why?)
// bad
{todos.map((todo, index) =>
<Todo
{...todo}
key={index}
/>
)}
// good
{todos.map(todo => (
<Todo
{...todo}
key={todo.id}
/>
))}- Always define explicit defaultProps for all non-required props.
Why? propTypes are a form of documentation, and providing defaultProps means the reader of your code doesn’t have to assume as much. In addition, it can mean that your code can omit certain type checks.
// bad
function SFC({ foo, bar, children }) {
return <div>{foo}{bar}{children}</div>;
}
SFC.propTypes = {
foo: PropTypes.number.isRequired,
bar: PropTypes.string,
children: PropTypes.node,
};
// good
function SFC({ foo, bar }) {
return <div>{foo}{bar}</div>;
}
SFC.propTypes = {
foo: PropTypes.number.isRequired,
bar: PropTypes.string,
children: PropTypes.node,
};
SFC.defaultProps = {
bar: '',
children: null,
};- Always use ref callbacks. eslint: react/no-string-refs
// bad
<Foo
ref="myRef"
/>
// good
<Foo
ref={(ref) => { this.myRef = ref; }}
/>- Management Plan
- Requirements Management Plan
- Non Functional Requirements
- Entity Relationship Model
- Risk Plan
- Chronogram
- Costs
- Scenarios and Lexicons
-
C1UC3 - Maintain Clinical Record
