-
Notifications
You must be signed in to change notification settings - Fork 50
FlowCrypt TypeScript Style Guide
The following style guide is current as of January 2019.
-
Do not in any way modify standard JS constructors such as
Array
,Object
, etc unless you are very sure and have discussed this with @tomholub -
Shims are OK but generally discouraged, except when there is potential to use the benefits throughout the app
-
When introducing new libraries, please notify & discuss with @tomholub. In particular, clear licensing is very important (MIT, Apache, BSD preferred). Please take care to find a small library with few dependencies. As a company, we are required to inform some of our customers every time we add a 3rd party library, so this cannot be taken lightly. Once a library has been selected, it should be included in
lib/
as a single, UNminified file, and checked into the repo. Our repo follows a batteries-included approach when it comes to 3rd party code that we distribute with our own code. -
All imports should be done using ES6
import
statement, except when not possible (some 3rd party libraries, in which case a html<script>
tag will be used on appropriate htm pages). -
we use
.htm
instead of.html
-
We do not use functions for looping. In particular, we never ever use
.each
nor$.each()
. Why? Because it's hard toreturn
from inside.each
. Since.each
can't be used in all cases, and consistency matters, we never use.each
.
const arr = ['a', 'b', 'c'];
const obj = { bar: 1, baz: 2 };
- arr.each((x, i) => doSomething(x, 'whatnot'));
+ for(const x of arr) { // iterate over array values using OF keyword
+ doSomething(x, 'whatnot');
+ }
- arr.each((x, i) => doSomething(i, 'whatnot'));
+ for(const i in arr) { // iterate over array indexes using IN keyword
+ doSomething(i, 'whatnot');
+ }
- $.each(obj)
- We turn on tscode auto-format on each save. We make sure
tslint
is set up and functioning in our IDE.