Skip to content

Commit 29af9a3

Browse files
committed
feat(lint): use ESLint for linting snippets
1 parent b30c979 commit 29af9a3

Some content is hidden

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

48 files changed

+836
-860
lines changed

apps/site/eslint.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default tseslint.config(
4040
{
4141
files: ['**/*.{md,mdx}'],
4242
extends: [mdx.flat],
43+
processor: mdx.createRemarkProcessor({ lintCodeBlocks: true }),
4344
rules: {
4445
'no-irregular-whitespace': 'off',
4546
'@next/next/no-img-element': 'off',
@@ -77,5 +78,6 @@ export default tseslint.config(
7778
},
7879
],
7980
},
80-
}
81+
},
82+
mdx.flatCodeBlocks
8183
);

apps/site/next.mdx.plugins.mjs

-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import rehypeShikiji from './next.mdx.shiki.mjs';
1010

1111
/**
1212
* Provides all our Rehype Plugins that are used within MDX
13-
*
14-
* @type {Array<import('unified').Plugin>}
1513
*/
1614
export const REHYPE_PLUGINS = [
1715
// Generates `id` attributes for headings (H1, ...)
@@ -25,8 +23,6 @@ export const REHYPE_PLUGINS = [
2523

2624
/**
2725
* Provides all our Remark Plugins that are used within MDX
28-
*
29-
* @type {Array<import('unified').Plugin>}
3026
*/
3127
export const REMARK_PLUGINS = [
3228
// Support GFM syntax to be used within Markdown

apps/site/package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
"check-types": "tsc --noEmit",
77
"deploy": "cross-env NEXT_PUBLIC_STATIC_EXPORT=true NODE_NO_WARNINGS=1 next build",
88
"dev": "cross-env NODE_NO_WARNINGS=1 next dev",
9-
"lint": "turbo run lint:md lint:snippets lint:js lint:css",
9+
"lint": "turbo run lint:md lint:js lint:css",
1010
"lint:css": "stylelint \"**/*.css\" --allow-empty-input --cache --cache-strategy=content --cache-location=.stylelintcache",
1111
"lint:fix": "turbo run lint:md lint:js lint:css --no-cache -- --fix",
1212
"lint:js": "eslint \"**/*.{js,mjs,ts,tsx}\"",
1313
"lint:md": "eslint \"**/*.md?(x)\" --cache --cache-strategy=content --cache-location=.eslintmdcache",
14-
"lint:snippets": "node ./scripts/lint-snippets/index.mjs",
1514
"scripts:release-post": "cross-env NODE_NO_WARNINGS=1 node scripts/release-post/index.mjs",
1615
"serve": "pnpm dev",
1716
"start": "cross-env NODE_NO_WARNINGS=1 next start",
@@ -97,7 +96,6 @@
9796
"remark-lint-no-unused-definitions": "^4.0.2",
9897
"remark-lint-prohibited-strings": "^4.0.0",
9998
"remark-lint-unordered-list-marker-style": "^4.0.1",
100-
"remark-parse": "11.0.0",
10199
"remark-preset-lint-node": "5.1.2",
102100
"stylelint": "16.19.1",
103101
"stylelint-config-standard": "38.0.0",
@@ -106,7 +104,6 @@
106104
"tsx": "^4.19.3",
107105
"typescript": "~5.8.2",
108106
"typescript-eslint": "~8.31.1",
109-
"unified": "^11.0.5",
110107
"user-agent-data-types": "0.4.2"
111108
}
112-
}
109+
}

apps/site/pages/en/blog/announcements/v20-release-announce.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ The test runner also includes some parts that are not yet stable, including repo
109109
This is a simple example of using the test runner:
110110

111111
```mjs
112-
import { test, mock } from 'node:test';
113112
import assert from 'node:assert';
114113
import fs from 'node:fs';
114+
import { test, mock } from 'node:test';
115115

116116
mock.method(fs, 'readFile', async () => 'Hello World');
117117
test('synchronous passing test', async t => {

apps/site/pages/en/blog/community/domain-postmortem.md

+17-13
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ the originator of the code from knowing about its own exceptions.
2020

2121
Here's an example of how one indirectly linked modules can affect another:
2222

23-
```js
24-
// module a.js
23+
```js displayName="a.js"
24+
const d = require('domain').create();
25+
2526
const b = require('./b');
2627
const c = require('./c');
28+
```
2729

28-
// module b.js
29-
const d = require('domain').create();
30+
```js displayName="b.js"
3031
d.on('error', () => {
3132
/* silence everything */
3233
});
3334
d.enter();
35+
```
3436

35-
// module c.js
37+
```js displayName="c.js"
3638
const dep = require('some-dep');
3739
dep.method(); // Uh-oh! This method doesn't actually exist.
3840
```
@@ -187,11 +189,11 @@ const pipeList = [];
187189
const FILENAME = '/tmp/tmp.tmp';
188190
const PIPENAME = '/tmp/node-domain-example-';
189191
const FILESIZE = 1024;
190-
var uid = 0;
192+
let uid = 0;
191193

192194
// Setting up temporary resources
193195
const buf = Buffer(FILESIZE);
194-
for (var i = 0; i < buf.length; i++) buf[i] = ((Math.random() * 1e3) % 78) + 48; // Basic ASCII
196+
for (let i = 0; i < buf.length; i++) buf[i] = ((Math.random() * 1e3) % 78) + 48; // Basic ASCII
195197
fs.writeFileSync(FILENAME, buf);
196198

197199
function ConnectionResource(c) {
@@ -249,7 +251,7 @@ net
249251

250252
function streamInParts(fd, cr, pos) {
251253
const d2 = domain.create();
252-
var alive = true;
254+
const alive = true;
253255
d2.on('error', er => {
254256
print('d2 error:', er.message);
255257
cr.end();
@@ -301,12 +303,12 @@ function pipeData(cr) {
301303
});
302304
});
303305
cr.on('data', chunk => {
304-
for (var i = 0; i < connectionList.length; i++) {
306+
for (let i = 0; i < connectionList.length; i++) {
305307
connectionList[i].write(chunk);
306308
}
307309
});
308310
cr.on('end', () => {
309-
for (var i = 0; i < connectionList.length; i++) {
311+
for (let i = 0; i < connectionList.length; i++) {
310312
connectionList[i].end();
311313
}
312314
ps.close();
@@ -318,11 +320,13 @@ function pipeData(cr) {
318320
process.on('SIGINT', () => process.exit());
319321
process.on('exit', () => {
320322
try {
321-
for (var i = 0; i < pipeList.length; i++) {
323+
for (let i = 0; i < pipeList.length; i++) {
322324
fs.unlinkSync(pipeList[i]);
323325
}
324326
fs.unlinkSync(FILENAME);
325-
} catch (e) {}
327+
} catch (e) {
328+
// Handle the error here
329+
}
326330
});
327331
```
328332

@@ -410,7 +414,7 @@ DataStream.prototype.data = function data(chunk) {
410414
this.domain.run(function () {
411415
// Simulate an async operation that does the data transform.
412416
setImmediate(() => {
413-
for (var i = 0; i < chunk.length; i++)
417+
for (let i = 0; i < chunk.length; i++)
414418
chunk[i] = ((chunk[i] + Math.random() * 100) % 96) + 33;
415419
// Grab the instance from the active domain and use that
416420
// to call the user's callback.

apps/site/pages/en/blog/feature/streams2.md

+24-23
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ this:
268268
// and an `ondata` member that gets called when it has data, and
269269
// an `onend` member that gets called when the data is over.
270270

271-
var stream = new Readable();
271+
const stream = new Readable();
272272

273273
source.ondata = function (chunk) {
274274
// if push() returns false, then we need to stop reading from source
@@ -316,15 +316,14 @@ function SimpleProtocol(source, options) {
316316
// source is a readable stream, such as a socket or file
317317
this._source = source;
318318

319-
var self = this;
320-
source.on('end', function () {
321-
self.push(null);
319+
source.on('end', () => {
320+
this.push(null);
322321
});
323322

324323
// give it a kick whenever the source is readable
325324
// read(0) will not consume any bytes
326-
source.on('readable', function () {
327-
self.read(0);
325+
source.on('readable', () => {
326+
this.read(0);
328327
});
329328

330329
this._rawHeader = [];
@@ -337,14 +336,14 @@ SimpleProtocol.prototype = Object.create(Readable.prototype, {
337336

338337
SimpleProtocol.prototype._read = function (n) {
339338
if (!this._inBody) {
340-
var chunk = this._source.read();
339+
const chunk = this._source.read();
341340

342341
// if the source doesn't have data, we don't have data yet.
343342
if (chunk === null) return this.push('');
344343

345344
// check if the chunk has a \n\n
346-
var split = -1;
347-
for (var i = 0; i < chunk.length; i++) {
345+
let split = -1;
346+
for (let i = 0; i < chunk.length; i++) {
348347
if (chunk[i] === 10) {
349348
// '\n'
350349
if (this._sawFirstCr) {
@@ -365,9 +364,9 @@ SimpleProtocol.prototype._read = function (n) {
365364
this.push('');
366365
} else {
367366
this._inBody = true;
368-
var h = chunk.slice(0, split);
367+
const h = chunk.slice(0, split);
369368
this._rawHeader.push(h);
370-
var header = Buffer.concat(this._rawHeader).toString();
369+
const header = Buffer.concat(this._rawHeader).toString();
371370
try {
372371
this.header = JSON.parse(header);
373372
} catch (er) {
@@ -376,7 +375,7 @@ SimpleProtocol.prototype._read = function (n) {
376375
}
377376
// now, because we got some extra data, unshift the rest
378377
// back into the read queue so that our consumer will see it.
379-
var b = chunk.slice(split);
378+
const b = chunk.slice(split);
380379
this.unshift(b);
381380

382381
// and let them know that we are done parsing the header.
@@ -385,13 +384,13 @@ SimpleProtocol.prototype._read = function (n) {
385384
} else {
386385
// from there on, just provide the data to our consumer.
387386
// careful not to push(null), since that would indicate EOF.
388-
var chunk = this._source.read();
387+
const chunk = this._source.read();
389388
if (chunk) this.push(chunk);
390389
}
391390
};
392391

393392
// Usage:
394-
var parser = new SimpleProtocol(source);
393+
const parser = new SimpleProtocol(source);
395394
// Now parser is a readable stream that will emit 'header'
396395
// with the parsed header data.
397396
```
@@ -408,10 +407,12 @@ as its data source.
408407
For example:
409408
410409
```javascript
411-
var OldReader = require('./old-api-module.js').OldReader;
412-
var oreader = new OldReader();
413-
var Readable = require('stream').Readable;
414-
var myReader = new Readable().wrap(oreader);
410+
const Readable = require('stream').Readable;
411+
412+
const OldReader = require('./old-api-module.js').OldReader;
413+
414+
const oreader = new OldReader();
415+
const myReader = new Readable().wrap(oreader);
415416

416417
myReader.on('readable', function () {
417418
myReader.read(); // etc.
@@ -793,8 +794,8 @@ SimpleProtocol.prototype = Object.create(Transform.prototype, {
793794
SimpleProtocol.prototype._transform = function (chunk, encoding, done) {
794795
if (!this._inBody) {
795796
// check if the chunk has a \n\n
796-
var split = -1;
797-
for (var i = 0; i < chunk.length; i++) {
797+
let split = -1;
798+
for (let i = 0; i < chunk.length; i++) {
798799
if (chunk[i] === 10) {
799800
// '\n'
800801
if (this._sawFirstCr) {
@@ -814,9 +815,9 @@ SimpleProtocol.prototype._transform = function (chunk, encoding, done) {
814815
this._rawHeader.push(chunk);
815816
} else {
816817
this._inBody = true;
817-
var h = chunk.slice(0, split);
818+
const h = chunk.slice(0, split);
818819
this._rawHeader.push(h);
819-
var header = Buffer.concat(this._rawHeader).toString();
820+
const header = Buffer.concat(this._rawHeader).toString();
820821
try {
821822
this.header = JSON.parse(header);
822823
} catch (er) {
@@ -836,7 +837,7 @@ SimpleProtocol.prototype._transform = function (chunk, encoding, done) {
836837
done();
837838
};
838839

839-
var parser = new SimpleProtocol();
840+
const parser = new SimpleProtocol();
840841
source.pipe(parser);
841842

842843
// Now parser is a readable stream that will emit 'header'

apps/site/pages/en/blog/module/service-logging-in-json-with-bunyan.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ make
122122
Our [server](https://github.com/trentm/hello-json-logging/blob/master/server.js) first creates a Bunyan logger:
123123

124124
```javascript
125-
var Logger = require('bunyan');
126-
var log = new Logger({
125+
const Logger = require('bunyan');
126+
const log = new Logger({
127127
name: 'helloapi',
128128
streams: [
129129
{
@@ -153,7 +153,7 @@ Bunyan has the concept of **serializers**: a registry of functions that know how
153153
Restify 1.x and above has bunyan support baked in. You pass in your Bunyan logger like this:
154154

155155
```javascript
156-
var server = restify.createServer({
156+
const server = restify.createServer({
157157
name: 'Hello API',
158158
log: log, // Pass our logger to restify.
159159
});
@@ -163,7 +163,7 @@ Our simple API will have a single `GET /hello?name=NAME` endpoint:
163163

164164
```javascript
165165
server.get({ path: '/hello', name: 'SayHello' }, function (req, res, next) {
166-
var caller = req.params.name || 'caller';
166+
const caller = req.params.name || 'caller';
167167
req.log.debug('caller is "%s"', caller);
168168
res.send({ hello: caller });
169169
return next();
@@ -205,7 +205,7 @@ server.pre(function (request, response, next) {
205205
This is the first time we've seen this `log.info` style with an object as the first argument. Bunyan logging methods (`log.trace`, `log.debug`, ...) all support an optional **first object argument with extra log record fields**:
206206

207207
```javascript
208-
log.info(<object> fields, <string> msg, ...)
208+
log.info(/* object */ fields, /* string */ msg /* ... */);
209209
```
210210

211211
Here we pass in the restify Request object, `req`. The "req" serializer we registered above will come into play here, but bear with me.
@@ -250,8 +250,9 @@ Here is the server log:
250250

251251
Lets look at each in turn to see what is interesting -- pretty-printed with `node server.js | ./node_modules/.bin/bunyan -j`:
252252

253-
```javascript
254-
{ // (1)
253+
```json
254+
{
255+
// (1)
255256
"name": "helloapi",
256257
"hostname": "banana.local",
257258
"pid": 40442,
@@ -277,8 +278,9 @@ Here we logged the incoming request with `request.log.info({req: request}, 'star
277278

278279
Next the `req.log.debug` in our handler:
279280

280-
```javascript
281-
{ // (2)
281+
```json
282+
{
283+
// (2)
282284
"name": "helloapi",
283285
"hostname": "banana.local",
284286
"pid": 40442,
@@ -293,8 +295,9 @@ Next the `req.log.debug` in our handler:
293295

294296
and the log of response in the "after" event:
295297

296-
```javascript
297-
{ // (3)
298+
```json
299+
{
300+
// (3)
298301
"name": "helloapi",
299302
"hostname": "banana.local",
300303
"pid": 40442,

apps/site/pages/en/blog/release/v12.17.0.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ HTTP request entering in a server, it will be possible to retrieve this id
4949
without having access the current HTTP request:
5050

5151
```js
52-
const http = require('http');
5352
const { AsyncLocalStorage } = require('async_hooks');
53+
const http = require('http');
5454

5555
const asyncLocalStorage = new AsyncLocalStorage();
5656

apps/site/pages/en/blog/release/v16.14.0.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This release adds experimental support for the import assertions stage 3 proposa
1515
To keep Node.js ESM implementation as compatible as possible with the HTML spec, import assertions are now required to import JSON modules (still behind the `--experimental-json-modules` CLI flag):
1616

1717
```mjs
18-
import info from `./package.json` assert { type: `json` };
18+
import info from './package.json' assert { type: `json` };
1919
```
2020

2121
Or use dynamic import:

0 commit comments

Comments
 (0)