summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEddie Louie <eddie.louie@mongodb.com>2017-03-28 13:42:11 -0400
committerEddie Louie <eddie.louie@mongodb.com>2017-04-05 18:40:37 -0400
commit2569b254a53586f1177b82bdc567463e84be75e2 (patch)
tree860eefcb637783cf310256bdabe5b9bda2fa89f3
parent2d00414fa0f31473f5fa7c1ad3c728051871ec4e (diff)
downloadmongo-2569b254a53586f1177b82bdc567463e84be75e2.tar.gz
SERVER-23728 Enable the no-unused-expressions ESLint rule
-rw-r--r--.eslintrc.yml1
-rw-r--r--jstests/auth/basic_role_auth.js37
-rw-r--r--jstests/core/covered_index_sort_3.js2
-rw-r--r--jstests/core/distinct_speed1.js25
-rw-r--r--jstests/core/elemMatchProjection.js1
-rw-r--r--jstests/core/eval_wait_for_read_write_concern.js2
-rw-r--r--jstests/core/group1.js4
-rw-r--r--jstests/core/js4.js2
-rw-r--r--jstests/core/ora.js2
-rw-r--r--jstests/replsets/command_response_operation_time.js4
-rw-r--r--jstests/replsets/pipelineout.js8
-rw-r--r--jstests/replsets/shutdown_primary.js5
-rw-r--r--jstests/replsets/stepdown_needs_electable_secondary.js4
-rw-r--r--jstests/replsets/stepdown_needs_majority.js4
14 files changed, 34 insertions, 67 deletions
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 8ce934e1774..de2e6f3ba06 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -33,6 +33,7 @@ rules:
no-sparse-arrays: 2
no-unexpected-multiline: 2
no-unreachable: 2
+ no-unused-expressions: 2
no-useless-call: 2
no-with: 2
semi: 2
diff --git a/jstests/auth/basic_role_auth.js b/jstests/auth/basic_role_auth.js
index 7188aa7e4f6..0dfef842da8 100644
--- a/jstests/auth/basic_role_auth.js
+++ b/jstests/auth/basic_role_auth.js
@@ -157,32 +157,27 @@ var testOps = function(db, allowedActions) {
var dbName = db.getName();
var db2 = newConn.getDB(dbName);
- if (db2 == 'admin') {
+ if (db2.getName() == 'admin') {
assert.eq(1, db2.auth('aro', AUTH_INFO.admin.aro.pwd));
} else {
assert.eq(1, db2.auth('ro', AUTH_INFO.test.ro.pwd));
}
- var cursor = db2.kill_cursor.find().batchSize(2);
-
- db.killCursor(cursor.id());
- // Send a synchronous message to make sure that kill cursor was processed
- // before proceeding.
- db.runCommand({whatsmyuri: 1});
-
- checkErr(!allowedActions.hasOwnProperty('killCursor'), function() {
- while (cursor.hasNext()) {
- var next = cursor.next();
-
- // This is a failure in mongos case. Standalone case will fail
- // when next() was called.
- if (next.code == 16336) {
- // could not find cursor in cache for id
- throw next.$err;
- }
- }
+ // Create cursor from db2.
+ var cmdRes = db2.runCommand({find: db2.kill_cursor.getName(), batchSize: 2});
+ assert.commandWorked(cmdRes);
+ var cursorId = cmdRes.cursor.id;
+ assert(!bsonBinaryEqual({cursorId: cursorId}, {cursorId: NumberLong(0)}),
+ "find command didn't return a cursor: " + tojson(cmdRes));
+
+ checkErr(allowedActions.hasOwnProperty('killCursor'), function() {
+ // Issue killCursor command from db.
+ cmdRes = db.runCommand({killCursors: db2.kill_cursor.getName(), cursors: [cursorId]});
+ assert.commandWorked(cmdRes);
+ assert(bsonBinaryEqual({cursorId: cmdRes.cursorsKilled}, {cursorId: [cursorId]}),
+ "unauthorized to kill cursor: " + tojson(cmdRes));
});
- }); // TODO: enable test after SERVER-5813 is fixed.
+ })();
var isMongos = db.runCommand({isdbgrid: 1}).isdbgrid;
// Note: fsyncUnlock is not supported in mongos.
@@ -192,7 +187,7 @@ var testOps = function(db, allowedActions) {
var errorCodeUnauthorized = 13;
if (res.code == errorCodeUnauthorized) {
- throw Error("unauthorized unauthorized fsyncUnlock");
+ throw Error("unauthorized fsyncUnlock");
}
});
}
diff --git a/jstests/core/covered_index_sort_3.js b/jstests/core/covered_index_sort_3.js
index b93b25f02a3..aeeb6f70773 100644
--- a/jstests/core/covered_index_sort_3.js
+++ b/jstests/core/covered_index_sort_3.js
@@ -13,7 +13,7 @@ coll.drop();
for (i = 0; i < 100; i++) {
coll.insert({a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10)});
}
-coll.insert;
+
coll.ensureIndex({a: 1, b: -1, c: 1});
// Test no query, sort on all fields in index order
diff --git a/jstests/core/distinct_speed1.js b/jstests/core/distinct_speed1.js
deleted file mode 100644
index 9d7a114e418..00000000000
--- a/jstests/core/distinct_speed1.js
+++ /dev/null
@@ -1,25 +0,0 @@
-
-t = db.distinct_speed1;
-
-t.drop();
-for (var i = 0; i < 10000; i++) {
- t.save({x: i % 10});
-}
-
-assert.eq(10, t.distinct("x").length, "A1");
-
-function fast() {
- t.find().explain("executionStats").executionStats.executionTimeMillis;
-}
-
-function slow() {
- t.distinct("x");
-}
-
-for (i = 0; i < 3; i++) {
- print("it: " + Date.timeFunc(fast));
- print("di: " + Date.timeFunc(slow));
-}
-
-t.ensureIndex({x: 1});
-t.distinct("x", {x: 5});
diff --git a/jstests/core/elemMatchProjection.js b/jstests/core/elemMatchProjection.js
index 4e80e8a296e..ce4fd0639a7 100644
--- a/jstests/core/elemMatchProjection.js
+++ b/jstests/core/elemMatchProjection.js
@@ -96,7 +96,6 @@ assert.throws(function() {
}, [], "throw on invalid sorted projection (field mismatch)");
assert.throws(function() {
- x;
t.find({group: 3, 'x.a': 2}, {'x.$': 1, group: 0}).sort({x: 1}).toArray();
}, [], "throw on invalid projection combination (include and exclude)");
diff --git a/jstests/core/eval_wait_for_read_write_concern.js b/jstests/core/eval_wait_for_read_write_concern.js
index 32184e7b8c1..e24fea467c4 100644
--- a/jstests/core/eval_wait_for_read_write_concern.js
+++ b/jstests/core/eval_wait_for_read_write_concern.js
@@ -13,4 +13,4 @@
writeConcern: {w: 'majority', wtimeout: 30000}
};
db.runCommand({'eval': 'db.runCommand(' + tojson(insertCommand) + ')'});
-});
+})();
diff --git a/jstests/core/group1.js b/jstests/core/group1.js
index 579c706ee3d..70a266e2a55 100644
--- a/jstests/core/group1.js
+++ b/jstests/core/group1.js
@@ -103,7 +103,7 @@ p = {
},
initial: {count: 0},
finalize: function(obj) {
- ob;
+ throw new Error("Intentionally throwing exception in finalize function");
}
};
assert.commandFailedWithCode(
@@ -117,7 +117,7 @@ p = {
},
initial: {count: 0},
finalize: function(obj) {
- ob;
+ throw new Error("Intentionally throwing exception in finalize function");
}
};
assert.commandFailedWithCode(
diff --git a/jstests/core/js4.js b/jstests/core/js4.js
index 51a85182866..af9c3f84d3c 100644
--- a/jstests/core/js4.js
+++ b/jstests/core/js4.js
@@ -16,7 +16,6 @@ assert.eq("/abc/i", real.c.toString(), "regex 1");
var cursor = t.find({
$where: function() {
- fullObject;
assert.eq(7, Object.keySet(obj).length, "A");
assert.eq(1, obj.a, "B");
assert.eq("abc", obj.b, "C");
@@ -37,7 +36,6 @@ t.drop();
t.save({a: 2, b: {c: 7, d: "d is good"}});
var cursor = t.find({
$where: function() {
- fullObject;
assert.eq(3, Object.keySet(obj).length);
assert.eq(2, obj.a);
assert.eq(7, obj.b.c);
diff --git a/jstests/core/ora.js b/jstests/core/ora.js
index f50f0d13027..2c0f4b6fc70 100644
--- a/jstests/core/ora.js
+++ b/jstests/core/ora.js
@@ -17,5 +17,5 @@ t.drop();
t.ensureIndex({loc: "2d"});
assert.throws(function() {
- t.find({$or: [{loc: {$near: [11, 11]}}]}).limit(1).next()['_id'];
+ t.find({$or: [{loc: {$near: [11, 11]}}]}).limit(1).next();
});
diff --git a/jstests/replsets/command_response_operation_time.js b/jstests/replsets/command_response_operation_time.js
index 2176e92ddc9..256e9079883 100644
--- a/jstests/replsets/command_response_operation_time.js
+++ b/jstests/replsets/command_response_operation_time.js
@@ -4,10 +4,10 @@
* and local reads and writes return the last applied optime's timestamp.
*/
(function() {
- load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
-
"use strict";
+ load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
+
function assertCorrectOperationTime(operationTime, expectedTimestamp, opTimeType) {
assert.eq(0,
timestampCmp(operationTime, expectedTimestamp),
diff --git a/jstests/replsets/pipelineout.js b/jstests/replsets/pipelineout.js
index 91e07d9a457..44441e63d5c 100644
--- a/jstests/replsets/pipelineout.js
+++ b/jstests/replsets/pipelineout.js
@@ -12,21 +12,21 @@ var secondary = replTest.liveNodes.slaves[0].getDB(name);
// populate the collection
for (i = 0; i < 5; i++) {
- primary.in .insert({x: i});
+ primary.coll.insert({x: i});
}
replTest.awaitReplication();
// make sure $out cannot be run on a secondary
assert.throws(function() {
- secondary.in .aggregate({$out: "out"}).itcount;
+ secondary.coll.aggregate({$out: "out"}).itcount();
});
// even if slaveOk
secondary.setSlaveOk();
assert.throws(function() {
- secondary.in .aggregate({$out: "out"}).itcount;
+ secondary.coll.aggregate({$out: "out"}).itcount();
});
// run one and check for proper replication
-primary.in .aggregate({$out: "out"}).itcount;
+primary.coll.aggregate({$out: "out"}).itcount();
replTest.awaitReplication();
assert.eq(primary.out.find().sort({x: 1}).toArray(), secondary.out.find().sort({x: 1}).toArray());
diff --git a/jstests/replsets/shutdown_primary.js b/jstests/replsets/shutdown_primary.js
index 66d429dec89..b294ce5370d 100644
--- a/jstests/replsets/shutdown_primary.js
+++ b/jstests/replsets/shutdown_primary.js
@@ -12,11 +12,10 @@
*
*/
(function() {
- load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries,
- // restartReplicationOnSecondaries
-
"use strict";
+ load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries,
+ // restartReplicationOnSecondaries
var name = "shutdown_primary";
var replTest = new ReplSetTest({name: name, nodes: 3});
diff --git a/jstests/replsets/stepdown_needs_electable_secondary.js b/jstests/replsets/stepdown_needs_electable_secondary.js
index 9a59ff0fd58..9cc53a4dfd7 100644
--- a/jstests/replsets/stepdown_needs_electable_secondary.js
+++ b/jstests/replsets/stepdown_needs_electable_secondary.js
@@ -20,12 +20,12 @@
*
*/
(function() {
+ 'use strict';
+
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries,
// restartServerReplication,
// restartReplSetReplication
- 'use strict';
-
var name = 'stepdown_needs_electable_secondary';
var replTest = new ReplSetTest({name: name, nodes: 5});
diff --git a/jstests/replsets/stepdown_needs_majority.js b/jstests/replsets/stepdown_needs_majority.js
index 7fe0e41dc19..080dd241338 100644
--- a/jstests/replsets/stepdown_needs_majority.js
+++ b/jstests/replsets/stepdown_needs_majority.js
@@ -16,12 +16,12 @@
*
*/
(function() {
+ 'use strict';
+
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries, //
// restartServerReplication,
// restartReplSetReplication
- 'use strict';
-
function assertStepDownFailsWithExceededTimeLimit(node) {
assert.commandFailedWithCode(
node.getDB("admin").runCommand({replSetStepDown: 5, secondaryCatchUpPeriodSecs: 5}),