Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: use stricter indentation checking for docs #13950

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ rules:
no-var: 2
prefer-const: 2
prefer-rest-params: 2

# use stricter indent over indent-legacy
indent-legacy: 0
indent: [2, 2, {ArrayExpression: first,
CallExpression: {arguments: first},
FunctionDeclaration: {parameters: first},
FunctionExpression: {parameters: first},
MemberExpression: off,
ObjectExpression: first,
SwitchCase: 1}]
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 @@ -659,7 +660,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