From fa00dc7a5332aee4c9840b54a3003374d1fea373 Mon Sep 17 00:00:00 2001 From: Philipp Kewisch Date: Sat, 10 Aug 2024 12:27:28 +0200 Subject: [PATCH] Include more comm-central eslint rules (#37) --- .eslintrc.js | 11 ++- NotificationBox/background.js | 2 +- .../parent/ext-notification-box.js | 18 ++--- calendar/background.js | 16 ++--- .../calendar/ext-calendar-utils.sys.mjs | 16 ++--- .../calendar/parent/ext-calendar-calendars.js | 40 +++++------ .../calendar/parent/ext-calendar-items.js | 50 ++++++------- .../calendar/parent/ext-calendar-provider.js | 72 +++++++++---------- .../calendar/parent/ext-calendarItemAction.js | 24 +++---- .../parent/ext-calendarItemDetails.js | 28 ++++---- 10 files changed, 141 insertions(+), 136 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 28642c1..829deee 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,6 +26,14 @@ module.exports = { "quotes": ["error", "double", { avoidEscape: true }], "padded-blocks": ["error", "never"], "indent": [2, 2, { SwitchCase: 1 }], + + // Rules from https://searchfox.org/comm-central/source/.eslintrc.js#70 + "complexity": ["error", 80], + "func-names": ["error", "never"], + "mozilla/prefer-boolean-length-check": "off", + // Enforce using `let` only when variables are reassigned. + "prefer-const": ["error", { destructuring: "all" }], + "mozilla/reject-chromeutils-import": "error", }, "overrides": [ @@ -42,9 +50,6 @@ module.exports = { global: true, Services: true, }, - rules: { - "no-unused-vars": ["error", { argsIgnorePattern: "^_|context" }] - } } ] }; diff --git a/NotificationBox/background.js b/NotificationBox/background.js index a8799bf..e9e4aaa 100644 --- a/NotificationBox/background.js +++ b/NotificationBox/background.js @@ -148,7 +148,7 @@ messenger.windows.onCreated.addListener(addBoxes); // add boxes to all existing windows messenger.windows.getAll() .then(windows => { - for (let window of windows) { + for (const window of windows) { addBoxes(window); } }); diff --git a/NotificationBox/experiments/NotificationBox/parent/ext-notification-box.js b/NotificationBox/experiments/NotificationBox/parent/ext-notification-box.js index e9e57ac..c739b10 100644 --- a/NotificationBox/experiments/NotificationBox/parent/ext-notification-box.js +++ b/NotificationBox/experiments/NotificationBox/parent/ext-notification-box.js @@ -38,7 +38,7 @@ this.parent.emitter .emit("buttonclicked", windowId, this.notificationId, id) .then((rv) => { - let keepOpen = rv.some((value) => value?.close === false); + const keepOpen = rv.some((value) => value?.close === false); if (!keepOpen) { this.remove(/* closedByUser */ true); } @@ -73,7 +73,7 @@ } }; - let element = await this.getNotificationBox().appendNotification( + const element = await this.getNotificationBox().appendNotification( `extension-notification-${this.notificationId}`, { label, @@ -93,7 +93,7 @@ "font", ]; - let containerElement = getContainerElement(element); + const containerElement = getContainerElement(element); if (style) { const sanitizedStyles = Object.keys(style).filter((cssPropertyName) => { const parts = cssPropertyName.split("-"); @@ -107,7 +107,7 @@ ); }); - for (let cssPropertyName of sanitizedStyles) { + for (const cssPropertyName of sanitizedStyles) { element.style[cssPropertyName] = style[cssPropertyName]; if (containerElement) { containerElement.style[cssPropertyName] = style[cssPropertyName]; @@ -116,8 +116,8 @@ } if (iconURL) { - let iconContainer = containerElement.querySelector(".icon-container"); - let iconElement = iconContainer.querySelector("img"); + const iconContainer = containerElement.querySelector(".icon-container"); + const iconElement = iconContainer.querySelector("img"); iconElement.remove(); const win = this.parent.extension.windowManager.get( @@ -222,7 +222,7 @@ } // if there is no default bottom box, use our own if (!win.gExtensionNotificationBottomBox) { - let statusbar = win.document.querySelector('[class~="statusbar"]'); + const statusbar = win.document.querySelector('[class~="statusbar"]'); win.gExtensionNotificationBottomBox = new win.MozElements.NotificationBox( (element) => { element.id = "extension-notification-bottom-box"; @@ -267,7 +267,7 @@ onShutdown() { Services.obs.removeObserver(this, "domwindowclosed"); - for (let notification of this.notificationsMap.values()) { + for (const notification of this.notificationsMap.values()) { notification.remove(/* closedByUser */ false); } } @@ -275,7 +275,7 @@ // Observer for the domwindowclosed notification, to remove // obsolete notifications from the notificationsMap. observe(aSubject) { - let win = this.context.extension.windowManager.convert(aSubject); + const win = this.context.extension.windowManager.convert(aSubject); this.notificationsMap.forEach((value, key) => { if (value.properties.windowId == win.id) { this.notificationsMap.delete(key); diff --git a/calendar/background.js b/calendar/background.js index 4a122e0..46743b8 100644 --- a/calendar/background.js +++ b/calendar/background.js @@ -47,7 +47,7 @@ lightning.provider.onItemRemoved.addListener(async (calendar, item) => { console.log("Provider remove from calendar", item); }); -let ticks = {}; +const ticks = {}; lightning.provider.onInit.addListener(async (calendar) => { console.log("Initializing", calendar); }); @@ -88,10 +88,10 @@ lightning.provider.onResetSync.addListener(async (calendar) => { // TODO - see comment in ext-calendar-provider.js. Provider should be registered after first tick so // onInit handler has a chance to execute, but before the async function is executed. setTimeout(async () => { - let calendars = await lightning.calendars.query({ type: "ext-" + messenger.runtime.id }); + const calendars = await lightning.calendars.query({ type: "ext-" + messenger.runtime.id }); await Promise.all(calendars.map((calendar) => lightning.calendars.remove(calendar.id))); - let calendar = await lightning.calendars.create({ + const calendar = await lightning.calendars.create({ type: "ext-" + messenger.runtime.id, url: "custom://test", name: "calendar ext" @@ -100,14 +100,14 @@ setTimeout(async () => { await lightning.calendars.update(calendar.id, { color: "#FF0000", readOnly: true }); - let calendar2 = await lightning.calendars.get(calendar.id); + const calendar2 = await lightning.calendars.get(calendar.id); console.log("got calendar", calendar2); await lightning.calendars.synchronize(); await new Promise(resolve => setTimeout(resolve, 500)); - let gotitem = await lightning.items.get(calendar2.id, "findme"); + const gotitem = await lightning.items.get(calendar2.id, "findme"); console.log("Retrieved item", gotitem); let gotitems = await lightning.items.query({ calendarId: calendar2.id }); @@ -153,16 +153,16 @@ setTimeout(async () => { await lightning.calendars.update(home.id, { enabled: home.enabled }); if (home.enabled) { - let item = await lightning.items.create(home.id, { type: "event", title: "hello", location: "here", categories: ["Birthdays"], returnFormat: "ical" }); + const item = await lightning.items.create(home.id, { type: "event", title: "hello", location: "here", categories: ["Birthdays"], returnFormat: "ical" }); console.log("Created item", item, home); - let updated = await lightning.items.update(home.id, item.id, { title: "world" }); + const updated = await lightning.items.update(home.id, item.id, { title: "world" }); console.log("Updated item", updated); await new Promise(resolve => setTimeout(resolve, 500)); // Moving & Removing - let home2 = await lightning.calendars.create({ + const home2 = await lightning.calendars.create({ type: "storage", url: "moz-storage-calendar://", name: "temp move", diff --git a/calendar/experiments/calendar/ext-calendar-utils.sys.mjs b/calendar/experiments/calendar/ext-calendar-utils.sys.mjs index e46829a..453073c 100644 --- a/calendar/experiments/calendar/ext-calendar-utils.sys.mjs +++ b/calendar/experiments/calendar/ext-calendar-utils.sys.mjs @@ -28,7 +28,7 @@ export function unwrapCalendar(calendar) { export function getResolvedCalendarById(extension, id) { let calendar; if (id.endsWith("#cache")) { - let cached = cal.manager.getCalendarById(id.substring(0, id.length - 6)); + const cached = cal.manager.getCalendarById(id.substring(0, id.length - 6)); calendar = cached && isOwnCalendar(cached, extension) && cached.wrappedJSObject.mCachedCalendar; } else { calendar = cal.manager.getCalendarById(id); @@ -54,7 +54,7 @@ export function convertCalendar(extension, calendar) { return null; } - let props = { + const props = { id: calendar.id, type: calendar.type, name: calendar.name, @@ -139,7 +139,7 @@ export function convertItem(item, options, extension) { return null; } - let props = {}; + const props = {}; if (item instanceof Ci.calIEvent) { props.type = "event"; @@ -156,7 +156,7 @@ export function convertItem(item, options, extension) { if (isOwnCalendar(item.calendar, extension)) { props.metadata = {}; - let cache = getCachedCalendar(item.calendar); + const cache = getCachedCalendar(item.calendar); try { // TODO This is a sync operation. Not great. Can we optimize this? props.metadata = JSON.parse(cache.getMetaData(item.id)) ?? {}; @@ -172,7 +172,7 @@ export function convertItem(item, options, extension) { formats = [formats]; } - for (let format of formats) { + for (const format of formats) { switch (format) { case "ical": props.formats.ical = item.icalString; @@ -243,7 +243,7 @@ export async function setupE10sBrowser(extension, browser, parent, initOptions={ browser.contentwindow; // eslint-disable-line no-unused-expressions } - let sheets = []; + const sheets = []; if (initOptions.browser_style) { delete initOptions.browser_style; sheets.push("chrome://browser/content/extension.css"); @@ -253,13 +253,13 @@ export async function setupE10sBrowser(extension, browser, parent, initOptions={ const initBrowser = () => { ExtensionParent.apiManager.emit("extension-browser-inserted", browser); - let mm = browser.messageManager; + const mm = browser.messageManager; mm.loadFrameScript( "chrome://extensions/content/ext-browser-content.js", false, true ); - let options = Object.assign({ + const options = Object.assign({ allowScriptsToClose: true, blockParser: false, maxWidth: 800, diff --git a/calendar/experiments/calendar/parent/ext-calendar-calendars.js b/calendar/experiments/calendar/parent/ext-calendar-calendars.js index 6a4a8b8..01d9238 100644 --- a/calendar/experiments/calendar/parent/ext-calendar-calendars.js +++ b/calendar/experiments/calendar/parent/ext-calendar-calendars.js @@ -20,7 +20,7 @@ this.calendar_calendars = class extends ExtensionAPI { calendar: { calendars: { async query({ type, url, name, color, readOnly, enabled }) { - let calendars = cal.manager.getCalendars(); + const calendars = cal.manager.getCalendars(); let pattern = null; if (url) { @@ -67,11 +67,11 @@ this.calendar_calendars = class extends ExtensionAPI { async get(id) { // TODO find a better way to determine cache id if (id.endsWith("#cache")) { - let calendar = unwrapCalendar(cal.manager.getCalendarById(id.substring(0, id.length - 6))); - let own = calendar.offlineStorage && isOwnCalendar(calendar, context.extension); + const calendar = unwrapCalendar(cal.manager.getCalendarById(id.substring(0, id.length - 6))); + const own = calendar.offlineStorage && isOwnCalendar(calendar, context.extension); return own ? convertCalendar(context.extension, calendar.offlineStorage) : null; } - let calendar = cal.manager.getCalendarById(id); + const calendar = cal.manager.getCalendarById(id); return convertCalendar(context.extension, calendar); }, async create(createProperties) { @@ -94,7 +94,7 @@ this.calendar_calendars = class extends ExtensionAPI { return convertCalendar(context.extension, calendar); }, async update(id, updateProperties) { - let calendar = cal.manager.getCalendarById(id); + const calendar = cal.manager.getCalendarById(id); if (!calendar) { throw new ExtensionError(`Invalid calendar id: ${id}`); } @@ -114,7 +114,7 @@ this.calendar_calendars = class extends ExtensionAPI { calendar.setProperty("disabled", !updateProperties.enabled); } - for (let prop of ["readOnly", "name", "color"]) { + for (const prop of ["readOnly", "name", "color"]) { if (updateProperties[prop] != null) { calendar.setProperty(prop, updateProperties[prop]); } @@ -122,7 +122,7 @@ this.calendar_calendars = class extends ExtensionAPI { if (updateProperties.capabilities) { // TODO validate capability names - let unwrappedCalendar = calendar.wrappedJSObject.mUncachedCalendar.wrappedJSObject; + const unwrappedCalendar = calendar.wrappedJSObject.mUncachedCalendar.wrappedJSObject; unwrappedCalendar.capabilities = Object.assign({}, unwrappedCalendar.capabilities, updateProperties.capabilities); } @@ -137,7 +137,7 @@ this.calendar_calendars = class extends ExtensionAPI { } }, async remove(id) { - let calendar = cal.manager.getCalendarById(id); + const calendar = cal.manager.getCalendarById(id); if (!calendar) { throw new ExtensionError(`Invalid calendar id: ${id}`); } @@ -149,15 +149,15 @@ this.calendar_calendars = class extends ExtensionAPI { throw new ExtensionError("Cannot clear non-cached calendar"); } - let offlineStorage = getResolvedCalendarById(context.extension, id); - let calendar = cal.manager.getCalendarById(id.substring(0, id.length - 6)); + const offlineStorage = getResolvedCalendarById(context.extension, id); + const calendar = cal.manager.getCalendarById(id.substring(0, id.length - 6)); if (!isOwnCalendar(calendar, context.extension)) { throw new ExtensionError("Cannot clear foreign calendar"); } await new Promise((resolve, reject) => { - let listener = { + const listener = { onDeleteCalendar(aCalendar, aStatus, aDetail) { if (Components.isSuccessCode(aStatus)) { resolve(); @@ -175,26 +175,26 @@ this.calendar_calendars = class extends ExtensionAPI { }, synchronize(ids) { - let calendars = []; + const calendars = []; if (ids) { if (!Array.isArray(ids)) { ids = [ids]; } - for (let id of ids) { - let calendar = cal.manager.getCalendarById(id); + for (const id of ids) { + const calendar = cal.manager.getCalendarById(id); if (!calendar) { throw new ExtensionError(`Invalid calendar id: ${id}`); } calendars.push(calendar); } } else { - for (let calendar of cal.manager.getCalendars()) { + for (const calendar of cal.manager.getCalendars()) { if (calendar.getProperty("calendar-main-in-composite")) { calendars.push(calendar); } } } - for (let calendar of calendars) { + for (const calendar of calendars) { if (!calendar.getProperty("disabled") && calendar.canRefresh) { calendar.refresh(); } @@ -205,7 +205,7 @@ this.calendar_calendars = class extends ExtensionAPI { context, name: "calendar.calendars.onCreated", register: fire => { - let observer = { + const observer = { QueryInterface: ChromeUtils.generateQI(["calICalendarManagerObserver"]), onCalendarRegistered(calendar) { fire.sync(convertCalendar(context.extension, calendar)); @@ -225,9 +225,9 @@ this.calendar_calendars = class extends ExtensionAPI { context, name: "calendar.calendars.onUpdated", register: fire => { - let observer = cal.createAdapter(Ci.calIObserver, { + const observer = cal.createAdapter(Ci.calIObserver, { onPropertyChanged(calendar, name, value, _oldValue) { - let converted = convertCalendar(context.extension, calendar); + const converted = convertCalendar(context.extension, calendar); switch (name) { case "name": case "color": @@ -255,7 +255,7 @@ this.calendar_calendars = class extends ExtensionAPI { context, name: "calendar.calendars.onRemoved", register: fire => { - let observer = { + const observer = { QueryInterface: ChromeUtils.generateQI(["calICalendarManagerObserver"]), onCalendarRegistered() {}, onCalendarUnregistering(calendar) { diff --git a/calendar/experiments/calendar/parent/ext-calendar-items.js b/calendar/experiments/calendar/parent/ext-calendar-items.js index 3b45ebd..dd7ac0f 100644 --- a/calendar/experiments/calendar/parent/ext-calendar-items.js +++ b/calendar/experiments/calendar/parent/ext-calendar-items.js @@ -51,8 +51,8 @@ this.calendar_items = class extends ExtensionAPI { filter |= Ci.calICalendar.ITEM_FILTER_CLASS_OCCURRENCES; } - let rangeStart = queryProps.rangeStart ? cal.createDateTime(queryProps.rangeStart) : null; - let rangeEnd = queryProps.rangeEnd ? cal.createDateTime(queryProps.rangeEnd) : null; + const rangeStart = queryProps.rangeStart ? cal.createDateTime(queryProps.rangeStart) : null; + const rangeEnd = queryProps.rangeEnd ? cal.createDateTime(queryProps.rangeEnd) : null; return calendar.getItemsAsArray(filter, queryProps.limit ?? 0, rangeStart, rangeEnd); })); @@ -61,17 +61,17 @@ this.calendar_items = class extends ExtensionAPI { return calendarItems.flat().map(item => convertItem(item, queryProps, context.extension)); }, async get(calendarId, id, options) { - let calendar = getResolvedCalendarById(context.extension, calendarId); - let item = await calendar.getItem(id); + const calendar = getResolvedCalendarById(context.extension, calendarId); + const item = await calendar.getItem(id); return convertItem(item, options, context.extension); }, async create(calendarId, createProperties) { - let calendar = getResolvedCalendarById(context.extension, calendarId); - let item = propsToItem(createProperties); + const calendar = getResolvedCalendarById(context.extension, calendarId); + const item = propsToItem(createProperties); item.calendar = calendar.superCalendar; if (createProperties.metadata && isOwnCalendar(calendar, context.extension)) { - let cache = getCachedCalendar(calendar); + const cache = getCachedCalendar(calendar); cache.setMetaData(item.id, JSON.stringify(createProperties.metadata)); } @@ -85,9 +85,9 @@ this.calendar_items = class extends ExtensionAPI { return convertItem(createdItem, createProperties, context.extension); }, async update(calendarId, id, updateProperties) { - let calendar = getResolvedCalendarById(context.extension, calendarId); + const calendar = getResolvedCalendarById(context.extension, calendarId); - let oldItem = await calendar.getItem(id); + const oldItem = await calendar.getItem(id); if (!oldItem) { throw new ExtensionError("Could not find item " + id); } @@ -96,16 +96,16 @@ this.calendar_items = class extends ExtensionAPI { } else if (oldItem instanceof Ci.calITodo) { updateProperties.type = "task"; } - let newItem = propsToItem(updateProperties, oldItem?.clone()); + const newItem = propsToItem(updateProperties, oldItem?.clone()); newItem.calendar = calendar.superCalendar; if (updateProperties.metadata && isOwnCalendar(calendar, context.extension)) { // TODO merge or replace? - let cache = getCachedCalendar(calendar); + const cache = getCachedCalendar(calendar); cache.setMetaData(newItem.id, JSON.stringify(updateProperties.metadata)); } - let modifiedItem = await calendar.modifyItem(newItem, oldItem); + const modifiedItem = await calendar.modifyItem(newItem, oldItem); return convertItem(modifiedItem, updateProperties, context.extension); }, async move(fromCalendarId, id, toCalendarId) { @@ -113,9 +113,9 @@ this.calendar_items = class extends ExtensionAPI { return; } - let fromCalendar = cal.manager.getCalendarById(fromCalendarId); - let toCalendar = cal.manager.getCalendarById(toCalendarId); - let item = await fromCalendar.getItem(id); + const fromCalendar = cal.manager.getCalendarById(fromCalendarId); + const toCalendar = cal.manager.getCalendarById(toCalendarId); + const item = await fromCalendar.getItem(id); if (!item) { throw new ExtensionError("Could not find item " + id); @@ -124,17 +124,17 @@ this.calendar_items = class extends ExtensionAPI { if (isOwnCalendar(toCalendar, context.extension) && isOwnCalendar(fromCalendar, context.extension)) { // TODO doing this first, the item may not be in the db and it will fail. Doing this // after addItem, the metadata will not be available for the onCreated listener - let fromCache = getCachedCalendar(fromCalendar); - let toCache = getCachedCalendar(toCalendar); + const fromCache = getCachedCalendar(fromCalendar); + const toCache = getCachedCalendar(toCalendar); toCache.setMetaData(item.id, fromCache.getMetaData(item.id)); } await toCalendar.addItem(item); await fromCalendar.deleteItem(item); }, async remove(calendarId, id) { - let calendar = getResolvedCalendarById(context.extension, calendarId); + const calendar = getResolvedCalendarById(context.extension, calendarId); - let item = await calendar.getItem(id); + const item = await calendar.getItem(id); if (!item) { throw new ExtensionError("Could not find item " + id); } @@ -145,7 +145,7 @@ this.calendar_items = class extends ExtensionAPI { context, name: "calendar.items.onCreated", register: (fire, options) => { - let observer = cal.createAdapter(Ci.calIObserver, { + const observer = cal.createAdapter(Ci.calIObserver, { onAddItem: item => { fire.sync(convertItem(item, options, context.extension)); }, @@ -162,10 +162,10 @@ this.calendar_items = class extends ExtensionAPI { context, name: "calendar.items.onUpdated", register: (fire, options) => { - let observer = cal.createAdapter(Ci.calIObserver, { + const observer = cal.createAdapter(Ci.calIObserver, { onModifyItem: (newItem, _oldItem) => { // TODO calculate changeInfo - let changeInfo = {}; + const changeInfo = {}; fire.sync(convertItem(newItem, options, context.extension), changeInfo); }, }); @@ -181,7 +181,7 @@ this.calendar_items = class extends ExtensionAPI { context, name: "calendar.items.onRemoved", register: fire => { - let observer = cal.createAdapter(Ci.calIObserver, { + const observer = cal.createAdapter(Ci.calIObserver, { onDeleteItem: item => { fire.sync(item.calendar.id, item.id); }, @@ -198,7 +198,7 @@ this.calendar_items = class extends ExtensionAPI { context, name: "calendar.items.onAlarm", register: (fire, options) => { - let observer = { + const observer = { QueryInterface: ChromeUtils.generateQI(["calIAlarmServiceObserver"]), onAlarm(item, alarm) { fire.sync(convertItem(item, options, context.extension), convertAlarm(item, alarm)); @@ -208,7 +208,7 @@ this.calendar_items = class extends ExtensionAPI { onAlarmsLoaded(_calendar) {}, }; - let alarmsvc = Cc["@mozilla.org/calendar/alarm-service;1"].getService( + const alarmsvc = Cc["@mozilla.org/calendar/alarm-service;1"].getService( Ci.calIAlarmService ); diff --git a/calendar/experiments/calendar/parent/ext-calendar-provider.js b/calendar/experiments/calendar/parent/ext-calendar-provider.js index 108890a..3bb60a3 100644 --- a/calendar/experiments/calendar/parent/ext-calendar-provider.js +++ b/calendar/experiments/calendar/parent/ext-calendar-provider.js @@ -31,7 +31,7 @@ class ItemError extends Error { } function convertProps(props, extension) { - let calendar = new ExtCalendar(extension); + const calendar = new ExtCalendar(extension); calendar.setProperty("name", props.name); calendar.setProperty("readOnly", props.readOnly); calendar.setProperty("disabled", props.enabled === false); @@ -46,7 +46,7 @@ class ExtCalendarProvider { QueryInterface = ChromeUtils.generateQI(["calICalendarProvider"]); static register(extension) { - let type = "ext-" + extension.id; + const type = "ext-" + extension.id; cal.manager.registerCalendarProvider( type, @@ -57,12 +57,12 @@ class ExtCalendarProvider { } ); - let provider = new ExtCalendarProvider(extension); + const provider = new ExtCalendarProvider(extension); cal.provider.register(provider); } static unregister(extension) { - let type = "ext-" + extension.id; + const type = "ext-" + extension.id; cal.manager.unregisterCalendarProvider(type, true); cal.provider.unregister(type); } @@ -88,13 +88,13 @@ class ExtCalendarProvider { } getCalendar(url) { - let calendar = new ExtCalendar(this.extension); + const calendar = new ExtCalendar(this.extension); calendar.uri = url; return calendar; } async detectCalendars(username, password, location=null, savePassword=null, extraProperties={}) { - let detectionResponses = await this.extension.emit("calendar.provider.onDetectCalendars", username, password, location, savePassword, extraProperties); + const detectionResponses = await this.extension.emit("calendar.provider.onDetectCalendars", username, password, location, savePassword, extraProperties); return detectionResponses.reduce((allCalendars, calendars) => allCalendars.concat(calendars)).map(props => convertProps(props, this.extension)); } } @@ -226,8 +226,8 @@ class ExtCalendar extends cal.provider.BaseClass { async adoptItem(aItem) { const adoptCallback = this._cachedAdoptItemCallback; try { - let items = await this.extension.emit("calendar.provider.onItemCreated", this, aItem); - let { item, metadata } = items.find(props => props.item) || {}; + const items = await this.extension.emit("calendar.provider.onItemCreated", this, aItem); + const { item, metadata } = items.find(props => props.item) || {}; if (!item) { throw new Components.Exception("Did not receive item from extension", Cr.NS_ERROR_FAILURE); } @@ -266,7 +266,7 @@ class ExtCalendar extends cal.provider.BaseClass { discoverItem(results) { let error, success; - for (let result of results) { + for (const result of results) { if (typeof result == "object" && result?.error) { success = null; error = result.error; @@ -292,7 +292,7 @@ class ExtCalendar extends cal.provider.BaseClass { const modifyCallback = this._cachedModifyItemCallback; try { - let results = await this.extension.emit( + const results = await this.extension.emit( "calendar.provider.onItemUpdated", this, aNewItem, @@ -300,7 +300,7 @@ class ExtCalendar extends cal.provider.BaseClass { aOptions ); - let { item, metadata } = this.discoverItem(results); + const { item, metadata } = this.discoverItem(results); if (!item) { throw new Components.Exception("Did not receive item from extension", Cr.NS_ERROR_FAILURE); @@ -322,7 +322,7 @@ class ExtCalendar extends cal.provider.BaseClass { let code; if (e instanceof ItemError) { if (e.reason == ItemError.CONFLICT) { - let overwrite = cal.provider.promptOverwrite("modify", aOldItem); + const overwrite = cal.provider.promptOverwrite("modify", aOldItem); if (overwrite) { return this.modifyItem(aNewItem, aOldItem, { force: true }); } @@ -340,7 +340,7 @@ class ExtCalendar extends cal.provider.BaseClass { async deleteItem(aItem, aOptions = {}) { try { - let results = await this.extension.emit( + const results = await this.extension.emit( "calendar.provider.onItemRemoved", this, aItem, @@ -362,7 +362,7 @@ class ExtCalendar extends cal.provider.BaseClass { let code; if (e instanceof ItemError) { if (e.reason == ItemError.CONFLICT) { - let overwrite = cal.provider.promptOverwrite("delete", aItem); + const overwrite = cal.provider.promptOverwrite("delete", aItem); if (overwrite) { return this.deleteItem(aItem, { force: true }); } @@ -428,11 +428,11 @@ class ExtFreeBusyProvider { unavailable: Ci.calIFreeBusyInterval.BUSY_UNAVAILABLE, tentative: Ci.calIFreeBusyInterval.BUSY_TENTATIVE, }; - let attendee = aCalId.replace(/^mailto:/, ""); - let start = aRangeStart.icalString; - let end = aRangeEnd.icalString; - let types = ["free", "busy", "unavailable", "tentative"].filter((type, index) => aBusyTypes & (1 << index)); - let results = await this.fire.async({ attendee, start, end, types }); + const attendee = aCalId.replace(/^mailto:/, ""); + const start = aRangeStart.icalString; + const end = aRangeEnd.icalString; + const types = ["free", "busy", "unavailable", "tentative"].filter((type, index) => aBusyTypes & (1 << index)); + const results = await this.fire.async({ attendee, start, end, types }); aListener.onResult({ status: Cr.NS_OK }, results.map(interval => new cal.provider.FreeBusyInterval(aCalId, TYPE_MAP[interval.type], @@ -463,11 +463,11 @@ this.calendar_provider = class extends ExtensionAPI { ExtensionSupport.registerWindowListener("ext-calendar-provider-" + this.extension.id, { chromeURLs: ["chrome://calendar/content/calendar-creation.xhtml"], onLoadWindow: (win) => { - let provider = this.extension.manifest.calendar_provider; + const provider = this.extension.manifest.calendar_provider; if (provider.creation_panel) { // Do our own browser setup to avoid a bug win.setUpAddonCalendarSettingsPanel = (calendarType) => { - let panel = win.document.getElementById("panel-addon-calendar-settings"); + const panel = win.document.getElementById("panel-addon-calendar-settings"); panel.setAttribute("flex", "1"); let browser = panel.lastElementChild; @@ -491,8 +491,8 @@ this.calendar_provider = class extends ExtensionAPI { panelSrc: this.extension.getURL(this.extension.localize(provider.creation_panel)), onCreated: () => { // TODO temporary - let browser = win.document.getElementById("panel-addon-calendar-settings").lastElementChild; - let actor = browser.browsingContext.currentWindowGlobal.getActor("CalendarProvider"); + const browser = win.document.getElementById("panel-addon-calendar-settings").lastElementChild; + const actor = browser.browsingContext.currentWindowGlobal.getActor("CalendarProvider"); actor.sendAsyncMessage("postMessage", { message: "create", origin: this.extension.getURL("") }); } }); @@ -523,7 +523,7 @@ this.calendar_provider = class extends ExtensionAPI { if (entryName != "calendar_provider") { return; } - let manifest = this.extension.manifest; + const manifest = this.extension.manifest; if (!manifest.browser_specific_settings?.gecko?.id && !manifest.applications?.gecko?.id) { console.warn( @@ -537,7 +537,7 @@ this.calendar_provider = class extends ExtensionAPI { // yet. this.extension.on("background-script-started", () => { ExtCalendarProvider.register(this.extension); - let provider = new ExtCalendarProvider(this.extension); + const provider = new ExtCalendarProvider(this.extension); cal.provider.register(provider); }); } @@ -556,8 +556,8 @@ this.calendar_provider = class extends ExtensionAPI { context, name: "calendar.provider.onItemCreated", register: (fire, options) => { - let listener = async (event, calendar, item, listenerOptions) => { - let props = await fire.async( + const listener = async (event, calendar, item, listenerOptions) => { + const props = await fire.async( convertCalendar(context.extension, calendar), convertItem(item, options, context.extension), listenerOptions @@ -587,8 +587,8 @@ this.calendar_provider = class extends ExtensionAPI { context, name: "calendar.provider.onItemUpdated", register: (fire, options) => { - let listener = async (event, calendar, item, oldItem, listenerOptions) => { - let props = await fire.async( + const listener = async (event, calendar, item, oldItem, listenerOptions) => { + const props = await fire.async( convertCalendar(context.extension, calendar), convertItem(item, options, context.extension), convertItem(oldItem, options, context.extension), @@ -614,8 +614,8 @@ this.calendar_provider = class extends ExtensionAPI { context, name: "calendar.provider.onItemRemoved", register: (fire, options) => { - let listener = async (event, calendar, item, listenerOptions) => { - let res = await fire.async( + const listener = async (event, calendar, item, listenerOptions) => { + const res = await fire.async( convertCalendar(context.extension, calendar), convertItem(item, options, context.extension), listenerOptions @@ -634,7 +634,7 @@ this.calendar_provider = class extends ExtensionAPI { context, name: "calendar.provider.onInit", register: fire => { - let listener = (event, calendar) => { + const listener = (event, calendar) => { return fire.async(convertCalendar(context.extension, calendar)); }; @@ -649,7 +649,7 @@ this.calendar_provider = class extends ExtensionAPI { context, name: "calendar.provider.onSync", register: fire => { - let listener = (event, calendar) => { + const listener = (event, calendar) => { return fire.async(convertCalendar(context.extension, calendar)); }; @@ -664,7 +664,7 @@ this.calendar_provider = class extends ExtensionAPI { context, name: "calendar.provider.onResetSync", register: fire => { - let listener = (event, calendar) => { + const listener = (event, calendar) => { return fire.async(convertCalendar(context.extension, calendar)); }; @@ -679,7 +679,7 @@ this.calendar_provider = class extends ExtensionAPI { context, name: "calendar.provider.onFreeBusy", register: fire => { - let provider = new ExtFreeBusyProvider(fire); + const provider = new ExtFreeBusyProvider(fire); cal.freeBusyService.addProvider(provider); return () => { @@ -692,7 +692,7 @@ this.calendar_provider = class extends ExtensionAPI { context, name: "calendar.provider.onDetectCalendars", register: fire => { - let listener = (event, username, password, location, savePassword, extraProperties) => { + const listener = (event, username, password, location, savePassword, extraProperties) => { return fire.async(username, password, location, savePassword, extraProperties); }; diff --git a/calendar/experiments/calendar/parent/ext-calendarItemAction.js b/calendar/experiments/calendar/parent/ext-calendarItemAction.js index 5e4df44..3fd93d1 100644 --- a/calendar/experiments/calendar/parent/ext-calendarItemAction.js +++ b/calendar/experiments/calendar/parent/ext-calendarItemAction.js @@ -17,9 +17,9 @@ this.calendarItemAction = class extends ToolbarButtonAPI { onStartup() { // TODO this is only necessary in the experiment, can drop this when moving to core. - let calendarItemAction = this.extension.manifest?.calendar_item_action; + const calendarItemAction = this.extension.manifest?.calendar_item_action; if (calendarItemAction) { - let localize = this.extension.localize.bind(this.extension); + const localize = this.extension.localize.bind(this.extension); if (calendarItemAction.default_popup) { calendarItemAction.default_popup = this.extension.getURL(localize(calendarItemAction.default_popup)); @@ -38,12 +38,12 @@ this.calendarItemAction = class extends ToolbarButtonAPI { ExtensionSupport.registerWindowListener("ext-calendar-itemAction-" + this.extension.id, { chromeURLs: ["chrome://calendar/content/calendar-event-dialog.xhtml"], onLoadWindow(win) { - let { document } = win; + const { document } = win; if (!document.getElementById("mainPopupSet")) { - let mainPopupSet = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "popupset"); + const mainPopupSet = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "popupset"); mainPopupSet.id = "mainPopupSet"; - let dialog = document.querySelector("dialog"); + const dialog = document.querySelector("dialog"); dialog.insertBefore(mainPopupSet, dialog.firstElementChild); } } @@ -115,7 +115,7 @@ this.calendarItemAction = class extends ToolbarButtonAPI { handleEvent(event) { super.handleEvent(event); - let window = event.target.ownerGlobal; + const window = event.target.ownerGlobal; switch (event.type) { case "popupshowing": { @@ -142,25 +142,25 @@ this.calendarItemAction = class extends ToolbarButtonAPI { onShutdown() { // TODO browserAction uses static onUninstall, this doesn't work in an experiment. - let extensionId = this.extension.id; + const extensionId = this.extension.id; ExtensionSupport.unregisterWindowListener("ext-calendar-itemAction-" + extensionId); - let widgetId = makeWidgetId(extensionId); - let id = `${widgetId}-calendarItemAction-toolbarbutton`; + const widgetId = makeWidgetId(extensionId); + const id = `${widgetId}-calendarItemAction-toolbarbutton`; - let windowURLs = [ + const windowURLs = [ "chrome://messenger/content/messenger.xhtml", "chrome://calendar/content/calendar-event-dialog.xhtml" ]; - for (let windowURL of windowURLs) { + for (const windowURL of windowURLs) { let currentSet = Services.xulStore.getValue( windowURL, "event-toolbar", "currentset" ); currentSet = currentSet.split(","); - let index = currentSet.indexOf(id); + const index = currentSet.indexOf(id); if (index >= 0) { currentSet.splice(index, 1); Services.xulStore.setValue( diff --git a/calendar/experiments/calendar/parent/ext-calendarItemDetails.js b/calendar/experiments/calendar/parent/ext-calendarItemDetails.js index 32c2e4d..fa9e56f 100644 --- a/calendar/experiments/calendar/parent/ext-calendarItemDetails.js +++ b/calendar/experiments/calendar/parent/ext-calendarItemDetails.js @@ -10,7 +10,7 @@ this.calendarItemDetails = class extends ExtensionAPI { onLoadCalendarItemPanel(window, origLoadCalendarItemPanel, iframeId, url) { const { setupE10sBrowser } = ChromeUtils.importESModule("resource://tb-experiments-calendar/experiments/calendar/ext-calendar-utils.sys.mjs"); - let res = origLoadCalendarItemPanel(iframeId, url); + const res = origLoadCalendarItemPanel(iframeId, url); if (this.extension.manifest.calendar_item_details) { let panelFrame; if (window.tabmail) { @@ -20,27 +20,27 @@ this.calendarItemDetails = class extends ExtensionAPI { } panelFrame.contentWindow.addEventListener("load", (event) => { - let document = event.target.ownerGlobal.document; + const document = event.target.ownerGlobal.document; - let widgetId = makeWidgetId(this.extension.id); + const widgetId = makeWidgetId(this.extension.id); - let tabs = document.getElementById("event-grid-tabs"); - let tab = document.createXULElement("tab"); + const tabs = document.getElementById("event-grid-tabs"); + const tab = document.createXULElement("tab"); tabs.appendChild(tab); tab.setAttribute("label", this.extension.manifest.calendar_item_details.default_title); tab.setAttribute("id", widgetId + "-calendarItemDetails-tab"); tab.setAttribute("image", this.extension.manifest.calendar_item_details.default_icon); tab.querySelector(".tab-icon").style.maxHeight = "19px"; - let tabpanels = document.getElementById("event-grid-tabpanels"); - let tabpanel = document.createXULElement("tabpanel"); + const tabpanels = document.getElementById("event-grid-tabpanels"); + const tabpanel = document.createXULElement("tabpanel"); tabpanels.appendChild(tabpanel); tabpanel.setAttribute("id", widgetId + "-calendarItemDetails-tabpanel"); tabpanel.setAttribute("flex", "1"); - let browser = document.createXULElement("browser"); + const browser = document.createXULElement("browser"); browser.setAttribute("flex", "1"); - let loadPromise = setupE10sBrowser(this.extension, browser, tabpanel); + const loadPromise = setupE10sBrowser(this.extension, browser, tabpanel); return loadPromise.then(() => { browser.fixupAndLoadURIString(this.extension.manifest.calendar_item_details.default_content, { triggeringPrincipal: this.extension.principal }); @@ -52,9 +52,9 @@ this.calendarItemDetails = class extends ExtensionAPI { } onStartup() { - let calendarItemDetails = this.extension.manifest?.calendar_item_details; + const calendarItemDetails = this.extension.manifest?.calendar_item_details; if (calendarItemDetails) { - let localize = this.extension.localize.bind(this.extension); + const localize = this.extension.localize.bind(this.extension); if (calendarItemDetails.default_icon) { calendarItemDetails.default_icon = this.extension.getURL(localize(calendarItemDetails.default_icon)); @@ -75,7 +75,7 @@ this.calendarItemDetails = class extends ExtensionAPI { ], onLoadWindow: (window) => { if (window.location.href == "chrome://messenger/content/messenger.xhtml") { - let orig = window.onLoadCalendarItemPanel; + const orig = window.onLoadCalendarItemPanel; window.onLoadCalendarItemPanel = this.onLoadCalendarItemPanel.bind(this, window, orig.bind(window)); window._onLoadCalendarItemPanelOrig = orig; } else { @@ -89,7 +89,7 @@ this.calendarItemDetails = class extends ExtensionAPI { onShutdown() { ExtensionSupport.unregisterWindowListener("ext-calendarItemDetails-" + this.extension.id); - for (let wnd of ExtensionSupport.openWindows) { + for (const wnd of ExtensionSupport.openWindows) { if (wnd.location.href == "chrome://messenger/content/messenger.xhtml") { if (wnd._onLoadCalendarItemPanelOrig) { wnd.onLoadCalendarItemPanel = wnd._onLoadCalendarItemPanelOrig; @@ -98,7 +98,7 @@ this.calendarItemDetails = class extends ExtensionAPI { } } } - getAPI(context) { + getAPI(_context) { return { calendar: { itemDetails: {} } }; } };