Skip to content

Commit 9e5d691

Browse files
ZYSzysBridgeAR
authored andcommitted
lib: introduce no-mixed-operators eslint rule to lib
PR-URL: #29834 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 3f15378 commit 9e5d691

20 files changed

+61
-58
lines changed

lib/.eslintrc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ env:
44
rules:
55
prefer-object-spread: error
66
no-buffer-constructor: error
7+
no-mixed-operators:
8+
- error
9+
- groups: [[ "&&", "||" ]]
710
no-restricted-globals:
811
- error
912
- name: JSON

lib/_http_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function ClientRequest(input, options, cb) {
144144
}
145145

146146
const defaultPort = options.defaultPort ||
147-
this.agent && this.agent.defaultPort;
147+
(this.agent && this.agent.defaultPort);
148148

149149
const port = options.port = options.port || defaultPort || 80;
150150
const host = options.host = validateHost(options.hostname, 'hostname') ||

lib/_stream_readable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
260260
er = chunkInvalid(state, chunk);
261261
if (er) {
262262
errorOrDestroy(stream, er);
263-
} else if (state.objectMode || chunk && chunk.length > 0) {
263+
} else if (state.objectMode || (chunk && chunk.length > 0)) {
264264
if (typeof chunk !== 'string' &&
265265
!state.objectMode &&
266266
// Do not use Object.getPrototypeOf as it is slower since V8 7.3.

lib/_tls_wrap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ function loadSession(hello) {
149149

150150
if (hello.sessionId.length <= 0 ||
151151
hello.tlsTicket ||
152-
owner.server &&
153-
!owner.server.emit('resumeSession', hello.sessionId, onSession)) {
152+
(owner.server &&
153+
!owner.server.emit('resumeSession', hello.sessionId, onSession))) {
154154
// Sessions without identifiers can't be resumed.
155155
// Sessions with tickets can be resumed directly from the ticket, no server
156156
// session storage is necessary.

lib/assert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,9 @@ function checkIsPromise(obj) {
647647
// way. Do not accept thenables that use a function as `obj` and that have no
648648
// `catch` handler.
649649
return isPromise(obj) ||
650-
obj !== null && typeof obj === 'object' &&
650+
(obj !== null && typeof obj === 'object' &&
651651
typeof obj.then === 'function' &&
652-
typeof obj.catch === 'function';
652+
typeof obj.catch === 'function');
653653
}
654654

655655
async function waitForActual(promiseFn) {

lib/internal/assert/assertion_error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class AssertionError extends Error {
349349
// In case "actual" is an object or a function, it should not be
350350
// reference equal.
351351
if (operator === 'notStrictEqual' &&
352-
(typeof actual === 'object' && actual !== null ||
352+
((typeof actual === 'object' && actual !== null) ||
353353
typeof actual === 'function')) {
354354
base = kReadableOperator.notStrictEqualObject;
355355
}

lib/internal/child_process.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ function getValidStdio(stdio, sync) {
934934

935935
if (stdio === 'ignore') {
936936
acc.push({ type: 'ignore' });
937-
} else if (stdio === 'pipe' || typeof stdio === 'number' && stdio < 0) {
937+
} else if (stdio === 'pipe' || (typeof stdio === 'number' && stdio < 0)) {
938938
var a = {
939939
type: 'pipe',
940940
readable: i === 0,

lib/internal/cluster/child.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ cluster._getServer = function(obj, options, cb) {
100100
cluster.worker.state = 'listening';
101101
const address = obj.address();
102102
message.act = 'listening';
103-
message.port = address && address.port || options.port;
103+
message.port = (address && address.port) || options.port;
104104
send(message);
105105
});
106106
};

lib/internal/errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,8 @@ const fatalExceptionStackEnhancers = {
656656
colors: defaultColors
657657
}
658658
} = lazyInternalUtilInspect();
659-
const colors = internalBinding('util').guessHandleType(2) === 'TTY' &&
660-
require('internal/tty').hasColors() ||
659+
const colors = (internalBinding('util').guessHandleType(2) === 'TTY' &&
660+
require('internal/tty').hasColors()) ||
661661
defaultColors;
662662
try {
663663
return inspect(error, { colors });

lib/internal/fs/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ const nullCheck = hideStackFrames((path, propName, throwError = true) => {
204204
const pathIsUint8Array = isUint8Array(path);
205205

206206
// We can only perform meaningful checks on strings and Uint8Arrays.
207-
if (!pathIsString && !pathIsUint8Array ||
208-
pathIsString && !path.includes('\u0000') ||
209-
pathIsUint8Array && !path.includes(0)) {
207+
if ((!pathIsString && !pathIsUint8Array) ||
208+
(pathIsString && !path.includes('\u0000')) ||
209+
(pathIsUint8Array && !path.includes(0))) {
210210
return;
211211
}
212212

0 commit comments

Comments
 (0)