0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-25 00:58:53 +01:00

SERVER-23728 Enable the no-unused-expressions ESLint rule

This commit is contained in:
Eddie Louie 2017-03-28 13:42:11 -04:00
parent 2d00414fa0
commit 2569b254a5
14 changed files with 33 additions and 66 deletions

View File

@ -33,6 +33,7 @@ rules:
no-sparse-arrays: 2 no-sparse-arrays: 2
no-unexpected-multiline: 2 no-unexpected-multiline: 2
no-unreachable: 2 no-unreachable: 2
no-unused-expressions: 2
no-useless-call: 2 no-useless-call: 2
no-with: 2 no-with: 2
semi: 2 semi: 2

View File

@ -157,32 +157,27 @@ var testOps = function(db, allowedActions) {
var dbName = db.getName(); var dbName = db.getName();
var db2 = newConn.getDB(dbName); var db2 = newConn.getDB(dbName);
if (db2 == 'admin') { if (db2.getName() == 'admin') {
assert.eq(1, db2.auth('aro', AUTH_INFO.admin.aro.pwd)); assert.eq(1, db2.auth('aro', AUTH_INFO.admin.aro.pwd));
} else { } else {
assert.eq(1, db2.auth('ro', AUTH_INFO.test.ro.pwd)); assert.eq(1, db2.auth('ro', AUTH_INFO.test.ro.pwd));
} }
var cursor = db2.kill_cursor.find().batchSize(2); // 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));
db.killCursor(cursor.id()); checkErr(allowedActions.hasOwnProperty('killCursor'), function() {
// Send a synchronous message to make sure that kill cursor was processed // Issue killCursor command from db.
// before proceeding. cmdRes = db.runCommand({killCursors: db2.kill_cursor.getName(), cursors: [cursorId]});
db.runCommand({whatsmyuri: 1}); assert.commandWorked(cmdRes);
assert(bsonBinaryEqual({cursorId: cmdRes.cursorsKilled}, {cursorId: [cursorId]}),
checkErr(!allowedActions.hasOwnProperty('killCursor'), function() { "unauthorized to kill cursor: " + tojson(cmdRes));
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;
}
}
}); });
}); // TODO: enable test after SERVER-5813 is fixed. })();
var isMongos = db.runCommand({isdbgrid: 1}).isdbgrid; var isMongos = db.runCommand({isdbgrid: 1}).isdbgrid;
// Note: fsyncUnlock is not supported in mongos. // Note: fsyncUnlock is not supported in mongos.
@ -192,7 +187,7 @@ var testOps = function(db, allowedActions) {
var errorCodeUnauthorized = 13; var errorCodeUnauthorized = 13;
if (res.code == errorCodeUnauthorized) { if (res.code == errorCodeUnauthorized) {
throw Error("unauthorized unauthorized fsyncUnlock"); throw Error("unauthorized fsyncUnlock");
} }
}); });
} }

View File

@ -13,7 +13,7 @@ coll.drop();
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
coll.insert({a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10)}); coll.insert({a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10)});
} }
coll.insert;
coll.ensureIndex({a: 1, b: -1, c: 1}); coll.ensureIndex({a: 1, b: -1, c: 1});
// Test no query, sort on all fields in index order // Test no query, sort on all fields in index order

View File

@ -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});

View File

@ -96,7 +96,6 @@ assert.throws(function() {
}, [], "throw on invalid sorted projection (field mismatch)"); }, [], "throw on invalid sorted projection (field mismatch)");
assert.throws(function() { assert.throws(function() {
x;
t.find({group: 3, 'x.a': 2}, {'x.$': 1, group: 0}).sort({x: 1}).toArray(); t.find({group: 3, 'x.a': 2}, {'x.$': 1, group: 0}).sort({x: 1}).toArray();
}, [], "throw on invalid projection combination (include and exclude)"); }, [], "throw on invalid projection combination (include and exclude)");

View File

@ -13,4 +13,4 @@
writeConcern: {w: 'majority', wtimeout: 30000} writeConcern: {w: 'majority', wtimeout: 30000}
}; };
db.runCommand({'eval': 'db.runCommand(' + tojson(insertCommand) + ')'}); db.runCommand({'eval': 'db.runCommand(' + tojson(insertCommand) + ')'});
}); })();

View File

@ -103,7 +103,7 @@ p = {
}, },
initial: {count: 0}, initial: {count: 0},
finalize: function(obj) { finalize: function(obj) {
ob; throw new Error("Intentionally throwing exception in finalize function");
} }
}; };
assert.commandFailedWithCode( assert.commandFailedWithCode(
@ -117,7 +117,7 @@ p = {
}, },
initial: {count: 0}, initial: {count: 0},
finalize: function(obj) { finalize: function(obj) {
ob; throw new Error("Intentionally throwing exception in finalize function");
} }
}; };
assert.commandFailedWithCode( assert.commandFailedWithCode(

View File

@ -16,7 +16,6 @@ assert.eq("/abc/i", real.c.toString(), "regex 1");
var cursor = t.find({ var cursor = t.find({
$where: function() { $where: function() {
fullObject;
assert.eq(7, Object.keySet(obj).length, "A"); assert.eq(7, Object.keySet(obj).length, "A");
assert.eq(1, obj.a, "B"); assert.eq(1, obj.a, "B");
assert.eq("abc", obj.b, "C"); assert.eq("abc", obj.b, "C");
@ -37,7 +36,6 @@ t.drop();
t.save({a: 2, b: {c: 7, d: "d is good"}}); t.save({a: 2, b: {c: 7, d: "d is good"}});
var cursor = t.find({ var cursor = t.find({
$where: function() { $where: function() {
fullObject;
assert.eq(3, Object.keySet(obj).length); assert.eq(3, Object.keySet(obj).length);
assert.eq(2, obj.a); assert.eq(2, obj.a);
assert.eq(7, obj.b.c); assert.eq(7, obj.b.c);

View File

@ -17,5 +17,5 @@ t.drop();
t.ensureIndex({loc: "2d"}); t.ensureIndex({loc: "2d"});
assert.throws(function() { assert.throws(function() {
t.find({$or: [{loc: {$near: [11, 11]}}]}).limit(1).next()['_id']; t.find({$or: [{loc: {$near: [11, 11]}}]}).limit(1).next();
}); });

View File

@ -4,10 +4,10 @@
* and local reads and writes return the last applied optime's timestamp. * and local reads and writes return the last applied optime's timestamp.
*/ */
(function() { (function() {
load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
"use strict"; "use strict";
load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
function assertCorrectOperationTime(operationTime, expectedTimestamp, opTimeType) { function assertCorrectOperationTime(operationTime, expectedTimestamp, opTimeType) {
assert.eq(0, assert.eq(0,
timestampCmp(operationTime, expectedTimestamp), timestampCmp(operationTime, expectedTimestamp),

View File

@ -12,21 +12,21 @@ var secondary = replTest.liveNodes.slaves[0].getDB(name);
// populate the collection // populate the collection
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
primary.in .insert({x: i}); primary.coll.insert({x: i});
} }
replTest.awaitReplication(); replTest.awaitReplication();
// make sure $out cannot be run on a secondary // make sure $out cannot be run on a secondary
assert.throws(function() { assert.throws(function() {
secondary.in .aggregate({$out: "out"}).itcount; secondary.coll.aggregate({$out: "out"}).itcount();
}); });
// even if slaveOk // even if slaveOk
secondary.setSlaveOk(); secondary.setSlaveOk();
assert.throws(function() { assert.throws(function() {
secondary.in .aggregate({$out: "out"}).itcount; secondary.coll.aggregate({$out: "out"}).itcount();
}); });
// run one and check for proper replication // run one and check for proper replication
primary.in .aggregate({$out: "out"}).itcount; primary.coll.aggregate({$out: "out"}).itcount();
replTest.awaitReplication(); replTest.awaitReplication();
assert.eq(primary.out.find().sort({x: 1}).toArray(), secondary.out.find().sort({x: 1}).toArray()); assert.eq(primary.out.find().sort({x: 1}).toArray(), secondary.out.find().sort({x: 1}).toArray());

View File

@ -12,11 +12,10 @@
* *
*/ */
(function() { (function() {
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries,
// restartReplicationOnSecondaries
"use strict"; "use strict";
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries,
// restartReplicationOnSecondaries
var name = "shutdown_primary"; var name = "shutdown_primary";
var replTest = new ReplSetTest({name: name, nodes: 3}); var replTest = new ReplSetTest({name: name, nodes: 3});

View File

@ -20,12 +20,12 @@
* *
*/ */
(function() { (function() {
'use strict';
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries, load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries,
// restartServerReplication, // restartServerReplication,
// restartReplSetReplication // restartReplSetReplication
'use strict';
var name = 'stepdown_needs_electable_secondary'; var name = 'stepdown_needs_electable_secondary';
var replTest = new ReplSetTest({name: name, nodes: 5}); var replTest = new ReplSetTest({name: name, nodes: 5});

View File

@ -16,12 +16,12 @@
* *
*/ */
(function() { (function() {
'use strict';
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries, // load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries, //
// restartServerReplication, // restartServerReplication,
// restartReplSetReplication // restartReplSetReplication
'use strict';
function assertStepDownFailsWithExceededTimeLimit(node) { function assertStepDownFailsWithExceededTimeLimit(node) {
assert.commandFailedWithCode( assert.commandFailedWithCode(
node.getDB("admin").runCommand({replSetStepDown: 5, secondaryCatchUpPeriodSecs: 5}), node.getDB("admin").runCommand({replSetStepDown: 5, secondaryCatchUpPeriodSecs: 5}),