Skip to content

Commit 0303c38

Browse files
nschonniXhmikosR
andauthored
chore: Turn on ESLint for markdown (#4287)
Co-authored-by: XhmikosR <[email protected]>
1 parent 886a089 commit 0303c38

File tree

66 files changed

+1574
-1032
lines changed

Some content is hidden

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

66 files changed

+1574
-1032
lines changed

Diff for: .eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
static/legacy/
33
external/
44
build/
5+
# Top level await isn't supported till ESLint 8
6+
locale/en/blog/release/v17.0.0.md

Diff for: .eslintrc

+34-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,38 @@
99
],
1010
"rules": {
1111
"prettier/prettier": "error"
12-
}
12+
},
13+
"overrides": [
14+
{
15+
"files": [
16+
"**/*.md"
17+
],
18+
"plugins": [
19+
"markdown"
20+
],
21+
"processor": "markdown/markdown"
22+
},
23+
{
24+
"files": [
25+
"**/*.md/*.js"
26+
],
27+
"rules": {
28+
"eqeqeq": "off",
29+
"no-const-assign": "off",
30+
"no-undef": "off",
31+
"no-unused-expressions": "off",
32+
"no-unused-vars": "off",
33+
"node/handle-callback-err": "off",
34+
"node/no-deprecated-api": "off",
35+
"prefer-const": "off",
36+
"prettier/prettier": [
37+
"error",
38+
{
39+
"singleQuote": true,
40+
"trailingComma": "none"
41+
}
42+
]
43+
}
44+
}
45+
]
1346
}

Diff for: locale/en/blog/release/v12.16.0.md

-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ The new `EventEmitter.on` static method allows to async iterate over events:
130130
const { on, EventEmitter } = require('events');
131131

132132
(async () => {
133-
134133
const ee = new EventEmitter();
135134

136135
// Emit later on
@@ -145,7 +144,6 @@ const { on, EventEmitter } = require('events');
145144
// if concurrent execution is required.
146145
console.log(event); // prints ['bar'] [42]
147146
}
148-
149147
})();
150148
```
151149

Diff for: locale/en/blog/release/v12.17.0.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,18 @@ function logWithId(msg) {
6262
}
6363

6464
let idSeq = 0;
65-
http.createServer((req, res) => {
66-
asyncLocalStorage.run(idSeq++, () => {
67-
logWithId('start');
68-
// Imagine any chain of async operations here.
69-
setImmediate(() => {
70-
logWithId('finish');
71-
res.end();
65+
http
66+
.createServer((req, res) => {
67+
asyncLocalStorage.run(idSeq++, () => {
68+
logWithId('start');
69+
// Imagine any chain of async operations here.
70+
setImmediate(() => {
71+
logWithId('finish');
72+
res.end();
73+
});
7274
});
73-
});
74-
}).listen(8080);
75+
})
76+
.listen(8080);
7577
```
7678

7779
In this example, the `logWithId` function will always know what the current

Diff for: locale/en/blog/release/v14.17.0.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ MySQL.prototype.query = function query(queryString, values, callback) {
2727
// Broadcast query information whenever a query is made
2828
channel.publish({
2929
query: queryString,
30-
host: this.hostname,
30+
host: this.hostname
3131
});
3232

3333
this.doQuery(queryString, values, callback);

Diff for: locale/en/blog/release/v15.1.0.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ MySQL.prototype.query = function query(queryString, values, callback) {
2424
// Broadcast query information whenever a query is made
2525
channel.publish({
2626
query: queryString,
27-
host: this.hostname,
27+
host: this.hostname
2828
});
2929

3030
this.doQuery(queryString, values, callback);

Diff for: locale/en/blog/release/v8.0.0.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ const util = require('util');
153153
const readfile = util.promisify(fs.readFile);
154154

155155
readfile('/some/file')
156-
.then((data) => { /** ... **/ })
157-
.catch((err) => { /** ... **/ });
156+
.then((data) => {
157+
/** ... **/
158+
})
159+
.catch((err) => {
160+
/** ... **/
161+
});
158162
```
159163

160164
### Console changes
@@ -183,7 +187,7 @@ Codes are manifest to the user in two ways:
183187
For instance, calling `assert(false)` will generate the following
184188
`AssertionError`:
185189

186-
```js
190+
```shell
187191
> assert(false)
188192
AssertionError [ERR_ASSERTION]: false == true
189193
at repl:1:1
@@ -240,7 +244,9 @@ const session = new inspector.Session();
240244
session.connect();
241245

242246
// Listen for inspector events
243-
session.on('inspectorNotification', (message) => { /** ... **/ });
247+
session.on('inspectorNotification', (message) => {
248+
/** ... **/
249+
});
244250

245251
// Send messages to the inspector
246252
session.post(message);

Diff for: locale/en/docs/guides/buffer-constructor-deprecation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ compiles to.
186186
For Node.js 0.10.x (and below) support:
187187

188188
```js
189-
var buf;
189+
let buf;
190190
if (Buffer.alloc) {
191191
buf = Buffer.alloc(number);
192192
} else {

Diff for: locale/en/docs/guides/domain-postmortem.md

+96-69
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ const c = require('./c');
2424

2525
// module b.js
2626
const d = require('domain').create();
27-
d.on('error', () => { /* silence everything */ });
27+
d.on('error', () => {
28+
/* silence everything */
29+
});
2830
d.enter();
2931

3032
// module c.js
@@ -57,10 +59,14 @@ const net = require('net');
5759
const d = domain.create();
5860
d.on('error', (err) => console.error(err.message));
5961

60-
d.run(() => net.createServer((c) => {
61-
c.end();
62-
c.write('bye');
63-
}).listen(8000));
62+
d.run(() =>
63+
net
64+
.createServer((c) => {
65+
c.end();
66+
c.write('bye');
67+
})
68+
.listen(8000)
69+
);
6470
```
6571

6672
Even manually removing the connection via `d.remove(c)` does not prevent the
@@ -77,17 +83,19 @@ const d = domain.create();
7783
d.on('error', () => console.error('d intercepted an error'));
7884

7985
d.run(() => {
80-
const server = net.createServer((c) => {
81-
const e = domain.create(); // No 'error' handler being set.
82-
e.run(() => {
83-
// This will not be caught by d's error handler.
84-
setImmediate(() => {
85-
throw new Error('thrown from setImmediate');
86+
const server = net
87+
.createServer((c) => {
88+
const e = domain.create(); // No 'error' handler being set.
89+
e.run(() => {
90+
// This will not be caught by d's error handler.
91+
setImmediate(() => {
92+
throw new Error('thrown from setImmediate');
93+
});
94+
// Though this one will bubble to d's error handler.
95+
throw new Error('immediately thrown');
8696
});
87-
// Though this one will bubble to d's error handler.
88-
throw new Error('immediately thrown');
89-
});
90-
}).listen(8080);
97+
})
98+
.listen(8080);
9199
});
92100
```
93101

@@ -118,21 +126,25 @@ example of the failing of error propagation:
118126
```js
119127
const d1 = domain.create();
120128
d1.foo = true; // custom member to make more visible in console
121-
d1.on('error', (er) => { /* handle error */ });
129+
d1.on('error', (er) => {
130+
/* handle error */
131+
});
122132

123-
d1.run(() => setTimeout(() => {
124-
const d2 = domain.create();
125-
d2.bar = 43;
126-
d2.on('error', (er) => console.error(er.message, domain._stack));
127-
d2.run(() => {
128-
setTimeout(() => {
133+
d1.run(() =>
134+
setTimeout(() => {
135+
const d2 = domain.create();
136+
d2.bar = 43;
137+
d2.on('error', (er) => console.error(er.message, domain._stack));
138+
d2.run(() => {
129139
setTimeout(() => {
130-
throw new Error('outer');
140+
setTimeout(() => {
141+
throw new Error('outer');
142+
});
143+
throw new Error('inner');
131144
});
132-
throw new Error('inner');
133145
});
134-
});
135-
}));
146+
})
147+
);
136148
```
137149

138150
Even in the case that the domain instances are being used for local storage so
@@ -176,16 +188,15 @@ let uid = 0;
176188

177189
// Setting up temporary resources
178190
const buf = Buffer.alloc(FILESIZE);
179-
for (let i = 0; i < buf.length; i++)
180-
buf[i] = ((Math.random() * 1e3) % 78) + 48; // Basic ASCII
191+
for (let i = 0; i < buf.length; i++) buf[i] = ((Math.random() * 1e3) % 78) + 48; // Basic ASCII
181192
fs.writeFileSync(FILENAME, buf);
182193

183194
function ConnectionResource(c) {
184195
EE.call(this);
185196
this._connection = c;
186197
this._alive = true;
187198
this._domain = domain.create();
188-
this._id = Math.random().toString(32).substr(2).substr(0, 8) + (++uid);
199+
this._id = Math.random().toString(32).substr(2).substr(0, 8) + ++uid;
189200

190201
this._domain.add(c);
191202
this._domain.on('error', () => {
@@ -214,18 +225,24 @@ ConnectionResource.prototype.write = function write(chunk) {
214225
};
215226

216227
// Example begin
217-
net.createServer((c) => {
218-
const cr = new ConnectionResource(c);
228+
net
229+
.createServer((c) => {
230+
const cr = new ConnectionResource(c);
219231

220-
const d1 = domain.create();
221-
fs.open(FILENAME, 'r', d1.intercept((fd) => {
222-
streamInParts(fd, cr, 0);
223-
}));
232+
const d1 = domain.create();
233+
fs.open(
234+
FILENAME,
235+
'r',
236+
d1.intercept((fd) => {
237+
streamInParts(fd, cr, 0);
238+
})
239+
);
224240

225-
pipeData(cr);
241+
pipeData(cr);
226242

227-
c.on('close', () => cr.end());
228-
}).listen(8080);
243+
c.on('close', () => cr.end());
244+
})
245+
.listen(8080);
229246

230247
function streamInParts(fd, cr, pos) {
231248
const d2 = domain.create();
@@ -234,24 +251,33 @@ function streamInParts(fd, cr, pos) {
234251
print('d2 error:', er.message);
235252
cr.end();
236253
});
237-
fs.read(fd, Buffer.alloc(10), 0, 10, pos, d2.intercept((bRead, buf) => {
238-
if (!cr.isAlive()) {
239-
return fs.close(fd);
240-
}
241-
if (cr._connection.bytesWritten < FILESIZE) {
242-
// Documentation says callback is optional, but doesn't mention that if
243-
// the write fails an exception will be thrown.
244-
const goodtogo = cr.write(buf);
245-
if (goodtogo) {
246-
setTimeout(() => streamInParts(fd, cr, pos + bRead), 1000);
247-
} else {
248-
cr._connection.once('drain', () => streamInParts(fd, cr, pos + bRead));
254+
fs.read(
255+
fd,
256+
Buffer.alloc(10),
257+
0,
258+
10,
259+
pos,
260+
d2.intercept((bRead, buf) => {
261+
if (!cr.isAlive()) {
262+
return fs.close(fd);
249263
}
250-
return;
251-
}
252-
cr.end(buf);
253-
fs.close(fd);
254-
}));
264+
if (cr._connection.bytesWritten < FILESIZE) {
265+
// Documentation says callback is optional, but doesn't mention that if
266+
// the write fails an exception will be thrown.
267+
const goodtogo = cr.write(buf);
268+
if (goodtogo) {
269+
setTimeout(() => streamInParts(fd, cr, pos + bRead), 1000);
270+
} else {
271+
cr._connection.once('drain', () =>
272+
streamInParts(fd, cr, pos + bRead)
273+
);
274+
}
275+
return;
276+
}
277+
cr.end(buf);
278+
fs.close(fd);
279+
})
280+
);
255281
}
256282

257283
function pipeData(cr) {
@@ -293,9 +319,8 @@ process.on('exit', () => {
293319
fs.unlinkSync(pipeList[i]);
294320
}
295321
fs.unlinkSync(FILENAME);
296-
} catch (e) { }
322+
} catch (e) {}
297323
});
298-
299324
```
300325

301326
* When a new connection happens, concurrently:
@@ -344,18 +369,20 @@ propagate data along asynchronous stacks:
344369
const domain = require('domain');
345370
const net = require('net');
346371

347-
const server = net.createServer((c) => {
348-
// Use a domain to propagate data across events within the
349-
// connection so that we don't have to pass arguments
350-
// everywhere.
351-
const d = domain.create();
352-
d.data = { connection: c };
353-
d.add(c);
354-
// Mock class that does some useless async data transformation
355-
// for demonstration purposes.
356-
const ds = new DataStream(dataTransformed);
357-
c.on('data', (chunk) => ds.data(chunk));
358-
}).listen(8080, () => console.log('listening on 8080'));
372+
const server = net
373+
.createServer((c) => {
374+
// Use a domain to propagate data across events within the
375+
// connection so that we don't have to pass arguments
376+
// everywhere.
377+
const d = domain.create();
378+
d.data = { connection: c };
379+
d.add(c);
380+
// Mock class that does some useless async data transformation
381+
// for demonstration purposes.
382+
const ds = new DataStream(dataTransformed);
383+
c.on('data', (chunk) => ds.data(chunk));
384+
})
385+
.listen(8080, () => console.log('listening on 8080'));
359386

360387
function dataTransformed(chunk) {
361388
// FAIL! Because the DataStream instance also created a

0 commit comments

Comments
 (0)