// Do
const units = 'μs';
// Don't
const units = '\\u03bcs'; // Greek letter mu, 's'
// Do
const output = '\\ufeff' + content; // byte order mark
// Don't (no idea what this is)
const output = '\\ufeff' + content;
Avoid using default
exports, as they allow inconsistent naming during import.
// Do
export class Foo {...}
// Or
class Foo {...}
export { Foo };
// Don't
export default class Foo {...}
Empty blocks,
// Do
function doNothing() {}
// Don't
function doNothing() {
// ...
}
Where to break line → a higher syntactic level,
// Do
const currentEstimate =
calc(currentEstimate + x * currentEstimate) /
2.0;
// Don't
const currentEstimate = calc(currentEstimate + x *
currentEstimate) / 2.0;
Horizontal alignment: discouraged.
// Do
{
tiny: 42, // this is great
longer: 435, // this too
};
// Don't
{
tiny: 42, // permitted, but future edits
longer: 435, // may leave it unaligned
};
Using markdown,
// Do
/**
* Computes weight based on three factors:
*
* - items sent
* - items received
* - last timestamp
*/