Bug 1372427 - add rule to not throw litterals. r=mattn
MozReview-Commit-ID: F962Z4jhm2l
--- a/toolkit/components/satchel/.eslintrc.js
+++ b/toolkit/components/satchel/.eslintrc.js
@@ -41,10 +41,11 @@ module.exports = {
max: 20,
}],
"dot-location": ["error", "property"],
"max-len": ["error", 100],
"no-fallthrough": "error",
"no-multiple-empty-lines": ["error", {
max: 2,
}],
+ "no-throw-literal": "error",
},
};
--- a/toolkit/components/satchel/test/test_bug_511615.html
+++ b/toolkit/components/satchel/test/test_bug_511615.html
@@ -87,17 +87,17 @@ function doKeyUnprivileged(key) {
if (key.length == 1) {
keycode = 0;
charcode = key.charCodeAt(0);
alwaysval = charcode;
} else {
keycode = KeyEvent[keyName];
if (!keycode) {
- throw "invalid keyname in test";
+ throw new Error("invalid keyname in test");
}
charcode = 0;
alwaysval = keycode;
}
let dnEvent = document.createEvent("KeyboardEvent");
let prEvent = document.createEvent("KeyboardEvent");
let upEvent = document.createEvent("KeyboardEvent");
--- a/toolkit/components/satchel/test/unit/test_db_update_v4.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v4.js
@@ -49,11 +49,11 @@ function* next_test() {
yield countEntries("name-A", "value-A",
function(num) {
do_check_true(num > 0);
do_test_finished();
}
);
} catch (e) {
- throw "FAILED in test #" + testnum + " -- " + e;
+ throw new Error(`FAILED in test #${testnum} -- ${e}`);
}
}
--- a/toolkit/components/satchel/test/unit/test_db_update_v4b.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v4b.js
@@ -47,11 +47,11 @@ function* next_test() {
yield countEntries("name-A", "value-A",
function(num) {
do_check_true(num > 0);
do_test_finished();
}
);
} catch (e) {
- throw "FAILED in test #" + testnum + " -- " + e;
+ throw new Error(`FAILED in test #${testnum} -- ${e}`);
}
}
--- a/toolkit/components/satchel/test/unit/test_db_update_v999a.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v999a.js
@@ -61,13 +61,13 @@ function* tests() {
// Exercise adding and removing a name/value pair
yield countEntries("name-D", "value-D", checkZero);
yield updateEntry("add", "name-D", "value-D", next_test);
yield countEntries("name-D", "value-D", checkOne);
yield updateEntry("remove", "name-D", "value-D", next_test);
yield countEntries("name-D", "value-D", checkZero);
} catch (e) {
- throw "FAILED in test #" + testnum + " -- " + e;
+ throw new Error(`FAILED in test #${testnum} -- ${e}`);
}
do_test_finished();
}
--- a/toolkit/components/satchel/test/unit/test_db_update_v999b.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v999b.js
@@ -79,13 +79,13 @@ function* tests() {
// ===== 4 =====
testnum++;
// Try removing an entry
yield updateEntry("remove", "name-A", "value-A", next_test);
yield countEntries(null, null, checkZero);
yield countEntries("name-A", "value-A", checkZero);
} catch (e) {
- throw "FAILED in test #" + testnum + " -- " + e;
+ throw new Error(`FAILED in test #${testnum} -- ${e}`);
}
do_test_finished();
}
--- a/toolkit/components/satchel/test/unit/test_history_api.js
+++ b/toolkit/components/satchel/test/unit/test_history_api.js
@@ -447,17 +447,17 @@ add_task(async function() {
"Invalid entries when form history is disabled should fail");
// Remove should work though.
await promiseUpdate([{ op: "remove", fieldname: "field5", value: null },
{ op: "remove", fieldname: null, value: null }]);
Services.prefs.clearUserPref("browser.formfill.enable");
} catch (e) {
- throw "FAILED in test #" + testnum + " -- " + e;
+ throw new Error(`FAILED in test #${testnum} -- ${e}`);
} finally {
FormHistory._supportsDeletedTable = oldSupportsDeletedTable;
dbConnection.asyncClose(do_test_finished);
}
});
function run_test() {
return run_next_test();
--- a/toolkit/components/satchel/test/unit/test_notify.js
+++ b/toolkit/components/satchel/test/unit/test_notify.js
@@ -164,11 +164,11 @@ function* run_test_steps() {
do_check_eq(expectedNotification, null);
os.removeObserver(TestObserver, "satchel-storage-changed");
do_test_finished();
} catch (e) {
- throw "FAILED in test #" + testnum + " -- " + testdesc + ": " + e;
+ throw new Error(`FAILED in test #${testnum} -- ${testdesc}: ${e}`);
}
}