From a596af0819aeb9d607a722eaaa5a06aa9b22caec Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 21 Apr 2024 18:53:08 +0200 Subject: [PATCH] tools: add lint rule to keep primordials in ASCII order PR-URL: https://github.com/nodejs/node/pull/52592 Reviewed-By: Yagiz Nizipli Reviewed-By: Jacob Smith Reviewed-By: Moshe Atlow --- lib/.eslintrc.yaml | 5 ++ lib/_http_common.js | 2 +- lib/_http_outgoing.js | 2 +- lib/_http_server.js | 2 +- lib/_tls_common.js | 4 +- lib/async_hooks.js | 2 +- lib/buffer.js | 2 +- lib/child_process.js | 2 +- lib/crypto.js | 2 +- lib/diagnostics_channel.js | 4 +- lib/events.js | 4 +- lib/internal/async_hooks.js | 2 +- lib/internal/blob.js | 2 +- lib/internal/bootstrap/node.js | 2 +- lib/internal/bootstrap/realm.js | 2 +- .../bootstrap/switches/is_main_thread.js | 5 +- .../bootstrap/switches/is_not_main_thread.js | 4 +- .../bootstrap/web/exposed-window-or-worker.js | 2 +- lib/internal/child_process/serialization.js | 2 +- lib/internal/cluster/shared_handle.js | 6 +- lib/internal/console/constructor.js | 2 +- lib/internal/crypto/aes.js | 3 +- lib/internal/crypto/keys.js | 2 +- lib/internal/dns/callback_resolver.js | 2 +- lib/internal/error_serdes.js | 7 ++- lib/internal/errors.js | 4 +- lib/internal/freeze_intrinsics.js | 4 +- lib/internal/fs/glob.js | 29 +++++----- lib/internal/fs/promises.js | 6 +- lib/internal/fs/utils.js | 4 +- lib/internal/heap_utils.js | 2 +- lib/internal/http.js | 2 +- lib/internal/http2/compat.js | 2 +- lib/internal/http2/core.js | 2 +- lib/internal/inspector_async_hook.js | 6 +- lib/internal/legacy/processbinding.js | 2 +- lib/internal/main/print_help.js | 4 +- lib/internal/main/run_main_module.js | 4 +- lib/internal/main/test_runner.js | 13 +++-- lib/internal/modules/esm/assert.js | 2 +- lib/internal/modules/esm/formats.js | 5 +- lib/internal/modules/esm/get_format.js | 4 +- .../modules/esm/initialize_import_meta.js | 5 +- lib/internal/modules/esm/loader.js | 13 +++-- lib/internal/modules/esm/module_job.js | 4 +- lib/internal/modules/esm/translators.js | 2 +- lib/internal/modules/esm/utils.js | 2 +- lib/internal/modules/package_json_reader.js | 4 +- lib/internal/navigator.js | 4 +- lib/internal/options.js | 8 +-- lib/internal/per_context/domexception.js | 2 +- lib/internal/per_context/primordials.js | 2 +- lib/internal/perf/timerify.js | 2 +- lib/internal/perf/usertiming.js | 2 +- lib/internal/policy/manifest.js | 2 +- lib/internal/process/execution.js | 2 +- lib/internal/process/per_thread.js | 2 +- lib/internal/process/report.js | 9 ++- lib/internal/process/warning.js | 4 +- lib/internal/promise_hooks.js | 2 +- lib/internal/readline/interface.js | 6 +- .../source_map/prepare_stack_trace.js | 2 +- lib/internal/streams/destroy.js | 6 +- lib/internal/streams/duplexify.js | 8 +-- lib/internal/streams/end-of-stream.js | 12 ++-- lib/internal/streams/operators.js | 26 ++++----- lib/internal/streams/utils.js | 6 +- lib/internal/streams/writable.js | 2 +- lib/internal/test_runner/coverage.js | 4 +- lib/internal/test_runner/mock/mock_timers.js | 12 ++-- lib/internal/test_runner/reporter/dot.js | 5 +- lib/internal/test_runner/reporter/junit.js | 2 +- lib/internal/test_runner/reporter/spec.js | 2 +- lib/internal/test_runner/reporter/tap.js | 2 +- lib/internal/test_runner/runner.js | 6 +- lib/internal/test_runner/test.js | 12 ++-- lib/internal/test_runner/utils.js | 8 +-- lib/internal/tls/secure-pair.js | 10 ++-- lib/internal/util.js | 4 +- lib/internal/util/comparisons.js | 2 +- lib/internal/util/inspect.js | 10 ++-- lib/internal/util/inspector.js | 2 +- lib/internal/vm/module.js | 2 +- lib/internal/webstreams/adapters.js | 2 +- lib/internal/webstreams/readablestream.js | 2 +- lib/internal/webstreams/transformstream.js | 2 +- lib/internal/webstreams/writablestream.js | 2 +- lib/internal/worker/io.js | 2 +- lib/repl.js | 2 +- lib/test.js | 7 ++- lib/test/reporters.js | 5 +- lib/timers.js | 2 +- lib/v8.js | 2 +- lib/vm.js | 2 +- .../test-eslint-alphabetize-primordials.js | 57 +++++++++++++++++++ tools/eslint-rules/alphabetize-primordials.js | 49 ++++++++++++++++ 96 files changed, 337 insertions(+), 190 deletions(-) create mode 100644 test/parallel/test-eslint-alphabetize-primordials.js create mode 100644 tools/eslint-rules/alphabetize-primordials.js diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 42cdb19cffc..cd438d415d5 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -185,6 +185,7 @@ rules: - groups: [['&&', '||']] # Custom rules in tools/eslint-rules + node-core/alphabetize-primordials: error node-core/avoid-prototype-pollution: error node-core/lowercase-name-for-primitive: error node-core/non-ascii-character: error @@ -266,3 +267,7 @@ globals: module: false internalBinding: false primordials: false +overrides: + - files: [internal/per_context/primordials.js] + rules: + node-core/alphabetize-primordials: [error, {enforceTopPosition: false}] diff --git a/lib/_http_common.js b/lib/_http_common.js index 2c7866d350e..7dbf44a7c46 100644 --- a/lib/_http_common.js +++ b/lib/_http_common.js @@ -23,8 +23,8 @@ const { MathMin, - Symbol, RegExpPrototypeExec, + Symbol, } = primordials; const { setImmediate } = require('timers'); diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index ddf742277a9..5e9df1c42b2 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -29,9 +29,9 @@ const { NumberPrototypeToString, ObjectDefineProperty, ObjectKeys, - ObjectValues, ObjectPrototypeHasOwnProperty, ObjectSetPrototypeOf, + ObjectValues, RegExpPrototypeExec, SafeSet, StringPrototypeToLowerCase, diff --git a/lib/_http_server.js b/lib/_http_server.js index 582054a58fe..d67669fea94 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -28,8 +28,8 @@ const { MathMin, ObjectKeys, ObjectSetPrototypeOf, - RegExpPrototypeExec, ReflectApply, + RegExpPrototypeExec, Symbol, SymbolAsyncDispose, SymbolFor, diff --git a/lib/_tls_common.js b/lib/_tls_common.js index 16c6a647cc2..b828785decc 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -21,14 +21,14 @@ 'use strict'; -const tls = require('tls'); - const { ArrayPrototypePush, JSONParse, RegExpPrototypeSymbolReplace, } = primordials; +const tls = require('tls'); + const { codes: { ERR_TLS_INVALID_PROTOCOL_VERSION, diff --git a/lib/async_hooks.js b/lib/async_hooks.js index b4dd54022d5..c352bff6d28 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -9,10 +9,10 @@ const { FunctionPrototypeBind, NumberIsSafeInteger, ObjectDefineProperties, + ObjectFreeze, ObjectIs, ReflectApply, Symbol, - ObjectFreeze, } = primordials; const { diff --git a/lib/buffer.js b/lib/buffer.js index fb0697d69ad..d593d9832f5 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -41,10 +41,10 @@ const { StringPrototypeTrim, SymbolSpecies, SymbolToPrimitive, + TypedArrayPrototypeFill, TypedArrayPrototypeGetBuffer, TypedArrayPrototypeGetByteLength, TypedArrayPrototypeGetByteOffset, - TypedArrayPrototypeFill, TypedArrayPrototypeGetLength, TypedArrayPrototypeSet, TypedArrayPrototypeSlice, diff --git a/lib/child_process.js b/lib/child_process.js index c09fca51258..6ecfb0b2d5a 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -28,11 +28,11 @@ const { ArrayPrototypeJoin, ArrayPrototypeLastIndexOf, ArrayPrototypePush, + ArrayPrototypePushApply, ArrayPrototypeSlice, ArrayPrototypeSort, ArrayPrototypeSplice, ArrayPrototypeUnshift, - ArrayPrototypePushApply, NumberIsInteger, ObjectAssign, ObjectDefineProperty, diff --git a/lib/crypto.js b/lib/crypto.js index a954a2736e7..73c2525e082 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -25,8 +25,8 @@ 'use strict'; const { - ObjectDefineProperty, ObjectDefineProperties, + ObjectDefineProperty, } = primordials; const { diff --git a/lib/diagnostics_channel.js b/lib/diagnostics_channel.js index 68f604e719d..dc26dc735a0 100644 --- a/lib/diagnostics_channel.js +++ b/lib/diagnostics_channel.js @@ -5,15 +5,15 @@ const { ArrayPrototypeIndexOf, ArrayPrototypePush, ArrayPrototypeSplice, - SafeFinalizationRegistry, ObjectDefineProperty, ObjectGetPrototypeOf, ObjectSetPrototypeOf, Promise, PromisePrototypeThen, - PromiseResolve, PromiseReject, + PromiseResolve, ReflectApply, + SafeFinalizationRegistry, SafeMap, SymbolHasInstance, } = primordials; diff --git a/lib/events.js b/lib/events.js index 6501b003ae4..83d85a1dc1b 100644 --- a/lib/events.js +++ b/lib/events.js @@ -34,8 +34,8 @@ const { FunctionPrototypeBind, FunctionPrototypeCall, NumberMAX_SAFE_INTEGER, - ObjectDefineProperty, ObjectDefineProperties, + ObjectDefineProperty, ObjectGetPrototypeOf, ObjectSetPrototypeOf, Promise, @@ -46,9 +46,9 @@ const { String, StringPrototypeSplit, Symbol, - SymbolFor, SymbolAsyncIterator, SymbolDispose, + SymbolFor, } = primordials; const kRejection = SymbolFor('nodejs.rejection'); diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index 56061b75757..c20be0eb15b 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -3,8 +3,8 @@ const { ArrayPrototypeSlice, ErrorCaptureStackTrace, - ObjectPrototypeHasOwnProperty, ObjectDefineProperty, + ObjectPrototypeHasOwnProperty, Symbol, } = primordials; diff --git a/lib/internal/blob.js b/lib/internal/blob.js index 3ebb1b8a84b..55ef31c72f1 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -10,8 +10,8 @@ const { PromiseReject, RegExpPrototypeExec, RegExpPrototypeSymbolReplace, - StringPrototypeToLowerCase, StringPrototypeSplit, + StringPrototypeToLowerCase, Symbol, SymbolIterator, SymbolToStringTag, diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index d42e766555a..ba8a913279e 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -59,9 +59,9 @@ const { Number, NumberIsNaN, ObjectDefineProperty, + ObjectFreeze, ObjectGetPrototypeOf, ObjectSetPrototypeOf, - ObjectFreeze, SymbolToStringTag, globalThis, } = primordials; diff --git a/lib/internal/bootstrap/realm.js b/lib/internal/bootstrap/realm.js index 9cb6a8add71..7e31786dcf2 100644 --- a/lib/internal/bootstrap/realm.js +++ b/lib/internal/bootstrap/realm.js @@ -64,8 +64,8 @@ const { SafeMap, SafeSet, String, - StringPrototypeStartsWith, StringPrototypeSlice, + StringPrototypeStartsWith, TypeError, } = primordials; diff --git a/lib/internal/bootstrap/switches/is_main_thread.js b/lib/internal/bootstrap/switches/is_main_thread.js index f15572dff1c..9d709ca743b 100644 --- a/lib/internal/bootstrap/switches/is_main_thread.js +++ b/lib/internal/bootstrap/switches/is_main_thread.js @@ -1,6 +1,9 @@ 'use strict'; -const { ObjectDefineProperty } = primordials; +const { + ObjectDefineProperty, +} = primordials; + const rawMethods = internalBinding('process_methods'); const { namespace: { diff --git a/lib/internal/bootstrap/switches/is_not_main_thread.js b/lib/internal/bootstrap/switches/is_not_main_thread.js index c2cb0106f09..c4c2a7cb280 100644 --- a/lib/internal/bootstrap/switches/is_not_main_thread.js +++ b/lib/internal/bootstrap/switches/is_not_main_thread.js @@ -1,6 +1,8 @@ 'use strict'; -const { ObjectDefineProperty } = primordials; +const { + ObjectDefineProperty, +} = primordials; delete process._debugProcess; delete process._debugEnd; diff --git a/lib/internal/bootstrap/web/exposed-window-or-worker.js b/lib/internal/bootstrap/web/exposed-window-or-worker.js index 6934fbdb436..3d638e1cb74 100644 --- a/lib/internal/bootstrap/web/exposed-window-or-worker.js +++ b/lib/internal/bootstrap/web/exposed-window-or-worker.js @@ -9,9 +9,9 @@ */ const { - globalThis, ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, + globalThis, } = primordials; const { diff --git a/lib/internal/child_process/serialization.js b/lib/internal/child_process/serialization.js index 365c1f6f573..7be39f0d48c 100644 --- a/lib/internal/child_process/serialization.js +++ b/lib/internal/child_process/serialization.js @@ -1,10 +1,10 @@ 'use strict'; const { + ArrayPrototypePush, JSONParse, JSONStringify, StringPrototypeSplit, - ArrayPrototypePush, Symbol, TypedArrayPrototypeSubarray, } = primordials; diff --git a/lib/internal/cluster/shared_handle.js b/lib/internal/cluster/shared_handle.js index 87b83df2008..88e981fdf07 100644 --- a/lib/internal/cluster/shared_handle.js +++ b/lib/internal/cluster/shared_handle.js @@ -1,5 +1,9 @@ 'use strict'; -const { SafeMap } = primordials; + +const { + SafeMap, +} = primordials; + const assert = require('internal/assert'); const dgram = require('internal/dgram'); const net = require('net'); diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 454652e3632..36868a34fe5 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -26,8 +26,8 @@ const { RegExpPrototypeSymbolReplace, SafeArrayIterator, SafeMap, - SafeWeakMap, SafeSet, + SafeWeakMap, StringPrototypeIncludes, StringPrototypePadStart, StringPrototypeRepeat, diff --git a/lib/internal/crypto/aes.js b/lib/internal/crypto/aes.js index b6d134dbfbf..bb35d2b21de 100644 --- a/lib/internal/crypto/aes.js +++ b/lib/internal/crypto/aes.js @@ -7,6 +7,7 @@ const { ArrayPrototypeIncludes, ArrayPrototypePush, MathFloor, + PromiseReject, SafeSet, TypedArrayPrototypeSlice, } = primordials; @@ -47,8 +48,6 @@ const { promisify, } = require('internal/util'); -const { PromiseReject } = primordials; - const { InternalCryptoKey, SecretKeyObject, diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index fc4240ffd28..260458e1f2a 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -3,8 +3,8 @@ const { ArrayFrom, ArrayPrototypeSlice, - ObjectDefineProperty, ObjectDefineProperties, + ObjectDefineProperty, ObjectSetPrototypeOf, Symbol, SymbolToStringTag, diff --git a/lib/internal/dns/callback_resolver.js b/lib/internal/dns/callback_resolver.js index 5b7758865a8..9675d680f3a 100644 --- a/lib/internal/dns/callback_resolver.js +++ b/lib/internal/dns/callback_resolver.js @@ -1,9 +1,9 @@ 'use strict'; const { + ArrayPrototypeMap, ObjectDefineProperty, ReflectApply, - ArrayPrototypeMap, Symbol, } = primordials; diff --git a/lib/internal/error_serdes.js b/lib/internal/error_serdes.js index f88dd09cb05..89f24eab9b1 100644 --- a/lib/internal/error_serdes.js +++ b/lib/internal/error_serdes.js @@ -1,6 +1,5 @@ 'use strict'; -const Buffer = require('buffer').Buffer; const { ArrayPrototypeForEach, Error, @@ -19,15 +18,17 @@ const { SafeSet, StringFromCharCode, StringPrototypeSubstring, + SymbolFor, SymbolToStringTag, SyntaxError, - SymbolFor, TypeError, TypedArrayPrototypeGetBuffer, - TypedArrayPrototypeGetByteOffset, TypedArrayPrototypeGetByteLength, + TypedArrayPrototypeGetByteOffset, URIError, } = primordials; + +const { Buffer } = require('buffer'); const { inspect: { custom: customInspectSymbol } } = require('util'); const kSerializedError = 0; diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 6742d4bf0ea..4f598ec812a 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -33,10 +33,10 @@ const { Number, NumberIsInteger, ObjectAssign, - ObjectDefineProperty, ObjectDefineProperties, - ObjectIsExtensible, + ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, + ObjectIsExtensible, ObjectKeys, ObjectPrototypeHasOwnProperty, RangeError, diff --git a/lib/internal/freeze_intrinsics.js b/lib/internal/freeze_intrinsics.js index 275d04f7f98..ac7723b528e 100644 --- a/lib/internal/freeze_intrinsics.js +++ b/lib/internal/freeze_intrinsics.js @@ -103,6 +103,8 @@ const { TypeErrorPrototype, TypedArray, TypedArrayPrototype, + URIError, + URIErrorPrototype, Uint16Array, Uint16ArrayPrototype, Uint32Array, @@ -111,8 +113,6 @@ const { Uint8ArrayPrototype, Uint8ClampedArray, Uint8ClampedArrayPrototype, - URIError, - URIErrorPrototype, WeakMap, WeakMapPrototype, WeakRef, diff --git a/lib/internal/fs/glob.js b/lib/internal/fs/glob.js index ce351d77ca3..cdf8c4dfbc2 100644 --- a/lib/internal/fs/glob.js +++ b/lib/internal/fs/glob.js @@ -1,4 +1,19 @@ 'use strict'; + +const { + ArrayFrom, + ArrayPrototypeAt, + ArrayPrototypeFlatMap, + ArrayPrototypeMap, + ArrayPrototypePop, + ArrayPrototypePush, + ArrayPrototypeSome, + PromisePrototypeThen, + SafeMap, + SafeSet, + StringPrototypeEndsWith, +} = primordials; + const { lstatSync, readdirSync } = require('fs'); const { lstat, readdir } = require('fs/promises'); const { join, resolve } = require('path'); @@ -13,20 +28,6 @@ const { validateStringArray, } = require('internal/validators'); -const { - ArrayFrom, - ArrayPrototypeAt, - ArrayPrototypeMap, - ArrayPrototypeFlatMap, - ArrayPrototypePop, - ArrayPrototypePush, - ArrayPrototypeSome, - PromisePrototypeThen, - SafeMap, - SafeSet, - StringPrototypeEndsWith, -} = primordials; - let minimatch; function lazyMinimatch() { minimatch ??= require('internal/deps/minimatch/index'); diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index a5df1f00b2e..5ae9966d937 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -1,22 +1,22 @@ 'use strict'; const { - ArrayPrototypePush, ArrayPrototypePop, + ArrayPrototypePush, Error, ErrorCaptureStackTrace, + FunctionPrototypeBind, MathMax, MathMin, Promise, PromisePrototypeThen, - PromiseResolve, PromiseReject, + PromiseResolve, SafeArrayIterator, SafePromisePrototypeFinally, Symbol, SymbolAsyncDispose, Uint8Array, - FunctionPrototypeBind, uncurryThis, } = primordials; diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 4666a1d78d8..10aeae4dfa4 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -8,10 +8,10 @@ const { DatePrototypeGetTime, ErrorCaptureStackTrace, FunctionPrototypeCall, - Number, - NumberIsFinite, MathMin, MathRound, + Number, + NumberIsFinite, ObjectDefineProperties, ObjectDefineProperty, ObjectIs, diff --git a/lib/internal/heap_utils.js b/lib/internal/heap_utils.js index c39d811ab79..1b18f997f08 100644 --- a/lib/internal/heap_utils.js +++ b/lib/internal/heap_utils.js @@ -1,8 +1,8 @@ 'use strict'; const { + ArrayPrototypeMap, Symbol, Uint8Array, - ArrayPrototypeMap, } = primordials; const { kUpdateTimer, diff --git a/lib/internal/http.js b/lib/internal/http.js index b20b3cd229e..da1e8d3332d 100644 --- a/lib/internal/http.js +++ b/lib/internal/http.js @@ -1,10 +1,10 @@ 'use strict'; const { - Symbol, Date, DatePrototypeGetMilliseconds, DatePrototypeToUTCString, + Symbol, } = primordials; const { setUnrefTimeout } = require('internal/timers'); diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index f0dd26de0d6..631d79ddfbf 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -11,8 +11,8 @@ const { Proxy, ReflectApply, ReflectGetPrototypeOf, - StringPrototypeIncludes, SafeArrayIterator, + StringPrototypeIncludes, StringPrototypeToLowerCase, StringPrototypeTrim, Symbol, diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 97d59ae5520..0e9bf899b5d 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -11,9 +11,9 @@ const { MathMin, Number, ObjectAssign, - ObjectKeys, ObjectDefineProperty, ObjectEntries, + ObjectKeys, ObjectPrototypeHasOwnProperty, Promise, PromisePrototypeThen, diff --git a/lib/internal/inspector_async_hook.js b/lib/internal/inspector_async_hook.js index d7bb663431e..e65fd05619a 100644 --- a/lib/internal/inspector_async_hook.js +++ b/lib/internal/inspector_async_hook.js @@ -1,12 +1,12 @@ 'use strict'; -let hook; -let config; - const { SafeSet, } = primordials; +let hook; +let config; + function lazyHookCreation() { const inspector = internalBinding('inspector'); const { createHook } = require('async_hooks'); diff --git a/lib/internal/legacy/processbinding.js b/lib/internal/legacy/processbinding.js index ecf6c7859bc..4fcb783cef7 100644 --- a/lib/internal/legacy/processbinding.js +++ b/lib/internal/legacy/processbinding.js @@ -2,8 +2,8 @@ const { ArrayPrototypeFilter, ArrayPrototypeIncludes, - ObjectFromEntries, ObjectEntries, + ObjectFromEntries, SafeArrayIterator, } = primordials; const { types } = require('util'); diff --git a/lib/internal/main/print_help.js b/lib/internal/main/print_help.js index 73227fbd9cb..0ae4d349660 100644 --- a/lib/internal/main/print_help.js +++ b/lib/internal/main/print_help.js @@ -9,11 +9,11 @@ const { ObjectKeys, RegExp, RegExpPrototypeSymbolReplace, + SafeMap, StringPrototypeLocaleCompare, + StringPrototypeRepeat, StringPrototypeSlice, StringPrototypeTrimStart, - StringPrototypeRepeat, - SafeMap, } = primordials; const { types } = internalBinding('options'); diff --git a/lib/internal/main/run_main_module.js b/lib/internal/main/run_main_module.js index 5d09203b8c2..ccab1595685 100644 --- a/lib/internal/main/run_main_module.js +++ b/lib/internal/main/run_main_module.js @@ -1,6 +1,8 @@ 'use strict'; -const { RegExpPrototypeExec } = primordials; +const { + RegExpPrototypeExec, +} = primordials; const { prepareMainThreadExecution, diff --git a/lib/internal/main/test_runner.js b/lib/internal/main/test_runner.js index 4f3f067cc74..5d4140bef94 100644 --- a/lib/internal/main/test_runner.js +++ b/lib/internal/main/test_runner.js @@ -1,4 +1,11 @@ 'use strict'; + +const { + NumberParseInt, + RegExpPrototypeExec, + StringPrototypeSplit, +} = primordials; + const { prepareMainThreadExecution, markBootstrapComplete, @@ -13,11 +20,7 @@ const { ERR_INVALID_ARG_VALUE, }, } = require('internal/errors'); -const { - NumberParseInt, - RegExpPrototypeExec, - StringPrototypeSplit, -} = primordials; + let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => { debug = fn; }); diff --git a/lib/internal/modules/esm/assert.js b/lib/internal/modules/esm/assert.js index 5672f8c8f99..66086536270 100644 --- a/lib/internal/modules/esm/assert.js +++ b/lib/internal/modules/esm/assert.js @@ -4,8 +4,8 @@ const { ArrayPrototypeFilter, ArrayPrototypeIncludes, ObjectKeys, - ObjectValues, ObjectPrototypeHasOwnProperty, + ObjectValues, } = primordials; const { validateString } = require('internal/validators'); diff --git a/lib/internal/modules/esm/formats.js b/lib/internal/modules/esm/formats.js index 2d69a3e93c3..470f679b92e 100644 --- a/lib/internal/modules/esm/formats.js +++ b/lib/internal/modules/esm/formats.js @@ -1,6 +1,9 @@ 'use strict'; -const { RegExpPrototypeExec } = primordials; +const { + RegExpPrototypeExec, +} = primordials; + const { getOptionValue } = require('internal/options'); const { getValidatedPath } = require('internal/fs/utils'); const pathModule = require('path'); diff --git a/lib/internal/modules/esm/get_format.js b/lib/internal/modules/esm/get_format.js index d79e24c4188..cd5c88dce8e 100644 --- a/lib/internal/modules/esm/get_format.js +++ b/lib/internal/modules/esm/get_format.js @@ -1,13 +1,13 @@ 'use strict'; const { - RegExpPrototypeExec, ObjectPrototypeHasOwnProperty, PromisePrototypeThen, PromiseResolve, + RegExpPrototypeExec, SafeSet, - StringPrototypeIncludes, StringPrototypeCharCodeAt, + StringPrototypeIncludes, StringPrototypeSlice, } = primordials; const { getOptionValue } = require('internal/options'); diff --git a/lib/internal/modules/esm/initialize_import_meta.js b/lib/internal/modules/esm/initialize_import_meta.js index 818c99479cd..43064f14b05 100644 --- a/lib/internal/modules/esm/initialize_import_meta.js +++ b/lib/internal/modules/esm/initialize_import_meta.js @@ -1,6 +1,9 @@ 'use strict'; -const { StringPrototypeStartsWith } = primordials; +const { + StringPrototypeStartsWith, +} = primordials; + const { getOptionValue } = require('internal/options'); const { fileURLToPath } = require('internal/url'); const { dirname } = require('path'); diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 551454a4b25..414e51ada75 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -1,11 +1,5 @@ 'use strict'; -// This is needed to avoid cycles in esm/resolve <-> cjs/loader -const { - kIsExecuting, - kRequiredModuleSymbol, -} = require('internal/modules/cjs/loader'); - const { ArrayPrototypeJoin, ArrayPrototypeMap, @@ -18,6 +12,13 @@ const { hardenRegExp, } = primordials; + +// This is needed to avoid cycles in esm/resolve <-> cjs/loader +const { + kIsExecuting, + kRequiredModuleSymbol, +} = require('internal/modules/cjs/loader'); + const { imported_cjs_symbol } = internalBinding('symbols'); const assert = require('internal/assert'); diff --git a/lib/internal/modules/esm/module_job.js b/lib/internal/modules/esm/module_job.js index 296dafe3ad2..853ad8c72bd 100644 --- a/lib/internal/modules/esm/module_job.js +++ b/lib/internal/modules/esm/module_job.js @@ -6,11 +6,11 @@ const { ArrayPrototypeSome, FunctionPrototype, ObjectSetPrototypeOf, - PromiseResolve, PromisePrototypeThen, + PromiseResolve, + ReflectApply, RegExpPrototypeExec, RegExpPrototypeSymbolReplace, - ReflectApply, SafePromiseAllReturnArrayLike, SafePromiseAllReturnVoid, SafeSet, diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index 8f4b6b25d88..e5775c8d521 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -5,8 +5,8 @@ const { Boolean, JSONParse, ObjectGetPrototypeOf, - ObjectPrototypeHasOwnProperty, ObjectKeys, + ObjectPrototypeHasOwnProperty, ReflectApply, SafeArrayIterator, SafeMap, diff --git a/lib/internal/modules/esm/utils.js b/lib/internal/modules/esm/utils.js index 622f9462ac2..70deb335f0e 100644 --- a/lib/internal/modules/esm/utils.js +++ b/lib/internal/modules/esm/utils.js @@ -2,9 +2,9 @@ const { ArrayIsArray, + ObjectFreeze, SafeSet, SafeWeakMap, - ObjectFreeze, } = primordials; const { diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js index 0842d543862..3df2b7bc6a0 100644 --- a/lib/internal/modules/package_json_reader.js +++ b/lib/internal/modules/package_json_reader.js @@ -3,9 +3,9 @@ const { ArrayIsArray, JSONParse, - StringPrototypeSlice, - StringPrototypeLastIndexOf, ObjectDefineProperty, + StringPrototypeLastIndexOf, + StringPrototypeSlice, } = primordials; const modulesBinding = internalBinding('modules'); const { resolve, sep } = require('path'); diff --git a/lib/internal/navigator.js b/lib/internal/navigator.js index db956fd02ab..546505e9460 100644 --- a/lib/internal/navigator.js +++ b/lib/internal/navigator.js @@ -2,12 +2,12 @@ const { ObjectDefineProperties, + ObjectFreeze, StringPrototypeIndexOf, StringPrototypeSlice, StringPrototypeToUpperCase, - ObjectFreeze, - globalThis, Symbol, + globalThis, } = primordials; const { diff --git a/lib/internal/options.js b/lib/internal/options.js index 5cecdc00e5c..9a9dd2000bd 100644 --- a/lib/internal/options.js +++ b/lib/internal/options.js @@ -1,14 +1,14 @@ 'use strict'; +const { + StringPrototypeSlice, +} = primordials; + const { getCLIOptions, getEmbedderOptions: getEmbedderOptionsFromBinding, } = internalBinding('options'); -const { - StringPrototypeSlice, -} = primordials; - let warnOnAllowUnauthorized = true; let optionsMap; diff --git a/lib/internal/per_context/domexception.js b/lib/internal/per_context/domexception.js index 14b496df8ee..cf9042fec7c 100644 --- a/lib/internal/per_context/domexception.js +++ b/lib/internal/per_context/domexception.js @@ -6,9 +6,9 @@ const { ObjectDefineProperties, ObjectDefineProperty, ObjectSetPrototypeOf, - SafeWeakMap, SafeMap, SafeSet, + SafeWeakMap, SymbolToStringTag, TypeError, } = primordials; diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 140c80566c9..89b8b0483c8 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -287,8 +287,8 @@ const { PromiseResolve, ReflectApply, ReflectConstruct, - ReflectSet, ReflectGet, + ReflectSet, RegExp, RegExpPrototype, RegExpPrototypeExec, diff --git a/lib/internal/perf/timerify.js b/lib/internal/perf/timerify.js index ad959aa42f0..f9e9b8a39d9 100644 --- a/lib/internal/perf/timerify.js +++ b/lib/internal/perf/timerify.js @@ -2,8 +2,8 @@ const { FunctionPrototypeBind, - ObjectDefineProperties, MathCeil, + ObjectDefineProperties, ReflectApply, ReflectConstruct, } = primordials; diff --git a/lib/internal/perf/usertiming.js b/lib/internal/perf/usertiming.js index cb7cfdd8596..ab109c3c04b 100644 --- a/lib/internal/perf/usertiming.js +++ b/lib/internal/perf/usertiming.js @@ -2,9 +2,9 @@ const { ObjectDefineProperties, + SafeArrayIterator, SafeMap, SafeSet, - SafeArrayIterator, Symbol, SymbolToStringTag, } = primordials; diff --git a/lib/internal/policy/manifest.js b/lib/internal/policy/manifest.js index fdba0c9bd98..61d32d1185d 100644 --- a/lib/internal/policy/manifest.js +++ b/lib/internal/policy/manifest.js @@ -9,9 +9,9 @@ const { ObjectKeys, ObjectSetPrototypeOf, RegExpPrototypeExec, + RegExpPrototypeSymbolReplace, SafeMap, SafeSet, - RegExpPrototypeSymbolReplace, StringPrototypeEndsWith, StringPrototypeStartsWith, Symbol, diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js index ee28dcf206f..9fcaa8372f8 100644 --- a/lib/internal/process/execution.js +++ b/lib/internal/process/execution.js @@ -1,8 +1,8 @@ 'use strict'; const { - Symbol, RegExpPrototypeExec, + Symbol, globalThis, } = primordials; diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 891767da529..9b820ffe71a 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -14,8 +14,8 @@ const { BigUint64Array, Float64Array, NumberMAX_SAFE_INTEGER, - ObjectFreeze, ObjectDefineProperty, + ObjectFreeze, ReflectApply, RegExpPrototypeExec, SafeArrayIterator, diff --git a/lib/internal/process/report.js b/lib/internal/process/report.js index 1639142dff0..3ca5273eb37 100644 --- a/lib/internal/process/report.js +++ b/lib/internal/process/report.js @@ -1,4 +1,9 @@ 'use strict'; + +const { + JSONParse, +} = primordials; + const { ERR_SYNTHETIC, } = require('internal/errors').codes; @@ -10,9 +15,7 @@ const { validateString, } = require('internal/validators'); const nr = internalBinding('report'); -const { - JSONParse, -} = primordials; + const report = { writeReport(file, err) { if (typeof file === 'object' && file !== null) { diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 9e1e6f7a6a2..162d0ca8153 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -3,10 +3,10 @@ const { ArrayIsArray, Error, - ErrorPrototypeToString, ErrorCaptureStackTrace, - String, + ErrorPrototypeToString, SafeSet, + String, } = primordials; const { diff --git a/lib/internal/promise_hooks.js b/lib/internal/promise_hooks.js index b58f2ba1cc6..7a29229ddbe 100644 --- a/lib/internal/promise_hooks.js +++ b/lib/internal/promise_hooks.js @@ -2,9 +2,9 @@ const { ArrayPrototypeIndexOf, + ArrayPrototypePush, ArrayPrototypeSlice, ArrayPrototypeSplice, - ArrayPrototypePush, FunctionPrototypeBind, } = primordials; diff --git a/lib/internal/readline/interface.js b/lib/internal/readline/interface.js index 8ae051e4ead..4b48d7ef993 100644 --- a/lib/internal/readline/interface.js +++ b/lib/internal/readline/interface.js @@ -9,8 +9,8 @@ const { ArrayPrototypePop, ArrayPrototypePush, ArrayPrototypeReverse, - ArrayPrototypeSplice, ArrayPrototypeShift, + ArrayPrototypeSplice, ArrayPrototypeUnshift, DateNow, FunctionPrototypeCall, @@ -21,6 +21,7 @@ const { NumberIsFinite, ObjectSetPrototypeOf, RegExpPrototypeExec, + SafeStringIterator, StringPrototypeCodePointAt, StringPrototypeEndsWith, StringPrototypeRepeat, @@ -28,9 +29,8 @@ const { StringPrototypeStartsWith, StringPrototypeTrim, Symbol, - SymbolDispose, SymbolAsyncIterator, - SafeStringIterator, + SymbolDispose, } = primordials; const { codes } = require('internal/errors'); diff --git a/lib/internal/source_map/prepare_stack_trace.js b/lib/internal/source_map/prepare_stack_trace.js index 568e86f7faa..776bb470bd1 100644 --- a/lib/internal/source_map/prepare_stack_trace.js +++ b/lib/internal/source_map/prepare_stack_trace.js @@ -6,10 +6,10 @@ const { ArrayPrototypeMap, ErrorPrototypeToString, RegExpPrototypeSymbolSplit, + SafeStringIterator, StringPrototypeRepeat, StringPrototypeSlice, StringPrototypeStartsWith, - SafeStringIterator, } = primordials; let debug = require('internal/util/debuglog').debuglog('source_map', (fn) => { diff --git a/lib/internal/streams/destroy.js b/lib/internal/streams/destroy.js index 96e61491f08..185ba6a17a2 100644 --- a/lib/internal/streams/destroy.js +++ b/lib/internal/streams/destroy.js @@ -1,5 +1,8 @@ 'use strict'; +const { + Symbol, +} = primordials; const { aggregateTwoErrors, codes: { @@ -7,9 +10,6 @@ const { }, AbortError, } = require('internal/errors'); -const { - Symbol, -} = primordials; const { kIsDestroyed, isDestroyed, diff --git a/lib/internal/streams/duplexify.js b/lib/internal/streams/duplexify.js index 2503b531519..4498f0f3905 100644 --- a/lib/internal/streams/duplexify.js +++ b/lib/internal/streams/duplexify.js @@ -1,5 +1,9 @@ 'use strict'; +const { + FunctionPrototypeCall, +} = primordials; + const { isReadable, isWritable, @@ -31,10 +35,6 @@ const { } = require('internal/blob'); const { AbortController } = require('internal/abort_controller'); -const { - FunctionPrototypeCall, -} = primordials; - // This is needed for pre node 17. class Duplexify extends Duplex { constructor(options) { diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js index eda08b5fc60..fc0cbb45494 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -3,6 +3,12 @@ 'use strict'; +const { + Promise, + PromisePrototypeThen, + SymbolDispose, +} = primordials; + const { AbortError, codes, @@ -22,12 +28,6 @@ const { validateBoolean, } = require('internal/validators'); -const { - Promise, - PromisePrototypeThen, - SymbolDispose, -} = primordials; - const { isClosed, isReadable, diff --git a/lib/internal/streams/operators.js b/lib/internal/streams/operators.js index 74c67b02801..36b657a727d 100644 --- a/lib/internal/streams/operators.js +++ b/lib/internal/streams/operators.js @@ -1,5 +1,18 @@ 'use strict'; +const { + ArrayPrototypePush, + Boolean, + MathFloor, + Number, + NumberIsNaN, + Promise, + PromisePrototypeThen, + PromiseReject, + PromiseResolve, + Symbol, +} = primordials; + const { AbortController, AbortSignal } = require('internal/abort_controller'); const { @@ -24,19 +37,6 @@ const { } = require('internal/streams/add-abort-signal'); const { isWritable, isNodeStream } = require('internal/streams/utils'); -const { - ArrayPrototypePush, - Boolean, - MathFloor, - Number, - NumberIsNaN, - Promise, - PromiseReject, - PromiseResolve, - PromisePrototypeThen, - Symbol, -} = primordials; - const kEmpty = Symbol('kEmpty'); const kEof = Symbol('kEof'); diff --git a/lib/internal/streams/utils.js b/lib/internal/streams/utils.js index 2c6b841a89e..d7d76783274 100644 --- a/lib/internal/streams/utils.js +++ b/lib/internal/streams/utils.js @@ -1,10 +1,10 @@ 'use strict'; const { - SymbolAsyncIterator, - SymbolIterator, - SymbolFor, Symbol, + SymbolAsyncIterator, + SymbolFor, + SymbolIterator, } = primordials; // We need to use SymbolFor to make these globally available diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index 0a16aee369b..a039e60b16c 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -29,8 +29,8 @@ const { ArrayPrototypeSlice, Error, FunctionPrototypeSymbolHasInstance, - ObjectDefineProperty, ObjectDefineProperties, + ObjectDefineProperty, ObjectSetPrototypeOf, StringPrototypeToLowerCase, Symbol, diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 50f9f94172e..51f8c4c0cf6 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -5,6 +5,8 @@ const { ArrayPrototypePush, JSONParse, MathFloor, + MathMax, + MathMin, NumberParseInt, ObjectAssign, RegExpPrototypeExec, @@ -14,8 +16,6 @@ const { StringPrototypeIncludes, StringPrototypeLocaleCompare, StringPrototypeStartsWith, - MathMax, - MathMin, } = primordials; const { copyFileSync, diff --git a/lib/internal/test_runner/mock/mock_timers.js b/lib/internal/test_runner/mock/mock_timers.js index fdb0935ab64..9991017653e 100644 --- a/lib/internal/test_runner/mock/mock_timers.js +++ b/lib/internal/test_runner/mock/mock_timers.js @@ -1,9 +1,5 @@ 'use strict'; -const { - emitExperimentalWarning, -} = require('internal/util'); - const { ArrayPrototypeAt, ArrayPrototypeForEach, @@ -13,23 +9,27 @@ const { FunctionPrototypeApply, FunctionPrototypeBind, FunctionPrototypeToString, - globalThis, NumberIsNaN, - ObjectDefineProperty, ObjectDefineProperties, + ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, ObjectGetOwnPropertyDescriptors, Promise, Symbol, SymbolAsyncIterator, SymbolDispose, + globalThis, } = primordials; + const { validateAbortSignal, validateArray, validateNumber, } = require('internal/validators'); +const { + emitExperimentalWarning, +} = require('internal/util'); const { AbortError, codes: { ERR_INVALID_STATE, ERR_INVALID_ARG_VALUE }, diff --git a/lib/internal/test_runner/reporter/dot.js b/lib/internal/test_runner/reporter/dot.js index 496c819d69e..3b8217caf25 100644 --- a/lib/internal/test_runner/reporter/dot.js +++ b/lib/internal/test_runner/reporter/dot.js @@ -1,5 +1,8 @@ 'use strict'; -const { MathMax } = primordials; + +const { + MathMax, +} = primordials; module.exports = async function* dot(source) { let count = 0; diff --git a/lib/internal/test_runner/reporter/junit.js b/lib/internal/test_runner/reporter/junit.js index b45c233861c..b9095aedbc0 100644 --- a/lib/internal/test_runner/reporter/junit.js +++ b/lib/internal/test_runner/reporter/junit.js @@ -1,8 +1,8 @@ 'use strict'; const { ArrayPrototypeFilter, - ArrayPrototypeMap, ArrayPrototypeJoin, + ArrayPrototypeMap, ArrayPrototypePush, ArrayPrototypeSome, NumberPrototypeToFixed, diff --git a/lib/internal/test_runner/reporter/spec.js b/lib/internal/test_runner/reporter/spec.js index fd4313ae19b..e0335c5bdd3 100644 --- a/lib/internal/test_runner/reporter/spec.js +++ b/lib/internal/test_runner/reporter/spec.js @@ -6,10 +6,10 @@ const { ArrayPrototypePush, ArrayPrototypeShift, ArrayPrototypeUnshift, - hardenRegExp, RegExpPrototypeSymbolSplit, SafeMap, StringPrototypeRepeat, + hardenRegExp, } = primordials; const assert = require('assert'); const Transform = require('internal/streams/transform'); diff --git a/lib/internal/test_runner/reporter/tap.js b/lib/internal/test_runner/reporter/tap.js index 780d06e8b3c..0f2aa6a722f 100644 --- a/lib/internal/test_runner/reporter/tap.js +++ b/lib/internal/test_runner/reporter/tap.js @@ -9,8 +9,8 @@ const { RegExpPrototypeSymbolSplit, SafeMap, SafeSet, - StringPrototypeReplaceAll, StringPrototypeRepeat, + StringPrototypeReplaceAll, } = primordials; const { inspectWithNoCustomRetry } = require('internal/errors'); const { isError, kEmptyObject } = require('internal/util'); diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index d83b4f1219a..bd86ad38023 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -5,8 +5,8 @@ const { ArrayPrototypeFilter, ArrayPrototypeForEach, ArrayPrototypeIncludes, - ArrayPrototypeMap, ArrayPrototypeJoin, + ArrayPrototypeMap, ArrayPrototypePush, ArrayPrototypeShift, ArrayPrototypeSlice, @@ -14,11 +14,11 @@ const { ArrayPrototypeSort, ObjectAssign, PromisePrototypeThen, + PromiseResolve, + SafeMap, SafePromiseAll, SafePromiseAllReturnVoid, SafePromiseAllSettledReturnVoid, - PromiseResolve, - SafeMap, SafeSet, StringPrototypeIndexOf, StringPrototypeSlice, diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 06409dd3a02..8b1a5b37471 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -11,21 +11,21 @@ const { FunctionPrototype, MathMax, Number, + ObjectDefineProperty, ObjectSeal, PromisePrototypeThen, PromiseResolve, - SafePromisePrototypeFinally, - StringPrototypeStartsWith, - StringPrototypeTrim, ReflectApply, RegExpPrototypeExec, SafeMap, - SafeSet, SafePromiseAll, + SafePromisePrototypeFinally, SafePromiseRace, - SymbolDispose, - ObjectDefineProperty, + SafeSet, + StringPrototypeStartsWith, + StringPrototypeTrim, Symbol, + SymbolDispose, } = primordials; const { getCallerLocation } = internalBinding('util'); const { addAbortListener } = require('internal/events/abort_listener'); diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index d6cd0430cc6..e15e6f206f1 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -1,22 +1,22 @@ 'use strict'; const { + ArrayPrototypeFlatMap, ArrayPrototypeJoin, ArrayPrototypeMap, - ArrayPrototypeFlatMap, ArrayPrototypePush, ArrayPrototypeReduce, ArrayPrototypeSome, - ObjectGetOwnPropertyDescriptor, MathFloor, MathMax, MathMin, NumberPrototypeToFixed, - SafePromiseAllReturnArrayLike, + ObjectGetOwnPropertyDescriptor, RegExp, RegExpPrototypeExec, SafeMap, - StringPrototypePadStart, + SafePromiseAllReturnArrayLike, StringPrototypePadEnd, + StringPrototypePadStart, StringPrototypeRepeat, StringPrototypeSlice, } = primordials; diff --git a/lib/internal/tls/secure-pair.js b/lib/internal/tls/secure-pair.js index 7e0a2f992a8..a7e02eee027 100644 --- a/lib/internal/tls/secure-pair.js +++ b/lib/internal/tls/secure-pair.js @@ -1,16 +1,16 @@ 'use strict'; +const { + ReflectConstruct, + Symbol, +} = primordials; + const EventEmitter = require('events'); const { kEmptyObject } = require('internal/util'); const { Duplex } = require('stream'); const _tls_wrap = require('_tls_wrap'); const _tls_common = require('_tls_common'); -const { - Symbol, - ReflectConstruct, -} = primordials; - const kCallback = Symbol('Callback'); const kOtherSide = Symbol('Other'); diff --git a/lib/internal/util.js b/lib/internal/util.js index 226a57ddda5..364f85c1056 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -12,10 +12,10 @@ const { FunctionPrototypeCall, ObjectDefineProperties, ObjectDefineProperty, + ObjectFreeze, ObjectGetOwnPropertyDescriptor, ObjectGetOwnPropertyDescriptors, ObjectGetPrototypeOf, - ObjectFreeze, ObjectPrototypeHasOwnProperty, ObjectSetPrototypeOf, ObjectValues, @@ -28,9 +28,9 @@ const { RegExpPrototypeGetHasIndices, RegExpPrototypeGetIgnoreCase, RegExpPrototypeGetMultiline, + RegExpPrototypeGetSource, RegExpPrototypeGetSticky, RegExpPrototypeGetUnicode, - RegExpPrototypeGetSource, SafeMap, SafeSet, SafeWeakMap, diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index f9354d01ce5..eed4cc61e8c 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -20,8 +20,8 @@ const { SafeSet, StringPrototypeValueOf, SymbolPrototypeValueOf, - TypedArrayPrototypeGetSymbolToStringTag, TypedArrayPrototypeGetByteLength, + TypedArrayPrototypeGetSymbolToStringTag, Uint8Array, } = primordials; diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 73da4446f82..d6096a5e09c 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -13,8 +13,8 @@ const { ArrayPrototypePush, ArrayPrototypePushApply, ArrayPrototypeSlice, - ArrayPrototypeSplice, ArrayPrototypeSort, + ArrayPrototypeSplice, ArrayPrototypeUnshift, BigIntPrototypeValueOf, BooleanPrototypeValueOf, @@ -26,8 +26,8 @@ const { FunctionPrototypeCall, FunctionPrototypeToString, JSONStringify, - MapPrototypeGetSize, MapPrototypeEntries, + MapPrototypeGetSize, MathFloor, MathMax, MathMin, @@ -61,14 +61,15 @@ const { RegExpPrototypeSymbolReplace, RegExpPrototypeSymbolSplit, RegExpPrototypeToString, - SafeStringIterator, SafeMap, SafeSet, + SafeStringIterator, SetPrototypeGetSize, SetPrototypeValues, String, StringPrototypeCharCodeAt, StringPrototypeCodePointAt, + StringPrototypeEndsWith, StringPrototypeIncludes, StringPrototypeIndexOf, StringPrototypeLastIndexOf, @@ -79,14 +80,13 @@ const { StringPrototypeReplaceAll, StringPrototypeSlice, StringPrototypeSplit, - StringPrototypeEndsWith, StringPrototypeStartsWith, StringPrototypeToLowerCase, StringPrototypeTrim, StringPrototypeValueOf, + SymbolIterator, SymbolPrototypeToString, SymbolPrototypeValueOf, - SymbolIterator, SymbolToStringTag, TypedArrayPrototypeGetLength, TypedArrayPrototypeGetSymbolToStringTag, diff --git a/lib/internal/util/inspector.js b/lib/internal/util/inspector.js index 6ff042af71f..8e2ae548d86 100644 --- a/lib/internal/util/inspector.js +++ b/lib/internal/util/inspector.js @@ -1,8 +1,8 @@ 'use strict'; const { - ArrayPrototypeSome, ArrayPrototypePushApply, + ArrayPrototypeSome, FunctionPrototypeBind, ObjectDefineProperty, ObjectKeys, diff --git a/lib/internal/vm/module.js b/lib/internal/vm/module.js index fe504a99f22..9ab73e4d3d1 100644 --- a/lib/internal/vm/module.js +++ b/lib/internal/vm/module.js @@ -1,6 +1,5 @@ 'use strict'; -const assert = require('internal/assert'); const { ArrayIsArray, ArrayPrototypeForEach, @@ -18,6 +17,7 @@ const { TypeError, } = primordials; +const assert = require('internal/assert'); const { isModuleNamespaceObject, } = require('internal/util/types'); diff --git a/lib/internal/webstreams/adapters.js b/lib/internal/webstreams/adapters.js index cffa549eafd..27abff94ca5 100644 --- a/lib/internal/webstreams/adapters.js +++ b/lib/internal/webstreams/adapters.js @@ -10,10 +10,10 @@ const { SafePromiseAll, SafePromisePrototypeFinally, SafeSet, + TypeError, TypedArrayPrototypeGetBuffer, TypedArrayPrototypeGetByteLength, TypedArrayPrototypeGetByteOffset, - TypeError, Uint8Array, } = primordials; diff --git a/lib/internal/webstreams/readablestream.js b/lib/internal/webstreams/readablestream.js index f30788421f2..76c690fb7a4 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -15,8 +15,8 @@ const { ObjectSetPrototypeOf, Promise, PromisePrototypeThen, - PromiseResolve, PromiseReject, + PromiseResolve, SafePromiseAll, Symbol, SymbolAsyncIterator, diff --git a/lib/internal/webstreams/transformstream.js b/lib/internal/webstreams/transformstream.js index 5bcb757dd5f..68b1e7aa83d 100644 --- a/lib/internal/webstreams/transformstream.js +++ b/lib/internal/webstreams/transformstream.js @@ -5,8 +5,8 @@ const { ObjectDefineProperties, ObjectSetPrototypeOf, PromisePrototypeThen, - SymbolToStringTag, Symbol, + SymbolToStringTag, } = primordials; const { diff --git a/lib/internal/webstreams/writablestream.js b/lib/internal/webstreams/writablestream.js index 121afc0e181..339ce6718a6 100644 --- a/lib/internal/webstreams/writablestream.js +++ b/lib/internal/webstreams/writablestream.js @@ -9,8 +9,8 @@ const { ObjectSetPrototypeOf, Promise, PromisePrototypeThen, - PromiseResolve, PromiseReject, + PromiseResolve, Symbol, SymbolToStringTag, } = primordials; diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index 6f4348f11d2..6e60ca373e0 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -8,8 +8,8 @@ const { FunctionPrototypeCall, ObjectAssign, ObjectCreate, - ObjectDefineProperty, ObjectDefineProperties, + ObjectDefineProperty, ObjectGetOwnPropertyDescriptors, ObjectGetPrototypeOf, ObjectSetPrototypeOf, diff --git a/lib/repl.js b/lib/repl.js index a06ca0dd990..45c9b2fd50e 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -87,9 +87,9 @@ const { StringPrototypeSlice, StringPrototypeSplit, StringPrototypeStartsWith, + StringPrototypeToLocaleLowerCase, StringPrototypeTrim, StringPrototypeTrimStart, - StringPrototypeToLocaleLowerCase, Symbol, SyntaxError, SyntaxErrorPrototype, diff --git a/lib/test.js b/lib/test.js index 1907eb7639b..ddfaa9e4bad 100644 --- a/lib/test.js +++ b/lib/test.js @@ -1,5 +1,10 @@ 'use strict'; -const { ObjectAssign, ObjectDefineProperty } = primordials; + +const { + ObjectAssign, + ObjectDefineProperty, +} = primordials; + const { test, suite, before, after, beforeEach, afterEach } = require('internal/test_runner/harness'); const { run } = require('internal/test_runner/runner'); diff --git a/lib/test/reporters.js b/lib/test/reporters.js index 401f476d290..52b54da6935 100644 --- a/lib/test/reporters.js +++ b/lib/test/reporters.js @@ -1,6 +1,9 @@ 'use strict'; -const { ObjectDefineProperties, ReflectConstruct } = primordials; +const { + ObjectDefineProperties, + ReflectConstruct, +} = primordials; let dot; let junit; diff --git a/lib/timers.js b/lib/timers.js index 7c77ca5c04e..628df3784fc 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -23,8 +23,8 @@ const { MathTrunc, - ObjectDefineProperty, ObjectDefineProperties, + ObjectDefineProperty, SymbolDispose, SymbolToPrimitive, } = primordials; diff --git a/lib/v8.js b/lib/v8.js index a9eee19fb9e..fcc1de6703a 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -25,6 +25,7 @@ const { Int16Array, Int32Array, Int8Array, + JSONParse, ObjectPrototypeToString, Uint16Array, Uint32Array, @@ -64,7 +65,6 @@ const { } = require('internal/heap_utils'); const promiseHooks = require('internal/promise_hooks'); const { getOptionValue } = require('internal/options'); -const { JSONParse } = primordials; /** * Generates a snapshot of the current V8 heap * and writes it to a JSON file. diff --git a/lib/vm.js b/lib/vm.js index 34814c430d3..e1ad4e30c33 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -24,9 +24,9 @@ const { ArrayPrototypeForEach, ObjectFreeze, - Symbol, PromiseReject, ReflectApply, + Symbol, } = primordials; const { diff --git a/test/parallel/test-eslint-alphabetize-primordials.js b/test/parallel/test-eslint-alphabetize-primordials.js new file mode 100644 index 00000000000..ee3e8b19269 --- /dev/null +++ b/test/parallel/test-eslint-alphabetize-primordials.js @@ -0,0 +1,57 @@ +'use strict'; + +const common = require('../common'); +if ((!common.hasCrypto) || (!common.hasIntl)) { + common.skip('ESLint tests require crypto and Intl'); +} + +common.skipIfEslintMissing(); + +const RuleTester = require('../../tools/node_modules/eslint').RuleTester; +const rule = require('../../tools/eslint-rules/alphabetize-primordials'); + +new RuleTester({ + parserOptions: { ecmaVersion: 6 }, + env: { es6: true } +}) + .run('alphabetize-primordials', rule, { + valid: [ + 'new Array()', + '"use strict";const {\nArray\n} = primordials;', + '"use strict";const {\n\tArray,\n\tDate,\n} = primordials', + '"use strict";const {\nDate,Array\n} = notPrimordials', + '"use strict";const {\nDate,globalThis:{Array}\n} = primordials', + '"use strict";const {\nBigInt,globalThis:{Array,Date,SharedArrayBuffer,parseInt}\n} = primordials', + '"use strict";const {\nFunctionPrototypeBind,Uint32Array,globalThis:{SharedArrayBuffer}\n} = primordials', + { + code: '"use strict";const fs = require("fs");const {\nArray\n} = primordials', + options: [{ enforceTopPosition: false }], + }, + ], + invalid: [ + { + code: '"use strict";const {Array} = primordials;', + errors: [{ message: /destructuring from primordials should be multiline/ }], + }, + { + code: '"use strict";const fs = require("fs");const {Date,Array} = primordials', + errors: [ + { message: /destructuring from primordials should be multiline/ }, + { message: /destructuring from primordials should be the first expression/ }, + { message: /Date >= Array/ }, + ], + }, + { + code: 'function fn() {"use strict";const {\nArray,\n} = primordials}', + errors: [{ message: /destructuring from primordials should be the first expression/ }], + }, + { + code: '"use strict";const {\nDate,Array} = primordials', + errors: [{ message: /Date >= Array/ }], + }, + { + code: '"use strict";const {\nglobalThis:{Date, Array}} = primordials', + errors: [{ message: /Date >= Array/ }], + }, + ] + }); diff --git a/tools/eslint-rules/alphabetize-primordials.js b/tools/eslint-rules/alphabetize-primordials.js new file mode 100644 index 00000000000..8aa0a6564b9 --- /dev/null +++ b/tools/eslint-rules/alphabetize-primordials.js @@ -0,0 +1,49 @@ +'use strict'; + +const prefix = 'Out of ASCIIbetical order - '; +const opStr = ' >= '; + +module.exports = { + meta: { + schema: [{ + type: 'object', + properties: { + enforceTopPosition: { type: 'boolean' }, + }, + additionalProperties: false, + }], + }, + create: function(context) { + const enforceTopPosition = context.options.every((option) => option.enforceTopPosition !== false); + return { + 'VariableDeclaration:not(Program>:first-child+*) > VariableDeclarator[init.name="primordials"]'(node) { + if (enforceTopPosition) { + context.report({ + node, + message: 'destructuring from primordials should be the first expression after "use strict"', + }); + } + }, + + 'VariableDeclaration > VariableDeclarator[init.name="primordials"]'({ id: node }) { + const { loc } = node; + if (loc.start.line === loc.end.line) { + context.report({ + node, + message: 'destructuring from primordials should be multiline', + }); + } + }, + + 'VariableDeclaration > VariableDeclarator[init.name="primordials"] Property:not(:first-child)'(node) { + const { properties } = node.parent; + const prev = properties[properties.indexOf(node) - 1].key.name; + const curr = node.key.name; + if (prev >= curr) { + const message = [prefix, prev, opStr, curr].join(''); + context.report({ node, message }); + } + }, + }; + }, +};