Skip to content

Commit

Permalink
refactor: Use node: protocol for built-in Node.js modules (#18434)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored May 9, 2024
1 parent 04e7c6e commit a63ed72
Show file tree
Hide file tree
Showing 57 changed files with 126 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

"use strict";

const path = require("path");
const path = require("node:path");

const INTERNAL_FILES = {
CLI_ENGINE_PATTERN: "lib/cli-engine/**/*",
Expand Down
8 changes: 4 additions & 4 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

const checker = require("npm-license"),
ReleaseOps = require("eslint-release"),
fs = require("fs"),
fs = require("node:fs"),
glob = require("glob"),
marked = require("marked"),
matter = require("gray-matter"),
os = require("os"),
path = require("path"),
os = require("node:os"),
path = require("node:path"),
semver = require("semver"),
ejs = require("ejs"),
loadPerf = require("load-perf"),
Expand Down Expand Up @@ -885,7 +885,7 @@ target.checkRuleFiles = function() {
};

target.checkRuleExamples = function() {
const { execFileSync } = require("child_process");
const { execFileSync } = require("node:child_process");

// We don't need the stack trace of execFileSync if the command fails.
try {
Expand Down
2 changes: 1 addition & 1 deletion bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function readStdin() {
function getErrorMessage(error) {

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

// Foolproof -- third-party module might throw non-object.
if (typeof error !== "object" || error === null) {
Expand Down
2 changes: 1 addition & 1 deletion docs/.eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const pluginTOC = require("eleventy-plugin-nesting-toc");
const markdownItAnchor = require("markdown-it-anchor");
const markdownItContainer = require("markdown-it-container");
const Image = require("@11ty/eleventy-img");
const path = require("path");
const path = require("node:path");
const { slug } = require("github-slugger");
const yaml = require("js-yaml");
const { highlighter, lineNumberPlugin } = require("./src/_plugins/md-syntax-highlighter");
Expand Down
4 changes: 2 additions & 2 deletions docs/src/_data/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Requirements
//-----------------------------------------------------------------------------

const path = require("path");
const fs = require("fs");
const path = require("node:path");
const fs = require("node:fs");
const yaml = require("js-yaml");

//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/validate-links.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const path = require("path");
const path = require("node:path");
const TapRender = require("@munter/tap-render");
const spot = require("tap-spot");
const hyperlink = require("hyperlink");
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// Requirements
//-----------------------------------------------------------------------------

const path = require("path");
const path = require("node:path");
const internalPlugin = require("eslint-plugin-internal-rules");
const eslintPluginRulesRecommendedConfig = require("eslint-plugin-eslint-plugin/configs/rules-recommended");
const eslintPluginTestsRecommendedConfig = require("eslint-plugin-eslint-plugin/configs/tests-recommended");
Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
const defaultOptions = require("../../conf/default-cli-options");
const pkg = require("../../package.json");

Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/file-enumerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
const getGlobParent = require("glob-parent");
const isGlob = require("is-glob");
const escapeRegExp = require("escape-string-regexp");
Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/lint-result-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// Requirements
//-----------------------------------------------------------------------------

const assert = require("assert");
const fs = require("fs");
const assert = require("node:assert");
const fs = require("node:fs");
const fileEntryCache = require("file-entry-cache");
const stringify = require("json-stable-stringify-without-jsonify");
const pkg = require("../../package.json");
Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/load-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs"),
path = require("path");
const fs = require("node:fs"),
path = require("node:path");

const rulesDirCache = {};

Expand Down
6 changes: 3 additions & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs"),
path = require("path"),
{ promisify } = require("util"),
const fs = require("node:fs"),
path = require("node:path"),
{ promisify } = require("node:util"),
{ LegacyESLint } = require("./eslint"),
{ ESLint, shouldUseFlatConfig, locateConfigFileToUse } = require("./eslint/eslint"),
createCLIOptions = require("./options"),
Expand Down
4 changes: 2 additions & 2 deletions lib/eslint/eslint-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Requirements
//-----------------------------------------------------------------------------

const path = require("path");
const fs = require("fs");
const path = require("node:path");
const fs = require("node:fs");
const fsp = fs.promises;
const isGlob = require("is-glob");
const hash = require("../cli-engine/hash");
Expand Down
8 changes: 4 additions & 4 deletions lib/eslint/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs/promises");
const { existsSync } = require("fs");
const path = require("path");
const fs = require("node:fs/promises");
const { existsSync } = require("node:fs");
const path = require("node:path");
const findUp = require("find-up");
const { version } = require("../../package.json");
const { Linter } = require("../linter");
Expand All @@ -38,7 +38,7 @@ const {

processOptions
} = require("./eslint-helpers");
const { pathToFileURL } = require("url");
const { pathToFileURL } = require("node:url");
const { FlatConfigArray } = require("../config/flat-config-array");
const LintResultCache = require("../cli-engine/lint-result-cache");
const { Retrier } = require("@humanwhocodes/retry");
Expand Down
6 changes: 3 additions & 3 deletions lib/eslint/legacy-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
// Requirements
//------------------------------------------------------------------------------

const path = require("path");
const fs = require("fs");
const { promisify } = require("util");
const path = require("node:path");
const fs = require("node:fs");
const { promisify } = require("node:util");
const { CLIEngine, getCLIEngineInternalSlots } = require("../cli-engine/cli-engine");
const BuiltinRules = require("../rules");
const {
Expand Down
2 changes: 1 addition & 1 deletion lib/linter/code-path-analysis/code-path-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Requirements
//------------------------------------------------------------------------------

const assert = require("assert"),
const assert = require("node:assert"),
{ breakableTypePattern } = require("../../shared/ast-utils"),
CodePath = require("./code-path"),
CodePathSegment = require("./code-path-segment"),
Expand Down
2 changes: 1 addition & 1 deletion lib/linter/code-path-analysis/fork-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Requirements
//------------------------------------------------------------------------------

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

//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//------------------------------------------------------------------------------

const
path = require("path"),
path = require("node:path"),
eslintScope = require("eslint-scope"),
evk = require("eslint-visitor-keys"),
espree = require("espree"),
Expand Down
2 changes: 1 addition & 1 deletion lib/linter/report-translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Requirements
//------------------------------------------------------------------------------

const assert = require("assert");
const assert = require("node:assert");
const ruleFixer = require("./rule-fixer");
const { interpolate } = require("./interpolate");

Expand Down
6 changes: 3 additions & 3 deletions lib/rule-tester/rule-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
//------------------------------------------------------------------------------

const
assert = require("assert"),
util = require("util"),
path = require("path"),
assert = require("node:assert"),
util = require("node:util"),
path = require("node:path"),
equal = require("fast-deep-equal"),
Traverser = require("../shared/traverser"),
{ getRuleOptionsSchema } = require("../config/flat-config-helpers"),
Expand Down
4 changes: 2 additions & 2 deletions lib/shared/runtime-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// Requirements
//------------------------------------------------------------------------------

const path = require("path");
const path = require("node:path");
const spawn = require("cross-spawn");
const os = require("os");
const os = require("node:os");
const log = require("../shared/logging");
const packageJson = require("../../package.json");

Expand Down
2 changes: 1 addition & 1 deletion lib/source-code/token-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Requirements
//------------------------------------------------------------------------------

const assert = require("assert");
const assert = require("node:assert");
const { isCommentToken } = require("@eslint-community/eslint-utils");
const cursors = require("./cursors");
const ForwardTokenCursor = require("./forward-token-cursor");
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config-eslint/nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const recommendedModuleConfig = require("eslint-plugin-n/configs/recommended-mod

const sharedRules = {
"n/callback-return": ["error", ["cb", "callback", "next"]],
"n/handle-callback-err": ["error", "err"]
"n/handle-callback-err": ["error", "err"],
"n/prefer-node-protocol": "error"
};

const cjsConfigs = [
Expand Down
4 changes: 2 additions & 2 deletions tests/_utils/test-lazy-loading-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

"use strict";

const path = require("path");
const assert = require("assert");
const path = require("node:path");
const assert = require("node:assert");
const { addHook } = require("pirates");

const {
Expand Down
6 changes: 3 additions & 3 deletions tests/bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
// Requirements
//-----------------------------------------------------------------------------

const childProcess = require("child_process");
const fs = require("fs");
const childProcess = require("node:child_process");
const fs = require("node:fs");
const assert = require("chai").assert;
const path = require("path");
const path = require("node:path");

//------------------------------------------------------------------------------
// Data
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/cli-engine/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
//------------------------------------------------------------------------------

const assert = require("chai").assert,
path = require("path"),
path = require("node:path"),
sinon = require("sinon"),
shell = require("shelljs"),
fs = require("fs"),
os = require("os"),
fs = require("node:fs"),
os = require("node:os"),
hash = require("../../../lib/cli-engine/hash"),
{
Legacy: {
Expand Down Expand Up @@ -787,7 +787,7 @@ describe("CLIEngine", () => {

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

/* eslint-disable no-underscore-dangle -- Private Node API overriding */
Expand Down Expand Up @@ -5123,7 +5123,7 @@ describe("CLIEngine", () => {
writeFileSync() {}
},
localCLIEngine = proxyquire("../../../lib/cli-engine/cli-engine", {
fs: fakeFS
"node:fs": fakeFS
}).CLIEngine,
report = {
results: [
Expand Down Expand Up @@ -5153,7 +5153,7 @@ describe("CLIEngine", () => {
writeFileSync() {}
},
localCLIEngine = proxyquire("../../../lib/cli-engine/cli-engine", {
fs: fakeFS
"node:fs": fakeFS
}).CLIEngine,
report = {
results: [
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/cli-engine/file-enumerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs");
const path = require("path");
const os = require("os");
const fs = require("node:fs");
const path = require("node:path");
const os = require("node:os");
const { assert } = require("chai");
const sh = require("shelljs");
const sinon = require("sinon");
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/cli-engine/lint-result-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

const assert = require("chai").assert,
{ CLIEngine } = require("../../../lib/cli-engine"),
fs = require("fs"),
path = require("path"),
fs = require("node:fs"),
path = require("node:path"),
proxyquire = require("proxyquire"),
sinon = require("sinon");

Expand Down
8 changes: 4 additions & 4 deletions tests/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
//------------------------------------------------------------------------------

const assert = require("chai").assert,
stdAssert = require("assert"),
stdAssert = require("node:assert"),
{ ESLint, LegacyESLint } = require("../../lib/eslint"),
BuiltinRules = require("../../lib/rules"),
path = require("path"),
path = require("node:path"),
sinon = require("sinon"),
fs = require("fs"),
os = require("os"),
fs = require("node:fs"),
os = require("node:os"),
sh = require("shelljs");

const proxyquire = require("proxyquire").noCallThru().noPreserveCache();
Expand Down
Loading

0 comments on commit a63ed72

Please # to comment.