[gjs: 26/43] CI: Add no-throw-literal to eslint rules
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 26/43] CI: Add no-throw-literal to eslint rules
- Date: Wed, 14 Aug 2019 17:29:15 +0000 (UTC)
commit 4d3f567674b7fde48362b1c1e25222e16f30b586
Author: Philip Chimento <philip chimento gmail com>
Date: Sat Aug 3 23:28:22 2019 -0700
CI: Add no-throw-literal to eslint rules
It can be confusing to throw something that's not an Error, since then
your catch code has to deal with that possibility. Additionally, Errors
have stack information, so throwing something that's not an error will
produce less useful debug messages.
.eslintrc.yml | 1 +
installed-tests/js/modules/overrides/.eslintrc.yml | 1 +
installed-tests/js/testGObjectClass.js | 2 +-
installed-tests/js/testLegacyGObject.js | 2 +-
installed-tests/js/testself.js | 2 +-
5 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 2e20540a..c9cd89b7 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -96,6 +96,7 @@ rules:
no-return-assign: error
no-shadow: error
no-tabs: error
+ no-throw-literal: error
no-unused-vars:
- error
- varsIgnorePattern: ^unused
diff --git a/installed-tests/js/modules/overrides/.eslintrc.yml
b/installed-tests/js/modules/overrides/.eslintrc.yml
index 189476b0..c65c1600 100644
--- a/installed-tests/js/modules/overrides/.eslintrc.yml
+++ b/installed-tests/js/modules/overrides/.eslintrc.yml
@@ -1,5 +1,6 @@
---
rules:
+ no-throw-literal: 'off' # these are intended to be bad code
no-unused-vars:
- error
- varsIgnorePattern: ^_init$
diff --git a/installed-tests/js/testGObjectClass.js b/installed-tests/js/testGObjectClass.js
index 629610b7..57101758 100644
--- a/installed-tests/js/testGObjectClass.js
+++ b/installed-tests/js/testGObjectClass.js
@@ -132,7 +132,7 @@ const MyInitable = GObject.registerClass({
}, class MyInitable extends GObject.Object {
vfunc_init(cancellable) {
if (!(cancellable instanceof Gio.Cancellable))
- throw 'Bad argument';
+ throw new Error('Bad argument');
this.inited = true;
}
diff --git a/installed-tests/js/testLegacyGObject.js b/installed-tests/js/testLegacyGObject.js
index ac637bbf..6c2b62b3 100644
--- a/installed-tests/js/testLegacyGObject.js
+++ b/installed-tests/js/testLegacyGObject.js
@@ -151,7 +151,7 @@ const MyInitable = new Lang.Class({
vfunc_init: function(cancellable) { // error?
if (!(cancellable instanceof Gio.Cancellable))
- throw 'Bad argument';
+ throw new Error('Bad argument');
this.inited = true;
},
diff --git a/installed-tests/js/testself.js b/installed-tests/js/testself.js
index 810acb72..40b611b6 100644
--- a/installed-tests/js/testself.js
+++ b/installed-tests/js/testself.js
@@ -23,7 +23,7 @@ describe('Test harness internal consistency', function () {
expect(someNumber).not.toBeNaN();
expect(() => {
- throw {};
+ throw new Error();
}).toThrow();
expect(() => expect(true).toThrow()).toThrow();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]