Skip to content

Latest commit

 

History

History
137 lines (102 loc) · 3.22 KB

formatting.md

File metadata and controls

137 lines (102 loc) · 3.22 KB

Formatting Guidelines

Just some guidelines to standardize the look of the code.

Language Specifics

Since it's available throught babel use ECMAScript 6 whenever is possible (if you don't know ECMAScript 6 a good starting point to learn is in the babel documentation), expecially try not to use var, define your variables with:

  const name = value;
  let name = value;

Note

  • We highly recommended the use of const as the default method to define variables. Use let only if it's really necessary.

Line width

Try not to exceed 80 character per line. This guideline is amended inside your test code for the description in describe() and it().

Spaces

  • if () {}: add a space after the if keyword before ()

  • functionCall(): no space after functionCall

  • { attribute }: add spaces before and after the attribute.

New Lines

  • multi-line if: add a new line after the opening {. Example:

    ```javascript
      if (true === true &&
        false === false) {
    
        // code here
      }
    ```
    
  • varable declaration: Always add a new line after a variable declaration. Example:

      const variable;
    
      // code here

Indentation

  • default indentation: we use two spaces as the default indentation.

  • multi-line function input: if you have multiple input for a function and the line width exceeds 80 characters, you can brake them in new lines.

    Use this type of indentation:

      function name(
        input1,
        input2,
        input3,
        input4
      ) {
        // correct input style
      }

    Don't use:

      function name(
                    input1,
                    input2,
                    input3,
                    input4
                  ) {
        // wrong input style
      }

Brace Style

The preferred brace style is Stroustrup in which the else statements in an if-else construct must be on its own line after the preceding closing brace, as in this example:

  if (foo) {
    bar();
  }
  else {
    baz();
  }

Lint & Flow

Due to the addition of Flowtype support to the code some formatting guidelines changed and some of the default linting of the code has been soften:

  • operator-linebreak: is not an error since you are encouraged to respect the 80 characters limit, to do so in some cases you will need to break the operator in a new line (this is similar to OCaml code fromatting):

    export const isRTL: (str: string) => boolean
      = (str) => DIRECTION_CHECK_RE.test(str);
  • no-multi-spaces: similar to the other rule this will not return an error since at some point you will need to add additional spaces for alignment purposes.