Skip to content

Commit d36860c

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[eslint] Enable useful rules
@typescript-eslint/no-inferrable-types Simplifies the code and makes type be more specific. @typescript-eslint/return-await In theory more performant, but also provides better debugging experience. @typescript-eslint/ban-ts-comment Disallow all but ts-expect-error, as else the error may get fixed not remove and later mask unrelated issues Bug: 397260638 Change-Id: I09f268eb9157336635c378fa76546a4196e448e9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6281149 Reviewed-by: Victor Porof <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]> Auto-Submit: Nikolay Vitkov <[email protected]>
1 parent dcf6750 commit d36860c

File tree

346 files changed

+1331
-1314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

346 files changed

+1331
-1314
lines changed

eslint.config.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,30 @@ export default [
502502
// certain TypeScript compilation errors after fixes
503503
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
504504

505+
'@typescript-eslint/no-inferrable-types': 'error',
506+
505507
'@typescript-eslint/consistent-generic-constructors': [
506508
'error',
507509
'constructor',
508510
],
509511

512+
// This is more performant
513+
// And should provide better stack trace when debugging
514+
// see https://v8.dev/blog/fast-async.
515+
'@typescript-eslint/return-await': ['error', 'always'],
516+
517+
'@typescript-eslint/ban-ts-comment': [
518+
'error',
519+
{
520+
// Change after we add some placeholder for old errors
521+
minimumDescriptionLength: 0,
522+
'ts-check': false,
523+
'ts-expect-error': 'allow-with-description',
524+
'ts-ignore': true,
525+
'ts-nocheck': true,
526+
},
527+
],
528+
510529
'rulesdir/no-underscored-properties': 'error',
511530
'rulesdir/inline-type-imports': 'error',
512531

extensions/cxx_debugging/src/CustomFormatters.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ export class CXXValue implements Value, LazyObject {
361361

362362
try {
363363
const formattedValue = await formatter.format(this.wasm, value);
364-
return lazyObjectFromAny(formattedValue, this.objectStore, this.type, this.displayValue, this.memoryAddress)
364+
return await lazyObjectFromAny(
365+
formattedValue, this.objectStore, this.type, this.displayValue, this.memoryAddress)
365366
.asRemoteObject();
366367
} catch {
367368
// Fallthrough
@@ -505,7 +506,7 @@ function lazyObjectFromAny(
505506
}
506507

507508
export class LazyObjectStore {
508-
private nextObjectId: number = 0;
509+
private nextObjectId = 0;
509510
private objects = new Map<string, LazyObject>();
510511

511512
store(lazyObject: LazyObject): string {

extensions/cxx_debugging/src/DWARFSymbols.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class DWARFLanguageExtensionPlugin implements Chrome.DevTools.LanguageExt
201201
// Ensure directory exists
202202
if (parentDirectory.length > 1) {
203203
// TypeScript doesn't know about createPath
204-
// @ts-ignore
204+
// @ts-expect-error
205205
backend.FS.createPath('/', parentDirectory.substring(1), true, true);
206206
}
207207

@@ -216,7 +216,7 @@ export class DWARFLanguageExtensionPlugin implements Chrome.DevTools.LanguageExt
216216
void this.hostInterface.reportResourceLoad(dwoURL, {success: false, errorMessage: (e as Error).message});
217217
// Rethrow any error fetching the content as errno 44 (EEXIST)
218218
// TypeScript doesn't know about the ErrnoError constructor
219-
// @ts-ignore
219+
// @ts-expect-error
220220
throw new backend.FS.ErrnoError(44);
221221
}
222222
};
@@ -557,7 +557,7 @@ export class DWARFLanguageExtensionPlugin implements Chrome.DevTools.LanguageExt
557557
description: '<optimized out>',
558558
};
559559
}
560-
return cxxObject.asRemoteObject();
560+
return await cxxObject.asRemoteObject();
561561
}
562562

563563
async getProperties(objectId: Chrome.DevTools.RemoteObjectId): Promise<Chrome.DevTools.PropertyDescriptor[]> {
@@ -582,7 +582,7 @@ export class DWARFLanguageExtensionPlugin implements Chrome.DevTools.LanguageExt
582582
export async function createPlugin(
583583
hostInterface: HostInterface, resourceLoader: ResourceLoader,
584584
moduleConfigurations: ModuleConfigurations = DEFAULT_MODULE_CONFIGURATIONS,
585-
logPluginApiCalls: boolean = false): Promise<DWARFLanguageExtensionPlugin> {
585+
logPluginApiCalls = false): Promise<DWARFLanguageExtensionPlugin> {
586586
const plugin = new DWARFLanguageExtensionPlugin(moduleConfigurations, resourceLoader, hostInterface);
587587
if (logPluginApiCalls) {
588588
const pluginLoggingProxy = {

extensions/cxx_debugging/src/DevToolsPluginHost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class WorkerPlugin implements Chrome.DevTools.LanguageExtensionPlugin, As
3535

3636
static async create(
3737
moduleConfigurations: ModuleConfigurations = DEFAULT_MODULE_CONFIGURATIONS,
38-
logPluginApiCalls: boolean = false): Promise<WorkerPlugin> {
38+
logPluginApiCalls = false): Promise<WorkerPlugin> {
3939
const plugin = new WorkerPlugin();
4040
await plugin.rpc.sendMessage('hello', moduleConfigurations, logPluginApiCalls);
4141
return plugin;

extensions/cxx_debugging/tests/RealBackend.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function waitFor<ReturnT>(
3636
reject(e);
3737
}
3838
};
39-
return new Promise<ReturnT>((resolve, reject) => callback(resolve, reject));
39+
return await new Promise<ReturnT>((resolve, reject) => callback(resolve, reject));
4040
}
4141

4242
export interface BreakLocation {
@@ -218,7 +218,7 @@ export class Debugger {
218218
}
219219

220220
async waitForScript(url: string, timeout = 0): Promise<string> {
221-
return waitFor(() => this.scripts.get(url)?.scriptId, timeout);
221+
return await waitFor(() => this.scripts.get(url)?.scriptId, timeout);
222222
}
223223

224224
async waitForPause(timeout = 0): Promise<PauseLocation> {
@@ -227,10 +227,10 @@ export class Debugger {
227227
}
228228
const waitPromise = new Promise<PauseLocation>(resolve => this.waitForPauseQueue.push({resolve}));
229229
if (timeout === 0) {
230-
return waitPromise;
230+
return await waitPromise;
231231
}
232232
const timeoutPromise = new Promise<PauseLocation>((_, r) => setTimeout(() => r(new Error('Timeout')), timeout));
233-
return Promise.race([waitPromise, timeoutPromise]);
233+
return await Promise.race([waitPromise, timeoutPromise]);
234234
}
235235

236236
async evaluateFunction<T>(expression: string): Promise<T> {
@@ -285,7 +285,7 @@ export class Debugger {
285285
async evaluateOnCallFrame<T>(
286286
expectValue: boolean, convert: (result: Protocol.Runtime.RemoteObject) => T, expression: string,
287287
{callFrameId}: Protocol.Debugger.CallFrame): Promise<T> {
288-
return this.evaluateOnCallFrameId(expectValue, convert, expression, callFrameId);
288+
return await this.evaluateOnCallFrameId(expectValue, convert, expression, callFrameId);
289289
}
290290

291291
async evaluateOnCallFrameId<T>(
@@ -301,7 +301,7 @@ export class Debugger {
301301
}
302302

303303
async waitForFunction<T>(expression: string, timeout = 0): Promise<T> {
304-
return waitFor(() => this.evaluateFunction<T>(expression), timeout);
304+
return await waitFor(() => this.evaluateFunction<T>(expression), timeout);
305305
}
306306

307307
page(script: string): WasmBackendPage {
@@ -465,7 +465,7 @@ class WasmBackendPage {
465465

466466
async go(timeout = 0): Promise<number> {
467467
await this.debug.waitForFunction('window.isReady && window.isReady()', timeout);
468-
return this.debug.evaluateFunction<number>('window.go()');
468+
return await this.debug.evaluateFunction<number>('window.go()');
469469
}
470470
}
471471

extensions/cxx_debugging/tests/TestUtils.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function makeURL(path: string): string {
3535
}
3636

3737
export async function createWorkerPlugin(debug?: Debugger): Promise<Chrome.DevTools.LanguageExtensionPlugin> {
38-
return WorkerPlugin.create([], true).then(p => {
38+
return await WorkerPlugin.create([], true).then(p => {
3939
if (debug) {
4040
p.getWasmLinearMemory = debug.getWasmLinearMemory.bind(debug);
4141
p.getWasmLocal = debug.getWasmLocal.bind(debug);
@@ -116,52 +116,52 @@ export class TestValue implements Value {
116116
size: number;
117117
typeNames: string[];
118118

119-
static fromInt8(value: number, typeName: string = 'int8_t'): TestValue {
119+
static fromInt8(value: number, typeName = 'int8_t'): TestValue {
120120
const content = new DataView(new ArrayBuffer(1));
121121
content.setInt8(0, value);
122122
return new TestValue(content, typeName);
123123
}
124-
static fromInt16(value: number, typeName: string = 'int16_t'): TestValue {
124+
static fromInt16(value: number, typeName = 'int16_t'): TestValue {
125125
const content = new DataView(new ArrayBuffer(2));
126126
content.setInt16(0, value, true);
127127
return new TestValue(content, typeName);
128128
}
129-
static fromInt32(value: number, typeName: string = 'int32_t'): TestValue {
129+
static fromInt32(value: number, typeName = 'int32_t'): TestValue {
130130
const content = new DataView(new ArrayBuffer(4));
131131
content.setInt32(0, value, true);
132132
return new TestValue(content, typeName);
133133
}
134-
static fromInt64(value: bigint, typeName: string = 'int64_t'): TestValue {
134+
static fromInt64(value: bigint, typeName = 'int64_t'): TestValue {
135135
const content = new DataView(new ArrayBuffer(8));
136136
content.setBigInt64(0, value, true);
137137
return new TestValue(content, typeName);
138138
}
139-
static fromUint8(value: number, typeName: string = 'uint8_t'): TestValue {
139+
static fromUint8(value: number, typeName = 'uint8_t'): TestValue {
140140
const content = new DataView(new ArrayBuffer(1));
141141
content.setUint8(0, value);
142142
return new TestValue(content, typeName);
143143
}
144-
static fromUint16(value: number, typeName: string = 'uint16_t'): TestValue {
144+
static fromUint16(value: number, typeName = 'uint16_t'): TestValue {
145145
const content = new DataView(new ArrayBuffer(2));
146146
content.setUint16(0, value, true);
147147
return new TestValue(content, typeName);
148148
}
149-
static fromUint32(value: number, typeName: string = 'uint32_t'): TestValue {
149+
static fromUint32(value: number, typeName = 'uint32_t'): TestValue {
150150
const content = new DataView(new ArrayBuffer(4));
151151
content.setUint32(0, value, true);
152152
return new TestValue(content, typeName);
153153
}
154-
static fromUint64(value: bigint, typeName: string = 'uint64_t'): TestValue {
154+
static fromUint64(value: bigint, typeName = 'uint64_t'): TestValue {
155155
const content = new DataView(new ArrayBuffer(8));
156156
content.setBigUint64(0, value, true);
157157
return new TestValue(content, typeName);
158158
}
159-
static fromFloat32(value: number, typeName: string = 'float'): TestValue {
159+
static fromFloat32(value: number, typeName = 'float'): TestValue {
160160
const content = new DataView(new ArrayBuffer(4));
161161
content.setFloat32(0, value, true);
162162
return new TestValue(content, typeName);
163163
}
164-
static fromFloat64(value: number, typeName: string = 'double'): TestValue {
164+
static fromFloat64(value: number, typeName = 'double'): TestValue {
165165
const content = new DataView(new ArrayBuffer(8));
166166
content.setFloat64(0, value, true);
167167
return new TestValue(content, typeName);

front_end/core/common/Color.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function normalizeHue(hue: number): number {
6565
// and returns the canonicalized `degree`.
6666
function parseAngle(angleText: string): number|null {
6767
const angle = angleText.replace(/(deg|g?rad|turn)$/, '');
68-
// @ts-ignore: isNaN can accept strings
68+
// @ts-expect-error: isNaN can accept strings
6969
if (isNaN(angle) || angleText.match(/\s+(deg|g?rad|turn)/)) {
7070
return null;
7171
}
@@ -337,7 +337,7 @@ function parseAlpha(value: string|undefined): number|null {
337337
* - 20% in range [0, 1] is 0.5
338338
*/
339339
function parsePercentOrNumber(value: string, range: [number, number] = [0, 1]): number|null {
340-
// @ts-ignore: isNaN can accept strings
340+
// @ts-expect-error: isNaN can accept strings
341341
if (isNaN(value.replace('%', ''))) {
342342
return null;
343343
}
@@ -366,7 +366,7 @@ function parseRgbNumeric(value: string): number|null {
366366

367367
export function parseHueNumeric(value: string): number|null {
368368
const angle = value.replace(/(deg|g?rad|turn)$/, '');
369-
// @ts-ignore: isNaN can accept strings
369+
// @ts-expect-error: isNaN can accept strings
370370
if (isNaN(angle) || value.match(/\s+(deg|g?rad|turn)/)) {
371371
return null;
372372
}
@@ -385,7 +385,7 @@ export function parseHueNumeric(value: string): number|null {
385385
}
386386

387387
function parseSatLightNumeric(value: string): number|null {
388-
// @ts-ignore: isNaN can accept strings
388+
// @ts-expect-error: isNaN can accept strings
389389
if (value.indexOf('%') !== value.length - 1 || isNaN(value.replace('%', ''))) {
390390
return null;
391391
}
@@ -762,7 +762,7 @@ export class Lab implements Color {
762762

763763
#getRGBArray(withAlpha: true): Color4DOr3D;
764764
#getRGBArray(withAlpha: false): Color3D;
765-
#getRGBArray(withAlpha: boolean = true): Color3D|Color4DOr3D {
765+
#getRGBArray(withAlpha = true): Color3D|Color4DOr3D {
766766
const params = ColorConverter.xyzd50ToSrgb(...this.#toXyzd50());
767767
if (withAlpha) {
768768
return [...params, this.alpha ?? undefined];
@@ -899,7 +899,7 @@ export class LCH implements Color {
899899

900900
#getRGBArray(withAlpha: true): Color4DOr3D;
901901
#getRGBArray(withAlpha: false): Color3D;
902-
#getRGBArray(withAlpha: boolean = true): Color4DOr3D|Color3D {
902+
#getRGBArray(withAlpha = true): Color4DOr3D|Color3D {
903903
const params = ColorConverter.xyzd50ToSrgb(...this.#toXyzd50());
904904
if (withAlpha) {
905905
return [...params, this.alpha ?? undefined];
@@ -1039,7 +1039,7 @@ export class Oklab implements Color {
10391039

10401040
#getRGBArray(withAlpha: true): Color4DOr3D;
10411041
#getRGBArray(withAlpha: false): Color3D;
1042-
#getRGBArray(withAlpha: boolean = true): Color4DOr3D|Color3D {
1042+
#getRGBArray(withAlpha = true): Color4DOr3D|Color3D {
10431043
const params = ColorConverter.xyzd50ToSrgb(...this.#toXyzd50());
10441044
if (withAlpha) {
10451045
return [...params, this.alpha ?? undefined];
@@ -1176,7 +1176,7 @@ export class Oklch implements Color {
11761176

11771177
#getRGBArray(withAlpha: true): Color4DOr3D;
11781178
#getRGBArray(withAlpha: false): Color3D;
1179-
#getRGBArray(withAlpha: boolean = true): Color4DOr3D|Color3D {
1179+
#getRGBArray(withAlpha = true): Color4DOr3D|Color3D {
11801180
const params = ColorConverter.xyzd50ToSrgb(...this.#toXyzd50());
11811181
if (withAlpha) {
11821182
return [...params, this.alpha ?? undefined];
@@ -1336,7 +1336,7 @@ export class ColorFunction implements Color {
13361336

13371337
#getRGBArray(withAlpha: true): Color4DOr3D;
13381338
#getRGBArray(withAlpha: false): Color3D;
1339-
#getRGBArray(withAlpha: boolean = true): Color4DOr3D|Color3D {
1339+
#getRGBArray(withAlpha = true): Color4DOr3D|Color3D {
13401340
// With color(), out-of-gamut inputs are to be used for intermediate computations
13411341
const [p0, p1, p2] = this.#rawParams;
13421342
const params: Color3D =
@@ -1531,7 +1531,7 @@ export class HSL implements Color {
15311531

15321532
#getRGBArray(withAlpha: true): Color4DOr3D;
15331533
#getRGBArray(withAlpha: false): Color3D;
1534-
#getRGBArray(withAlpha: boolean = true): Color4DOr3D|Color3D {
1534+
#getRGBArray(withAlpha = true): Color4DOr3D|Color3D {
15351535
const rgb = hsl2rgb([this.h, this.s, this.l, 0]);
15361536
if (withAlpha) {
15371537
return [rgb[0], rgb[1], rgb[2], this.alpha ?? undefined];
@@ -1682,7 +1682,7 @@ export class HWB implements Color {
16821682

16831683
#getRGBArray(withAlpha: true): Color4DOr3D;
16841684
#getRGBArray(withAlpha: false): Color3D;
1685-
#getRGBArray(withAlpha: boolean = true): Color4DOr3D|Color3D {
1685+
#getRGBArray(withAlpha = true): Color4DOr3D|Color3D {
16861686
const rgb = hwb2rgb([this.h, this.w, this.b, 0]);
16871687
if (withAlpha) {
16881688
return [rgb[0], rgb[1], rgb[2], this.alpha ?? undefined];
@@ -2200,9 +2200,9 @@ export class Legacy implements Color {
22002200
}
22012201
}
22022202

2203-
export const Regex: RegExp =
2203+
export const Regex =
22042204
/((?:rgba?|hsla?|hwba?|lab|lch|oklab|oklch|color)\([^)]+\)|#[0-9a-fA-F]{8}|#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3,4}|\b[a-zA-Z]+\b(?!-))/g;
2205-
export const ColorMixRegex: RegExp = /color-mix\(.*,\s*(?<firstColor>.+)\s*,\s*(?<secondColor>.+)\s*\)/g;
2205+
export const ColorMixRegex = /color-mix\(.*,\s*(?<firstColor>.+)\s*,\s*(?<secondColor>.+)\s*\)/g;
22062206

22072207
const COLOR_TO_RGBA_ENTRIES: Array<readonly[string, number[]]> = [
22082208
['aliceblue', [240, 248, 255]],

front_end/core/common/ColorConverter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class TransferFunction {
6666
e: number;
6767
f: number;
6868

69-
constructor(g: number, a: number, b: number = 0, c: number = 0, d: number = 0, e: number = 0, f: number = 0) {
69+
constructor(g: number, a: number, b = 0, c = 0, d = 0, e = 0, f = 0) {
7070
this.g = g;
7171
this.a = a;
7272
this.b = b;

front_end/core/common/ResolverBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export abstract class ResolverBase<Id, T> {
2828
async waitFor(id: Id): Promise<T> {
2929
const obj = this.getForId(id);
3030
if (!obj) {
31-
return this.getOrCreatePromise(id);
31+
return await this.getOrCreatePromise(id);
3232
}
3333
return obj;
3434
}

front_end/core/common/Revealer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export function registerRevealer<T>(registration: RevealerRegistration<T>): void
164164
* @param revealable the object to reveal.
165165
* @param omitFocus whether to omit focusing on the presentation of `revealable` afterwards.
166166
*/
167-
export async function reveal(revealable: unknown, omitFocus: boolean = false): Promise<void> {
167+
export async function reveal(revealable: unknown, omitFocus = false): Promise<void> {
168168
await RevealerRegistry.instance().reveal(revealable, omitFocus);
169169
}
170170

0 commit comments

Comments
 (0)