Skip to content

Commit 84495ce

Browse files
authored
Merge pull request microsoft#182635 from Juneezee/refactor/includes
refactor(userDataSync): replace `indexOf` with `includes`
2 parents 4847f32 + 9546e47 commit 84495ce

File tree

9 files changed

+21
-22
lines changed

9 files changed

+21
-22
lines changed

src/vs/platform/userDataSync/common/extensionsMerge.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ export function merge(localExtensions: ILocalSyncExtension[], remoteExtensions:
254254
function compare(from: Map<string, ISyncExtension> | null, to: Map<string, ISyncExtension>, ignoredExtensions: Set<string>, checkVersionProperty: boolean): { added: Set<string>; removed: Set<string>; updated: Set<string> } {
255255
const fromKeys = from ? [...from.keys()].filter(key => !ignoredExtensions.has(key)) : [];
256256
const toKeys = [...to.keys()].filter(key => !ignoredExtensions.has(key));
257-
const added = toKeys.filter(key => fromKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
258-
const removed = fromKeys.filter(key => toKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
257+
const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
258+
const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
259259
const updated: Set<string> = new Set<string>();
260260

261261
for (const key of fromKeys) {
@@ -365,8 +365,8 @@ function mergeExtensionState(localExtension: ISyncExtension, remoteExtension: IS
365365
function compareExtensionState(from: IStringDictionary<any>, to: IStringDictionary<any>): { added: Set<string>; removed: Set<string>; updated: Set<string> } {
366366
const fromKeys = Object.keys(from);
367367
const toKeys = Object.keys(to);
368-
const added = toKeys.filter(key => fromKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
369-
const removed = fromKeys.filter(key => toKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
368+
const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
369+
const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
370370
const updated: Set<string> = new Set<string>();
371371

372372
for (const key of fromKeys) {

src/vs/platform/userDataSync/common/globalStateMerge.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ export function merge(localStorage: IStringDictionary<IStorageValue>, remoteStor
123123
function compare(from: IStringDictionary<any>, to: IStringDictionary<any>): { added: Set<string>; removed: Set<string>; updated: Set<string> } {
124124
const fromKeys = Object.keys(from);
125125
const toKeys = Object.keys(to);
126-
const added = toKeys.filter(key => fromKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
127-
const removed = fromKeys.filter(key => toKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
126+
const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
127+
const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
128128
const updated: Set<string> = new Set<string>();
129129

130130
for (const key of fromKeys) {
@@ -140,4 +140,3 @@ function compare(from: IStringDictionary<any>, to: IStringDictionary<any>): { ad
140140

141141
return { added, removed, updated };
142142
}
143-

src/vs/platform/userDataSync/common/ignoredExtensions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class IgnoredExtensionsManagementService implements IIgnoredExtensionsMan
7878
}
7979
}
8080
}
81-
return distinct([...defaultIgnoredExtensions, ...added,].filter(setting => removed.indexOf(setting) === -1));
81+
return distinct([...defaultIgnoredExtensions, ...added,].filter(setting => !removed.includes(setting)));
8282
}
8383

8484
private getConfiguredIgnoredExtensions(): ReadonlyArray<string> {

src/vs/platform/userDataSync/common/keybindingsMerge.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ function byCommand(keybindings: IUserFriendlyKeybinding[]): Map<string, IUserFri
255255
function compareByKeybinding(from: Map<string, IUserFriendlyKeybinding[]>, to: Map<string, IUserFriendlyKeybinding[]>): ICompareResult {
256256
const fromKeys = [...from.keys()];
257257
const toKeys = [...to.keys()];
258-
const added = toKeys.filter(key => fromKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
259-
const removed = fromKeys.filter(key => toKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
258+
const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
259+
const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
260260
const updated: Set<string> = new Set<string>();
261261

262262
for (const key of fromKeys) {
@@ -276,8 +276,8 @@ function compareByKeybinding(from: Map<string, IUserFriendlyKeybinding[]>, to: M
276276
function compareByCommand(from: Map<string, IUserFriendlyKeybinding[]>, to: Map<string, IUserFriendlyKeybinding[]>, normalizedKeys: IStringDictionary<string>): ICompareResult {
277277
const fromKeys = [...from.keys()];
278278
const toKeys = [...to.keys()];
279-
const added = toKeys.filter(key => fromKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
280-
const removed = fromKeys.filter(key => toKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
279+
const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
280+
const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
281281
const updated: Set<string> = new Set<string>();
282282

283283
for (const key of fromKeys) {

src/vs/platform/userDataSync/common/settingsMerge.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function getIgnoredSettings(defaultIgnoredSettings: string[], configurati
3737
}
3838
}
3939
}
40-
return distinct([...defaultIgnoredSettings, ...added,].filter(setting => removed.indexOf(setting) === -1));
40+
return distinct([...defaultIgnoredSettings, ...added,].filter(setting => !removed.includes(setting)));
4141
}
4242

4343
function getIgnoredSettingsFromConfig(configurationService: IConfigurationService): ReadonlyArray<string> {
@@ -298,8 +298,8 @@ export function isEmpty(content: string): boolean {
298298
function compare(from: IStringDictionary<any> | null, to: IStringDictionary<any>, ignored: Set<string>): { added: Set<string>; removed: Set<string>; updated: Set<string> } {
299299
const fromKeys = from ? Object.keys(from).filter(key => !ignored.has(key)) : [];
300300
const toKeys = Object.keys(to).filter(key => !ignored.has(key));
301-
const added = toKeys.filter(key => fromKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
302-
const removed = fromKeys.filter(key => toKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
301+
const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
302+
const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
303303
const updated: Set<string> = new Set<string>();
304304

305305
if (from) {

src/vs/platform/userDataSync/common/snippetsMerge.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ export function merge(local: IStringDictionary<string>, remote: IStringDictionar
153153
function compare(from: IStringDictionary<string> | null, to: IStringDictionary<string> | null): { added: Set<string>; removed: Set<string>; updated: Set<string> } {
154154
const fromKeys = from ? Object.keys(from) : [];
155155
const toKeys = to ? Object.keys(to) : [];
156-
const added = toKeys.filter(key => fromKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
157-
const removed = fromKeys.filter(key => toKeys.indexOf(key) === -1).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
156+
const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
157+
const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
158158
const updated: Set<string> = new Set<string>();
159159

160160
for (const key of fromKeys) {

src/vs/platform/userDataSync/common/userDataProfilesManifestMerge.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ function compare(from: IUserDataProfileInfo[] | null, to: IUserDataProfileInfo[]
113113
to = to.filter(({ id }) => !ignoredProfiles.includes(id));
114114
const fromKeys = from.map(({ id }) => id);
115115
const toKeys = to.map(({ id }) => id);
116-
const added = toKeys.filter(key => fromKeys.indexOf(key) === -1);
117-
const removed = fromKeys.filter(key => toKeys.indexOf(key) === -1);
116+
const added = toKeys.filter(key => !fromKeys.includes(key));
117+
const removed = fromKeys.filter(key => !toKeys.includes(key));
118118
const updated: string[] = [];
119119

120120
for (const { id, name, shortName } of from) {

src/vs/platform/userDataSync/common/userDataSync.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export function registerConfiguration(): IDisposable {
9595
const registerIgnoredSettingsSchema = () => {
9696
const disallowedIgnoredSettings = getDisallowedIgnoredSettings();
9797
const defaultIgnoredSettings = getDefaultIgnoredSettings().filter(s => s !== CONFIGURATION_SYNC_STORE_KEY);
98-
const settings = Object.keys(allSettings.properties).filter(setting => defaultIgnoredSettings.indexOf(setting) === -1);
99-
const ignoredSettings = defaultIgnoredSettings.filter(setting => disallowedIgnoredSettings.indexOf(setting) === -1);
98+
const settings = Object.keys(allSettings.properties).filter(setting => !defaultIgnoredSettings.includes(setting));
99+
const ignoredSettings = defaultIgnoredSettings.filter(setting => !disallowedIgnoredSettings.includes(setting));
100100
const ignoredSettingsSchema: IJSONSchema = {
101101
items: {
102102
type: 'string',

src/vs/platform/userDataSync/common/userDataSyncStoreService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ export class UserDataSyncStoreClient extends Disposable {
528528

529529
const operationId = context.res.headers[HEADER_OPERATION_ID];
530530
const requestInfo = { url, status: context.res.statusCode, 'execution-id': options.headers[HEADER_EXECUTION_ID], 'operation-id': operationId };
531-
const isSuccess = isSuccessContext(context) || (context.res.statusCode && successCodes.indexOf(context.res.statusCode) !== -1);
531+
const isSuccess = isSuccessContext(context) || (context.res.statusCode && successCodes.includes(context.res.statusCode));
532532
let failureMessage = '';
533533
if (isSuccess) {
534534
this.logService.trace('Request succeeded', requestInfo);

0 commit comments

Comments
 (0)