xo: Enable @typescript-eslint/restrict-template-expressions.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-04-25 16:53:33 -07:00
committed by Anders Kaseorg
parent fc6ff83485
commit 849df4adaf
6 changed files with 22 additions and 9 deletions

View File

@@ -59,7 +59,11 @@ electron_bridge.on('realm_name', realmName => {
ipcRenderer.send('realm-name-changed', serverURL, realmName);
});
electron_bridge.on('realm_icon_url', iconURL => {
electron_bridge.on('realm_icon_url', (iconURL: unknown) => {
if (typeof iconURL !== 'string') {
throw new TypeError('Expected string for iconURL');
}
const serverURL = location.origin;
iconURL = iconURL.includes('http') ? iconURL : `${serverURL}${iconURL}`;
ipcRenderer.send('realm-icon-changed', serverURL, iconURL);

View File

@@ -21,9 +21,9 @@ export async function loadBots(): Promise<void> {
const response = await fetch('/json/users');
if (response.ok) {
const { members } = await response.json();
members.forEach((membersRow: any) => {
if (membersRow.is_bot) {
const bot = `@${membersRow.full_name}`;
members.forEach(({ is_bot, full_name }: any) => {
if (is_bot && typeof full_name === 'string') {
const bot = `@${full_name}`;
const mention = `@**${bot.replace(/^@/, '')}**`;
botsList.push([bot, mention]);
}

View File

@@ -115,7 +115,7 @@ export default class GeneralSection extends BaseSection {
</div>
<div class="setting-row" id="remove-custom-css">
<div class="setting-description">
<div class="selected-css-path" id="custom-css-path">${ConfigUtil.getConfigItem('customCSS')}</div>
<div class="selected-css-path" id="custom-css-path">${ConfigUtil.getConfigString('customCSS', '')}</div>
</div>
<div class="action red" id="css-delete-action">
<i class="material-icons">indeterminate_check_box</i>
@@ -130,7 +130,7 @@ export default class GeneralSection extends BaseSection {
</div>
<div class="setting-row">
<div class="setting-description">
<div class="download-folder-path">${ConfigUtil.getConfigItem('downloadsPath', `${app.getPath('downloads')}`)}</div>
<div class="download-folder-path">${ConfigUtil.getConfigString('downloadsPath', app.getPath('downloads'))}</div>
</div>
</div>
<div class="setting-row" id="prompt-download">

View File

@@ -45,6 +45,16 @@ export function getConfigItem(key: string, defaultValue: any = null): any {
}
}
export function getConfigString(key: string, defaultValue: string): string {
const value = getConfigItem(key, defaultValue);
if (typeof value === 'string') {
return value;
} else {
setConfigItem(key, defaultValue);
return defaultValue;
}
}
// This function returns whether a key exists in the configuration file (settings.json)
export function isConfigItemExists(key: string): boolean {
try {

View File

@@ -45,7 +45,7 @@ export function requestOptions(domain: string, ignoreCerts: boolean): RequestUti
try {
certificateLocation = fs.readFileSync(certificateFile, 'utf8');
} catch (error) {
logger.warn(`Error while trying to get certificate: ${error}`);
logger.warn('Error while trying to get certificate:', error);
}
}

View File

@@ -207,7 +207,6 @@
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"capitalized-comments": "off",
"import/no-mutable-exports": "off",
"import/unambiguous": "error",