Bug 1372427 - add rule to not throw litterals. r=mattn draft
authorJonathan Guillotte-Blouin <jguillotteblouin@mozilla.com>
Wed, 14 Jun 2017 12:01:50 -0700
changeset 597779 11898a6ae9b2e0cc136babcddfc438d06fb9bb59
parent 597778 cd378409d15c8f7965bf9dbc265d3122a5fc2bd9
child 597780 621c4656a1b3c900256811416d3c07007ee4a91b
push id65025
push userbmo:jguillotteblouin@mozilla.com
push dateTue, 20 Jun 2017 23:10:16 +0000
reviewersmattn
bugs1372427
milestone56.0a1
Bug 1372427 - add rule to not throw litterals. r=mattn MozReview-Commit-ID: F962Z4jhm2l
toolkit/components/satchel/.eslintrc.js
toolkit/components/satchel/test/test_bug_511615.html
toolkit/components/satchel/test/unit/test_db_update_v4.js
toolkit/components/satchel/test/unit/test_db_update_v4b.js
toolkit/components/satchel/test/unit/test_db_update_v999a.js
toolkit/components/satchel/test/unit/test_db_update_v999b.js
toolkit/components/satchel/test/unit/test_history_api.js
toolkit/components/satchel/test/unit/test_notify.js
--- 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}`);
   }
 }