-
Notifications
You must be signed in to change notification settings - Fork 0
Coding Guidelines
Matias Pierobon edited this page Aug 3, 2017
·
4 revisions
- Use camelCase for function names
- Use PascalCase for classes names.
- Use camelCase for property names and local variables.
- Do not use "_" as a prefix for private properties.
- Use whole words in names when possible.
- 1 file per logical component
- 1 Index file per component folder exporting the module
- Use stateless-function components over class components.
- Use null. Do not use undefined.
- Consider objects like Nodes, Symbols, etc. as immutable outside the component that created them. Do not change them.
- Consider arrays as immutable by default after creation.
- Use single quotes for strings.
- Use double quotes for imports.
- Use arrow functions over anonymous function expressions.
- Only surround arrow function parameters when necessary.
For example,(x) => x + xis wrong but the following are correct:
x => x + x(x,y) => x + y
- Always surround loop and conditional bodies with curly braces.
- 2 spaces – for indentation
- Single quotes for strings – except to avoid escaping
- No unused variables – this one catches tons of bugs!
- No semicolons
- Never start a line with (, [, or `
- Space after keywords
if (condition) { ... } - Always use === instead of == – but obj == null is allowed to check null || undefined.
- Always surround loop and conditional bodies with curly braces. Statements on the same line are allowed to omit braces.
- Open curly braces always go on the same line as whatever necessitates them.
- Parenthesized constructs should have no surrounding whitespace.
A single space follows commas, colons, and semicolons in those constructs. For example:
for (var i = 0, n = str.length; i < 10; i++) { }if (x < 10) { }
- Use a single declaration per variable statement
- Use
constwhenever possible. - Use
letinstead ofvar -
elsegoes on the same line from the closing curly brace.