Skip to content

Commit bcd8cd9

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[eslint] Allow !! instead of Boolean
This provides better type inference when using TypeScript, specifically the .filter methods Also allowed by Google style guide. https://google.github.io/styleguide/tsguide.html#type-coercion Change-Id: I79745812f57670a0057145609b7949b2a12d9fbe Bug:397260638 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6403239 Commit-Queue: Nikolay Vitkov <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]>
1 parent f2a6d0e commit bcd8cd9

File tree

17 files changed

+21
-24
lines changed

17 files changed

+21
-24
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export default [
205205
radix: 'error',
206206
'valid-typeof': 'error',
207207
'no-return-assign': ['error', 'always'],
208-
'no-implicit-coercion': 'error',
208+
'no-implicit-coercion': ['error', { allow: ['!!'] }],
209209

210210
'no-array-constructor': 'error',
211211

front_end/core/sdk/NetworkRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ export class NetworkRequest extends Common.ObjectWrapper.ObjectWrapper<EventType
11971197
...this.responseCookies,
11981198
...this.blockedRequestCookies().map(blockedRequestCookie => blockedRequestCookie.cookie),
11991199
...this.blockedResponseCookies().map(blockedResponseCookie => blockedResponseCookie.cookie),
1200-
].filter(v => Boolean(v)) as Cookie[];
1200+
].filter(v => !!v);
12011201
}
12021202

12031203
get serverTimings(): ServerTiming[]|null {

front_end/models/ai_assistance/AiHistoryStorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class AiHistoryStorage {
199199
}
200200
return undefined;
201201
})
202-
.filter(item => Boolean(item));
202+
.filter(item => !!item);
203203
this.#historySetting.set(
204204
history.filter(entry => entry.id !== id),
205205
);

front_end/models/ai_assistance/data_formatters/NetworkRequestFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Request initiator chain:\n${this.formatRequestInitiatorChain()}`;
146146
},
147147
];
148148

149-
return labels.filter(label => Boolean(label.value)).map(label => `${label.label}: ${label.value}`).join('\n');
149+
return labels.filter(label => !!label.value).map(label => `${label.label}: ${label.value}`).join('\n');
150150
}
151151

152152
#formatRequestInitiated(

front_end/models/bindings/DebuggerWorkspaceBinding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ class StackTraceTopFrameLocation extends LiveLocationWithPool {
628628
const location = new StackTraceTopFrameLocation(updateDelegate, locationPool);
629629
const locationsPromises = rawLocations.map(
630630
rawLocation => binding.createLiveLocation(rawLocation, location.scheduleUpdate.bind(location), locationPool));
631-
location.#locations = ((await Promise.all(locationsPromises)).filter(l => Boolean(l)) as Location[]);
631+
location.#locations = ((await Promise.all(locationsPromises)).filter(l => !!l));
632632
await location.updateLocation();
633633
return location;
634634
}

front_end/models/bindings/NetworkProject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,6 @@ export class NetworkProject {
178178
return [];
179179
}
180180
const frames = Array.from(attribution.keys()).map(frameId => resourceTreeModel.frameForId(frameId));
181-
return frames.filter(frame => Boolean(frame)) as SDK.ResourceTreeModel.ResourceTreeFrame[];
181+
return frames.filter(frame => !!frame);
182182
}
183183
}

front_end/models/live-metrics/LiveMetrics.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class LiveMetrics extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
234234
this.#lcpValue?.nodeRef,
235235
...this.#interactions.values().map(i => i.nodeRef),
236236
...this.#layoutShifts.flatMap(shift => shift.affectedNodeRefs),
237-
].filter((nodeRef): nodeRef is NodeRef => Boolean(nodeRef));
237+
].filter(nodeRef => !!nodeRef);
238238

239239
const idsToRefresh = new Set(toRefresh.map(nodeRef => nodeRef.node.backendNodeId()));
240240
const nodes = await domModel.pushNodesByBackendIdsToFrontend(idsToRefresh);
@@ -351,8 +351,7 @@ export class LiveMetrics extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
351351
return this.#resolveNodeRef(nodeIndex, executionContextId);
352352
});
353353

354-
const affectedNodes =
355-
(await Promise.all(nodePromises)).filter((nodeRef): nodeRef is NodeRef => Boolean(nodeRef));
354+
const affectedNodes = (await Promise.all(nodePromises)).filter(nodeRef => !!nodeRef);
356355

357356
const layoutShift: LayoutShift = {
358357
score: webVitalsEvent.score,

front_end/models/persistence/Automapping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export class Automapping {
344344
this.sourceCodeToMetadataMap.set(sourceCode, await sourceCode.requestMetadata());
345345
}));
346346

347-
const activeFiles = similarFiles.filter(file => Boolean(this.activeFoldersIndex.closestParentFolder(file.url())));
347+
const activeFiles = similarFiles.filter(file => !!this.activeFoldersIndex.closestParentFolder(file.url()));
348348
const networkMetadata = this.sourceCodeToMetadataMap.get(networkSourceCode);
349349
if (!networkMetadata || (!networkMetadata.modificationTime && typeof networkMetadata.contentSize !== 'number')) {
350350
// If networkSourceCode does not have metadata, try to match against active folders.

front_end/models/persistence/IsolatedFileSystemManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class IsolatedFileSystemManager extends Common.ObjectWrapper.ObjectWrappe
150150
}
151151

152152
function onFileSystemsAdded(fileSystems: Array<IsolatedFileSystem|null>): void {
153-
resolve(fileSystems.filter(fs => Boolean(fs)) as IsolatedFileSystem[]);
153+
resolve(fileSystems.filter(fs => !!fs));
154154
}
155155
}
156156

front_end/panels/console/ConsoleViewMessage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ describeWithMockConnection('ConsoleViewMessage', () => {
255255
}
256256

257257
async function createConsoleMessageWithIgnoreListing(
258-
ignoreListFn: (url: string) => Boolean, withBuiltinFrames?: boolean): Promise<HTMLElement> {
258+
ignoreListFn: (url: string) => boolean, withBuiltinFrames?: boolean): Promise<HTMLElement> {
259259
const target = createTarget();
260260
const runtimeModel = target.model(SDK.RuntimeModel.RuntimeModel);
261261
const stackTrace = createStackTrace([

0 commit comments

Comments
 (0)