diff --git a/.eslintrc.js b/.eslintrc.js index e82e1afcae2b6b..9340889b83dc5d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -53,11 +53,6 @@ module.exports = { overrides: [ { files: [ - 'doc/api/esm.md/*.js', - 'doc/api/module.md/*.js', - 'doc/api/modules.md/*.js', - 'doc/api/packages.md/*.js', - 'doc/api/wasi.md/*.js', 'test/es-module/test-esm-type-flag.js', 'test/es-module/test-esm-type-flag-alias.js', '*.mjs', @@ -70,10 +65,21 @@ module.exports = { processor: 'markdown/markdown', }, { - files: ['**/*.md/*.js'], - parserOptions: { ecmaFeatures: { impliedStrict: true } }, + files: ['**/*.md/*.cjs', '**/*.md/*.js'], + parserOptions: { + sourceType: 'script', + ecmaFeatures: { impliedStrict: true } + }, rules: { strict: 'off' }, }, + { + files: [ + '**/*.md/*.mjs', + 'doc/api/esm.md/*.js', + 'doc/api/packages.md/*.js', + ], + parserOptions: { sourceType: 'module' }, + }, ], rules: { // ESLint built-in rules diff --git a/Makefile b/Makefile index 72c0d815361423..ebe2fc0c83556f 100644 --- a/Makefile +++ b/Makefile @@ -1233,6 +1233,7 @@ lint-js-fix: .PHONY: lint-js-doc # Note that on the CI `lint-js-ci` is run instead. # Lints the JavaScript code with eslint. +lint-js-doc: LINT_JS_TARGETS=doc lint-js lint-js-doc: @if [ "$(shell $(node_use_openssl))" != "true" ]; then \ echo "Skipping $@ (no crypto)"; \ diff --git a/doc/api/buffer.md b/doc/api/buffer.md index c0b4a99b540fe9..c1423229ca6a34 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -2492,7 +2492,6 @@ buf.writeFloatBE(0xcafebabe, 0); console.log(buf); // Prints: - ``` ### `buf.writeFloatLE(value[, offset])` @@ -2701,7 +2700,6 @@ buf.writeIntBE(0x1234567890ab, 0, 6); console.log(buf); // Prints: - ``` ### `buf.writeIntLE(value, offset, byteLength)` diff --git a/doc/api/module.md b/doc/api/module.md index 983f0a5969fcc9..65744b68d95a8e 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -29,13 +29,13 @@ if a module is maintained by a third party or not. `module` in this context isn't the same object that's provided by the [module wrapper][]. To access it, require the `Module` module: -```js +```mjs // module.mjs // In an ECMAScript module import { builtinModules as builtin } from 'module'; ``` -```js +```cjs // module.cjs // In a CommonJS module const builtin = require('module').builtinModules; @@ -51,7 +51,7 @@ added: v12.2.0 string. * Returns: {require} Require function -```js +```mjs import { createRequire } from 'module'; const require = createRequire(import.meta.url); @@ -134,13 +134,13 @@ To enable source map parsing, Node.js must be run with the flag [`--enable-source-maps`][], or with code coverage enabled by setting [`NODE_V8_COVERAGE=dir`][]. -```js +```mjs // module.mjs // In an ECMAScript module import { findSourceMap, SourceMap } from 'module'; ``` -```js +```cjs // module.cjs // In a CommonJS module const { findSourceMap, SourceMap } = require('module'); diff --git a/doc/api/wasi.md b/doc/api/wasi.md index 100e7eac3eb94a..e72eac2091003b 100644 --- a/doc/api/wasi.md +++ b/doc/api/wasi.md @@ -10,7 +10,7 @@ The WASI API provides an implementation of the [WebAssembly System Interface][] specification. WASI gives sandboxed WebAssembly applications access to the underlying operating system via a collection of POSIX-like functions. -```js +```mjs import fs from 'fs'; import { WASI } from 'wasi'; diff --git a/doc/guides/writing-tests.md b/doc/guides/writing-tests.md index 29facf4cc25527..8424f744d16927 100644 --- a/doc/guides/writing-tests.md +++ b/doc/guides/writing-tests.md @@ -221,7 +221,6 @@ const server = http.createServer(common.mustCall((req, res) => { server.close(); })); })); - ``` **Note:** Many functions invoke their callback with an `err` value as the first