Skip to content

Commit a63ed72

Browse files
authored
refactor: Use node: protocol for built-in Node.js modules (#18434)
1 parent 04e7c6e commit a63ed72

Some content is hidden

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

57 files changed

+126
-117
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
"use strict";
1818

19-
const path = require("path");
19+
const path = require("node:path");
2020

2121
const INTERNAL_FILES = {
2222
CLI_ENGINE_PATTERN: "lib/cli-engine/**/*",

Makefile.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
const checker = require("npm-license"),
1414
ReleaseOps = require("eslint-release"),
15-
fs = require("fs"),
15+
fs = require("node:fs"),
1616
glob = require("glob"),
1717
marked = require("marked"),
1818
matter = require("gray-matter"),
19-
os = require("os"),
20-
path = require("path"),
19+
os = require("node:os"),
20+
path = require("node:path"),
2121
semver = require("semver"),
2222
ejs = require("ejs"),
2323
loadPerf = require("load-perf"),
@@ -885,7 +885,7 @@ target.checkRuleFiles = function() {
885885
};
886886

887887
target.checkRuleExamples = function() {
888-
const { execFileSync } = require("child_process");
888+
const { execFileSync } = require("node:child_process");
889889

890890
// We don't need the stack trace of execFileSync if the command fails.
891891
try {

bin/eslint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function readStdin() {
6464
function getErrorMessage(error) {
6565

6666
// Lazy loading because this is used only if an error happened.
67-
const util = require("util");
67+
const util = require("node:util");
6868

6969
// Foolproof -- third-party module might throw non-object.
7070
if (typeof error !== "object" || error === null) {

docs/.eleventy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const pluginTOC = require("eleventy-plugin-nesting-toc");
77
const markdownItAnchor = require("markdown-it-anchor");
88
const markdownItContainer = require("markdown-it-container");
99
const Image = require("@11ty/eleventy-img");
10-
const path = require("path");
10+
const path = require("node:path");
1111
const { slug } = require("github-slugger");
1212
const yaml = require("js-yaml");
1313
const { highlighter, lineNumberPlugin } = require("./src/_plugins/md-syntax-highlighter");

docs/src/_data/site.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// Requirements
1010
//-----------------------------------------------------------------------------
1111

12-
const path = require("path");
13-
const fs = require("fs");
12+
const path = require("node:path");
13+
const fs = require("node:fs");
1414
const yaml = require("js-yaml");
1515

1616
//-----------------------------------------------------------------------------

docs/tools/validate-links.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const path = require("path");
3+
const path = require("node:path");
44
const TapRender = require("@munter/tap-render");
55
const spot = require("tap-spot");
66
const hyperlink = require("hyperlink");

eslint.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// Requirements
2626
//-----------------------------------------------------------------------------
2727

28-
const path = require("path");
28+
const path = require("node:path");
2929
const internalPlugin = require("eslint-plugin-internal-rules");
3030
const eslintPluginRulesRecommendedConfig = require("eslint-plugin-eslint-plugin/configs/rules-recommended");
3131
const eslintPluginTestsRecommendedConfig = require("eslint-plugin-eslint-plugin/configs/tests-recommended");

lib/cli-engine/cli-engine.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// Requirements
1616
//------------------------------------------------------------------------------
1717

18-
const fs = require("fs");
19-
const path = require("path");
18+
const fs = require("node:fs");
19+
const path = require("node:path");
2020
const defaultOptions = require("../../conf/default-cli-options");
2121
const pkg = require("../../package.json");
2222

lib/cli-engine/file-enumerator.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
// Requirements
3535
//------------------------------------------------------------------------------
3636

37-
const fs = require("fs");
38-
const path = require("path");
37+
const fs = require("node:fs");
38+
const path = require("node:path");
3939
const getGlobParent = require("glob-parent");
4040
const isGlob = require("is-glob");
4141
const escapeRegExp = require("escape-string-regexp");

lib/cli-engine/lint-result-cache.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// Requirements
99
//-----------------------------------------------------------------------------
1010

11-
const assert = require("assert");
12-
const fs = require("fs");
11+
const assert = require("node:assert");
12+
const fs = require("node:fs");
1313
const fileEntryCache = require("file-entry-cache");
1414
const stringify = require("json-stable-stringify-without-jsonify");
1515
const pkg = require("../../package.json");

lib/cli-engine/load-rules.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// Requirements
1010
//------------------------------------------------------------------------------
1111

12-
const fs = require("fs"),
13-
path = require("path");
12+
const fs = require("node:fs"),
13+
path = require("node:path");
1414

1515
const rulesDirCache = {};
1616

lib/cli.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
// Requirements
1616
//------------------------------------------------------------------------------
1717

18-
const fs = require("fs"),
19-
path = require("path"),
20-
{ promisify } = require("util"),
18+
const fs = require("node:fs"),
19+
path = require("node:path"),
20+
{ promisify } = require("node:util"),
2121
{ LegacyESLint } = require("./eslint"),
2222
{ ESLint, shouldUseFlatConfig, locateConfigFileToUse } = require("./eslint/eslint"),
2323
createCLIOptions = require("./options"),

lib/eslint/eslint-helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// Requirements
1010
//-----------------------------------------------------------------------------
1111

12-
const path = require("path");
13-
const fs = require("fs");
12+
const path = require("node:path");
13+
const fs = require("node:fs");
1414
const fsp = fs.promises;
1515
const isGlob = require("is-glob");
1616
const hash = require("../cli-engine/hash");

lib/eslint/eslint.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// Requirements
1010
//------------------------------------------------------------------------------
1111

12-
const fs = require("fs/promises");
13-
const { existsSync } = require("fs");
14-
const path = require("path");
12+
const fs = require("node:fs/promises");
13+
const { existsSync } = require("node:fs");
14+
const path = require("node:path");
1515
const findUp = require("find-up");
1616
const { version } = require("../../package.json");
1717
const { Linter } = require("../linter");
@@ -38,7 +38,7 @@ const {
3838

3939
processOptions
4040
} = require("./eslint-helpers");
41-
const { pathToFileURL } = require("url");
41+
const { pathToFileURL } = require("node:url");
4242
const { FlatConfigArray } = require("../config/flat-config-array");
4343
const LintResultCache = require("../cli-engine/lint-result-cache");
4444
const { Retrier } = require("@humanwhocodes/retry");

lib/eslint/legacy-eslint.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
// Requirements
1111
//------------------------------------------------------------------------------
1212

13-
const path = require("path");
14-
const fs = require("fs");
15-
const { promisify } = require("util");
13+
const path = require("node:path");
14+
const fs = require("node:fs");
15+
const { promisify } = require("node:util");
1616
const { CLIEngine, getCLIEngineInternalSlots } = require("../cli-engine/cli-engine");
1717
const BuiltinRules = require("../rules");
1818
const {

lib/linter/code-path-analysis/code-path-analyzer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Requirements
1010
//------------------------------------------------------------------------------
1111

12-
const assert = require("assert"),
12+
const assert = require("node:assert"),
1313
{ breakableTypePattern } = require("../../shared/ast-utils"),
1414
CodePath = require("./code-path"),
1515
CodePathSegment = require("./code-path-segment"),

lib/linter/code-path-analysis/fork-context.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Requirements
1414
//------------------------------------------------------------------------------
1515

16-
const assert = require("assert"),
16+
const assert = require("node:assert"),
1717
CodePathSegment = require("./code-path-segment");
1818

1919
//------------------------------------------------------------------------------

lib/linter/linter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//------------------------------------------------------------------------------
1212

1313
const
14-
path = require("path"),
14+
path = require("node:path"),
1515
eslintScope = require("eslint-scope"),
1616
evk = require("eslint-visitor-keys"),
1717
espree = require("espree"),

lib/linter/report-translator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Requirements
1010
//------------------------------------------------------------------------------
1111

12-
const assert = require("assert");
12+
const assert = require("node:assert");
1313
const ruleFixer = require("./rule-fixer");
1414
const { interpolate } = require("./interpolate");
1515

lib/rule-tester/rule-tester.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
//------------------------------------------------------------------------------
1212

1313
const
14-
assert = require("assert"),
15-
util = require("util"),
16-
path = require("path"),
14+
assert = require("node:assert"),
15+
util = require("node:util"),
16+
path = require("node:path"),
1717
equal = require("fast-deep-equal"),
1818
Traverser = require("../shared/traverser"),
1919
{ getRuleOptionsSchema } = require("../config/flat-config-helpers"),

lib/shared/runtime-info.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// Requirements
1010
//------------------------------------------------------------------------------
1111

12-
const path = require("path");
12+
const path = require("node:path");
1313
const spawn = require("cross-spawn");
14-
const os = require("os");
14+
const os = require("node:os");
1515
const log = require("../shared/logging");
1616
const packageJson = require("../../package.json");
1717

lib/source-code/token-store/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Requirements
99
//------------------------------------------------------------------------------
1010

11-
const assert = require("assert");
11+
const assert = require("node:assert");
1212
const { isCommentToken } = require("@eslint-community/eslint-utils");
1313
const cursors = require("./cursors");
1414
const ForwardTokenCursor = require("./forward-token-cursor");

packages/eslint-config-eslint/nodejs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const recommendedModuleConfig = require("eslint-plugin-n/configs/recommended-mod
55

66
const sharedRules = {
77
"n/callback-return": ["error", ["cb", "callback", "next"]],
8-
"n/handle-callback-err": ["error", "err"]
8+
"n/handle-callback-err": ["error", "err"],
9+
"n/prefer-node-protocol": "error"
910
};
1011

1112
const cjsConfigs = [

tests/_utils/test-lazy-loading-rules.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
"use strict";
1313

14-
const path = require("path");
15-
const assert = require("assert");
14+
const path = require("node:path");
15+
const assert = require("node:assert");
1616
const { addHook } = require("pirates");
1717

1818
const {

tests/bin/eslint.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
// Requirements
1010
//-----------------------------------------------------------------------------
1111

12-
const childProcess = require("child_process");
13-
const fs = require("fs");
12+
const childProcess = require("node:child_process");
13+
const fs = require("node:fs");
1414
const assert = require("chai").assert;
15-
const path = require("path");
15+
const path = require("node:path");
1616

1717
//------------------------------------------------------------------------------
1818
// Data

tests/lib/cli-engine/cli-engine.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
//------------------------------------------------------------------------------
1111

1212
const assert = require("chai").assert,
13-
path = require("path"),
13+
path = require("node:path"),
1414
sinon = require("sinon"),
1515
shell = require("shelljs"),
16-
fs = require("fs"),
17-
os = require("os"),
16+
fs = require("node:fs"),
17+
os = require("node:os"),
1818
hash = require("../../../lib/cli-engine/hash"),
1919
{
2020
Legacy: {
@@ -787,7 +787,7 @@ describe("CLIEngine", () => {
787787

788788
// @scope for @scope/eslint-plugin
789789
describe("(plugin shorthand)", () => {
790-
const Module = require("module");
790+
const Module = require("node:module");
791791
let originalFindPath = null;
792792

793793
/* eslint-disable no-underscore-dangle -- Private Node API overriding */
@@ -5123,7 +5123,7 @@ describe("CLIEngine", () => {
51235123
writeFileSync() {}
51245124
},
51255125
localCLIEngine = proxyquire("../../../lib/cli-engine/cli-engine", {
5126-
fs: fakeFS
5126+
"node:fs": fakeFS
51275127
}).CLIEngine,
51285128
report = {
51295129
results: [
@@ -5153,7 +5153,7 @@ describe("CLIEngine", () => {
51535153
writeFileSync() {}
51545154
},
51555155
localCLIEngine = proxyquire("../../../lib/cli-engine/cli-engine", {
5156-
fs: fakeFS
5156+
"node:fs": fakeFS
51575157
}).CLIEngine,
51585158
report = {
51595159
results: [

tests/lib/cli-engine/file-enumerator.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// Requirements
99
//------------------------------------------------------------------------------
1010

11-
const fs = require("fs");
12-
const path = require("path");
13-
const os = require("os");
11+
const fs = require("node:fs");
12+
const path = require("node:path");
13+
const os = require("node:os");
1414
const { assert } = require("chai");
1515
const sh = require("shelljs");
1616
const sinon = require("sinon");

tests/lib/cli-engine/lint-result-cache.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
const assert = require("chai").assert,
1212
{ CLIEngine } = require("../../../lib/cli-engine"),
13-
fs = require("fs"),
14-
path = require("path"),
13+
fs = require("node:fs"),
14+
path = require("node:path"),
1515
proxyquire = require("proxyquire"),
1616
sinon = require("sinon");
1717

tests/lib/cli.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
//------------------------------------------------------------------------------
1616

1717
const assert = require("chai").assert,
18-
stdAssert = require("assert"),
18+
stdAssert = require("node:assert"),
1919
{ ESLint, LegacyESLint } = require("../../lib/eslint"),
2020
BuiltinRules = require("../../lib/rules"),
21-
path = require("path"),
21+
path = require("node:path"),
2222
sinon = require("sinon"),
23-
fs = require("fs"),
24-
os = require("os"),
23+
fs = require("node:fs"),
24+
os = require("node:os"),
2525
sh = require("shelljs");
2626

2727
const proxyquire = require("proxyquire").noCallThru().noPreserveCache();

0 commit comments

Comments
 (0)