[gjs/ewlsh/implicit-mainloop] temp: lint
- From: Evan Welsh <ewlsh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/ewlsh/implicit-mainloop] temp: lint
- Date: Sat, 30 Jan 2021 20:42:22 +0000 (UTC)
commit e2f3ac61b08e5d2271a78998686c8c086fd030cf
Author: Evan Welsh <contact evanwelsh com>
Date: Sat Jan 30 12:42:16 2021 -0800
temp: lint
.eslintrc.yml | 5 ++
examples/timers.js | 18 +++----
installed-tests/js/minijasmine.js | 2 +-
installed-tests/js/testImporter.js | 6 +--
installed-tests/js/testTimers.js | 99 +++++++++++++++++-------------------
modules/core/.eslintrc.yml | 6 +++
modules/core/_timers.js | 48 ++++++++---------
modules/script/_bootstrap/default.js | 10 ++--
nest.js | 25 ---------
promise.js | 6 ---
10 files changed, 99 insertions(+), 126 deletions(-)
---
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 0a07f205..509af99a 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -246,5 +246,10 @@ globals:
print: readonly
printerr: readonly
window: readonly
+ setTimeout: readonly
+ setInterval: readonly
+ setImmediate: readonly
+ clearTimeout: readonly
+ clearInterval: readonly
parserOptions:
ecmaVersion: 2020
diff --git a/examples/timers.js b/examples/timers.js
index 62bd82fe..66aa54e2 100644
--- a/examples/timers.js
+++ b/examples/timers.js
@@ -1,14 +1,14 @@
const promise = new Promise(r => {
- let i = 100
+ let i = 100;
+ // eslint-disable-next-line no-empty
while (i--) { }
- r()
-})
+ r();
+});
setTimeout(() => {
- promise.then(() => log('no'))
-})
+ promise.then(() => log('no'));
+});
-setTimeout(() =>
-{
- log('de')
-})
+setTimeout(() => {
+ log('de');
+});
diff --git a/installed-tests/js/minijasmine.js b/installed-tests/js/minijasmine.js
index 3443631e..4ecd573e 100644
--- a/installed-tests/js/minijasmine.js
+++ b/installed-tests/js/minijasmine.js
@@ -23,7 +23,7 @@ let jasmineRequire = imports.jasmine.getJasmineRequireObj();
let jasmineCore = jasmineRequire.core(jasmineRequire);
globalThis._jasmineEnv = jasmineCore.getEnv();
globalThis._jasmineEnv.configure({
- random: false
+ random: false,
});
globalThis._jasmineMain = GLib.MainLoop.new(null, false);
globalThis._jasmineRetval = 0;
diff --git a/installed-tests/js/testImporter.js b/installed-tests/js/testImporter.js
index b121ba5c..ada6726b 100644
--- a/installed-tests/js/testImporter.js
+++ b/installed-tests/js/testImporter.js
@@ -39,9 +39,9 @@ describe('GI importer', function () {
});
function formatImporter(obj) {
- if (typeof obj === 'object' && obj.toString && (obj.toString()?.startsWith('[object GjsModule') ||
obj.toString()?.startsWith('[GjsFileImporter '))) {
+ if (typeof obj === 'object' && obj.toString && (obj.toString()?.startsWith('[object GjsModule') ||
obj.toString()?.startsWith('[GjsFileImporter ')))
return obj.toString();
- }
+
return undefined;
}
@@ -64,7 +64,7 @@ describe('Importer', function () {
imports.searchPath = oldSearchPath;
});
- beforeEach(function() {
+ beforeEach(function () {
jasmine.addCustomObjectFormatter(formatImporter);
});
diff --git a/installed-tests/js/testTimers.js b/installed-tests/js/testTimers.js
index 487b75e4..c65eb504 100644
--- a/installed-tests/js/testTimers.js
+++ b/installed-tests/js/testTimers.js
@@ -1,11 +1,12 @@
+/* eslint-disable require-await */
+
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-const { GLib } = imports.gi;
+const {GLib} = imports.gi;
function deferred() {
let resolve_;
let reject_;
function resolve() {
-
resolve_();
}
function reject() {
@@ -18,18 +19,17 @@ function deferred() {
return {
promise,
resolve,
- reject
+ reject,
};
}
async function waitForMs(ms) {
- return new Promise((resolve) => setTimeout(resolve, ms));
+ return new Promise(resolve => setTimeout(resolve, ms));
}
describe('Timers', function () {
it('times out successfully', async function timeoutSuccess() {
-
- const { promise, resolve } = deferred();
+ const {promise, resolve} = deferred();
let count = 0;
setTimeout(() => {
count++;
@@ -45,8 +45,7 @@ describe('Timers', function () {
});
it('has correct timeout args', async function timeoutArgs() {
-
- const { promise, resolve } = deferred();
+ const {promise, resolve} = deferred();
const arg = 1;
setTimeout(
@@ -65,7 +64,6 @@ describe('Timers', function () {
});
it('cancels successfully', async function timeoutCancelSuccess() {
-
let count = 0;
const id = setTimeout(() => {
count++;
@@ -78,7 +76,7 @@ describe('Timers', function () {
it('cancels multiple correctly', async function timeoutCancelMultiple() {
function uncalled() {
- throw new Error("This function should not be called.");
+ throw new Error('This function should not be called.');
}
// Set timers and cancel them in the same order.
@@ -103,7 +101,7 @@ describe('Timers', function () {
it('cancels invalid silent fail', async function timeoutCancelInvalidSilentFail() {
// Expect no panic
- const { promise, resolve } = deferred();
+ const {promise, resolve} = deferred();
let count = 0;
const id = setTimeout(() => {
count++;
@@ -119,7 +117,7 @@ describe('Timers', function () {
});
it('interval success', async function intervalSuccess() {
- const { promise, resolve } = deferred();
+ const {promise, resolve} = deferred();
let count = 0;
const id = setInterval(() => {
count++;
@@ -148,13 +146,12 @@ describe('Timers', function () {
let timeouts = 0;
function onTimeout() {
++timeouts;
- for (let i = 1; i < timers.length; i++) {
+ for (let i = 1; i < timers.length; i++)
clearTimeout(timers[i]);
- }
}
- for (let i = 0; i < 10; i++) {
+ for (let i = 0; i < 10; i++)
timers[i] = setTimeout(onTimeout, 1);
- }
+
await waitForMs(500);
expect(timeouts).toBe(1);
});
@@ -166,7 +163,7 @@ describe('Timers', function () {
it('fire immediately', async function fireCallbackImmediatelyWhenDelayOverMaxValue() {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
- '*does not fit into*');
+ '*does not fit into*');
let count = 0;
setTimeout(() => {
@@ -177,12 +174,12 @@ describe('Timers', function () {
});
it('callback this', async function timeoutCallbackThis() {
- const { promise, resolve } = deferred();
+ const {promise, resolve} = deferred();
const obj = {
foo() {
expect(this).toBe(window);
resolve();
- }
+ },
};
setTimeout(obj.foo, 1);
await promise;
@@ -195,27 +192,25 @@ describe('Timers', function () {
const thisCheckFailed = [
0,
- "",
+ '',
true,
false,
{},
[],
- "foo",
+ 'foo',
() => { },
- Object.prototype
+ Object.prototype,
];
thisCheckPassed.forEach(
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- (thisArg) => {
+ thisArg => {
expect(() => {
setTimeout.call(thisArg, noop, 1);
}).not.toThrow();
});
thisCheckFailed.forEach(
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- (thisArg) => {
+ thisArg => {
expect(() => {
setTimeout.call(thisArg, noop, 1);
}).toThrowError(TypeError);
@@ -229,7 +224,7 @@ describe('Timers', function () {
valueOf() {
called = true;
return 1;
- }
+ },
};
clearTimeout(obj);
expect(called).toBe(true);
@@ -248,8 +243,8 @@ describe('Timers', function () {
});
it('', function testFunctionName() {
- expect(clearTimeout.name).toBe("clearTimeout");
- expect(clearInterval.name).toBe("clearInterval");
+ expect(clearTimeout.name).toBe('clearTimeout');
+ expect(clearInterval.name).toBe('clearInterval');
});
it('length', function testFunctionParamsLength() {
@@ -260,58 +255,56 @@ describe('Timers', function () {
});
it('clear and interval', function clearTimeoutAndClearIntervalNotBeEquals() {
- expect(clearTimeout).not.toBe(clearInterval);
+ expect(clearTimeout).not.toBe(clearInterval);
});
it('microtask ordering', async function timerBasicMicrotaskOrdering() {
- let s = "";
+ let s = '';
let count = 0;
- const { promise, resolve } = deferred();
+ const {promise, resolve} = deferred();
setTimeout(() => {
Promise.resolve().then(() => {
count++;
- s += "de";
- if (count === 2) {
+ s += 'de';
+ if (count === 2)
resolve();
- }
});
});
setTimeout(() => {
count++;
- s += "no";
- if (count === 2) {
+ s += 'no';
+ if (count === 2)
resolve();
- }
});
await promise;
- expect(s).toBe("deno");
+ expect(s).toBe('deno');
});
it('nested microtask ordering', async function timerNestedMicrotaskOrdering() {
- let s = "";
- const { promise, resolve } = deferred();
- s += "0";
+ let s = '';
+ const {promise, resolve} = deferred();
+ s += '0';
setTimeout(() => {
- s += "4";
- setTimeout(() => (s += "8"));
+ s += '4';
+ setTimeout(() => (s += '8'));
Promise.resolve().then(() => {
setTimeout(() => {
- s += "9";
+ s += '9';
resolve();
});
});
});
- setTimeout(() => (s += "5"));
- Promise.resolve().then(() => (s += "2"));
+ setTimeout(() => (s += '5'));
+ Promise.resolve().then(() => (s += '2'));
Promise.resolve().then(() =>
setTimeout(() => {
- s += "6";
- Promise.resolve().then(() => (s += "7"));
+ s += '6';
+ Promise.resolve().then(() => (s += '7'));
})
);
- Promise.resolve().then(() => Promise.resolve().then(() => (s += "3")));
- s += "1";
+ Promise.resolve().then(() => Promise.resolve().then(() => (s += '3')));
+ s += '1';
await promise;
- expect(s).toBe("0123456789");
+ expect(s).toBe('0123456789');
});
-});
\ No newline at end of file
+});
diff --git a/modules/core/.eslintrc.yml b/modules/core/.eslintrc.yml
index 6c9c0253..49689391 100644
--- a/modules/core/.eslintrc.yml
+++ b/modules/core/.eslintrc.yml
@@ -3,3 +3,9 @@
# SPDX-FileCopyrightText: 2020 Evan Welsh <contact evanwelsh com>
rules:
jsdoc/require-jsdoc: 'off'
+globals:
+ setTimeout: 'off'
+ setInterval: 'off'
+ setImmediate: 'off'
+ clearTimeout: 'off'
+ clearInterval: 'off'
\ No newline at end of file
diff --git a/modules/core/_timers.js b/modules/core/_timers.js
index d06b2638..5434b827 100644
--- a/modules/core/_timers.js
+++ b/modules/core/_timers.js
@@ -1,4 +1,6 @@
-const { GLib } = imports.gi;
+/* exported setTimeout, setInterval, setImmediate, clearTimeout, clearInterval */
+
+const {GLib} = imports.gi;
const jobs = imports._promiseNative;
@@ -7,7 +9,7 @@ const ids = new Map();
let idIncrementor = 1;
/**
- * @param {number} id
+ * @param {number} id the GSource id to map to a timer id
* @returns {number}
*/
function nextId(id) {
@@ -21,25 +23,23 @@ function nextId(id) {
const TIMEOUT_MAX = 2 ** 31 - 1;
function checkThis(thisArg) {
- if (thisArg !== null && thisArg !== undefined && thisArg !== globalThis) {
- throw new TypeError("Illegal invocation");
- }
+ if (thisArg !== null && thisArg !== undefined && thisArg !== globalThis)
+ throw new TypeError('Illegal invocation');
}
function checkBigInt(n) {
- if (typeof n === "bigint") {
- throw new TypeError("Cannot convert a BigInt value to a number");
- }
+ if (typeof n === 'bigint')
+ throw new TypeError('Cannot convert a BigInt value to a number');
}
function ToNumber(interval) {
- if (typeof interval === 'number') {
+ if (typeof interval === 'number')
return interval;
- } else if (typeof interval === 'object') {
- return +(interval.valueOf()) || +interval;
- }
+ else if (typeof interval === 'object')
+ return Number(interval.valueOf()) || Number(interval);
+
- return +interval;
+ return Number(interval);
}
function setTimeout(callback, delay = 0, ...args) {
@@ -49,9 +49,9 @@ function setTimeout(callback, delay = 0, ...args) {
delay = wrapDelay(delay);
const cb = callback.bind(globalThis, ...args);
const id = nextId(GLib.timeout_add(GLib.PRIORITY_DEFAULT, delay, () => {
- if (!ids.has(id)) {
+ if (!ids.has(id))
return GLib.SOURCE_REMOVE;
- }
+
cb();
ids.delete(id);
@@ -69,8 +69,8 @@ function wrapDelay(delay) {
if (delay > TIMEOUT_MAX) {
imports._print.warn(
`${delay} does not fit into` +
- " a 32-bit signed integer." +
- "\nTimeout duration was set to 1."
+ ' a 32-bit signed integer.' +
+ '\nTimeout duration was set to 1.'
);
delay = 1;
}
@@ -83,9 +83,9 @@ function setInterval(callback, delay = 0, ...args) {
delay = wrapDelay(delay);
const cb = callback.bind(globalThis, ...args);
const id = nextId(GLib.timeout_add(GLib.PRIORITY_DEFAULT, delay, () => {
- if (!ids.has(id)) {
+ if (!ids.has(id))
return GLib.SOURCE_REMOVE;
- }
+
cb();
@@ -104,9 +104,9 @@ function setImmediate(callback, ...args) {
const cb = callback.bind(globalThis, ...args);
const id = nextId(GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
- if (!ids.has(id)) {
+ if (!ids.has(id))
return GLib.SOURCE_REMOVE;
- }
+
cb();
ids.delete(id);
@@ -125,11 +125,11 @@ function clearTimer(id) {
const _id = ToNumber(id);
- if (!ids.has(_id)) {
+ if (!ids.has(_id))
return;
- }
- const cx = GLib.MainContext.default()
+
+ const cx = GLib.MainContext.default();
const source_id = ids.get(_id);
const source = cx.find_source_by_id(source_id);
diff --git a/modules/script/_bootstrap/default.js b/modules/script/_bootstrap/default.js
index 13ad22f7..dd217cfa 100644
--- a/modules/script/_bootstrap/default.js
+++ b/modules/script/_bootstrap/default.js
@@ -13,31 +13,31 @@
configurable: false,
enumerable: true,
writable: true,
- value: setTimeout
+ value: setTimeout,
},
setInterval: {
configurable: false,
enumerable: true,
writable: true,
- value: setInterval
+ value: setInterval,
},
setImmediate: {
configurable: false,
enumerable: true,
writable: true,
- value: setImmediate
+ value: setImmediate,
},
clearTimeout: {
configurable: false,
enumerable: true,
writable: true,
- value: clearTimeout
+ value: clearTimeout,
},
clearInterval: {
configurable: false,
enumerable: true,
writable: true,
- value: clearInterval
+ value: clearInterval,
},
print: {
configurable: false,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]