diff --git a/src/models/data/cipherData.ts b/src/models/data/cipherData.ts index c1867235..94cc046a 100644 --- a/src/models/data/cipherData.ts +++ b/src/models/data/cipherData.ts @@ -62,16 +62,16 @@ class CipherData { if (response.data.Fields != null) { this.fields = []; - for (const field of response.data.Fields) { + response.data.Fields.forEach((field: any) => { this.fields.push(new FieldData(field)); - } + }); } if (response.attachments != null) { this.attachments = []; - for (const attachment of response.attachments) { + response.attachments.forEach((attachment) => { this.attachments.push(new AttachmentData(attachment)); - } + }); } } } diff --git a/src/models/response/domainsResponse.ts b/src/models/response/domainsResponse.ts index 87b6794c..d6507714 100644 --- a/src/models/response/domainsResponse.ts +++ b/src/models/response/domainsResponse.ts @@ -9,9 +9,9 @@ class DomainsResponse { this.globalEquivalentDomains = []; if (response.GlobalEquivalentDomains) { - for (const domain of response.GlobalEquivalentDomains) { + response.GlobalEquivalentDomains.forEach((domain: any) => { this.globalEquivalentDomains.push(new GlobalDomainResponse(domain)); - } + }); } } } diff --git a/src/models/response/profileResponse.ts b/src/models/response/profileResponse.ts index 16131451..69e4f3e9 100644 --- a/src/models/response/profileResponse.ts +++ b/src/models/response/profileResponse.ts @@ -28,9 +28,9 @@ class ProfileResponse { this.securityStamp = response.SecurityStamp; if (response.Organizations) { - for (const org of response.Organizations) { + response.Organizations.forEach((org: any) => { this.organizations.push(new ProfileOrganizationResponse(org)); - } + }); } } } diff --git a/src/models/response/syncResponse.ts b/src/models/response/syncResponse.ts index 45e9e5e8..4fa2c0b1 100644 --- a/src/models/response/syncResponse.ts +++ b/src/models/response/syncResponse.ts @@ -15,15 +15,15 @@ class SyncResponse { } if (response.Folders) { - for (const folder of response.Folders) { + response.Folders.forEach((folder: any) => { this.folders.push(new FolderResponse(folder)); - } + }); } if (response.Ciphers) { - for (const cipher of response.Ciphers) { + response.Ciphers.forEach((cipher: any) => { this.ciphers.push(new CipherResponse(cipher)); - } + }); } if (response.Domains) { diff --git a/src/services/autofill.service.ts b/src/services/autofill.service.ts index 4140d3e9..f214c23a 100644 --- a/src/services/autofill.service.ts +++ b/src/services/autofill.service.ts @@ -104,7 +104,8 @@ export default class AutofillService { continue; } - for (const pf of passwordFields) { + for (let i = 0; i < passwordFields.length; i++) { + const pf = passwordFields[i]; if (formKey !== pf.form) { continue; } @@ -135,10 +136,10 @@ export default class AutofillService { } let didAutofill = false; - for (const pd of options.pageDetails) { + options.pageDetails.forEach((pd: any) => { // make sure we're still on correct tab if (pd.tab.id !== tab.id || pd.tab.url !== tab.url) { - continue; + return; } const fillScript = this.generateFillScript(pd.details, { @@ -147,7 +148,7 @@ export default class AutofillService { }); if (!fillScript || !fillScript.script || !fillScript.script.length) { - continue; + return; } didAutofill = true; @@ -164,7 +165,7 @@ export default class AutofillService { if (options.cipher.type !== CipherType.Login || totpPromise || (options.fromBackground && this.utilsService.isFirefox()) || options.skipTotp || !options.cipher.login.totp || !this.tokenService.getPremium()) { - continue; + return; } totpPromise = this.totpService.isAutoCopyEnabled().then((enabled) => { @@ -180,7 +181,7 @@ export default class AutofillService { return code; }); - } + }); if (didAutofill) { if (totpPromise != null) { @@ -248,17 +249,17 @@ export default class AutofillService { if (fields && fields.length) { const fieldNames: string[] = []; - for (const f of fields) { + fields.forEach((f: any) => { if (f.name && f.name !== '') { fieldNames.push(f.name.toLowerCase()); } else { fieldNames.push(null); } - } + }); - for (const field of pageDetails.fields) { + pageDetails.fields.forEach((field: any) => { if (filledFields.hasOwnProperty(field.opid) || !field.viewable) { - continue; + return; } const matchingIndex = this.findMatchingFieldIndex(field, fieldNames); @@ -267,7 +268,7 @@ export default class AutofillService { fillScript.script.push(['click_on_opid', field.opid]); fillScript.script.push(['fill_by_opid', field.opid, fields[matchingIndex].value]); } - } + }); } switch (options.cipher.type) { @@ -318,13 +319,13 @@ export default class AutofillService { } const passwordFieldsForForm: AutofillField[] = []; - for (const passField of passwordFields) { + passwordFields.forEach((passField) => { if (formKey === passField.form) { passwordFieldsForForm.push(passField); } - } + }); - for (const passField of passwordFields) { + passwordFields.forEach((passField) => { pf = passField; passwords.push(pf); @@ -340,7 +341,7 @@ export default class AutofillService { usernames.push(username); } } - } + }); } if (passwordFields.length && !passwords.length) { @@ -366,33 +367,33 @@ export default class AutofillService { if (!passwordFields.length && !options.skipUsernameOnlyFill) { // No password fields on this page. Let's try to just fuzzy fill the username. - for (const f of pageDetails.fields) { + pageDetails.fields.forEach((f: any) => { if (f.viewable && (f.type === 'text' || f.type === 'email' || f.type === 'tel') && this.fieldIsFuzzyMatch(f, UsernameFieldNames)) { usernames.push(f); } - } + }); } - for (const u of usernames) { + usernames.forEach((u) => { if (filledFields.hasOwnProperty(u.opid)) { - continue; + return; } filledFields[u.opid] = u; fillScript.script.push(['click_on_opid', u.opid]); fillScript.script.push(['fill_by_opid', u.opid, login.username]); - } + }); - for (const p of passwords) { + passwords.forEach((p) => { if (filledFields.hasOwnProperty(p.opid)) { - continue; + return; } filledFields[p.opid] = p; fillScript.script.push(['click_on_opid', p.opid]); fillScript.script.push(['fill_by_opid', p.opid, login.password]); - } + }); fillScript = this.setFillScriptForFocus(filledFields, fillScript); return fillScript; @@ -407,10 +408,10 @@ export default class AutofillService { const fillFields: { [id: string]: AutofillField; } = {}; - for (const f of pageDetails.fields) { - for (const attr of CardAttributes) { + pageDetails.fields.forEach((f: any) => { + CardAttributes.forEach((attr) => { if (!f.hasOwnProperty(attr) || !f[attr] || !f.viewable) { - continue; + return; } // ref https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill @@ -446,8 +447,8 @@ export default class AutofillService { ['cc-type', 'card-type', 'card-brand', 'cc-brand'])) { fillFields.brand = f; } - } - } + }); + }); const card = options.cipher.card; this.makeScriptAction(fillScript, card, fillFields, filledFields, 'cardholderName'); @@ -481,10 +482,10 @@ export default class AutofillService { const fillFields: { [id: string]: AutofillField; } = {}; - for (const f of pageDetails.fields) { - for (const attr of IdentityAttributes) { + pageDetails.fields.forEach((f: any) => { + IdentityAttributes.forEach((attr) => { if (!f.hasOwnProperty(attr) || !f[attr] || !f.viewable) { - continue; + return; } // ref https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill @@ -544,8 +545,8 @@ export default class AutofillService { ['company', 'company-name', 'organization', 'organization-name'])) { fillFields.company = f; } - } - } + }); + }); const identity = options.cipher.identity; this.makeScriptAction(fillScript, identity, fillFields, filledFields, 'title'); @@ -645,7 +646,8 @@ export default class AutofillService { private isFieldMatch(value: string, options: string[], containsOptions?: string[]): boolean { value = value.trim().toLowerCase().replace(/[^a-zA-Z]+/g, ''); - for (let option of options) { + for (let i = 0; i < options.length; i++) { + let option = options[i]; const checkValueContains = containsOptions == null || containsOptions.indexOf(option) > -1; option = option.replace(/-/g, ''); if (value === option || (checkValueContains && value.indexOf(option) > -1)) { @@ -669,11 +671,11 @@ export default class AutofillService { private loadPasswordFields(pageDetails: AutofillPageDetails, canBeHidden: boolean) { const arr: AutofillField[] = []; - for (const f of pageDetails.fields) { + pageDetails.fields.forEach((f: any) => { if (f.type === 'password' && (canBeHidden || f.viewable)) { arr.push(f); } - } + }); return arr; } @@ -681,7 +683,8 @@ export default class AutofillService { private findUsernameField(pageDetails: AutofillPageDetails, passwordField: AutofillField, canBeHidden: boolean, withoutForm: boolean) { let usernameField: AutofillField = null; - for (const f of pageDetails.fields) { + for (let i = 0; i < pageDetails.fields.length; i++) { + const f = pageDetails.fields[i]; if (f.elementNumber >= passwordField.elementNumber) { break; } @@ -738,7 +741,8 @@ export default class AutofillService { const csvParts = name.split('=', 2); if (csvParts.length === 2) { const csvVals = csvParts[1].split(','); - for (const val of csvVals) { + for (let i = 0; i < csvVals.length; i++) { + const val = csvVals[i]; if (val != null && val.trim().toLowerCase() === fieldVal.toLowerCase()) { return true; } @@ -774,8 +778,8 @@ export default class AutofillService { return false; } - for (const o of options) { - if (value.indexOf(o) > -1) { + for (let i = 0; i < options.length; i++) { + if (value.indexOf(options[i]) > -1) { return true; } } diff --git a/src/services/cipher.service.ts b/src/services/cipher.service.ts index f51af0e7..56c73040 100644 --- a/src/services/cipher.service.ts +++ b/src/services/cipher.service.ts @@ -165,13 +165,13 @@ export default class CipherService { throw new Error('No key.'); } - const promises = []; + const promises: any[] = []; const ciphers = await this.getAll(); - for (const cipher of ciphers) { + ciphers.forEach((cipher) => { promises.push(cipher.decrypt().then((c: any) => { decCiphers.push(c); })); - } + }); await Promise.all(promises); this.decryptedCipherCache = decCiphers; @@ -180,13 +180,13 @@ export default class CipherService { async getAllDecryptedForFolder(folderId: string): Promise { const ciphers = await this.getAllDecrypted(); - const ciphersToReturn = []; + const ciphersToReturn: any[] = []; - for (const cipher of ciphers) { + ciphers.forEach((cipher) => { if (cipher.folderId === folderId) { ciphersToReturn.push(cipher); } - } + }); return ciphersToReturn; } @@ -199,11 +199,11 @@ export default class CipherService { const eqDomainsPromise = domain == null ? Promise.resolve([]) : this.settingsService.getEquivalentDomains().then((eqDomains: any[][]) => { let matches: any[] = []; - for (const eqDomain of eqDomains) { + eqDomains.forEach((eqDomain) => { if (eqDomain.length && eqDomain.indexOf(domain) >= 0) { matches = matches.concat(eqDomain); } - } + }); if (!matches.length) { matches.push(domain); @@ -215,16 +215,16 @@ export default class CipherService { const result = await Promise.all([eqDomainsPromise, this.getAllDecrypted()]); const matchingDomains = result[0]; const ciphers = result[1]; - const ciphersToReturn = []; + const ciphersToReturn: any[] = []; - for (const cipher of ciphers) { + ciphers.forEach((cipher) => { if (domain && cipher.type === CipherType.Login && cipher.login.domain && matchingDomains.indexOf(cipher.login.domain) > -1) { ciphersToReturn.push(cipher); } else if (includeOtherTypes && includeOtherTypes.indexOf(cipher.type) > -1) { ciphersToReturn.push(cipher); } - } + }); return ciphersToReturn; } @@ -259,7 +259,8 @@ export default class CipherService { return; } - for (const cached of this.decryptedCipherCache) { + for (let i = 0; i < this.decryptedCipherCache.length; i++) { + const cached = this.decryptedCipherCache[i]; if (cached.id === id) { cached.localData = ciphersLocalData[id]; break; @@ -345,9 +346,9 @@ export default class CipherService { const c = cipher as CipherData; ciphers[c.id] = c; } else { - for (const c of (cipher as CipherData[])) { + (cipher as CipherData[]).forEach((c) => { ciphers[c.id] = c; - } + }); } await UtilsService.saveObjToStorage(Keys.ciphersPrefix + userId, ciphers); @@ -377,9 +378,9 @@ export default class CipherService { const i = id as string; delete ciphers[id]; } else { - for (const i of (id as string[])) { + (id as string[]).forEach((i) => { delete ciphers[i]; - } + }); } await UtilsService.saveObjToStorage(Keys.ciphersPrefix + userId, ciphers); diff --git a/src/services/crypto.service.ts b/src/services/crypto.service.ts index 4943451b..ea385c70 100644 --- a/src/services/crypto.service.ts +++ b/src/services/crypto.service.ts @@ -74,9 +74,9 @@ export default class CryptoService implements CryptoServiceInterface { setOrgKeys(orgs: ProfileOrganizationResponse[]): Promise<{}> { const orgKeys: any = {}; - for (const org of orgs) { + orgs.forEach((org) => { orgKeys[org.id] = org.key; - } + }); return UtilsService.saveObjToStorage(Keys.encOrgKeys, orgKeys); } diff --git a/src/services/folder.service.ts b/src/services/folder.service.ts index 774532fc..b6c58cf8 100644 --- a/src/services/folder.service.ts +++ b/src/services/folder.service.ts @@ -20,7 +20,7 @@ export default class FolderService { decryptedFolderCache: any[]; constructor(private cryptoService: CryptoService, private userService: UserService, - private i18nService: any, private apiService: ApiService) { + private i18nService: any, private apiService: ApiService) { } clearCache(): void { @@ -73,13 +73,13 @@ export default class FolderService { throw new Error('No key.'); } - const promises = []; + const promises: Array> = []; const folders = await this.getAll(); - for (const folder of folders) { + folders.forEach((folder) => { promises.push(folder.decrypt().then((f: any) => { decFolders.push(f); })); - } + }); await Promise.all(promises); this.decryptedFolderCache = decFolders; @@ -114,9 +114,9 @@ export default class FolderService { const f = folder as FolderData; folders[f.id] = f; } else { - for (const f of (folder as FolderData[])) { + (folder as FolderData[]).forEach((f) => { folders[f.id] = f; - } + }); } await UtilsService.saveObjToStorage(Keys.foldersPrefix + userId, folders); @@ -146,9 +146,9 @@ export default class FolderService { const i = id as string; delete folders[id]; } else { - for (const i of (id as string[])) { + (id as string[]).forEach((i) => { delete folders[i]; - } + }); } await UtilsService.saveObjToStorage(Keys.foldersPrefix + userId, folders); diff --git a/src/services/sync.service.ts b/src/services/sync.service.ts index 93307e73..c84ebcf8 100644 --- a/src/services/sync.service.ts +++ b/src/services/sync.service.ts @@ -23,9 +23,9 @@ export default class SyncService { syncInProgress: boolean = false; constructor(private userService: UserService, private apiService: ApiService, - private settingsService: SettingsService, private folderService: FolderService, - private cipherService: CipherService, private cryptoService: CryptoService, - private logoutCallback: Function) { + private settingsService: SettingsService, private folderService: FolderService, + private cipherService: CipherService, private cryptoService: CryptoService, + private logoutCallback: Function) { } async getLastSync() { @@ -135,17 +135,17 @@ export default class SyncService { private async syncFolders(userId: string, response: FolderResponse[]) { const folders: { [id: string]: FolderData; } = {}; - for (const f of response) { + response.forEach((f) => { folders[f.id] = new FolderData(f, userId); - } + }); return await this.folderService.replace(folders); } private async syncCiphers(userId: string, response: CipherResponse[]) { const ciphers: { [id: string]: CipherData; } = {}; - for (const c of response) { + response.forEach((c) => { ciphers[c.id] = new CipherData(c, userId); - } + }); return await this.cipherService.replace(ciphers); } @@ -156,11 +156,11 @@ export default class SyncService { } if (response != null && response.globalEquivalentDomains != null) { - for (const global of response.globalEquivalentDomains) { + response.globalEquivalentDomains.forEach((global) => { if (global.domains.length > 0) { eqDomains.push(global.domains); } - } + }); } return this.settingsService.setEquivalentDomains(eqDomains); diff --git a/src/services/totp.service.ts b/src/services/totp.service.ts index 58342a91..ae4d4ec5 100644 --- a/src/services/totp.service.ts +++ b/src/services/totp.service.ts @@ -62,13 +62,13 @@ export default class TotpService { private buff2hex(buff: ArrayBuffer): string { const bytes = new Uint8Array(buff); - const hex = []; - for (const b of bytes) { + const hex: string[] = []; + bytes.forEach((b) => { // tslint:disable-next-line hex.push((b >>> 4).toString(16)); // tslint:disable-next-line hex.push((b & 0xF).toString(16)); - } + }); return hex.join(''); } @@ -76,12 +76,12 @@ export default class TotpService { s = s.toUpperCase(); let cleanedInput = ''; - for (const c of s) { - if (b32Chars.indexOf(c) < 0) { + for (let i = 0; i < s.length; i++) { + if (b32Chars.indexOf(s[i]) < 0) { continue; } - cleanedInput += c; + cleanedInput += s[i]; } s = cleanedInput; diff --git a/tslint.json b/tslint.json index e23699d1..c58665a8 100644 --- a/tslint.json +++ b/tslint.json @@ -36,6 +36,7 @@ ], "no-empty": [ true, "allow-empty-catch" ], "object-literal-sort-keys": false, + "prefer-for-of": false, "quotemark": [ true, "single" ], "whitespace": [ true,