Skip to content

Coding standards

Matt Acosta edited this page Nov 24, 2017 · 4 revisions

Coding standards

Whitespace

Files

  • Use an indent of 2 spaces.
  • Lines should not have trailing whitespace.
  • Text files should end in a single new line.

Comments

  • Multi-line documentation comments should have a single leading new line.

Operators

  • There should be a single space before and after binary operators.
  • There should not be any whitespace between a unary operator and its operand.

Statements

  • Control structures should have a single space between the keyword and ( or {.
  • Function calls should not have whitespace between:
    • The identifier and (.
    • The ( and the first parameter.
    • The last parameter and ).
    • The ) and ;.
  • Array declarations should not have whitespace between the [ and first element, or last element and ], unless the line exceeds 80 characters, in which case each element should be placed on its own line and indented one level.

Strings

Single-quoted strings should be used by default.

Semicolons

All statements must end in a semicolon.

Variables

All variable declarations must use let or const.

Naming conventions

Functions and variables

  • Should use lowerCamelCase.

Class and interface declarations

  • Should use UpperCamelCase.
  • Interfaces should start with I.
  • Test classes should end with Test.
  • Only the first letter of acronyms should be uppercase.

Class and interface members

  • Methods should use lowerCamelCase.
  • Properties should use lowerCamelCase.
    • If a getter or setter exists with the same name as a protected or private property, the property may start with a _.

Member visibility

  • All class members except constructors must include a visibility modifier.
Clone this wiki locally