Skip to content

ESLint and TSC fixes #79

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

Merged
merged 2 commits into from
Oct 19, 2022
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
9 changes: 8 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"compilerOptions": {
"target": "es2020",
"target": "es2021",
"module": "es2021",
"checkJs": true,
"strict": true,
"noImplicitAny": false,
"forceConsistentCasingInFileNames": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"baseUrl": "./src",
"paths": {
"/*": ["./*"],
Expand Down
52 changes: 26 additions & 26 deletions src/background/modules/AutocorrectHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { COMMUNICATION_MESSAGE_TYPE } from "/common/modules/data/BrowserCommunic
import * as symbols from "/common/modules/data/Symbols.js";

const settings = {
enabled: null,
autocorrectEmojis: null,
quotes: null,
fracts: null,
enabled: null,
autocorrectEmojis: null,
quotes: null,
fracts: null
};

let autocorrections = {};
Expand Down Expand Up @@ -50,7 +50,7 @@ function applySettings() {
console.log("Longest autocorrection", longest);

// Escape special characters
const regExSpecialChars = /[.*+?^${}()|[\]\\]/g;
const regExSpecialChars = /[.*+?^${}()|[\]\\]/gu;

symbolpatterns = Object.keys(autocorrections).map((symbol) => symbol.replace(regExSpecialChars, "\\$&"));

Expand Down Expand Up @@ -87,8 +87,8 @@ function applySettings() {

antipatterns = antipatterns.map((symbol) => symbol.replace(regExSpecialChars, "\\$&"));

symbolpatterns = new RegExp(`(${symbolpatterns.join("|")})$`);
antipatterns = new RegExp(`(${antipatterns.join("|")})$`);
symbolpatterns = new RegExp(`(${symbolpatterns.join("|")})$`, "u");
antipatterns = new RegExp(`(${antipatterns.join("|")})$`, "u");
}

/**
Expand Down Expand Up @@ -133,14 +133,14 @@ function sendSettings(autocorrect) {
browser.tabs.sendMessage(
tab.id,
{
"type": COMMUNICATION_MESSAGE_TYPE.AUTOCORRECT_CONTENT,
"enabled": settings.enabled,
"quotes": settings.quotes,
"fracts": settings.fracts,
"autocorrections": autocorrections,
"longest": longest,
"symbolpatterns": IS_CHROME ? symbolpatterns.source : symbolpatterns,
"antipatterns": IS_CHROME ? antipatterns.source : antipatterns,
type: COMMUNICATION_MESSAGE_TYPE.AUTOCORRECT_CONTENT,
enabled: settings.enabled,
quotes: settings.quotes,
fracts: settings.fracts,
autocorrections: autocorrections,
longest: longest,
symbolpatterns: IS_CHROME ? symbolpatterns.source : symbolpatterns,
antipatterns: IS_CHROME ? antipatterns.source : antipatterns
}
).catch(onError);
}
Expand All @@ -151,7 +151,7 @@ function sendSettings(autocorrect) {
* Init autocorrect module.
*
* @public
* @returns {void}
* @returns {Promise<void>}
*/
export async function init() {
const autocorrect = await AddonSettings.get("autocorrect");
Expand All @@ -163,8 +163,8 @@ export async function init() {
if (typeof messenger !== "undefined") {
browser.composeScripts.register({
js: [
{ file: "/content_scripts/autocorrect.js" },
],
{ file: "/content_scripts/autocorrect.js" }
]
});
}
}
Expand All @@ -180,14 +180,14 @@ browser.runtime.onMessage.addListener((message) => {
// console.log(message);
if (message.type === COMMUNICATION_MESSAGE_TYPE.AUTOCORRECT_CONTENT) {
const response = {
"type": COMMUNICATION_MESSAGE_TYPE.AUTOCORRECT_CONTENT,
"enabled": settings.enabled,
"quotes": settings.quotes,
"fracts": settings.fracts,
"autocorrections": autocorrections,
"longest": longest,
"symbolpatterns": IS_CHROME ? symbolpatterns.source : symbolpatterns,
"antipatterns": IS_CHROME ? antipatterns.source : antipatterns,
type: COMMUNICATION_MESSAGE_TYPE.AUTOCORRECT_CONTENT,
enabled: settings.enabled,
quotes: settings.quotes,
fracts: settings.fracts,
autocorrections: autocorrections,
longest: longest,
symbolpatterns: IS_CHROME ? symbolpatterns.source : symbolpatterns,
antipatterns: IS_CHROME ? antipatterns.source : antipatterns
};
return Promise.resolve(response);
}
Expand Down
22 changes: 11 additions & 11 deletions src/background/modules/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function handleMenuChoosen(info, tab) {
*
* @param {Object} info
* @param {Object} tab
* @returns {void}
* @returns {Promise<void>}
* @throws {Error}
*/
async function handleMenuShown(info) {
Expand All @@ -95,7 +95,7 @@ async function handleMenuShown(info) {
// shorten preview text as it may not be shown anyway
if (text.length > PREVIEW_STRING_CUT_LENGTH) {
// to be sure, we append … anyway, in case some strange OS has a tooltip for context menus or so
text = `${text.substring(0, PREVIEW_STRING_CUT_LENGTH)}…`;
text = `${text.slice(0, PREVIEW_STRING_CUT_LENGTH)}…`;
}
text = text.normalize();

Expand All @@ -118,7 +118,7 @@ async function handleMenuShown(info) {
*
* @param {Object} unicodeFontSettings
* @param {string?} [exampleText=null]
* @returns {void}
* @returns {Promise<void>}
*/
async function buildMenu(unicodeFontSettings, exampleText = null) {
if (unicodeFontSettings.changeFont) {
Expand All @@ -143,10 +143,10 @@ async function buildMenu(unicodeFontSettings, exampleText = null) {
/**
* Add Unicode menu items.
*
* @param {string[]} menuItems
* @param {string[]|symbol[]} menuItems
* @param {Object} [unicodeFontSettings]
* @param {string?} [exampleText=null]
* @returns {void}
* @returns {Promise<void>}
*/
async function addMenuItems(menuItems, unicodeFontSettings = lastCachedUnicodeFontSettings, exampleText = null) {
for (const transformationId of menuItems) {
Expand Down Expand Up @@ -178,13 +178,13 @@ async function addMenuItems(menuItems, unicodeFontSettings = lastCachedUnicodeFo

if (menuIsShown) {
menus.update(transformationId, {
"title": menuText,
title: menuText
});
} else {
await menus.create({
"id": transformationId,
"title": menuText,
"contexts": ["editable"],
id: transformationId,
title: menuText,
contexts: ["editable"]
});
}
}
Expand All @@ -203,7 +203,7 @@ BrowserCommunication.addListener(COMMUNICATION_MESSAGE_TYPE.UPDATE_CONTEXT_MENU,
// shorten preview text as it may not be shown anyway
if (text.length > PREVIEW_STRING_CUT_LENGTH) {
// to be sure, we append … anyway, in case some strange OS has a tooltip for context menus or so
text = `${text.substring(0, PREVIEW_STRING_CUT_LENGTH)}…`;
text = `${text.slice(0, PREVIEW_STRING_CUT_LENGTH)}…`;
}
text = text.normalize();

Expand All @@ -223,7 +223,7 @@ BrowserCommunication.addListener(COMMUNICATION_MESSAGE_TYPE.UPDATE_CONTEXT_MENU,
* Init Unicode font module.
*
* @public
* @returns {void}
* @returns {Promise<void>}
*/
export async function init() {
const platformInfo = await browser.runtime.getPlatformInfo();
Expand Down
12 changes: 6 additions & 6 deletions src/common/modules/BrowserCompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
* Returns a value based on what browser this is running in.
*
* @private
* @param {Object} switchBrowser an object with values to return per browser
* @returns {string}
* @param {Object.<string, string>} switchBrowser an object with values to return per browser
* @returns {Promise<string>}
*/
export async function getBrowserValue(switchBrowser) {
if (browser.runtime.getBrowserInfo) {
const browserInfo = await browser.runtime.getBrowserInfo();

if (browserInfo.name === "Thunderbird") {
return switchBrowser.thunderbird;
} else {
return switchBrowser.firefox;
}
} else {
return switchBrowser.chrome;
return switchBrowser.firefox;

}
return switchBrowser.chrome;

}
12 changes: 6 additions & 6 deletions src/common/modules/LanguageHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@
* @private
* @type {string[]}
*/
const ADDON_TRANSLATED_INTO = [
const ADDON_TRANSLATED_INTO = new Set([
// English
"en", "en-US",
// German
"de", "de-DE",
].map((lang) => lang.toLowerCase());
"de", "de-DE"
].map((lang) => lang.toLowerCase()));

/**
* Returns whether the user also speaks a language that the add-on is not
* translated into.
*
* @public
* @returns {boolean}
* @returns {Promise<boolean>}
*/
export async function userSpeaksLocaleNotYetTranslated() {
const addonLanguage = browser.i18n.getMessage("@@ui_locale");
const uiLanguage = browser.i18n.getUILanguage();
const acceptedLanguages = await browser.i18n.getAcceptLanguages();

console.log("Addon is translated into", addonLanguage, ", browser into ", uiLanguage, "and user accepts the languages", acceptedLanguages, ".");
console.log("Addon is translated into", addonLanguage, ", browser into", uiLanguage, "and user accepts the languages", acceptedLanguages, ".");
// Note: actually addonLanguage and uiLanguage should be the same, see https://discourse.mozilla.org/t/not-clear-that-there-are-three-locales/27533

// for evaluation, we can assume the user also speaks the language their browser is translated into
acceptedLanguages.push(uiLanguage);

// if the language the user speaks is not already translated, they probably know another locale we do not know yet
return acceptedLanguages.some((userLang) => ! ADDON_TRANSLATED_INTO.includes(userLang.toLowerCase()));
return acceptedLanguages.some((userLang) => !ADDON_TRANSLATED_INTO.has(userLang.toLowerCase()));
}
2 changes: 1 addition & 1 deletion src/common/modules/MobileHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Returns whether the current runtime is a mobile one (true) or not (false).
*
* @public
* @returns {Promise} with Boolean
* @returns {Promise<boolean>} with Boolean
*/
export async function isMobile() {
const platformInfo = await browser.runtime.getPlatformInfo();
Expand Down
12 changes: 6 additions & 6 deletions src/common/modules/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const ICON = (browser.runtime.getManifest()).icons[32];
* @public
* @param {string} title the title
* @param {string} content the message content
* @param {string[] | string} substitutions the message parameters to pass for i18n.getMessage
* @returns {Promise}
* @param {string[] | string} [substitutions] the message parameters to pass for i18n.getMessage
* @returns {void}
* @see {@link https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions/API/notifications/create}
*/
export function showNotification(title, content, substitutions) {
Expand All @@ -23,9 +23,9 @@ export function showNotification(title, content, substitutions) {

console.info("Showing notification:", title, content);
browser.notifications.create({
"type": "basic",
"iconUrl": browser.runtime.getURL(ICON),
"title": title,
"message": content
type: "basic",
iconUrl: browser.runtime.getURL(ICON),
title: title,
message: content
});
}
8 changes: 4 additions & 4 deletions src/common/modules/UnicodeTransformationHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ export function transformText(text, transformationId) {
*
* @public
* @param {string} transformationId
* @returns {Symbol} TRANSFORMATION_TYPE
* @returns {symbol} TRANSFORMATION_TYPE
* @throws {Error}
*/
export function getTransformationType(transformationId) {
if (transformationId.startsWith(CASE_ID_PREFIX)) {
return TRANSFORMATION_TYPE.CASING;
} else if (transformationId.startsWith(FONT_ID_PREFIX)) {
return TRANSFORMATION_TYPE.FONT;
} else {
throw new Error(`Error while getting transformation type. Transformation with id=${transformationId} is unknown.`);
}
throw new Error(`Error while getting transformation type. Transformation with id=${transformationId} is unknown.`);

}

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ function toggleCase(atext) {
* Change Case
*
* @const
* @type {Object.<string, function>}
* @type {Object.<string, function(string): string>}
*/
const changeCase = Object.freeze({
[`${CASE_ID_PREFIX}Lowercase`]: (str) => str.toLocaleLowerCase(),
Expand Down
10 changes: 5 additions & 5 deletions src/common/modules/data/Fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const smallCaps = "ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘꞯʀꜱᴛᴜᴠ
*
* @public
* @const
* @type {Symbol}
* @type {Object.<string, symbol>}
*/
export const TRANSFORMATION_TYPE = Object.freeze({
CASING: Symbol("casing transformation"),
Expand All @@ -21,7 +21,7 @@ export const TRANSFORMATION_TYPE = Object.freeze({
*
* @public
* @const
* @type {Symbol}
* @type {symbol}
*/
export const SEPARATOR_ID = Symbol("separator");

Expand All @@ -30,7 +30,7 @@ export const SEPARATOR_ID = Symbol("separator");
*
* @public
* @const
* @type {Symbol}
* @type {string}
*/
export const CASE_ID_PREFIX = "menuCase";

Expand All @@ -48,7 +48,7 @@ export const FONT_ID_PREFIX = "menuFont";
*
* @public
* @const
* @type {Object.<Symbol, string[]>}
* @type {Object.<symbol, string[]|symbol[]>}
*/
export const menuStructure = Object.freeze({
[TRANSFORMATION_TYPE.FONT]: [
Expand All @@ -75,7 +75,7 @@ export const menuStructure = Object.freeze({
`${FONT_ID_PREFIX}CircledBlack`,
`${FONT_ID_PREFIX}Squared`,
`${FONT_ID_PREFIX}SquaredBlack`,
`${FONT_ID_PREFIX}Fullwidth`,
`${FONT_ID_PREFIX}Fullwidth`
],
[TRANSFORMATION_TYPE.CASING]: [
`${CASE_ID_PREFIX}Lowercase`,
Expand Down
12 changes: 6 additions & 6 deletions src/common/modules/data/MessageLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
* Specifies the message level to use,
*
* @readonly
* @enum {int}
* @enum {number}
* @default
*/
export const MESSAGE_LEVEL = Object.freeze({
"ERROR": 3,
"WARN": 2,
"INFO": 1,
"LOADING": -2,
"SUCCESS": -3
ERROR: 3,
WARN: 2,
INFO: 1,
LOADING: -2,
SUCCESS: -3
});
2 changes: 1 addition & 1 deletion src/common/modules/data/Symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const symbols = Object.freeze({
"|==>": "⟾",

"::=": "⩴",
"__": "_",
__: "_",
"==": "⩵",
"!=": "≠",
"===": "⩶",
Expand Down
Loading