wallet-core/style.txt

48 lines
1.7 KiB
Plaintext
Raw Normal View History

2016-01-04 14:36:26 +01:00
TypeScript style
2015-12-13 18:11:34 +01:00
================
Basics:
- Indent with 2 spaces.
- Keep a maximum line length of 120 characters.
2016-01-04 14:36:26 +01:00
- Prefer "double quotes" for strings.
2015-12-13 18:11:34 +01:00
- Never omit optional semicolons.
- Do not put opening braces or brackets on a new line.
- Call functions without spaces: foo(bar)
- Use 'let' instead of 'var' whenever possible.
- Declare "use strict;".
- Use rocket (=>) syntax for anonymous functions. If an anonymous function is
too long, make it a named function.
2016-01-04 14:36:26 +01:00
- Use the strict equality operator (===).
2015-12-13 18:11:34 +01:00
- Document functions with JSDoc comments (http://usejsdoc.org).
2016-01-04 14:36:26 +01:00
JavaScript version:
2016-01-06 15:10:47 +01:00
Stick to ES6 features. Do not rely on any vendor-specific extensions (such as
Firefox often offers). ES6 features not yet supported by major browsers are
2016-01-04 14:36:26 +01:00
okay as long as there is a well-supported and reasonable polyfill (such as
babel) available.
2015-12-13 18:11:34 +01:00
Names:
- Use PascalCase for classes/types, camelCase for variables, functions and
properties, UPPER_SNAKE_CASE for constants, kebab-case for event names.
2016-01-04 14:36:26 +01:00
- Only capitalize the first letter of an acronym in identifiers (e.g. HttpResponseCode).
2015-12-13 18:11:34 +01:00
APIs:
- Prefer 'Promise' to one-shot continuations whenever possible.
2016-01-04 14:38:23 +01:00
- Prefer handlebars templates to poking around in the DOM.
2016-01-06 15:10:47 +01:00
Dependency Injection (DI):
DI is a useful pattern when components need to be replaced by mocks or have
multiple co-existing implementations. But DI also makes code overly generic,
bureaucratic and less readble. Only use DI if there is a definite need for it,
do not use it by default. Inject individual dependencies via class
constructors and avoid service locators.
2016-01-04 14:38:23 +01:00
Misc:
- Do not use ES6 template strings for constructing HTML,
use TSX/JSX literals instead.