Skip to content

Commit b4fea2a

Browse files
committed
doc: add eslint-plugin-markdown
* install eslint-plugin-markdown * add doc/.eslintrc.yaml * add `<!-- eslint-disable rule -->` or `<!-- eslint-disable -->` for the rest of problematic code * .js files in doc folder added to .eslintignore * update Makefile and vcbuild.bat PR-URL: #12563 Refs: #12557 (comment) Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
1 parent e2c3e47 commit b4fea2a

File tree

219 files changed

+34509
-33
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+34509
-33
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ test/tmp*/
77
tools/eslint
88
node_modules
99
benchmark/tmp/
10+
doc/**/*.js

.eslintrc.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
root: true
22

3+
plugins:
4+
- markdown
5+
36
env:
47
node: true
58
es6: true

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,8 @@ bench-ci: bench
855855

856856
jslint:
857857
@echo "Running JS linter..."
858-
$(NODE) tools/eslint/bin/eslint.js --cache --rulesdir=tools/eslint-rules \
859-
benchmark lib test tools
858+
$(NODE) tools/eslint/bin/eslint.js --cache --rulesdir=tools/eslint-rules --ext=.js,.md \
859+
benchmark doc lib test tools
860860

861861
jslint-ci:
862862
@echo "Running JS linter..."

doc/.eslintrc.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rules:
2+
strict: 0
3+
no-restricted-properties: 0
4+
no-undef: 0
5+
no-unused-vars: 0

doc/api/assert.md

+1
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ Note that `error` can not be a string. If a string is provided as the second
554554
argument, then `error` is assumed to be omitted and the string will be used for
555555
`message` instead. This can lead to easy-to-miss mistakes:
556556

557+
<!-- eslint-disable assert-throws-arguments -->
557558
```js
558559
// THIS IS A MISTAKE! DO NOT DO THIS!
559560
assert.throws(myFunction, 'missing foo', 'did not throw with expected message');

doc/api/cluster.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,11 @@ When any of the workers die the cluster module will emit the `'exit'` event.
523523
This can be used to restart the worker by calling `.fork()` again.
524524

525525
```js
526-
cluster.on(
527-
'exit',
528-
(worker, code, signal) => {
529-
console.log('worker %d died (%s). restarting...',
530-
worker.process.pid, signal || code);
531-
cluster.fork();
532-
}
533-
);
526+
cluster.on('exit', (worker, code, signal) => {
527+
console.log('worker %d died (%s). restarting...',
528+
worker.process.pid, signal || code);
529+
cluster.fork();
530+
});
534531
```
535532

536533
See [child_process event: 'exit'][].

doc/api/console.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ by extending Node.js' `console` and overriding the `console.assert()` method.
135135
In the following example, a simple module is created that extends and overrides
136136
the default behavior of `console` in Node.js.
137137

138+
<!-- eslint-disable func-name-matching -->
138139
```js
139140
'use strict';
140141

141142
// Creates a simple extension of console with a
142143
// new impl for assert without monkey-patching.
143144
const myConsole = Object.create(console, {
144145
assert: {
145-
value(assertion, message, ...args) {
146+
value: function assert(assertion, message, ...args) {
146147
try {
147148
console.assert(assertion, message, ...args);
148149
} catch (err) {
@@ -276,7 +277,7 @@ prints the result to `stdout`:
276277

277278
```js
278279
console.time('100-elements');
279-
for (let i = 0; i < 100; i++) ;
280+
for (let i = 0; i < 100; i++) {}
280281
console.timeEnd('100-elements');
281282
// prints 100-elements: 225.438ms
282283
```

doc/api/crypto.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ decipher.on('end', () => {
289289
});
290290

291291
const encrypted =
292-
'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504';
292+
'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504';
293293
decipher.write(encrypted, 'hex');
294294
decipher.end();
295295
```
@@ -314,7 +314,7 @@ const crypto = require('crypto');
314314
const decipher = crypto.createDecipher('aes192', 'a password');
315315

316316
const encrypted =
317-
'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504';
317+
'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504';
318318
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
319319
decrypted += decipher.final('utf8');
320320
console.log(decrypted);

doc/api/debugger.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ inspection are possible.
2626
Inserting the statement `debugger;` into the source code of a script will
2727
enable a breakpoint at that position in the code:
2828

29+
<!-- eslint-disable no-debugger -->
2930
```js
3031
// myscript.js
3132
global.x = 5;

doc/api/dns.md

+3
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ function will contain an array of objects with the following properties:
293293

294294
For example:
295295

296+
<!-- eslint-disable -->
296297
```js
297298
{
298299
flags: 's',
@@ -352,6 +353,7 @@ be an object with the following properties:
352353
* `expire`
353354
* `minttl`
354355

356+
<!-- eslint-disable -->
355357
```js
356358
{
357359
nsname: 'ns.example.com',
@@ -382,6 +384,7 @@ be an array of objects with the following properties:
382384
* `port`
383385
* `name`
384386

387+
<!-- eslint-disable -->
385388
```js
386389
{
387390
priority: 10,

doc/api/fs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ synchronous counterparts are of this type.
217217
For a regular file [`util.inspect(stats)`][] would return a string very
218218
similar to this:
219219

220-
```txt
220+
```
221221
Stats {
222222
dev: 2114,
223223
ino: 48064969,

doc/api/http.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ user is able to stream data.
1212

1313
HTTP message headers are represented by an object like this:
1414

15+
<!-- eslint-disable -->
1516
```js
1617
{ 'content-length': '123',
1718
'content-type': 'text/plain',
@@ -34,6 +35,7 @@ property, which is an array of `[key, value, key2, value2, ...]`. For
3435
example, the previous message header object might have a `rawHeaders`
3536
list like the following:
3637

38+
<!-- eslint-disable semi -->
3739
```js
3840
[ 'ConTent-Length', '123456',
3941
'content-LENGTH', '123',
@@ -1460,6 +1462,7 @@ Accept: text/plain\r\n
14601462

14611463
Then `request.url` will be:
14621464

1465+
<!-- eslint-disable semi -->
14631466
```js
14641467
'/status?name=ryan'
14651468
```

doc/api/modules.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ The module system is implemented in the `require('module')` module.
6767

6868
When a file is run directly from Node.js, `require.main` is set to its
6969
`module`. That means that you can determine whether a file has been run
70-
directly by testing
71-
72-
```js
73-
require.main === module;
74-
```
70+
directly by testing `require.main === module`.
7571

7672
For a file `foo.js`, this will be `true` if run via `node foo.js`, but
7773
`false` if run by `require('./foo')`.
@@ -556,6 +552,7 @@ exports = { hello: false }; // Not exported, only available in the module
556552
When the `module.exports` property is being completely replaced by a new
557553
object, it is common to also reassign `exports`, for example:
558554

555+
<!-- eslint-disable func-name-matching -->
559556
```js
560557
module.exports = exports = function Constructor() {
561558
// ... etc.

doc/api/os.md

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ The properties included on each object include:
7171

7272
For example:
7373

74+
<!-- eslint-disable semi -->
7475
```js
7576
[
7677
{
@@ -253,6 +254,7 @@ The properties available on the assigned network address object include:
253254
* `scopeid` {number} The numeric IPv6 scope ID (only specified when `family`
254255
is `IPv6`)
255256

257+
<!-- eslint-disable -->
256258
```js
257259
{
258260
lo: [

doc/api/process.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ running the `./configure` script.
528528

529529
An example of the possible output looks like:
530530

531-
```txt
531+
<!-- eslint-disable -->
532+
```js
532533
{
533534
target_defaults:
534535
{ cflags: [],
@@ -745,6 +746,7 @@ See environ(7).
745746

746747
An example of this object looks like:
747748

749+
<!-- eslint-disable -->
748750
```js
749751
{
750752
TERM: 'xterm-256color',
@@ -832,12 +834,14 @@ $ node --harmony script.js --version
832834

833835
Results in `process.execArgv`:
834836

837+
<!-- eslint-disable semi -->
835838
```js
836839
['--harmony']
837840
```
838841

839842
And `process.argv`:
840843

844+
<!-- eslint-disable semi -->
841845
```js
842846
['/usr/local/bin/node', 'script.js', '--version']
843847
```
@@ -854,6 +858,7 @@ that started the Node.js process.
854858

855859
For example:
856860

861+
<!-- eslint-disable semi -->
857862
```js
858863
'/usr/local/bin/node'
859864
```
@@ -1173,6 +1178,7 @@ console.log(process.memoryUsage());
11731178

11741179
Will generate:
11751180

1181+
<!-- eslint-disable -->
11761182
```js
11771183
{
11781184
rss: 4935680,
@@ -1344,6 +1350,7 @@ tarball.
13441350

13451351
For example:
13461352

1353+
<!-- eslint-disable -->
13471354
```js
13481355
{
13491356
name: 'node',
@@ -1705,6 +1712,7 @@ console.log(process.versions);
17051712

17061713
Will generate an object similar to:
17071714

1715+
<!-- eslint-disable -->
17081716
```js
17091717
{
17101718
http_parser: '2.3.0',

doc/api/querystring.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ collection of key and value pairs.
5959

6060
For example, the query string `'foo=bar&abc=xyz&abc=123'` is parsed into:
6161

62+
<!-- eslint-disable -->
6263
```js
6364
{
6465
foo: 'bar',

doc/api/readline.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ For instance: `[[substr1, substr2, ...], originalsubstring]`.
414414
```js
415415
function completer(line) {
416416
const completions = '.help .error .exit .quit .q'.split(' ');
417-
const hits = completions.filter((c) => { return c.indexOf(line) === 0; });
417+
const hits = completions.filter((c) => c.indexOf(line) === 0);
418418
// show all completions if none found
419419
return [hits.length ? hits : completions, line];
420420
}

doc/api/repl.md

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The following special commands are supported by all REPL instances:
4040
`> .load ./file/to/load.js`
4141
* `.editor` - Enter editor mode (`<ctrl>-D` to finish, `<ctrl>-C` to cancel)
4242

43+
<!-- eslint-disable -->
4344
```js
4445
> .editor
4546
// Entering editor mode (^D to finish, ^C to cancel)
@@ -75,6 +76,7 @@ evaluation function when the `repl.REPLServer` instance is created.
7576

7677
The default evaluator supports direct evaluation of JavaScript expressions:
7778

79+
<!-- eslint-disable -->
7880
```js
7981
> 1 + 1
8082
2
@@ -103,6 +105,7 @@ repl.start('> ').context.m = msg;
103105

104106
Properties in the `context` object appear as local within the REPL:
105107

108+
<!-- eslint-disable -->
106109
```js
107110
$ node repl_test.js
108111
> m
@@ -132,6 +135,7 @@ REPL environment when used. For instance, unless otherwise declared as a
132135
global or scoped variable, the input `fs` will be evaluated on-demand as
133136
`global.fs = require('fs')`.
134137

138+
<!-- eslint-disable -->
135139
```js
136140
> fs.createReadStream('./some/file');
137141
```
@@ -142,6 +146,7 @@ The default evaluator will, by default, assign the result of the most recently
142146
evaluated expression to the special variable `_` (underscore).
143147
Explicitly setting `_` to a value will disable this behavior.
144148

149+
<!-- eslint-disable -->
145150
```js
146151
> [ 'a', 'b', 'c' ]
147152
[ 'a', 'b', 'c' ]
@@ -288,6 +293,7 @@ r.on('reset', initializeContext);
288293
When this code is executed, the global `'m'` variable can be modified but then
289294
reset to its initial value using the `.clear` command:
290295

296+
<!-- eslint-disable -->
291297
```js
292298
$ ./node example.js
293299
> m
@@ -438,6 +444,7 @@ Node.js itself uses the `repl` module to provide its own interactive interface
438444
for executing JavaScript. This can be used by executing the Node.js binary
439445
without passing any arguments (or by passing the `-i` argument):
440446

447+
<!-- eslint-disable -->
441448
```js
442449
$ node
443450
> const a = [1, 2, 3];

doc/api/stream.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ has been called, and all data has been flushed to the underlying system.
280280

281281
```js
282282
const writer = getWritableStreamSomehow();
283-
for (var i = 0; i < 100; i++) {
283+
for (let i = 0; i < 100; i++) {
284284
writer.write(`hello, #${i}!\n`);
285285
}
286286
writer.end('This is the end\n');

doc/api/v8.md

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ swapped out by the operating system.
116116

117117
For example:
118118

119+
<!-- eslint-disable -->
119120
```js
120121
{
121122
total_heap_size: 7326976,

doc/api/zlib.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ From `zlib/zconf.h`, modified to node.js's usage:
151151

152152
The memory requirements for deflate are (in bytes):
153153

154+
<!-- eslint-disable semi -->
154155
```js
155-
(1 << (windowBits + 2)) + (1 << (memLevel + 9));
156+
(1 << (windowBits + 2)) + (1 << (memLevel + 9))
156157
```
157158

158159
That is: 128K for windowBits=15 + 128K for memLevel = 8
@@ -167,12 +168,7 @@ const options = { windowBits: 14, memLevel: 7 };
167168

168169
This will, however, generally degrade compression.
169170

170-
The memory requirements for inflate are (in bytes)
171-
172-
```js
173-
1 << windowBits;
174-
```
175-
171+
The memory requirements for inflate are (in bytes) `1 << windowBits`.
176172
That is, 32K for windowBits=15 (default value) plus a few kilobytes
177173
for small objects.
178174

test/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ A non-op `Function` that can be used for a variety of scenarios.
352352

353353
For instance,
354354

355+
<!-- eslint-disable strict, no-undef -->
355356
```js
356357
const common = require('../common');
357358

0 commit comments

Comments
 (0)