Skip to content

[WIP] lib: rename functions named value #57901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@

ObjectDefineProperty(exists, kCustomPromisifiedSymbol, {
__proto__: null,
value: function exists(path) { // eslint-disable-line func-name-matching
value: function exists(path) {

Check failure on line 256 in lib/fs.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Function name `exists` should match property name `value`
return new Promise((resolve) => fs.exists(path, resolve));
},
});
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/web/exposed-window-or-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
configurable: true,
enumerable: true,
writable: true,
value: function fetch(input, init = undefined) { // eslint-disable-line func-name-matching
value: function fetch(input, init = undefined) {

Check failure on line 78 in lib/internal/bootstrap/web/exposed-window-or-worker.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Function name `fetch` should match property name `value`
if (!fetchImpl) { // Implement lazy loading of undici module for fetch function
const undiciModule = require('internal/deps/undici/undici');
fetchImpl = undiciModule.fetch;
Expand Down
33 changes: 17 additions & 16 deletions lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 };
Expand All @@ -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, {
Expand All @@ -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,
Expand Down Expand Up @@ -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) || '';

Expand Down Expand Up @@ -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);
Expand All @@ -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);
},
}),
},
});

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/per_context/domexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
toString: {
__proto__: null,
value() {
value: function toString() {

Check failure on line 29 in lib/internal/per_context/domexception.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Function name `toString` should match property name `value`
return `${this.name} [${key}]: ${this.message}`;
},
enumerable: false,
Expand Down
10 changes: 6 additions & 4 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const {
kOnConstructed,
} = require('internal/streams/utils');

const { assignFunctionName } = require('internal/util');

const { errorOrDestroy } = destroyImpl;

ObjectSetPrototypeOf(Writable.prototype, Stream.prototype);
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions lib/internal/util/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,40 +76,40 @@
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) {

Check failure on line 87 in lib/internal/util/types.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Function name `isKeyObject` should match property name `value`
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) {

Check failure on line 103 in lib/internal/util/types.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Function name `isCryptoKey` should match property name `value`
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);
},
},
});
7 changes: 4 additions & 3 deletions lib/internal/worker/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
} = primordials;

const {
assignFunctionName,
kEnumerableProperty,
setOwnProperty,
} = require('internal/util');
Expand Down Expand Up @@ -131,14 +132,14 @@
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,
Expand Down Expand Up @@ -189,7 +190,7 @@
__proto__: null,
enumerable: false,
writable: false,
value: function inspect() { // eslint-disable-line func-name-matching
value: function inspect() {

Check failure on line 193 in lib/internal/worker/io.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Function name `inspect` should match property name `value`
let ref;
try {
// This may throw when `this` does not refer to a native object,
Expand Down
16 changes: 8 additions & 8 deletions lib/test/reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

let dot;
let junit;
let spec;
let specFn;
let tap;
let lcov;
let lcovFn;

ObjectDefineProperties(module.exports, {
__proto__: null,
Expand All @@ -35,9 +35,9 @@
__proto__: null,
configurable: true,
enumerable: true,
value: function value() {
spec ??= require('internal/test_runner/reporter/spec');
return ReflectConstruct(spec, arguments);
value: function spec() {

Check failure on line 38 in lib/test/reporters.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Function name `spec` should match property name `value`
specFn ??= require('internal/test_runner/reporter/spec');
return ReflectConstruct(specFn, arguments);
},
},
tap: {
Expand All @@ -53,9 +53,9 @@
__proto__: null,
configurable: true,
enumerable: true,
value: function value() {
lcov ??= require('internal/test_runner/reporter/lcov');
return ReflectConstruct(lcov, arguments);
value: function lcov() {

Check failure on line 56 in lib/test/reporters.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Function name `lcov` should match property name `value`
lcovFn ??= require('internal/test_runner/reporter/lcov');
return ReflectConstruct(lcovFn, arguments);
},
},
});
5 changes: 3 additions & 2 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const {
} = require('internal/errors');
const { Transform, finished } = require('stream');
const {
assignFunctionName,
deprecateInstantiation,
} = require('internal/util');
const {
Expand Down Expand Up @@ -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);
},
}),
};
}

Expand Down
Loading