Skip to content

Commit 15860ff

Browse files
LiviaMedeiroslouiellan
authored andcommitted
lib,tools: add node-core/func-name-matching lint rule
And rename functions accordingly. Signed-off-by: LiviaMedeiros <livia@cirno.name> Co-authored-by: louiellan <louie.lou.llaneta@gmail.com> PR-URL: #57901 Refs: #57899 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 778d126 commit 15860ff

18 files changed

Lines changed: 1492 additions & 51 deletions

File tree

doc/api/modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ exports = { hello: false }; // Not exported, only available in the module
11321132
When the `module.exports` property is being completely replaced by a new
11331133
object, it is common to also reassign `exports`:
11341134

1135-
<!-- eslint-disable func-name-matching -->
1135+
<!-- eslint-disable node-core/func-name-matching -->
11361136

11371137
```js
11381138
module.exports = exports = function Constructor() {

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ export default [
179179
'default-case-last': 'error',
180180
'dot-notation': 'error',
181181
'eqeqeq': ['error', 'smart'],
182-
'func-name-matching': 'error',
183182
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
184183
'no-constant-condition': ['error', { checkLoops: false }],
185184
'no-constructor-return': 'error',
@@ -391,6 +390,7 @@ export default [
391390
'node-core/no-duplicate-requires': 'error',
392391
'node-core/prefer-proto': 'error',
393392
'node-core/prefer-optional-chaining': 'error',
393+
'node-core/func-name-matching': ['error', { considerPropertyDescriptor: true }],
394394
},
395395
},
396396
// #endregion

lib/fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ function exists(path, callback) {
304304

305305
ObjectDefineProperty(exists, kCustomPromisifiedSymbol, {
306306
__proto__: null,
307-
value: function exists(path) { // eslint-disable-line func-name-matching
307+
value: function exists(path) {
308308
return new Promise((resolve) => fs.exists(path, resolve));
309309
},
310310
});

lib/internal/bootstrap/web/exposed-window-or-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ ObjectDefineProperty(globalThis, 'fetch', {
7575
configurable: true,
7676
enumerable: true,
7777
writable: true,
78-
value: function fetch(input, init = undefined) { // eslint-disable-line func-name-matching
78+
value: function fetch(input, init = undefined) {
7979
if (!fetchImpl) { // Implement lazy loading of undici module for fetch function
8080
const undiciModule = require('internal/deps/undici/undici');
8181
fetchImpl = undiciModule.fetch;

lib/internal/console/constructor.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const {
5151
} = require('internal/validators');
5252
const { previewEntries } = internalBinding('util');
5353
const { Buffer: { isBuffer } } = require('buffer');
54+
const { assignFunctionName } = require('internal/util');
5455
const {
5556
inspect,
5657
formatWithOptions,
@@ -182,9 +183,9 @@ const consolePropAttributes = {
182183
// Fixup global.console instanceof global.console.Console
183184
ObjectDefineProperty(Console, SymbolHasInstance, {
184185
__proto__: null,
185-
value(instance) {
186+
value: assignFunctionName(SymbolHasInstance, function(instance) {
186187
return instance[kIsConsole];
187-
},
188+
}),
188189
});
189190

190191
const kColorInspectOptions = { colors: true };
@@ -197,19 +198,19 @@ ObjectDefineProperties(Console.prototype, {
197198
__proto__: null,
198199
...consolePropAttributes,
199200
// Eager version for the Console constructor
200-
value: function(stdout, stderr) {
201+
value: assignFunctionName(kBindStreamsEager, function(stdout, stderr) {
201202
ObjectDefineProperties(this, {
202203
'_stdout': { __proto__: null, ...consolePropAttributes, value: stdout },
203204
'_stderr': { __proto__: null, ...consolePropAttributes, value: stderr },
204205
});
205-
},
206+
}),
206207
},
207208
[kBindStreamsLazy]: {
208209
__proto__: null,
209210
...consolePropAttributes,
210211
// Lazily load the stdout and stderr from an object so we don't
211212
// create the stdio streams when they are not even accessed
212-
value: function(object) {
213+
value: assignFunctionName(kBindStreamsLazy, function(object) {
213214
let stdout;
214215
let stderr;
215216
ObjectDefineProperties(this, {
@@ -232,12 +233,12 @@ ObjectDefineProperties(Console.prototype, {
232233
set(value) { stderr = value; },
233234
},
234235
});
235-
},
236+
}),
236237
},
237238
[kBindProperties]: {
238239
__proto__: null,
239240
...consolePropAttributes,
240-
value: function(ignoreErrors, colorMode, groupIndentation = 2) {
241+
value: assignFunctionName(kBindProperties, function(ignoreErrors, colorMode, groupIndentation = 2) {
241242
ObjectDefineProperties(this, {
242243
'_stdoutErrorHandler': {
243244
__proto__: null,
@@ -277,12 +278,12 @@ ObjectDefineProperties(Console.prototype, {
277278
value: 'console',
278279
},
279280
});
280-
},
281+
}),
281282
},
282283
[kWriteToConsole]: {
283284
__proto__: null,
284285
...consolePropAttributes,
285-
value: function(streamSymbol, string) {
286+
value: assignFunctionName(kWriteToConsole, function(streamSymbol, string) {
286287
const ignoreErrors = this._ignoreErrors;
287288
const groupIndent = this[kGroupIndentationString];
288289

@@ -320,12 +321,12 @@ ObjectDefineProperties(Console.prototype, {
320321
} finally {
321322
stream.removeListener('error', noop);
322323
}
323-
},
324+
}),
324325
},
325326
[kGetInspectOptions]: {
326327
__proto__: null,
327328
...consolePropAttributes,
328-
value: function(stream) {
329+
value: assignFunctionName(kGetInspectOptions, function(stream) {
329330
let color = this[kColorMode];
330331
if (color === 'auto') {
331332
color = lazyUtilColors().shouldColorize(stream);
@@ -341,12 +342,12 @@ ObjectDefineProperties(Console.prototype, {
341342
}
342343

343344
return color ? kColorInspectOptions : kNoColorInspectOptions;
344-
},
345+
}),
345346
},
346347
[kFormatForStdout]: {
347348
__proto__: null,
348349
...consolePropAttributes,
349-
value: function(args) {
350+
value: assignFunctionName(kFormatForStdout, function(args) {
350351
if (args.length === 1) {
351352
// Fast path: single string, don't call format.
352353
// Avoids ReflectApply and validation overhead.
@@ -358,12 +359,12 @@ ObjectDefineProperties(Console.prototype, {
358359
const opts = this[kGetInspectOptions](this._stdout);
359360
ArrayPrototypeUnshift(args, opts);
360361
return ReflectApply(formatWithOptions, null, args);
361-
},
362+
}),
362363
},
363364
[kFormatForStderr]: {
364365
__proto__: null,
365366
...consolePropAttributes,
366-
value: function(args) {
367+
value: assignFunctionName(kFormatForStderr, function(args) {
367368
if (args.length === 1) {
368369
// Fast path: single string, don't call format.
369370
// Avoids ReflectApply and validation overhead.
@@ -375,7 +376,7 @@ ObjectDefineProperties(Console.prototype, {
375376
const opts = this[kGetInspectOptions](this._stderr);
376377
ArrayPrototypeUnshift(args, opts);
377378
return ReflectApply(formatWithOptions, null, args);
378-
},
379+
}),
379380
},
380381
});
381382

lib/internal/modules/esm/hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ function nextHookFactory(current, meta, { validateArgs, validateOutput }) {
742742
if (next) {
743743
nextNextHook = nextHookFactory(next, meta, { validateArgs, validateOutput });
744744
} else {
745-
// eslint-disable-next-line func-name-matching
745+
// eslint-disable-next-line node-core/func-name-matching
746746
nextNextHook = function chainAdvancedTooFar() {
747747
throw new ERR_INTERNAL_ASSERTION(
748748
`ESM custom loader '${hookName}' advanced beyond the end of the chain.`,

lib/internal/modules/esm/translators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function loadCJSModuleWithSpecialRequire(module, source, url, filename, isMain,
121121
}
122122
const cascadedLoader = require('internal/modules/esm/loader').getOrInitializeCascadedLoader();
123123
const __dirname = dirname(filename);
124-
// eslint-disable-next-line func-name-matching,func-style
124+
// eslint-disable-next-line node-core/func-name-matching,func-style
125125
const requireFn = function require(specifier) {
126126
let importAttributes = kEmptyObject;
127127
if (!StringPrototypeStartsWith(specifier, 'node:') && !BuiltinModule.normalizeRequirableId(specifier)) {

lib/internal/per_context/domexception.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function throwInvalidThisError(Base, type) {
4141
},
4242
toString: {
4343
__proto__: null,
44-
value() {
44+
value: function toString() {
4545
return `${this.name} [${key}]: ${this.message}`;
4646
},
4747
enumerable: false,

lib/internal/streams/writable.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ const {
8484
kOnConstructed,
8585
} = require('internal/streams/utils');
8686

87+
const { assignFunctionName } = require('internal/util');
88+
8789
const { errorOrDestroy } = destroyImpl;
8890

8991
ObjectSetPrototypeOf(Writable.prototype, Stream.prototype);
@@ -434,12 +436,12 @@ function Writable(options) {
434436

435437
ObjectDefineProperty(Writable, SymbolHasInstance, {
436438
__proto__: null,
437-
value: function(object) {
438-
if (FunctionPrototypeSymbolHasInstance(this, object)) return true;
439+
value: assignFunctionName(SymbolHasInstance, function(instance) {
440+
if (FunctionPrototypeSymbolHasInstance(this, instance)) return true;
439441
if (this !== Writable) return false;
440442

441-
return object && object._writableState instanceof WritableState;
442-
},
443+
return instance && instance._writableState instanceof WritableState;
444+
}),
443445
});
444446

445447
// Otherwise people can pipe Writable streams, which is just wrong.

lib/internal/test_runner/mock/mock_timers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ class MockTimers {
644644
__proto__: null,
645645
configurable: true,
646646
writable: true,
647-
value: function value(delay) {
647+
value: function timeout(delay) {
648648
validateUint32(delay, 'delay', false);
649649
const controller = new AbortController();
650650
// Don't keep an unused binding to the timer; mock tick controls it

0 commit comments

Comments
 (0)