Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include more comm-central eslint rules #37

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -42,9 +50,6 @@ module.exports = {
global: true,
Services: true,
},
rules: {
"no-unused-vars": ["error", { argsIgnorePattern: "^_|context" }]
}
}
]
};
2 changes: 1 addition & 1 deletion NotificationBox/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -73,7 +73,7 @@
}
};

let element = await this.getNotificationBox().appendNotification(
const element = await this.getNotificationBox().appendNotification(
`extension-notification-${this.notificationId}`,
{
label,
Expand All @@ -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("-");
Expand All @@ -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];
Expand All @@ -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(
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -267,15 +267,15 @@

onShutdown() {
Services.obs.removeObserver(this, "domwindowclosed");
for (let notification of this.notificationsMap.values()) {
for (const notification of this.notificationsMap.values()) {
notification.remove(/* closedByUser */ false);
}
}

// 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);
Expand Down
16 changes: 8 additions & 8 deletions calendar/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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"
Expand All @@ -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 });
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions calendar/experiments/calendar/ext-calendar-utils.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -54,7 +54,7 @@ export function convertCalendar(extension, calendar) {
return null;
}

let props = {
const props = {
id: calendar.id,
type: calendar.type,
name: calendar.name,
Expand Down Expand Up @@ -139,7 +139,7 @@ export function convertItem(item, options, extension) {
return null;
}

let props = {};
const props = {};

if (item instanceof Ci.calIEvent) {
props.type = "event";
Expand All @@ -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)) ?? {};
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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,
Expand Down
40 changes: 20 additions & 20 deletions calendar/experiments/calendar/parent/ext-calendar-calendars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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}`);
}
Expand All @@ -114,15 +114,15 @@ 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]);
}
}

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);
}

Expand All @@ -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}`);
}
Expand All @@ -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();
Expand All @@ -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();
}
Expand All @@ -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));
Expand All @@ -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":
Expand Down Expand Up @@ -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) {
Expand Down
Loading