Skip to content

Coding Guidelines

Matias Pierobon edited this page Aug 3, 2017 · 4 revisions

Names

  1. Use camelCase for function names
  2. Use PascalCase for classes names.
  3. Use camelCase for property names and local variables.
  4. Do not use "_" as a prefix for private properties.
  5. Use whole words in names when possible.

Components

  1. 1 file per logical component
  2. 1 Index file per component folder exporting the module
  3. Use stateless-function components over class components.

null and undefined

  1. Use null. Do not use undefined.

General Assumptions

  1. Consider objects like Nodes, Symbols, etc. as immutable outside the component that created them. Do not change them.
  2. Consider arrays as immutable by default after creation.

Strings

  1. Use single quotes for strings.
  2. Use double quotes for imports.

Style

  1. Use arrow functions over anonymous function expressions.
  2. Only surround arrow function parameters when necessary.
    For example, (x) => x + x is wrong but the following are correct:
  • x => x + x
  • (x,y) => x + y
  1. Always surround loop and conditional bodies with curly braces.
  2. 2 spaces – for indentation
  3. Single quotes for strings – except to avoid escaping
  4. No unused variables – this one catches tons of bugs!
  5. No semicolons
  6. Never start a line with (, [, or `
  7. Space after keywords if (condition) { ... }
  8. Always use === instead of == – but obj == null is allowed to check null || undefined.
  9. Always surround loop and conditional bodies with curly braces. Statements on the same line are allowed to omit braces.
  10. Open curly braces always go on the same line as whatever necessitates them.
  11. 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) { }
  1. Use a single declaration per variable statement
  2. Use const whenever possible.
  3. Use let instead of var
  4. else goes on the same line from the closing curly brace.

Clone this wiki locally