Skip to content

Commit 2569b25

Browse files
author
Eddie Louie
committed
SERVER-23728 Enable the no-unused-expressions ESLint rule
1 parent 2d00414 commit 2569b25

14 files changed

+34
-67
lines changed

.eslintrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ rules:
3333
no-sparse-arrays: 2
3434
no-unexpected-multiline: 2
3535
no-unreachable: 2
36+
no-unused-expressions: 2
3637
no-useless-call: 2
3738
no-with: 2
3839
semi: 2

jstests/auth/basic_role_auth.js

+16-21
Original file line numberDiff line numberDiff line change
@@ -157,32 +157,27 @@ var testOps = function(db, allowedActions) {
157157
var dbName = db.getName();
158158
var db2 = newConn.getDB(dbName);
159159

160-
if (db2 == 'admin') {
160+
if (db2.getName() == 'admin') {
161161
assert.eq(1, db2.auth('aro', AUTH_INFO.admin.aro.pwd));
162162
} else {
163163
assert.eq(1, db2.auth('ro', AUTH_INFO.test.ro.pwd));
164164
}
165165

166-
var cursor = db2.kill_cursor.find().batchSize(2);
167-
168-
db.killCursor(cursor.id());
169-
// Send a synchronous message to make sure that kill cursor was processed
170-
// before proceeding.
171-
db.runCommand({whatsmyuri: 1});
172-
173-
checkErr(!allowedActions.hasOwnProperty('killCursor'), function() {
174-
while (cursor.hasNext()) {
175-
var next = cursor.next();
176-
177-
// This is a failure in mongos case. Standalone case will fail
178-
// when next() was called.
179-
if (next.code == 16336) {
180-
// could not find cursor in cache for id
181-
throw next.$err;
182-
}
183-
}
166+
// Create cursor from db2.
167+
var cmdRes = db2.runCommand({find: db2.kill_cursor.getName(), batchSize: 2});
168+
assert.commandWorked(cmdRes);
169+
var cursorId = cmdRes.cursor.id;
170+
assert(!bsonBinaryEqual({cursorId: cursorId}, {cursorId: NumberLong(0)}),
171+
"find command didn't return a cursor: " + tojson(cmdRes));
172+
173+
checkErr(allowedActions.hasOwnProperty('killCursor'), function() {
174+
// Issue killCursor command from db.
175+
cmdRes = db.runCommand({killCursors: db2.kill_cursor.getName(), cursors: [cursorId]});
176+
assert.commandWorked(cmdRes);
177+
assert(bsonBinaryEqual({cursorId: cmdRes.cursorsKilled}, {cursorId: [cursorId]}),
178+
"unauthorized to kill cursor: " + tojson(cmdRes));
184179
});
185-
}); // TODO: enable test after SERVER-5813 is fixed.
180+
})();
186181

187182
var isMongos = db.runCommand({isdbgrid: 1}).isdbgrid;
188183
// Note: fsyncUnlock is not supported in mongos.
@@ -192,7 +187,7 @@ var testOps = function(db, allowedActions) {
192187
var errorCodeUnauthorized = 13;
193188

194189
if (res.code == errorCodeUnauthorized) {
195-
throw Error("unauthorized unauthorized fsyncUnlock");
190+
throw Error("unauthorized fsyncUnlock");
196191
}
197192
});
198193
}

jstests/core/covered_index_sort_3.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ coll.drop();
1313
for (i = 0; i < 100; i++) {
1414
coll.insert({a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10)});
1515
}
16-
coll.insert;
16+
1717
coll.ensureIndex({a: 1, b: -1, c: 1});
1818

1919
// Test no query, sort on all fields in index order

jstests/core/distinct_speed1.js

-25
This file was deleted.

jstests/core/elemMatchProjection.js

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ assert.throws(function() {
9696
}, [], "throw on invalid sorted projection (field mismatch)");
9797

9898
assert.throws(function() {
99-
x;
10099
t.find({group: 3, 'x.a': 2}, {'x.$': 1, group: 0}).sort({x: 1}).toArray();
101100
}, [], "throw on invalid projection combination (include and exclude)");
102101

jstests/core/eval_wait_for_read_write_concern.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
writeConcern: {w: 'majority', wtimeout: 30000}
1414
};
1515
db.runCommand({'eval': 'db.runCommand(' + tojson(insertCommand) + ')'});
16-
});
16+
})();

jstests/core/group1.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ p = {
103103
},
104104
initial: {count: 0},
105105
finalize: function(obj) {
106-
ob;
106+
throw new Error("Intentionally throwing exception in finalize function");
107107
}
108108
};
109109
assert.commandFailedWithCode(
@@ -117,7 +117,7 @@ p = {
117117
},
118118
initial: {count: 0},
119119
finalize: function(obj) {
120-
ob;
120+
throw new Error("Intentionally throwing exception in finalize function");
121121
}
122122
};
123123
assert.commandFailedWithCode(

jstests/core/js4.js

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ assert.eq("/abc/i", real.c.toString(), "regex 1");
1616

1717
var cursor = t.find({
1818
$where: function() {
19-
fullObject;
2019
assert.eq(7, Object.keySet(obj).length, "A");
2120
assert.eq(1, obj.a, "B");
2221
assert.eq("abc", obj.b, "C");
@@ -37,7 +36,6 @@ t.drop();
3736
t.save({a: 2, b: {c: 7, d: "d is good"}});
3837
var cursor = t.find({
3938
$where: function() {
40-
fullObject;
4139
assert.eq(3, Object.keySet(obj).length);
4240
assert.eq(2, obj.a);
4341
assert.eq(7, obj.b.c);

jstests/core/ora.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ t.drop();
1717
t.ensureIndex({loc: "2d"});
1818

1919
assert.throws(function() {
20-
t.find({$or: [{loc: {$near: [11, 11]}}]}).limit(1).next()['_id'];
20+
t.find({$or: [{loc: {$near: [11, 11]}}]}).limit(1).next();
2121
});

jstests/replsets/command_response_operation_time.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* and local reads and writes return the last applied optime's timestamp.
55
*/
66
(function() {
7-
load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
8-
97
"use strict";
108

9+
load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
10+
1111
function assertCorrectOperationTime(operationTime, expectedTimestamp, opTimeType) {
1212
assert.eq(0,
1313
timestampCmp(operationTime, expectedTimestamp),

jstests/replsets/pipelineout.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ var secondary = replTest.liveNodes.slaves[0].getDB(name);
1212

1313
// populate the collection
1414
for (i = 0; i < 5; i++) {
15-
primary.in .insert({x: i});
15+
primary.coll.insert({x: i});
1616
}
1717
replTest.awaitReplication();
1818

1919
// make sure $out cannot be run on a secondary
2020
assert.throws(function() {
21-
secondary.in .aggregate({$out: "out"}).itcount;
21+
secondary.coll.aggregate({$out: "out"}).itcount();
2222
});
2323
// even if slaveOk
2424
secondary.setSlaveOk();
2525
assert.throws(function() {
26-
secondary.in .aggregate({$out: "out"}).itcount;
26+
secondary.coll.aggregate({$out: "out"}).itcount();
2727
});
2828

2929
// run one and check for proper replication
30-
primary.in .aggregate({$out: "out"}).itcount;
30+
primary.coll.aggregate({$out: "out"}).itcount();
3131
replTest.awaitReplication();
3232
assert.eq(primary.out.find().sort({x: 1}).toArray(), secondary.out.find().sort({x: 1}).toArray());

jstests/replsets/shutdown_primary.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
*
1313
*/
1414
(function() {
15-
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries,
16-
// restartReplicationOnSecondaries
17-
1815
"use strict";
1916

17+
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries,
18+
// restartReplicationOnSecondaries
2019
var name = "shutdown_primary";
2120

2221
var replTest = new ReplSetTest({name: name, nodes: 3});

jstests/replsets/stepdown_needs_electable_secondary.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
*
2121
*/
2222
(function() {
23+
'use strict';
24+
2325
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries,
2426
// restartServerReplication,
2527
// restartReplSetReplication
2628

27-
'use strict';
28-
2929
var name = 'stepdown_needs_electable_secondary';
3030

3131
var replTest = new ReplSetTest({name: name, nodes: 5});

jstests/replsets/stepdown_needs_majority.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
*
1717
*/
1818
(function() {
19+
'use strict';
20+
1921
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries, //
2022
// restartServerReplication,
2123
// restartReplSetReplication
2224

23-
'use strict';
24-
2525
function assertStepDownFailsWithExceededTimeLimit(node) {
2626
assert.commandFailedWithCode(
2727
node.getDB("admin").runCommand({replSetStepDown: 5, secondaryCatchUpPeriodSecs: 5}),

0 commit comments

Comments
 (0)