Skip to content

Commit b0d7be0

Browse files
committed
Fix markdownlint formatting issues.
Added few missing references.
1 parent b8a7539 commit b0d7be0

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

README.md

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function getUser(): User;
118118

119119
### Use searchable names
120120

121-
We will read more code than we will ever write. It's important that the code we do write is readable and searchable. By not naming variables that end up being meaningful for understanding our program, we hurt our readers. Make your names searchable. Tools like [TSLint](https://palantir.github.io/tslint/rules/no-magic-numbers/) can help identify unnamed constants.
121+
We will read more code than we will ever write. It's important that the code we do write is readable and searchable. By *not* naming variables that end up being meaningful for understanding our program, we hurt our readers. Make your names searchable. Tools like [TSLint](https://palantir.github.io/tslint/rules/no-magic-numbers/) can help identify unnamed constants.
122122

123123
**Bad:**
124124

@@ -658,11 +658,11 @@ console.log(name);
658658

659659
### Avoid Side Effects (part 2)
660660

661-
In JavaScript, primitives are passed by value and objects/arrays are passed by reference. In the case of objects and arrays, if your function makes a change in a shopping cart array, for example, by adding an item to purchase, then any other function that uses that cart array will be affected by this addition. That may be great, however it can be bad too. Let's imagine a bad situation:
661+
In JavaScript, primitives are passed by value and objects/arrays are passed by reference. In the case of objects and arrays, if your function makes a change in a shopping cart array, for example, by adding an item to purchase, then any other function that uses that `cart` array will be affected by this addition. That may be great, however it can be bad too. Let's imagine a bad situation:
662662

663-
The user clicks the "Purchase", button which calls a purchase function that spawns a network request and sends the cart array to the server. Because of a bad network connection, the purchase function has to keep retrying the request. Now, what if in the meantime the user accidentally clicks "Add to Cart" button on an item they don't actually want before the network request begins? If that happens and the network request begins, then that purchase function will send the accidentally added item because it has a reference to a shopping cart array that the *addItemToCart* function modified by adding an unwanted item.
663+
The user clicks the "Purchase", button which calls a `purchase` function that spawns a network request and sends the `cart` array to the server. Because of a bad network connection, the purchase function has to keep retrying the request. Now, what if in the meantime the user accidentally clicks "Add to Cart" button on an item they don't actually want before the network request begins? If that happens and the network request begins, then that purchase function will send the accidentally added item because it has a reference to a shopping cart array that the `addItemToCart` function modified by adding an unwanted item.
664664

665-
A great solution would be for the *addItemToCart* to always clone the cart, edit it, and return the clone. This ensures that no other functions that are holding onto a reference of the shopping cart will be affected by any changes.
665+
A great solution would be for the `addItemToCart` to always clone the `cart`, edit it, and return the clone. This ensures that no other functions that are holding onto a reference of the shopping cart will be affected by any changes.
666666

667667
Two caveats to mention to this approach:
668668

@@ -690,7 +690,7 @@ function addItemToCart(cart: CartItem[], item: Item): CartItem[] {
690690

691691
### Don't write to global functions
692692

693-
Polluting globals is a bad practice in JavaScript because you could clash with another library and the user of your API would be none-the-wiser until they get an exception in production. Let's think about an example: what if you wanted to extend JavaScript's native Array method to have a diff method that could show the difference between two arrays? You could write your new function to the `Array.prototype`, but it could clash with another library that tried to do the same thing. What if that other library was just using `diff` to find the difference between the first and last elements of an array? This is why it would be much better to just use classes and simply extend the `Array` global.
693+
Polluting globals is a bad practice in JavaScript because you could clash with another library and the user of your API would be none-the-wiser until they get an exception in production. Let's think about an example: what if you wanted to extend JavaScript's native Array method to have a `diff` method that could show the difference between two arrays? You could write your new function to the `Array.prototype`, but it could clash with another library that tried to do the same thing. What if that other library was just using `diff` to find the difference between the first and last elements of an array? This is why it would be much better to just use classes and simply extend the `Array` global.
694694

695695
**Bad:**
696696

@@ -985,6 +985,7 @@ inventoryTracker('apples', req, 'www.inventory-awesome.io');
985985

986986
Use generators and iterables when working with collections of data used like a stream.
987987
There are some good reasons:
988+
988989
- decouples the callee from the generator implementation in a sense that callee decides how many
989990
items to access
990991
- lazy execution, items are streamed on demand
@@ -998,7 +999,7 @@ function fibonacci(n: number): number[] {
998999
if (n === 1) return [0];
9991000
if (n === 2) return [0, 1];
10001001

1001-
const items: number[] = [0, 1];
1002+
const items: number[] = [0, 1];
10021003
while (items.length < n) {
10031004
items.push(items[items.length - 2] + items[items.length - 1]);
10041005
}
@@ -1021,7 +1022,7 @@ print(10);
10211022
// The generator doesn't keep the array of all numbers.
10221023
function* fibonacci(): IterableIterator<number> {
10231024
let [a, b] = [0, 1];
1024-
1025+
10251026
while (true) {
10261027
yield a;
10271028
[a, b] = [b, a + b];
@@ -1040,9 +1041,9 @@ function print(n: number) {
10401041
print(10);
10411042
```
10421043

1043-
There are libraries that allow working with iterables in a simillar way as with native arrays, by
1044+
There are libraries that allow working with iterables in a similar way as with native arrays, by
10441045
chaining methods like `map`, `slice`, `forEach` etc. See [itiriri](https://www.npmjs.com/package/itiriri) for
1045-
an example of advanced manipulation with iterables (or [itiriri-async](https://www.npmjs.com/package/itiriri-async) for manipulation of async iterables).
1046+
an example of advanced manipulation with iterables (or [itiriri-async](https://www.npmjs.com/package/itiriri-async) for manipulation of async iterables).
10461047

10471048
```ts
10481049
import itiriri from 'itiriri';
@@ -1071,11 +1072,11 @@ TypeScript supports getter/setter syntax.
10711072
Using getters and setters to access data from objects that encapsulate behavior could be better that simply looking for a property on an object.
10721073
"Why?" you might ask. Well, here's a list of reasons:
10731074

1074-
* When you want to do more beyond getting an object property, you don't have to look up and change every accessor in your codebase.
1075-
* Makes adding validation simple when doing a *set*.
1076-
* Encapsulates the internal representation.
1077-
* Easy to add logging and error handling when getting and setting.
1078-
* You can lazy load your object's properties, let's say getting it from a server.
1075+
- When you want to do more beyond getting an object property, you don't have to look up and change every accessor in your codebase.
1076+
- Makes adding validation simple when doing a `set`.
1077+
- Encapsulates the internal representation.
1078+
- Easy to add logging and error handling when getting and setting.
1079+
- You can lazy load your object's properties, let's say getting it from a server.
10791080

10801081
**Bad:**
10811082

@@ -1086,9 +1087,9 @@ type BankAccount = {
10861087
}
10871088

10881089
const value = 100;
1089-
const account: BankAccount = {
1090+
const account: BankAccount = {
10901091
balance: 0,
1091-
// ...
1092+
// ...
10921093
};
10931094

10941095
if (value < 0) {
@@ -1121,8 +1122,8 @@ class BankAccount {
11211122

11221123
// Now `BankAccount` encapsulates the validation logic.
11231124
// If one day the specifications change, and we need extra validation rule,
1124-
// we would have to alter only the `setter` implementation,
1125-
// leaving all dependent code unchanged.
1125+
// we would have to alter only the `setter` implementation,
1126+
// leaving all dependent code unchanged.
11261127
const account = new BankAccount();
11271128
account.balance = 100;
11281129
```
@@ -1440,7 +1441,7 @@ class Employee {
14401441

14411442
class EmployeeTaxData {
14421443
constructor(
1443-
public readonly ssn: string,
1444+
public readonly ssn: string,
14441445
public readonly salary: number) {
14451446
}
14461447

@@ -1979,9 +1980,9 @@ await report = await reader.read('report.json');
19791980

19801981
Testing is more important than shipping. If you have no tests or an inadequate amount, then every time you ship code you won't be sure that you didn't break anything.
19811982
Deciding on what constitutes an adequate amount is up to your team, but having 100% coverage (all statements and branches)
1982-
is how you achieve very high confidence and developer peace of mind. This means that in addition to having a great testing framework, you also need to use a good coverage tool.
1983+
is how you achieve very high confidence and developer peace of mind. This means that in addition to having a great testing framework, you also need to use a good [coverage tool](https://github.com/gotwarlost/istanbul).
19831984

1984-
There's no excuse to not write tests. There are plenty of good JS test frameworks with typings support for TypeScript, so find one that your team prefers. When you find one that works for your team, then aim to always write tests for every new feature/module you introduce. If your preferred method is Test Driven Development (TDD), that is great, but the main point is to just make sure you are reaching your coverage goals before launching any feature, or refactoring an existing one.
1985+
There's no excuse to not write tests. There are [plenty of good JS test frameworks](http://jstherightway.org/#testing-tools) with typings support for TypeScript, so find one that your team prefers. When you find one that works for your team, then aim to always write tests for every new feature/module you introduce. If your preferred method is Test Driven Development (TDD), that is great, but the main point is to just make sure you are reaching your coverage goals before launching any feature, or refactoring an existing one.
19851986

19861987
### The three laws of TDD
19871988

@@ -1997,15 +1998,15 @@ There's no excuse to not write tests. There are plenty of good JS test framework
19971998

19981999
Clean tests should follow the rules:
19992000

2000-
* **Fast** tests should be fast because we want to run them frequently.
2001+
- **Fast** tests should be fast because we want to run them frequently.
20012002

2002-
* **Independent** tests should not depend on each other. They should provide same output whether run independently or all together in any order.
2003+
- **Independent** tests should not depend on each other. They should provide same output whether run independently or all together in any order.
20032004

2004-
* **Repeatable** tests should be repeatable in any environment and there should be no excuse for why they fail.
2005+
- **Repeatable** tests should be repeatable in any environment and there should be no excuse for why they fail.
20052006

2006-
* **Self-Validating** a test should answer with either *Passed* or *Failed*. You don't need to compare log files to answer if a test passed.
2007+
- **Self-Validating** a test should answer with either *Passed* or *Failed*. You don't need to compare log files to answer if a test passed.
20072008

2008-
* **Timely** unit tests should be written before the production code. If you write tests after the production code, you might find writing tests too hard.
2009+
- **Timely** unit tests should be written before the production code. If you write tests after the production code, you might find writing tests too hard.
20092010

20102011
**[⬆ back to top](#table-of-contents)**
20112012

@@ -2362,19 +2363,19 @@ Formatting is subjective. Like many rules herein, there is no hard and fast rule
23622363

23632364
For TypeScript there is a powerful tool called [TSLint](https://palantir.github.io/tslint/). It's a static analysis tool that can help you improve dramatically the readability and maintainability of your code. There are ready to use TSLint configurations that you can reference in your projects:
23642365

2365-
* [TSLint Config Standard](https://www.npmjs.com/package/tslint-config-standard) - standard style rules
2366+
- [TSLint Config Standard](https://www.npmjs.com/package/tslint-config-standard) - standard style rules
23662367

2367-
* [TSLint Config Airbnb](https://www.npmjs.com/package/tslint-config-airbnb) - Airbnb style guide
2368+
- [TSLint Config Airbnb](https://www.npmjs.com/package/tslint-config-airbnb) - Airbnb style guide
23682369

2369-
* [TSLint Clean Code](https://www.npmjs.com/package/tslint-clean-code) - TSLint rules inspired by the [Clean Code: A Handbook of Agile Software Craftsmanship](https://www.amazon.ca/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882)
2370+
- [TSLint Clean Code](https://www.npmjs.com/package/tslint-clean-code) - TSLint rules inspired by the [Clean Code: A Handbook of Agile Software Craftsmanship](https://www.amazon.ca/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882)
23702371

2371-
* [TSLint react](https://www.npmjs.com/package/tslint-react) - lint rules related to React & JSX
2372+
- [TSLint react](https://www.npmjs.com/package/tslint-react) - lint rules related to React & JSX
23722373

2373-
* [TSLint + Prettier](https://www.npmjs.com/package/tslint-config-prettier) - lint rules for [Prettier](https://github.com/prettier/prettier) code formatter
2374+
- [TSLint + Prettier](https://www.npmjs.com/package/tslint-config-prettier) - lint rules for [Prettier](https://github.com/prettier/prettier) code formatter
23742375

2375-
* [ESLint rules for TSLint](https://www.npmjs.com/package/tslint-eslint-rules) - ESLint rules for TypeScript
2376+
- [ESLint rules for TSLint](https://www.npmjs.com/package/tslint-eslint-rules) - ESLint rules for TypeScript
23762377

2377-
* [Immutable](https://www.npmjs.com/package/tslint-immutable) - rules to disable mutation in TypeScript
2378+
- [Immutable](https://www.npmjs.com/package/tslint-immutable) - rules to disable mutation in TypeScript
23782379

23792380
Refer also to this great [TypeScript StyleGuide and Coding Conventions](https://basarat.gitbooks.io/typescript/docs/styleguide/styleguide.html) source.
23802381

@@ -2495,7 +2496,7 @@ class PerformanceReview {
24952496

24962497
private lookupManager() {
24972498
return db.lookup(this.employee, 'manager');
2498-
}
2499+
}
24992500

25002501
private getSelfReview() {
25012502
// ...
@@ -2597,7 +2598,7 @@ The use of a comments is an indication of failure to express without them. Code
25972598
25982599
### Prefer self explanatory code instead of comments
25992600

2600-
Comments are an apology, not a requirement. Good code mostly documents itself.
2601+
Comments are an apology, not a requirement. Good code *mostly* documents itself.
26012602

26022603
**Bad:**
26032604

@@ -2643,7 +2644,7 @@ type User = {
26432644
26442645
### Don't have journal comments
26452646
2646-
Remember, use version control! There's no need for dead code, commented code, and especially journal comments. Use git log to get history!
2647+
Remember, use version control! There's no need for dead code, commented code, and especially journal comments. Use `git log` to get history!
26472648
26482649
**Bad:**
26492650
@@ -2748,7 +2749,7 @@ function getActiveSubscriptions(): Promise<Subscription[]> {
27482749
}
27492750
```
27502751

2751-
**Good**
2752+
**Good:**
27522753

27532754
```ts
27542755
function getActiveSubscriptions(): Promise<Subscription[]> {

0 commit comments

Comments
 (0)