diff --git a/eslint.config.mjs b/eslint.config.mjs index cc1cfa751ab986..9eaa067eba75d3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -173,7 +173,10 @@ export default [ 'default-case-last': 'error', 'dot-notation': 'error', 'eqeqeq': ['error', 'smart'], - 'func-name-matching': 'error', + + // TODO: make this rule consider primordials + 'func-name-matching': ['error', { considerPropertyDescriptor: true }], + 'func-style': ['error', 'declaration', { allowArrowFunctions: true }], 'no-constant-condition': ['error', { checkLoops: false }], 'no-constructor-return': 'error', diff --git a/lib/fs.js b/lib/fs.js index 35179db26e5dc1..0ba633d9efe642 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -253,7 +253,7 @@ function exists(path, callback) { ObjectDefineProperty(exists, kCustomPromisifiedSymbol, { __proto__: null, - value: function exists(path) { // eslint-disable-line func-name-matching + value: function exists(path) { return new Promise((resolve) => fs.exists(path, resolve)); }, }); diff --git a/lib/internal/bootstrap/web/exposed-window-or-worker.js b/lib/internal/bootstrap/web/exposed-window-or-worker.js index f86efb261f0c9d..4132a162996e3c 100644 --- a/lib/internal/bootstrap/web/exposed-window-or-worker.js +++ b/lib/internal/bootstrap/web/exposed-window-or-worker.js @@ -75,7 +75,7 @@ ObjectDefineProperty(globalThis, 'fetch', { configurable: true, enumerable: true, writable: true, - value: function fetch(input, init = undefined) { // eslint-disable-line func-name-matching + value: function fetch(input, init = undefined) { if (!fetchImpl) { // Implement lazy loading of undici module for fetch function const undiciModule = require('internal/deps/undici/undici'); fetchImpl = undiciModule.fetch; diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 26f2e837d74f6f..0fe4de86cebd7e 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -49,6 +49,7 @@ const { } = require('internal/validators'); const { previewEntries } = internalBinding('util'); const { Buffer: { isBuffer } } = require('buffer'); +const { assignFunctionName } = require('internal/util'); const { inspect, formatWithOptions, @@ -172,9 +173,9 @@ const consolePropAttributes = { // Fixup global.console instanceof global.console.Console ObjectDefineProperty(Console, SymbolHasInstance, { __proto__: null, - value(instance) { + value: assignFunctionName(SymbolHasInstance, function(instance) { return instance[kIsConsole]; - }, + }), }); const kColorInspectOptions = { colors: true }; @@ -187,19 +188,19 @@ ObjectDefineProperties(Console.prototype, { __proto__: null, ...consolePropAttributes, // Eager version for the Console constructor - value: function(stdout, stderr) { + value: assignFunctionName(kBindStreamsEager, function(stdout, stderr) { ObjectDefineProperties(this, { '_stdout': { __proto__: null, ...consolePropAttributes, value: stdout }, '_stderr': { __proto__: null, ...consolePropAttributes, value: stderr }, }); - }, + }), }, [kBindStreamsLazy]: { __proto__: null, ...consolePropAttributes, // Lazily load the stdout and stderr from an object so we don't // create the stdio streams when they are not even accessed - value: function(object) { + value: assignFunctionName(kBindStreamsLazy, function(object) { let stdout; let stderr; ObjectDefineProperties(this, { @@ -222,12 +223,12 @@ ObjectDefineProperties(Console.prototype, { set(value) { stderr = value; }, }, }); - }, + }), }, [kBindProperties]: { __proto__: null, ...consolePropAttributes, - value: function(ignoreErrors, colorMode, groupIndentation = 2) { + value: assignFunctionName(kBindProperties, function(ignoreErrors, colorMode, groupIndentation = 2) { ObjectDefineProperties(this, { '_stdoutErrorHandler': { __proto__: null, @@ -262,12 +263,12 @@ ObjectDefineProperties(Console.prototype, { value: 'console', }, }); - }, + }), }, [kWriteToConsole]: { __proto__: null, ...consolePropAttributes, - value: function(streamSymbol, string) { + value: assignFunctionName(kWriteToConsole, function(streamSymbol, string) { const ignoreErrors = this._ignoreErrors; const groupIndent = internalIndentationMap.get(this) || ''; @@ -305,12 +306,12 @@ ObjectDefineProperties(Console.prototype, { } finally { stream.removeListener('error', noop); } - }, + }), }, [kGetInspectOptions]: { __proto__: null, ...consolePropAttributes, - value: function(stream) { + value: assignFunctionName(kGetInspectOptions, function(stream) { let color = this[kColorMode]; if (color === 'auto') { color = lazyUtilColors().shouldColorize(stream); @@ -325,25 +326,25 @@ ObjectDefineProperties(Console.prototype, { } return color ? kColorInspectOptions : kNoColorInspectOptions; - }, + }), }, [kFormatForStdout]: { __proto__: null, ...consolePropAttributes, - value: function(args) { + value: assignFunctionName(kFormatForStdout, function(args) { const opts = this[kGetInspectOptions](this._stdout); ArrayPrototypeUnshift(args, opts); return ReflectApply(formatWithOptions, null, args); - }, + }), }, [kFormatForStderr]: { __proto__: null, ...consolePropAttributes, - value: function(args) { + value: assignFunctionName(kFormatForStderr, function(args) { const opts = this[kGetInspectOptions](this._stderr); ArrayPrototypeUnshift(args, opts); return ReflectApply(formatWithOptions, null, args); - }, + }), }, }); diff --git a/lib/internal/per_context/domexception.js b/lib/internal/per_context/domexception.js index cf9042fec7c341..9a14910e2bc5e1 100644 --- a/lib/internal/per_context/domexception.js +++ b/lib/internal/per_context/domexception.js @@ -26,7 +26,7 @@ function throwInvalidThisError(Base, type) { }, toString: { __proto__: null, - value() { + value: function toString() { return `${this.name} [${key}]: ${this.message}`; }, enumerable: false, diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index ac14b202b6639c..7549c2cf372a7a 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -85,6 +85,8 @@ const { kOnConstructed, } = require('internal/streams/utils'); +const { assignFunctionName } = require('internal/util'); + const { errorOrDestroy } = destroyImpl; ObjectSetPrototypeOf(Writable.prototype, Stream.prototype); @@ -435,12 +437,12 @@ function Writable(options) { ObjectDefineProperty(Writable, SymbolHasInstance, { __proto__: null, - value: function(object) { - if (FunctionPrototypeSymbolHasInstance(this, object)) return true; + value: assignFunctionName(SymbolHasInstance, function(instance) { + if (FunctionPrototypeSymbolHasInstance(this, instance)) return true; if (this !== Writable) return false; - return object && object._writableState instanceof WritableState; - }, + return instance && instance._writableState instanceof WritableState; + }), }); // Otherwise people can pipe Writable streams, which is just wrong. diff --git a/lib/internal/util/types.js b/lib/internal/util/types.js index 393608331aa1f5..e56d3b72010fdc 100644 --- a/lib/internal/util/types.js +++ b/lib/internal/util/types.js @@ -76,40 +76,40 @@ module.exports = { isBigUint64Array, }; -let isCryptoKey; -let isKeyObject; +let isCryptoKeyFn; +let isKeyObjectFn; ObjectDefineProperties(module.exports, { isKeyObject: { __proto__: null, configurable: false, enumerable: true, - value(obj) { + value: function isKeyObject(obj) { if (!process.versions.openssl) { return false; } - if (!isKeyObject) { - ({ isKeyObject } = require('internal/crypto/keys')); + if (!isKeyObjectFn) { + ({ isKeyObject: isKeyObjectFn } = require('internal/crypto/keys')); } - return isKeyObject(obj); + return isKeyObjectFn(obj); }, }, isCryptoKey: { __proto__: null, configurable: false, enumerable: true, - value(obj) { + value: function isCryptoKey(obj) { if (!process.versions.openssl) { return false; } - if (!isCryptoKey) { - ({ isCryptoKey } = require('internal/crypto/keys')); + if (!isCryptoKeyFn) { + ({ isCryptoKey: isCryptoKeyFn } = require('internal/crypto/keys')); } - return isCryptoKey(obj); + return isCryptoKeyFn(obj); }, }, }); diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index 29c7914982b67a..d8b4c7a701fe69 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -18,6 +18,7 @@ const { } = primordials; const { + assignFunctionName, kEnumerableProperty, setOwnProperty, } = require('internal/util'); @@ -131,14 +132,14 @@ ObjectDefineProperty( kCreateEvent, { __proto__: null, - value: function(data, type) { + value: assignFunctionName(kCreateEvent, function(data, type) { if (type !== 'message' && type !== 'messageerror') { return ReflectApply(originalCreateEvent, this, arguments); } const ports = this[kCurrentlyReceivingPorts]; this[kCurrentlyReceivingPorts] = undefined; return lazyMessageEvent(type, { data, ports }); - }, + }), configurable: false, writable: false, enumerable: false, @@ -189,7 +190,7 @@ ObjectDefineProperty(MessagePort.prototype, inspect.custom, { __proto__: null, enumerable: false, writable: false, - value: function inspect() { // eslint-disable-line func-name-matching + value: function inspect() { let ref; try { // This may throw when `this` does not refer to a native object, diff --git a/lib/test/reporters.js b/lib/test/reporters.js index 52b54da6935130..a03b17a9eb0bbb 100644 --- a/lib/test/reporters.js +++ b/lib/test/reporters.js @@ -7,9 +7,9 @@ const { let dot; let junit; -let spec; +let specFn; let tap; -let lcov; +let lcovFn; ObjectDefineProperties(module.exports, { __proto__: null, @@ -35,9 +35,9 @@ ObjectDefineProperties(module.exports, { __proto__: null, configurable: true, enumerable: true, - value: function value() { - spec ??= require('internal/test_runner/reporter/spec'); - return ReflectConstruct(spec, arguments); + value: function spec() { + specFn ??= require('internal/test_runner/reporter/spec'); + return ReflectConstruct(specFn, arguments); }, }, tap: { @@ -53,9 +53,9 @@ ObjectDefineProperties(module.exports, { __proto__: null, configurable: true, enumerable: true, - value: function value() { - lcov ??= require('internal/test_runner/reporter/lcov'); - return ReflectConstruct(lcov, arguments); + value: function lcov() { + lcovFn ??= require('internal/test_runner/reporter/lcov'); + return ReflectConstruct(lcovFn, arguments); }, }, }); diff --git a/lib/zlib.js b/lib/zlib.js index 058e03c7180620..1d7b27c48bbffb 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -48,6 +48,7 @@ const { } = require('internal/errors'); const { Transform, finished } = require('stream'); const { + assignFunctionName, deprecateInstantiation, } = require('internal/util'); const { @@ -914,9 +915,9 @@ function createProperty(ctor) { __proto__: null, configurable: true, enumerable: true, - value: function(options) { + value: assignFunctionName(`create${ctor.name}`, function(options) { return new ctor(options); - }, + }), }; }