Skip to content

Commit 07fc61b

Browse files
aduh95danielleadams
authored andcommittedMar 16, 2021
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 <rtrott@gmail.com>
1 parent f50db89 commit 07fc61b

File tree

7 files changed

+20
-18
lines changed

7 files changed

+20
-18
lines changed
 

‎.eslintrc.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ module.exports = {
5353
overrides: [
5454
{
5555
files: [
56-
'doc/api/esm.md/*.js',
57-
'doc/api/fs.md/*.js',
58-
'doc/api/module.md/*.js',
59-
'doc/api/modules.md/*.js',
60-
'doc/api/packages.md/*.js',
61-
'doc/api/wasi.md/*.js',
6256
'test/es-module/test-esm-type-flag.js',
6357
'test/es-module/test-esm-type-flag-alias.js',
6458
'*.mjs',
@@ -71,10 +65,21 @@ module.exports = {
7165
processor: 'markdown/markdown',
7266
},
7367
{
74-
files: ['**/*.md/*.js'],
75-
parserOptions: { ecmaFeatures: { impliedStrict: true } },
68+
files: ['**/*.md/*.cjs', '**/*.md/*.js'],
69+
parserOptions: {
70+
sourceType: 'script',
71+
ecmaFeatures: { impliedStrict: true }
72+
},
7673
rules: { strict: 'off' },
7774
},
75+
{
76+
files: [
77+
'**/*.md/*.mjs',
78+
'doc/api/esm.md/*.js',
79+
'doc/api/packages.md/*.js',
80+
],
81+
parserOptions: { sourceType: 'module' },
82+
},
7883
],
7984
rules: {
8085
// ESLint built-in rules

‎Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ lint-js-fix:
12201220
.PHONY: lint-js-doc
12211221
# Note that on the CI `lint-js-ci` is run instead.
12221222
# Lints the JavaScript code with eslint.
1223+
lint-js-doc: LINT_JS_TARGETS=doc
12231224
lint-js lint-js-doc:
12241225
@if [ "$(shell $(node_use_openssl))" != "true" ]; then \
12251226
echo "Skipping $@ (no crypto)"; \

‎doc/api/buffer.md

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

26482648
console.log(buf);
26492649
// Prints: <Buffer 4f 4a fe bb>
2650-
26512650
```
26522651

26532652
### `buf.writeFloatLE(value[, offset])`
@@ -2856,7 +2855,6 @@ buf.writeIntBE(0x1234567890ab, 0, 6);
28562855

28572856
console.log(buf);
28582857
// Prints: <Buffer 12 34 56 78 90 ab>
2859-
28602858
```
28612859

28622860
### `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/stream.md

-1
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,6 @@ const myWritable = new Writable({
20902090
});
20912091
// Later, abort the operation closing the stream
20922092
controller.abort();
2093-
20942093
```
20952094
#### `writable._construct(callback)`
20962095
<!-- YAML

‎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)