Browse Source

Linter updates and fixes (#1604)

snyk-upgrade-8e887f317ce97ae157ed096bba8dcc4a
Matt Gibson 8 months ago
committed by GitHub
parent
commit
1868b99d17
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/background/contextMenus.background.ts
  2. 20
      src/background/main.background.ts
  3. 8
      src/background/nativeMessaging.background.ts
  4. 12
      src/background/runtime.background.ts
  5. 6
      src/browser/browserApi.ts
  6. 2
      src/browser/safariApp.ts
  7. 2
      src/content/autofiller.ts
  8. 8
      src/content/notificationBar.ts
  9. 2
      src/content/shortcuts.ts
  10. 2
      src/content/sso.ts
  11. 6
      src/popup/app-routing.module.ts
  12. 2
      src/popup/app.component.ts
  13. 4
      src/popup/app.module.ts
  14. 22
      src/services/autofill.service.ts
  15. 6
      src/services/browserPlatformUtils.service.ts
  16. 8
      src/services/browserStorage.service.ts
  17. 17
      tslint.json

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

20
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<any> => new Promise((resolve) => {
const getStorage = (): Promise<any> => new Promise(resolve => {
chrome.storage.local.get(null, (o: any) => resolve(o));
});
const clearStorage = (): Promise<void> => new Promise((resolve) => {
const clearStorage = (): Promise<void> => 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());
});
}

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

12
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<boolean>(
@ -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;
}

6
src/browser/browserApi.ts

@ -32,7 +32,7 @@ export class BrowserApi {
}
static async tabsQuery(options: any): Promise<any[]> {
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();
});
}

2
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', {

2
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;

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

2
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;

2
src/content/sso.ts

@ -1,4 +1,4 @@
window.addEventListener('message', (event) => {
window.addEventListener('message', event => {
if (event.source !== window)
return;

6
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';

2
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 &&

4
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: [

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

6
src/services/browserPlatformUtils.service.ts

@ -158,7 +158,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
type: type,
dialogId: dialogId,
});
return new Promise<boolean>((resolve) => {
return new Promise<boolean>(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);
});
}

8
src/services/browserStorage.service.ts

@ -8,7 +8,7 @@ export default class BrowserStorageService implements StorageService {
}
async get<T>(key: string): Promise<T> {
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<any> {
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<any> {
return new Promise((resolve) => {
return new Promise(resolve => {
this.chromeStorageApi.remove(key, () => {
resolve();
});

17
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"
}
]
}
}
Loading…
Cancel
Save