Skip to content

Commit d803355

Browse files
avivkellertargos
authored andcommittedOct 4, 2024
lib: prefer optional chaining
PR-URL: #55045 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent cbfc980 commit d803355

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+228
-121
lines changed
 

‎eslint.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ export default [
313313
'node-core/no-unescaped-regexp-dot': 'error',
314314
'node-core/no-duplicate-requires': 'error',
315315
'node-core/prefer-proto': 'error',
316+
'node-core/prefer-optional-chaining': 'error',
316317
},
317318
},
318319
// #endregion

‎lib/_http_agent.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function Agent(options) {
128128
}
129129

130130
const requests = this.requests[name];
131-
if (requests && requests.length) {
131+
if (requests?.length) {
132132
const req = requests.shift();
133133
const reqAsyncRes = req[kRequestAsyncResource];
134134
if (reqAsyncRes) {
@@ -437,7 +437,7 @@ Agent.prototype.removeSocket = function removeSocket(s, options) {
437437
}
438438

439439
let req;
440-
if (this.requests[name] && this.requests[name].length) {
440+
if (this.requests[name]?.length) {
441441
debug('removeSocket, have a request, make a socket');
442442
req = this.requests[name][0];
443443
} else {
@@ -449,7 +449,7 @@ Agent.prototype.removeSocket = function removeSocket(s, options) {
449449
for (let i = 0; i < keys.length; i++) {
450450
const prop = keys[i];
451451
// Check whether this specific origin is already at maxSockets
452-
if (this.sockets[prop] && this.sockets[prop].length) break;
452+
if (this.sockets[prop]?.length) break;
453453
debug('removeSocket, have a request with different origin,' +
454454
' make a socket');
455455
req = this.requests[prop][0];

0 commit comments

Comments
 (0)
Please sign in to comment.