taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

style.txt (1801B)


      1 TypeScript style
      2 ================
      3 
      4 Basics:
      5 - Indent with 2 spaces.
      6 - Keep a maximum line length of 120 characters.
      7 - Prefer "double quotes" for strings.
      8 - Never omit optional semicolons.
      9 - Do not put opening braces or brackets on a new line.
     10 - Call functions without spaces: foo(bar)
     11 - Use 'let' instead of 'var' whenever possible.
     12 - Declare "use strict;".
     13 - Use rocket (=>) syntax for anonymous functions.  If an anonymous function is
     14   too long, make it a named function.
     15 - Use the strict equality operator (===).
     16 - Document functions with JSDoc comments (http://usejsdoc.org).
     17 
     18 
     19 JavaScript version:
     20 Stick to ES6 features.  Do not rely on any vendor-specific extensions (such as
     21 Firefox often offers).  ES6 features not yet supported by major browsers are
     22 okay as long as there is a well-supported and reasonable polyfill (such as
     23 babel) available.
     24 
     25 
     26 Names:
     27 - Use PascalCase for classes/types, camelCase for variables, functions and
     28   properties, UPPER_SNAKE_CASE for constants, kebab-case for event names.
     29 - Only capitalize the first letter of an acronym in identifiers (e.g. HttpResponseCode).
     30 
     31 
     32 APIs:
     33 - Prefer 'Promise' to one-shot continuations whenever possible.
     34 - Prefer handlebars templates to poking around in the DOM.
     35 
     36 
     37 Dependency Injection (DI):
     38 DI is a useful pattern when components need to be replaced by mocks or have
     39 multiple co-existing implementations.  But DI also makes code overly generic,
     40 bureaucratic and less readable.  Only use DI if there is a definite need for it,
     41 do not use it by default.  Inject individual dependencies via class
     42 constructors and avoid service locators.
     43 
     44 
     45 Misc:
     46 - Do not use ES6 template strings for constructing HTML,
     47   use TSX/JSX literals instead.
     48 - For everything not covered here, stick to this style guide:
     49   https://github.com/airbnb/javascript.