Skip to content

Commit

Permalink
doc: fix indentation issues in sample code
Browse files Browse the repository at this point in the history
In preparation for stricter ESLint indentation checking, fix a few
issues in sample code.

PR-URL: #13950
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and addaleax committed Jul 18, 2017
1 parent f53bfe4 commit f1d92fb
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 104 deletions.
8 changes: 5 additions & 3 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ const aliceSecret = alice.computeSecret(bobKey);
const bobSecret = bob.computeSecret(aliceKey);

assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
// OK
// OK
```

### ecdh.computeSecret(otherPublicKey[, inputEncoding][, outputEncoding])
Expand Down Expand Up @@ -746,10 +746,11 @@ const hash = crypto.createHash('sha256');

hash.on('readable', () => {
const data = hash.read();
if (data)
if (data) {
console.log(data.toString('hex'));
// Prints:
// 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
}
});

hash.write('some data to hash');
Expand Down Expand Up @@ -836,10 +837,11 @@ const hmac = crypto.createHmac('sha256', 'a secret');

hmac.on('readable', () => {
const data = hmac.read();
if (data)
if (data) {
console.log(data.toString('hex'));
// Prints:
// 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
}
});

hmac.write('some data to hash');
Expand Down
39 changes: 20 additions & 19 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,22 @@ function makeFaster() {
});
}

makeFaster(); // will throw:
// /home/gbusey/file.js:6
// throw new Error('oh no!');
// ^
// Error: oh no!
// at speedy (/home/gbusey/file.js:6:11)
// at makeFaster (/home/gbusey/file.js:5:3)
// at Object.<anonymous> (/home/gbusey/file.js:10:1)
// at Module._compile (module.js:456:26)
// at Object.Module._extensions..js (module.js:474:10)
// at Module.load (module.js:356:32)
// at Function.Module._load (module.js:312:12)
// at Function.Module.runMain (module.js:497:10)
// at startup (node.js:119:16)
// at node.js:906:3
makeFaster();
// will throw:
// /home/gbusey/file.js:6
// throw new Error('oh no!');
// ^
// Error: oh no!
// at speedy (/home/gbusey/file.js:6:11)
// at makeFaster (/home/gbusey/file.js:5:3)
// at Object.<anonymous> (/home/gbusey/file.js:10:1)
// at Module._compile (module.js:456:26)
// at Object.Module._extensions..js (module.js:474:10)
// at Module.load (module.js:356:32)
// at Function.Module._load (module.js:312:12)
// at Function.Module.runMain (module.js:497:10)
// at startup (node.js:119:16)
// at node.js:906:3
```

The location information will be one of:
Expand Down Expand Up @@ -368,7 +369,7 @@ For example:

```js
require('net').connect(-1);
// throws "RangeError: "port" option should be >= 0 and < 65536: -1"
// throws "RangeError: "port" option should be >= 0 and < 65536: -1"
```

Node.js will generate and throw `RangeError` instances *immediately* as a form
Expand All @@ -385,7 +386,7 @@ will do so.

```js
doesNotExist;
// throws ReferenceError, doesNotExist is not a variable in this program.
// throws ReferenceError, doesNotExist is not a variable in this program.
```

Unless an application is dynamically generating and running code,
Expand Down Expand Up @@ -419,7 +420,7 @@ string would be considered a TypeError.

```js
require('url').parse(() => { });
// throws TypeError, since it expected a string
// throws TypeError, since it expected a string
```

Node.js will generate and throw `TypeError` instances *immediately* as a form
Expand Down Expand Up @@ -640,7 +641,7 @@ const urlSearchParams = new URLSearchParams('foo=bar&baz=new');

const buf = Buffer.alloc(1);
urlSearchParams.has.call(buf, 'foo');
// Throws a TypeError with code 'ERR_INVALID_THIS'
// Throws a TypeError with code 'ERR_INVALID_THIS'
```

<a id="ERR_INVALID_TUPLE"></a>
Expand Down
3 changes: 2 additions & 1 deletion doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ support. If `filename` is provided, it will be provided as a `Buffer` if
```js
// Example when handled through fs.watch listener
fs.watch('./tmp', { encoding: 'buffer' }, (eventType, filename) => {
if (filename)
if (filename) {
console.log(filename);
// Prints: <Buffer ...>
}
});
```

Expand Down
2 changes: 1 addition & 1 deletion doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ double-backslashes, such as:

```js
net.createServer().listen(
path.join('\\\\?\\pipe', process.cwd(), 'myctl'));
path.join('\\\\?\\pipe', process.cwd(), 'myctl'));
```

## Class: net.Server
Expand Down
4 changes: 2 additions & 2 deletions doc/api/querystring.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ in the following example:
// Assuming gbkDecodeURIComponent function already exists...

querystring.parse('w=%D6%D0%CE%C4&foo=bar', null, null,
{ decodeURIComponent: gbkDecodeURIComponent });
{ decodeURIComponent: gbkDecodeURIComponent });
```

## querystring.stringify(obj[, sep[, eq[, options]]])
Expand Down Expand Up @@ -125,7 +125,7 @@ following example:
// Assuming gbkEncodeURIComponent function already exists,

querystring.stringify({ w: '中文', foo: 'bar' }, null, null,
{ encodeURIComponent: gbkEncodeURIComponent });
{ encodeURIComponent: gbkEncodeURIComponent });
```

## querystring.unescape(str)
Expand Down
Loading

0 comments on commit f1d92fb

Please sign in to comment.