From 1868b99d177fd1e93be9a9de5a72ac95dd525de9 Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Wed, 10 Feb 2021 09:40:15 -0600 Subject: [PATCH] Linter updates and fixes (#1604) --- src/background/contextMenus.background.ts | 2 +- src/background/main.background.ts | 20 +++++++++--------- src/background/nativeMessaging.background.ts | 8 +++---- src/background/runtime.background.ts | 12 +++++------ src/browser/browserApi.ts | 6 +++--- src/browser/safariApp.ts | 2 +- src/content/autofiller.ts | 2 +- src/content/notificationBar.ts | 8 +++---- src/content/shortcuts.ts | 2 +- src/content/sso.ts | 2 +- src/popup/app-routing.module.ts | 6 +++--- src/popup/app.component.ts | 2 +- src/popup/app.module.ts | 4 ++-- src/services/autofill.service.ts | 22 ++++++++++---------- src/services/browserPlatformUtils.service.ts | 6 +++--- src/services/browserStorage.service.ts | 8 +++---- tslint.json | 17 +++++++++++++++ 17 files changed, 73 insertions(+), 56 deletions(-) diff --git a/src/background/contextMenus.background.ts b/src/background/contextMenus.background.ts index 7a34acd659..c07ced8d71 100644 --- a/src/background/contextMenus.background.ts +++ b/src/background/contextMenus.background.ts @@ -66,7 +66,7 @@ export default class ContextMenusBackground { } const ciphers = await this.cipherService.getAllDecrypted(); - const cipher = ciphers.find((c) => c.id === id); + const cipher = ciphers.find(c => c.id === id); if (cipher == null) { return; } diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 82d1f739a6..399b385ebb 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -78,12 +78,12 @@ import TabsBackground from './tabs.background'; import WebRequestBackground from './webRequest.background'; import WindowsBackground from './windows.background'; +import { PopupUtilsService } from '../popup/services/popup-utils.service'; import AutofillService from '../services/autofill.service'; import BrowserMessagingService from '../services/browserMessaging.service'; import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service'; import BrowserStorageService from '../services/browserStorage.service'; import I18nService from '../services/i18n.service'; -import { PopupUtilsService } from '../popup/services/popup-utils.service'; import { AutofillService as AutofillServiceAbstraction } from '../services/abstractions/autofill.service'; @@ -164,7 +164,7 @@ export default class MainBackground { return Promise.reject(e); } - return promise.then((result) => result.response === 'unlocked'); + return promise.then(result => result.response === 'unlocked'); } }); this.storageService = new BrowserStorageService(); @@ -279,7 +279,7 @@ export default class MainBackground { await this.webRequestBackground.init(); await this.windowsBackground.init(); - return new Promise((resolve) => { + return new Promise(resolve => { setTimeout(async () => { await this.environmentService.setUrlsFromStorage(); await this.setIcon(); @@ -422,11 +422,11 @@ export default class MainBackground { return; } - const getStorage = (): Promise => new Promise((resolve) => { + const getStorage = (): Promise => new Promise(resolve => { chrome.storage.local.get(null, (o: any) => resolve(o)); }); - const clearStorage = (): Promise => new Promise((resolve) => { + const clearStorage = (): Promise => new Promise(resolve => { chrome.storage.local.clear(() => resolve()); }); @@ -527,7 +527,7 @@ export default class MainBackground { ciphers.sort((a, b) => this.cipherService.sortCiphersByLastUsedThenName(a, b)); if (contextMenuEnabled) { - ciphers.forEach((cipher) => { + ciphers.forEach(cipher => { this.loadLoginContextMenuOptions(cipher); }); } @@ -560,7 +560,7 @@ export default class MainBackground { const tabs = await BrowserApi.getActiveTabs(); if (tabs != null) { - tabs.forEach((tab) => { + tabs.forEach(tab => { if (tab.id != null) { this.browserActionSetBadgeText('', tab.id); this.sidebarActionSetBadgeText('', tab.id); @@ -703,7 +703,7 @@ export default class MainBackground { // Browser API Helpers private contextMenusRemoveAll() { - return new Promise((resolve) => { + return new Promise(resolve => { chrome.contextMenus.removeAll(() => { resolve(); if (chrome.runtime.lastError) { @@ -714,7 +714,7 @@ export default class MainBackground { } private contextMenusCreate(options: any) { - return new Promise((resolve) => { + return new Promise(resolve => { chrome.contextMenus.create(options, () => { resolve(); if (chrome.runtime.lastError) { @@ -739,7 +739,7 @@ export default class MainBackground { if (this.platformUtilsService.isFirefox()) { await theAction.setIcon(options); } else { - return new Promise((resolve) => { + return new Promise(resolve => { theAction.setIcon(options, () => resolve()); }); } diff --git a/src/background/nativeMessaging.background.ts b/src/background/nativeMessaging.background.ts index 7c74c38db3..7a3cea9af0 100644 --- a/src/background/nativeMessaging.background.ts +++ b/src/background/nativeMessaging.background.ts @@ -1,12 +1,12 @@ -import { ConstantsService } from 'jslib/services/constants.service'; import { AppIdService } from 'jslib/abstractions/appId.service'; -import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service'; import { CryptoService } from 'jslib/abstractions/crypto.service'; +import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { MessagingService } from 'jslib/abstractions/messaging.service'; import { StorageService } from 'jslib/abstractions/storage.service'; import { UserService } from 'jslib/abstractions/user.service'; import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; +import { ConstantsService } from 'jslib/services/constants.service'; import { Utils } from 'jslib/misc/utils'; import { SymmetricCryptoKey } from 'jslib/models/domain'; @@ -38,7 +38,7 @@ export class NativeMessagingBackground { if (BrowserApi.isChromeApi) { // Reload extension to activate nativeMessaging - chrome.permissions.onAdded.addListener((permissions) => { + chrome.permissions.onAdded.addListener(permissions => { BrowserApi.reloadExtension(null); }); } @@ -264,7 +264,7 @@ export class NativeMessagingBackground { this.sendUnencrypted({ command: 'setupEncryption', publicKey: Utils.fromBufferToB64(publicKey), - userId: await this.userService.getUserId() + userId: await this.userService.getUserId(), }); return new Promise((resolve, reject) => this.secureSetupResolve = resolve); diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 685ffc1414..916c55e8cc 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -4,10 +4,7 @@ import { CipherView } from 'jslib/models/view/cipherView'; import { LoginUriView } from 'jslib/models/view/loginUriView'; import { LoginView } from 'jslib/models/view/loginView'; -import { AutofillService } from '../services/abstractions/autofill.service'; -import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service'; import { CipherService } from 'jslib/abstractions/cipher.service'; -import { ConstantsService } from 'jslib/services/constants.service'; import { EnvironmentService } from 'jslib/abstractions/environment.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { NotificationsService } from 'jslib/abstractions/notifications.service'; @@ -16,6 +13,9 @@ import { StorageService } from 'jslib/abstractions/storage.service'; import { SystemService } from 'jslib/abstractions/system.service'; import { UserService } from 'jslib/abstractions/user.service'; import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; +import { ConstantsService } from 'jslib/services/constants.service'; +import { AutofillService } from '../services/abstractions/autofill.service'; +import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service'; import { BrowserApi } from '../browser/browserApi'; @@ -185,7 +185,7 @@ export default class RuntimeBackground { const totpCode = await this.autofillService.doAutoFill({ cipher: this.main.loginToAutoFill, pageDetails: this.pageDetailsToAutoFill, - fillNewPassword: true + fillNewPassword: true, }); if (totpCode != null) { @@ -306,7 +306,7 @@ export default class RuntimeBackground { } const ciphers = await this.cipherService.getAllDecryptedForUrl(loginInfo.url); - const usernameMatches = ciphers.filter((c) => + const usernameMatches = ciphers.filter(c => c.login.username != null && c.login.username.toLowerCase() === normalizedUsername); if (usernameMatches.length === 0) { const disabledAddLogin = await this.storageService.get( @@ -354,7 +354,7 @@ export default class RuntimeBackground { let id: string = null; const ciphers = await this.cipherService.getAllDecryptedForUrl(changeData.url); if (changeData.currentPassword != null) { - const passwordMatches = ciphers.filter((c) => c.login.password === changeData.currentPassword); + const passwordMatches = ciphers.filter(c => c.login.password === changeData.currentPassword); if (passwordMatches.length === 1) { id = passwordMatches[0].id; } diff --git a/src/browser/browserApi.ts b/src/browser/browserApi.ts index c5e5b2f118..521e947c7e 100644 --- a/src/browser/browserApi.ts +++ b/src/browser/browserApi.ts @@ -32,7 +32,7 @@ export class BrowserApi { } static async tabsQuery(options: any): Promise { - return new Promise((resolve) => { + return new Promise(resolve => { chrome.tabs.query(options, (tabs: any[]) => { resolve(tabs); }); @@ -65,7 +65,7 @@ export class BrowserApi { return; } - return new Promise((resolve) => { + return new Promise(resolve => { chrome.tabs.sendMessage(tab.id, obj, options, () => { if (chrome.runtime.lastError) { // Some error happened @@ -155,7 +155,7 @@ export class BrowserApi { static reloadOpenWindows() { const views = chrome.extension.getViews() as Window[]; - views.filter((w) => w.location.href != null).forEach((w) => { + views.filter(w => w.location.href != null).forEach(w => { w.location.reload(); }); } diff --git a/src/browser/safariApp.ts b/src/browser/safariApp.ts index b53d3754b7..80930a3d57 100644 --- a/src/browser/safariApp.ts +++ b/src/browser/safariApp.ts @@ -5,7 +5,7 @@ export class SafariApp { if (!BrowserApi.isSafariApi) { return Promise.resolve(null); } - return new Promise((resolve) => { + return new Promise(resolve => { const now = new Date(); const messageId = now.getTime().toString() + '_' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); (browser as any).runtime.sendNativeMessage('com.bitwarden.desktop', { diff --git a/src/content/autofiller.ts b/src/content/autofiller.ts index 1d756b8451..5e73c4a5c5 100644 --- a/src/content/autofiller.ts +++ b/src/content/autofiller.ts @@ -1,4 +1,4 @@ -document.addEventListener('DOMContentLoaded', (event) => { +document.addEventListener('DOMContentLoaded', event => { let pageHref: string = null; let filledThisHref = false; let delayFillTimeout: number; diff --git a/src/content/notificationBar.ts b/src/content/notificationBar.ts index 70fbd5e413..a3e215d411 100644 --- a/src/content/notificationBar.ts +++ b/src/content/notificationBar.ts @@ -1,4 +1,4 @@ -document.addEventListener('DOMContentLoaded', (event) => { +document.addEventListener('DOMContentLoaded', event => { if (window.location.hostname.indexOf('vault.bitwarden.com') > -1) { return; } @@ -83,7 +83,7 @@ document.addEventListener('DOMContentLoaded', (event) => { function observeDom() { const bodies = document.querySelectorAll('body'); if (bodies && bodies.length > 0) { - observer = new MutationObserver((mutations) => { + observer = new MutationObserver(mutations => { if (mutations == null || mutations.length === 0 || pageHref !== window.location.href) { return; } @@ -333,7 +333,7 @@ document.addEventListener('DOMContentLoaded', (event) => { } else { const buttonText = getButtonText(getSubmitButton(form, changePasswordButtonNames)); const matches = Array.from(changePasswordButtonContainsNames) - .filter((n) => buttonText.indexOf(n) > -1); + .filter(n => buttonText.indexOf(n) > -1); if (matches.length > 0) { curPass = passwords[0]; newPass = passwords[1]; @@ -379,7 +379,7 @@ document.addEventListener('DOMContentLoaded', (event) => { const possibleSubmitButtons = Array.from(wrappingEl.querySelectorAll('a, span, button[type="button"], ' + 'input[type="button"], button:not([type])')) as HTMLElement[]; let typelessButton: HTMLElement = null; - possibleSubmitButtons.forEach((button) => { + possibleSubmitButtons.forEach(button => { if (submitButton != null || button == null || button.tagName == null) { return; } diff --git a/src/content/shortcuts.ts b/src/content/shortcuts.ts index fe9699ac52..8aa72deccb 100644 --- a/src/content/shortcuts.ts +++ b/src/content/shortcuts.ts @@ -1,6 +1,6 @@ import * as Mousetrap from 'mousetrap'; -document.addEventListener('DOMContentLoaded', (event) => { +document.addEventListener('DOMContentLoaded', event => { const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 && navigator.userAgent.indexOf('Chrome') === -1; const isVivaldi = !isSafari && navigator.userAgent.indexOf(' Vivaldi/') !== -1; diff --git a/src/content/sso.ts b/src/content/sso.ts index 508bc2aea3..8c57d72de3 100644 --- a/src/content/sso.ts +++ b/src/content/sso.ts @@ -1,4 +1,4 @@ -window.addEventListener('message', (event) => { +window.addEventListener('message', event => { if (event.source !== window) return; diff --git a/src/popup/app-routing.module.ts b/src/popup/app-routing.module.ts index cf253b8d9f..16a4598fdd 100644 --- a/src/popup/app-routing.module.ts +++ b/src/popup/app-routing.module.ts @@ -1,4 +1,4 @@ -import { NgModule, Injectable } from '@angular/core'; +import { Injectable, NgModule } from '@angular/core'; import { ActivatedRouteSnapshot, RouteReuseStrategy, @@ -17,12 +17,12 @@ import { LockComponent } from './accounts/lock.component'; import { LoginComponent } from './accounts/login.component'; import { RegisterComponent } from './accounts/register.component'; import { SetPasswordComponent } from './accounts/set-password.component'; +import { SsoComponent } from './accounts/sso.component'; import { TwoFactorOptionsComponent } from './accounts/two-factor-options.component'; import { TwoFactorComponent } from './accounts/two-factor.component'; -import { SsoComponent } from './accounts/sso.component'; -import { PasswordGeneratorComponent } from './generator/password-generator.component'; import { PasswordGeneratorHistoryComponent } from './generator/password-generator-history.component'; +import { PasswordGeneratorComponent } from './generator/password-generator.component'; import { PrivateModeComponent } from './private-mode.component'; import { TabsComponent } from './tabs.component'; diff --git a/src/popup/app.component.ts b/src/popup/app.component.ts index 5e10d08ecb..33fea7c59f 100644 --- a/src/popup/app.component.ts +++ b/src/popup/app.component.ts @@ -139,7 +139,7 @@ export class AppComponent implements OnInit { BrowserApi.messageListener('app.component', (window as any).bitwardenPopupMainMessageListener); - this.router.events.subscribe((event) => { + this.router.events.subscribe(event => { if (event instanceof NavigationEnd) { const url = event.urlAfterRedirects || event.url || ''; if (url.startsWith('/tabs/') && (window as any).previousPopupUrl != null && diff --git a/src/popup/app.module.ts b/src/popup/app.module.ts index b1a1efc800..13ea36c4f1 100644 --- a/src/popup/app.module.ts +++ b/src/popup/app.module.ts @@ -22,9 +22,9 @@ import { LockComponent } from './accounts/lock.component'; import { LoginComponent } from './accounts/login.component'; import { RegisterComponent } from './accounts/register.component'; import { SetPasswordComponent } from './accounts/set-password.component'; +import { SsoComponent } from './accounts/sso.component'; import { TwoFactorOptionsComponent } from './accounts/two-factor-options.component'; import { TwoFactorComponent } from './accounts/two-factor.component'; -import { SsoComponent } from './accounts/sso.component'; import { PasswordGeneratorHistoryComponent } from './generator/password-generator-history.component'; import { PasswordGeneratorComponent } from './generator/password-generator.component'; @@ -223,7 +223,7 @@ registerLocaleData(localeZhTw, 'zh-TW'); TwoFactorComponent, SsoComponent, ViewComponent, - SetPasswordComponent + SetPasswordComponent, ], entryComponents: [], providers: [ diff --git a/src/services/autofill.service.ts b/src/services/autofill.service.ts index 82d5224a6e..841e27098d 100644 --- a/src/services/autofill.service.ts +++ b/src/services/autofill.service.ts @@ -41,14 +41,14 @@ const FirstnameFieldNames: string[] = [ // English 'f-name', 'first-name', 'given-name', 'first-n', // German - 'vorname' + 'vorname', ]; const LastnameFieldNames: string[] = [ // English 'l-name', 'last-name', 's-name', 'surname', 'family-name', 'family-n', 'last-n', // German - 'nachname', 'familienname' + 'nachname', 'familienname', ]; const ExcludedAutofillTypes: string[] = ['radio', 'checkbox', 'hidden', 'file', 'button', 'image', 'reset', 'search']; @@ -150,7 +150,7 @@ export default class AutofillService implements AutofillServiceInterface { continue; } - const formPasswordFields = passwordFields.filter((pf) => formKey === pf.form); + const formPasswordFields = passwordFields.filter(pf => formKey === pf.form); if (formPasswordFields.length > 0) { let uf = this.findUsernameField(pageDetails, formPasswordFields[0], false, false, false); if (uf == null) { @@ -215,7 +215,7 @@ export default class AutofillService implements AutofillServiceInterface { return; } - totpPromise = this.totpService.isAutoCopyEnabled().then((enabled) => { + totpPromise = this.totpService.isAutoCopyEnabled().then(enabled => { if (enabled) { return this.totpService.getCode(options.cipher.login.totp); } @@ -369,13 +369,13 @@ export default class AutofillService implements AutofillServiceInterface { } const passwordFieldsForForm: AutofillField[] = []; - passwordFields.forEach((passField) => { + passwordFields.forEach(passField => { if (formKey === passField.form) { passwordFieldsForForm.push(passField); } }); - passwordFields.forEach((passField) => { + passwordFields.forEach(passField => { pf = passField; passwords.push(pf); @@ -425,7 +425,7 @@ export default class AutofillService implements AutofillServiceInterface { }); } - usernames.forEach((u) => { + usernames.forEach(u => { if (filledFields.hasOwnProperty(u.opid)) { return; } @@ -434,7 +434,7 @@ export default class AutofillService implements AutofillServiceInterface { this.fillByOpid(fillScript, u, login.username); }); - passwords.forEach((p) => { + passwords.forEach(p => { if (filledFields.hasOwnProperty(p.opid)) { return; } @@ -666,7 +666,7 @@ export default class AutofillService implements AutofillServiceInterface { } let doesContain = false; - CardAttributesExtended.forEach((attr) => { + CardAttributesExtended.forEach(attr => { if (doesContain || !field.hasOwnProperty(attr) || !field[attr]) { return; } @@ -924,7 +924,7 @@ export default class AutofillService implements AutofillServiceInterface { private loadPasswordFields(pageDetails: AutofillPageDetails, canBeHidden: boolean, canBeReadOnly: boolean, mustBeEmpty: boolean, fillNewPassword: boolean) { const arr: AutofillField[] = []; - pageDetails.fields.forEach((f) => { + pageDetails.fields.forEach(f => { const isPassword = f.type === 'password'; const valueIsLikePassword = (value: string) => { if (value == null) { @@ -938,7 +938,7 @@ export default class AutofillService implements AutofillServiceInterface { } const ignoreList = ['onetimepassword', 'captcha', 'findanything']; - if (ignoreList.some((i) => cleanedValue.indexOf(i) > -1)) { + if (ignoreList.some(i => cleanedValue.indexOf(i) > -1)) { return false; } diff --git a/src/services/browserPlatformUtils.service.ts b/src/services/browserPlatformUtils.service.ts index dad8166a65..16876542d6 100644 --- a/src/services/browserPlatformUtils.service.ts +++ b/src/services/browserPlatformUtils.service.ts @@ -158,7 +158,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService type: type, dialogId: dialogId, }); - return new Promise((resolve) => { + return new Promise(resolve => { this.showDialogResolves.set(dialogId, { resolve: resolve, date: new Date() }); }); } @@ -190,7 +190,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService } const clearing = options ? !!options.clearing : false; const clearMs: number = options && options.clearMs ? options.clearMs : null; - + if (this.isSafari()) { SafariApp.sendMessageToApp('copyToClipboard', text).then(() => { if (!clearing && this.clipboardWriteCallback != null) { @@ -285,7 +285,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService deleteIds.push(key); } }); - deleteIds.forEach((id) => { + deleteIds.forEach(id => { this.showDialogResolves.delete(id); }); } diff --git a/src/services/browserStorage.service.ts b/src/services/browserStorage.service.ts index 9d3a6bc677..f2b3146fdb 100644 --- a/src/services/browserStorage.service.ts +++ b/src/services/browserStorage.service.ts @@ -8,7 +8,7 @@ export default class BrowserStorageService implements StorageService { } async get(key: string): Promise { - return new Promise((resolve) => { + return new Promise(resolve => { this.chromeStorageApi.get(key, (obj: any) => { if (obj != null && obj[key] != null) { resolve(obj[key] as T); @@ -22,7 +22,7 @@ export default class BrowserStorageService implements StorageService { async save(key: string, obj: any): Promise { if (obj == null) { // Fix safari not liking null in set - return new Promise((resolve) => { + return new Promise(resolve => { this.chromeStorageApi.remove(key, () => { resolve(); }); @@ -30,7 +30,7 @@ export default class BrowserStorageService implements StorageService { } const keyedObj = { [key]: obj }; - return new Promise((resolve) => { + return new Promise(resolve => { this.chromeStorageApi.set(keyedObj, () => { resolve(); }); @@ -38,7 +38,7 @@ export default class BrowserStorageService implements StorageService { } async remove(key: string): Promise { - return new Promise((resolve) => { + return new Promise(resolve => { this.chromeStorageApi.remove(key, () => { resolve(); }); diff --git a/tslint.json b/tslint.json index cb3f6b016f..56dfb1f867 100644 --- a/tslint.json +++ b/tslint.json @@ -50,9 +50,26 @@ "check-type" ], "max-classes-per-file": false, + "ordered-imports": true, + "arrow-parens": [ + true, + "ban-single-arg-parens" + ], "semicolon": [ true, "always" + ], + "trailing-comma": [ + true, + { + "multiline": { + "objects": "always", + "arrays": "always", + "functions": "ignore", + "typeLiterals": "ignore" + }, + "singleline": "never" + } ] } }