Coding Standards

Introduction

Javascript/Typescript is a very flexible language. This flexibility can be a blessing and a curse. It can be hard to enforce a coding standard that is both flexible and consistent. This document is an attempt to define a coding standard that is flexible enough to allow for different coding styles, but also consistent enough to allow for easy code reviews and code sharing.

General code styling rules

Most rules should be enforced by your IDE and the linters.

If you are using VSCode, you can use the Prettier extension to automatically format your code on save. For the rest of the rules, you can use the ESLint extension to automatically fix them on save.

  • Indentation: This project uses 2 spaces for indentation
  • Semicolons: This project uses semicolons ;
  • Quotes: This project uses single quotes ''
  • Trailing commas: This project uses trailing commas ,
  • New line usage:
    • At end-of-file: This project uses new line end-of-file
    • Between logical blocks: This project uses new line between logical blocks
    • Before return statements: This project uses new line before return
  • Naming:
    • Use english for all programming
    • Variables:
      1. Use camelCase
      2. Use descriptive names (e.g. const numberOfItems = 5;)
      3. Use plural for arrays
      4. Don’t use abbreviations or special characters
    • Functions:
      1. Use camelCase
      2. Use meaningful names/phrases (e.g. const getSomethingFromSomewhere = () => {...};)
      3. Use verbs for functions
      4. Don’t use abbreviations or special characters
    • Class names and test IDs:
      1. Where applicable use the BEM naming convention (block__element--modifier)

Full list of linters, their plugins: