Skip to content

Commit d77a713

Browse files
author
Gergely Nemeth
committed
Indent fixes
1 parent 0c9aedb commit d77a713

File tree

1 file changed

+63
-63
lines changed

1 file changed

+63
-63
lines changed

README.md

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -474,43 +474,43 @@ Heavily inspired by
474474
475475
- Always check for errors in callbacks
476476
477-
```javascript
478-
//bad
479-
database.get('pokemons', function (err, pokemons) {
480-
console.log(pokemons);
481-
});
482-
483-
//good
484-
database.get('drabonballs', function (err, drabonballs) {
485-
if (err) {
486-
// handle the error somehow, maybe return with a callback
487-
return console.log(err);
488-
}
489-
console.log(drabonballs);
490-
});
491-
```
477+
```javascript
478+
//bad
479+
database.get('pokemons', function (err, pokemons) {
480+
console.log(pokemons);
481+
});
482+
483+
//good
484+
database.get('drabonballs', function (err, drabonballs) {
485+
if (err) {
486+
// handle the error somehow, maybe return with a callback
487+
return console.log(err);
488+
}
489+
console.log(drabonballs);
490+
});
491+
```
492492
493493
- Return on callbacks
494-
```javascript
495-
//bad
496-
database.get('drabonballs', function (err, drabonballs) {
497-
if (err) {
498-
// if not return here
499-
console.log(err);
500-
}
501-
// this line will be executed as well
502-
console.log(drabonballs);
503-
});
504-
505-
//good
506-
database.get('drabonballs', function (err, drabonballs) {
507-
if (err) {
508-
// handle the error somehow, maybe return with a callback
509-
return console.log(err);
510-
}
511-
console.log(drabonballs);
512-
});
513-
```
494+
```javascript
495+
//bad
496+
database.get('drabonballs', function (err, drabonballs) {
497+
if (err) {
498+
// if not return here
499+
console.log(err);
500+
}
501+
// this line will be executed as well
502+
console.log(drabonballs);
503+
});
504+
505+
//good
506+
database.get('drabonballs', function (err, drabonballs) {
507+
if (err) {
508+
// handle the error somehow, maybe return with a callback
509+
return console.log(err);
510+
}
511+
console.log(drabonballs);
512+
});
513+
```
514514
**[⬆ back to top](#table-of-contents)**
515515
516516
@@ -522,40 +522,40 @@ Heavily inspired by
522522
down the entire process.
523523
524524
```javascript
525-
//bad
526-
function readPackageJson (callback) {
527-
fs.readFile('package.json', function (err, file) {
528-
if (err) {
529-
throw err;
530-
}
531-
...
532-
});
533-
}
534-
//good
535-
function readPackageJson (callback) {
536-
fs.readFile('package.json', function (err, file) {
537-
if (err) {
538-
return callback(err);
539-
}
540-
...
541-
});
525+
//bad
526+
function readPackageJson (callback) {
527+
fs.readFile('package.json', function (err, file) {
528+
if (err) {
529+
throw err;
530+
}
531+
...
532+
});
533+
}
534+
//good
535+
function readPackageJson (callback) {
536+
fs.readFile('package.json', function (err, file) {
537+
if (err) {
538+
return callback(err);
542539
}
540+
...
541+
});
542+
}
543543
```
544544
545545
- Catch errors in sync calls
546546
547547
```javascript
548-
//bad
549-
var data = JSON.parse(jsonAsAString);
550-
551-
//good
552-
var data;
553-
try {
554-
data = JSON.parse(jsonAsAString);
555-
} catch (e) {
556-
//handle error - hopefully not with a console.log ;)
557-
console.log(e);
558-
}
548+
//bad
549+
var data = JSON.parse(jsonAsAString);
550+
551+
//good
552+
var data;
553+
try {
554+
data = JSON.parse(jsonAsAString);
555+
} catch (e) {
556+
//handle error - hopefully not with a console.log ;)
557+
console.log(e);
558+
}
559559
```
560560
561561
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)