Skip to content

Commit 90716ff

Browse files
avivkelleraduh95
authored andcommitted
lib: prefer logical assignment
PR-URL: #55044 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
1 parent 8bb2c1d commit 90716ff

Some content is hidden

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

74 files changed

+178
-304
lines changed

benchmark/_http-benchmarkers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class TestDoubleBenchmarker {
110110
}
111111

112112
create(options) {
113-
process.env.duration = process.env.duration || options.duration || 5;
113+
process.env.duration ||= options.duration || 5;
114114

115115
const scheme = options.scheme || 'http';
116116
const env = {

benchmark/common.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ class Benchmark {
113113
}
114114
const [, key, value] = match;
115115
if (configs[key] !== undefined) {
116-
if (!cliOptions[key])
117-
cliOptions[key] = [];
116+
cliOptions[key] ||= [];
118117
cliOptions[key].push(
119118
// Infer the type from the config object and parse accordingly
120119
typeof configs[key][0] === 'number' ? +value : value,
@@ -177,10 +176,9 @@ class Benchmark {
177176

178177
http(options, cb) {
179178
const http_options = { ...options };
180-
http_options.benchmarker = http_options.benchmarker ||
181-
this.config.benchmarker ||
182-
this.extra_options.benchmarker ||
183-
http_benchmarkers.default_http_benchmarker;
179+
http_options.benchmarker ||= this.config.benchmarker ||
180+
this.extra_options.benchmarker ||
181+
http_benchmarkers.default_http_benchmarker;
184182
http_benchmarkers.run(
185183
http_options, (error, code, used_benchmarker, result, elapsed) => {
186184
if (cb) {

benchmark/es/defaultparams-bench.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const bench = common.createBenchmark(main, {
99
});
1010

1111
function oldStyleDefaults(x, y) {
12-
x = x || 1;
13-
y = y || 2;
12+
x ||= 1;
13+
y ||= 2;
1414
assert.strictEqual(x, 1);
1515
assert.strictEqual(y, 2);
1616
}

benchmark/perf_hooks/resourcetiming.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,12 @@ function createTimingInfo({
2121
finalConnectionTimingInfo = null,
2222
}) {
2323
if (finalConnectionTimingInfo !== null) {
24-
finalConnectionTimingInfo.domainLookupStartTime =
25-
finalConnectionTimingInfo.domainLookupStartTime || 0;
26-
finalConnectionTimingInfo.domainLookupEndTime =
27-
finalConnectionTimingInfo.domainLookupEndTime || 0;
28-
finalConnectionTimingInfo.connectionStartTime =
29-
finalConnectionTimingInfo.connectionStartTime || 0;
30-
finalConnectionTimingInfo.connectionEndTime =
31-
finalConnectionTimingInfo.connectionEndTime || 0;
32-
finalConnectionTimingInfo.secureConnectionStartTime =
33-
finalConnectionTimingInfo.secureConnectionStartTime || 0;
34-
finalConnectionTimingInfo.ALPNNegotiatedProtocol =
35-
finalConnectionTimingInfo.ALPNNegotiatedProtocol || [];
24+
finalConnectionTimingInfo.domainLookupStartTime ||= 0;
25+
finalConnectionTimingInfo.domainLookupEndTime ||= 0;
26+
finalConnectionTimingInfo.connectionStartTime ||= 0;
27+
finalConnectionTimingInfo.connectionEndTime ||= 0;
28+
finalConnectionTimingInfo.secureConnectionStartTime ||= 0;
29+
finalConnectionTimingInfo.ALPNNegotiatedProtocol ||= [];
3630
}
3731
return {
3832
startTime,

benchmark/zlib/deflate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const bench = common.createBenchmark(main, {
1010

1111
function main({ n, method, inputLen }) {
1212
// Default method value for testing.
13-
method = method || 'deflate';
13+
method ||= 'deflate';
1414
const chunk = Buffer.alloc(inputLen, 'a');
1515

1616
switch (method) {

benchmark/zlib/inflate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const bench = common.createBenchmark(main, {
1010

1111
function main({ n, method, inputLen }) {
1212
// Default method value for tests.
13-
method = method || 'inflate';
13+
method ||= 'inflate';
1414
const chunk = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));
1515

1616
let i = 0;

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export default [
142142
ignorePattern: '.*',
143143
},
144144
}],
145+
'logical-assignment-operators': ['error', 'always', { enforceForIfStatements: true }],
145146
'default-case-last': 'error',
146147
'dot-notation': 'error',
147148
'eqeqeq': ['error', 'smart'],

lib/_http_agent.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
246246
normalizeServerName(options, req);
247247

248248
const name = this.getName(options);
249-
if (!this.sockets[name]) {
250-
this.sockets[name] = [];
251-
}
249+
this.sockets[name] ||= [];
252250

253251
const freeSockets = this.freeSockets[name];
254252
let socket;
@@ -284,9 +282,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
284282
} else {
285283
debug('wait for socket');
286284
// We are over limit so we'll add it to the queue.
287-
if (!this.requests[name]) {
288-
this.requests[name] = [];
289-
}
285+
this.requests[name] ||= [];
290286

291287
// Used to create sockets for pending requests from different origin
292288
req[kRequestOptions] = options;
@@ -313,9 +309,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
313309
const oncreate = once((err, s) => {
314310
if (err)
315311
return cb(err);
316-
if (!this.sockets[name]) {
317-
this.sockets[name] = [];
318-
}
312+
this.sockets[name] ||= [];
319313
this.sockets[name].push(s);
320314
this.totalSocketCount++;
321315
debug('sockets', name, this.sockets[name].length, this.totalSocketCount);

lib/_http_client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ function ClientRequest(input, options, cb) {
348348
opts = { ...optsWithoutSignal };
349349
if (opts.socketPath) {
350350
opts.path = opts.socketPath;
351-
} else if (opts.path) {
352-
opts.path = undefined;
351+
} else {
352+
opts.path &&= undefined;
353353
}
354354
}
355355
if (typeof opts.createConnection === 'function') {

lib/_http_server.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ function writeHead(statusCode, reason, obj) {
364364
this.statusMessage = reason;
365365
} else {
366366
// writeHead(statusCode[, headers])
367-
if (!this.statusMessage)
368-
this.statusMessage = STATUS_CODES[statusCode] || 'unknown';
367+
this.statusMessage ||= STATUS_CODES[statusCode] || 'unknown';
369368
obj ??= reason;
370369
}
371370
this.statusCode = statusCode;
@@ -517,9 +516,7 @@ function storeHTTPOptions(options) {
517516

518517
function setupConnectionsTracking() {
519518
// Start connection handling
520-
if (!this[kConnections]) {
521-
this[kConnections] = new ConnectionsList();
522-
}
519+
this[kConnections] ||= new ConnectionsList();
523520

524521
if (this[kConnectionsCheckingInterval]) {
525522
clearInterval(this[kConnectionsCheckingInterval]);
@@ -930,8 +927,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) {
930927
const req = parser.incoming;
931928
debug('SERVER upgrade or connect', req.method);
932929

933-
if (!d)
934-
d = parser.getCurrentBuffer();
930+
d ||= parser.getCurrentBuffer();
935931

936932
socket.removeListener('data', state.onData);
937933
socket.removeListener('end', state.onEnd);
@@ -969,7 +965,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) {
969965
}
970966

971967
function clearIncoming(req) {
972-
req = req || this;
968+
req ||= this;
973969
const parser = req.socket?.parser;
974970
// Reset the .incoming property so that the request object can be gc'ed.
975971
if (parser && parser.incoming === req) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy