Skip to content

Commit 8399766

Browse files
aduh95targos
authored andcommitted
tools: add support for mjs and cjs JS snippet linting
Refs: #37162 Refs: nodejs/remark-preset-lint-node#176 PR-URL: #37311 Refs: eslint/markdown#172 Reviewed-By: Rich Trott <[email protected]>
1 parent 2463bd0 commit 8399766

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

.eslintrc.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ module.exports = {
5353
overrides: [
5454
{
5555
files: [
56-
'doc/api/esm.md/*.js',
57-
'doc/api/module.md/*.js',
58-
'doc/api/modules.md/*.js',
59-
'doc/api/packages.md/*.js',
60-
'doc/api/wasi.md/*.js',
6156
'test/es-module/test-esm-type-flag.js',
6257
'test/es-module/test-esm-type-flag-alias.js',
6358
'*.mjs',
@@ -70,10 +65,21 @@ module.exports = {
7065
processor: 'markdown/markdown',
7166
},
7267
{
73-
files: ['**/*.md/*.js'],
74-
parserOptions: { ecmaFeatures: { impliedStrict: true } },
68+
files: ['**/*.md/*.cjs', '**/*.md/*.js'],
69+
parserOptions: {
70+
sourceType: 'script',
71+
ecmaFeatures: { impliedStrict: true }
72+
},
7573
rules: { strict: 'off' },
7674
},
75+
{
76+
files: [
77+
'**/*.md/*.mjs',
78+
'doc/api/esm.md/*.js',
79+
'doc/api/packages.md/*.js',
80+
],
81+
parserOptions: { sourceType: 'module' },
82+
},
7783
],
7884
rules: {
7985
// ESLint built-in rules

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,7 @@ lint-js-fix:
12331233
.PHONY: lint-js-doc
12341234
# Note that on the CI `lint-js-ci` is run instead.
12351235
# Lints the JavaScript code with eslint.
1236+
lint-js-doc: LINT_JS_TARGETS=doc
12361237
lint-js lint-js-doc:
12371238
@if [ "$(shell $(node_use_openssl))" != "true" ]; then \
12381239
echo "Skipping $@ (no crypto)"; \

doc/api/buffer.md

-2
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,6 @@ buf.writeFloatBE(0xcafebabe, 0);
24922492

24932493
console.log(buf);
24942494
// Prints: <Buffer 4f 4a fe bb>
2495-
24962495
```
24972496

24982497
### `buf.writeFloatLE(value[, offset])`
@@ -2701,7 +2700,6 @@ buf.writeIntBE(0x1234567890ab, 0, 6);
27012700

27022701
console.log(buf);
27032702
// Prints: <Buffer 12 34 56 78 90 ab>
2704-
27052703
```
27062704

27072705
### `buf.writeIntLE(value, offset, byteLength)`

doc/api/module.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ if a module is maintained by a third party or not.
2929
`module` in this context isn't the same object that's provided
3030
by the [module wrapper][]. To access it, require the `Module` module:
3131

32-
```js
32+
```mjs
3333
// module.mjs
3434
// In an ECMAScript module
3535
import { builtinModules as builtin } from 'module';
3636
```
3737

38-
```js
38+
```cjs
3939
// module.cjs
4040
// In a CommonJS module
4141
const builtin = require('module').builtinModules;
@@ -51,7 +51,7 @@ added: v12.2.0
5151
string.
5252
* Returns: {require} Require function
5353

54-
```js
54+
```mjs
5555
import { createRequire } from 'module';
5656
const require = createRequire(import.meta.url);
5757

@@ -134,13 +134,13 @@ To enable source map parsing, Node.js must be run with the flag
134134
[`--enable-source-maps`][], or with code coverage enabled by setting
135135
[`NODE_V8_COVERAGE=dir`][].
136136
137-
```js
137+
```mjs
138138
// module.mjs
139139
// In an ECMAScript module
140140
import { findSourceMap, SourceMap } from 'module';
141141
```
142142
143-
```js
143+
```cjs
144144
// module.cjs
145145
// In a CommonJS module
146146
const { findSourceMap, SourceMap } = require('module');

doc/api/wasi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The WASI API provides an implementation of the [WebAssembly System Interface][]
1010
specification. WASI gives sandboxed WebAssembly applications access to the
1111
underlying operating system via a collection of POSIX-like functions.
1212

13-
```js
13+
```mjs
1414
import fs from 'fs';
1515
import { WASI } from 'wasi';
1616

doc/guides/writing-tests.md

-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ const server = http.createServer(common.mustCall((req, res) => {
221221
server.close();
222222
}));
223223
}));
224-
225224
```
226225

227226
**Note:** Many functions invoke their callback with an `err` value as the first

0 commit comments

Comments
 (0)