Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Code Conventions

Oscar S edited this page Apr 8, 2019 · 3 revisions

Code Conventions

This document covers the code conventions that should be observed when making changes to the VisualGit codebase.

If there is any doubt as to whether code is conformant with the conventions, you should run the linter to check. The use of the linter is documented in Section 2.1.6.

  1. To ensure the readability of the code, lines should be under 140 characters.
  2. Semicolons should be used at the end of lines. While JavaScript allows the omission of semicolons (via 'automatic semicolon insertion'), it can cause bugs.
  3. Open braces should be on the same line as the expression that precedes them, like:
if (x) {
  //...
}

and not:

if (x)
{
  //...
}

This rule is to ensure stylistic consistency.

  1. Indentation should be using 2 spaces.
  2. Strings should be single-quoted, like: let x = "hello, world!";
  3. Use of the new operator should use parens like: new Car() to maintain stylistic consistency with function calls.
  4. Bitwise operators should not be used. Mostly, the use of these operators is a mistake, e.g. if (x & y), or is a symptom of overly-clever, unmaintainable code.
  5. Assignment in conditionals like if (x = y) is not allowed. This is because usually this is not what programmers intend to write, and is the source of bugs.
  6. for (... of ...) loops are preferred.