Skip to content

Commit 84b0fcc

Browse files
bmeurerDevtools-frontend LUCI CQ
authored andcommitted
[eslint] Replace prefer-readonly-keyword with @typescript-eslint/array-type.
We had our own homegrown ESLint rule that was trying to enforce some consistency around `ReadonlyArray<T>` vs. `readonly T[]`, but that was fairly limited and still allowed for `Array<T>` vs `T[]` with no shared discipline. We now use the `@typescript-eslint/array-type` rule instead and enforce that for simple types the `T[]` (and `readonly T[]`) syntax is used, while for complex types the `Array<A & B>` (and `ReadonlyArray<A & B>`) syntax is used. Bug: none Change-Id: I8933869f98577d4afc4141c5736fccb2159924a6 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6257990 Commit-Queue: Benedikt Meurer <[email protected]> Auto-Submit: Benedikt Meurer <[email protected]> Reviewed-by: Nikolay Vitkov <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent 19ef182 commit 84b0fcc

File tree

279 files changed

+717
-823
lines changed

Some content is hidden

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

279 files changed

+717
-823
lines changed

eslint.config.mjs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import jsdocPlugin from 'eslint-plugin-jsdoc';
1212
import mochaPlugin from 'eslint-plugin-mocha';
1313
import rulesdirPlugin from 'eslint-plugin-rulesdir';
1414
import globals from 'globals';
15-
import { join } from 'path';
15+
import {join} from 'path';
1616

1717
rulesdirPlugin.RULES_DIR = join(
18-
import.meta.dirname,
19-
'scripts',
20-
'eslint_rules',
21-
'lib',
18+
import.meta.dirname,
19+
'scripts',
20+
'eslint_rules',
21+
'lib',
2222
);
2323

2424
/**
@@ -302,15 +302,21 @@ export default [
302302
parserOptions: {
303303
allowAutomaticSingleRunInference: true,
304304
project: join(
305-
import.meta.dirname,
306-
'config',
307-
'typescript',
308-
'tsconfig.eslint.json',
309-
),
305+
import.meta.dirname,
306+
'config',
307+
'typescript',
308+
'tsconfig.eslint.json',
309+
),
310310
},
311311
},
312312

313313
rules: {
314+
'@typescript-eslint/array-type': [
315+
'error',
316+
{
317+
default: 'array-simple',
318+
},
319+
],
314320
'@typescript-eslint/no-explicit-any': [
315321
'error',
316322
{
@@ -487,20 +493,19 @@ export default [
487493
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
488494

489495
'rulesdir/no-underscored-properties': 'error',
490-
'rulesdir/prefer-readonly-keyword': 'error',
491496
'rulesdir/inline-type-imports': 'error',
492497

493498
'rulesdir/enforce-default-import-name': [
494499
'error',
495500
{
496501
// Enforce that any import of models/trace/trace.js names the import Trace.
497502
modulePath: join(
498-
import.meta.dirname,
499-
'front_end',
500-
'models',
501-
'trace',
502-
'trace.js',
503-
),
503+
import.meta.dirname,
504+
'front_end',
505+
'models',
506+
'trace',
507+
'trace.js',
508+
),
504509
importName: 'Trace',
505510
},
506511
],

extensions/cxx_debugging/src/CustomFormatters.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class CXXValue implements Value, LazyObject {
325325
this.typeMap, data);
326326
}
327327

328-
async getProperties(): Promise<{name: string, property: LazyObject}[]> {
328+
async getProperties(): Promise<Array<{name: string, property: LazyObject}>> {
329329
const properties = [];
330330
if (this.type.arraySize > 0) {
331331
for (let index = 0; index < this.type.arraySize; ++index) {
@@ -461,7 +461,7 @@ export class CXXValue implements Value, LazyObject {
461461
}
462462

463463
export interface LazyObject {
464-
getProperties(): Promise<{name: string, property: LazyObject}[]>;
464+
getProperties(): Promise<Array<{name: string, property: LazyObject}>>;
465465
asRemoteObject(): Promise<Chrome.DevTools.RemoteObject|Chrome.DevTools.ForeignObject>;
466466
}
467467

@@ -543,7 +543,7 @@ export class PrimitiveLazyObject<T> implements LazyObject {
543543
this.linearMemorySize = linearMemorySize;
544544
}
545545

546-
async getProperties(): Promise<{name: string, property: LazyObject}[]> {
546+
async getProperties(): Promise<Array<{name: string, property: LazyObject}>> {
547547
return [];
548548
}
549549

@@ -568,7 +568,7 @@ export class LocalLazyObject implements LazyObject {
568568
this.linearMemoryAddress = linearMemoryAddress;
569569
}
570570

571-
async getProperties(): Promise<{name: string, property: LazyObject}[]> {
571+
async getProperties(): Promise<Array<{name: string, property: LazyObject}>> {
572572
return Object.entries(this.value).map(([name, value]) => {
573573
const property = lazyObjectFromAny(value, this.objectStore);
574574
return {name, property};
@@ -592,8 +592,8 @@ export class LocalLazyObject implements LazyObject {
592592
export type FormatterResult = number|string|boolean|bigint|undefined|CXXValue|object|(() => LazyObject);
593593
export type FormatterCallback = (wasm: WasmInterface, value: Value) => FormatterResult;
594594
export interface Formatter {
595-
types: Array<string>|((t: TypeInfo) => boolean);
596-
imports?: Array<FormatterCallback>;
595+
types: string[]|((t: TypeInfo) => boolean);
596+
imports?: FormatterCallback[];
597597
format: FormatterCallback;
598598
}
599599

extensions/cxx_debugging/src/Formatters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ CustomFormatters.addFormatter({types: ['__int128'], format: formatInt128});
269269

270270
export function formatExternRef(wasm: WasmInterface, value: Value): () => LazyObject {
271271
const obj = {
272-
async getProperties(): Promise<{name: string, property: LazyObject}[]> {
272+
async getProperties(): Promise<Array<{name: string, property: LazyObject}>> {
273273
return [];
274274
},
275275
async asRemoteObject(): Promise<ForeignObject> {

extensions/cxx_debugging/tests/RealBackend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class Debugger {
6060
private readonly scripts: Map<string, Protocol.Debugger.ScriptParsedEvent> = new Map();
6161
private readonly scriptsById: Map<string, Protocol.Debugger.ScriptParsedEvent> = new Map();
6262
private nextStopId = 0n;
63-
private waitForPauseQueue: {resolve: (pauseLocation: PauseLocation) => void}[] = [];
63+
private waitForPauseQueue: Array<{resolve: (pauseLocation: PauseLocation) => void}> = [];
6464
private pauseLocation?: PauseLocation;
6565
private readonly callFrameToStopId = new Map<string, bigint>();
6666
private readonly stopIdToCallFrame = new Map<bigint, string>();
@@ -347,7 +347,7 @@ export class Debugger {
347347

348348
async setBreakpointsOnSourceLines(
349349
sourceLines: Array<string|RegExp>, sourceFileURL: URL, plugin: Chrome.DevTools.LanguageExtensionPlugin,
350-
rawModuleId: string): Promise<Array<BreakLocation>> {
350+
rawModuleId: string): Promise<BreakLocation[]> {
351351
if (sourceFileURL.protocol !== 'file:') {
352352
throw new Error('Not a file URL');
353353
}

front_end/core/common/JavaScriptMetaData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
export interface DOMPinnedWebIDLProp {
66
global?: boolean;
77
specs?: number;
8-
rules?: Array<DOMPinnedWebIDLRule>;
8+
rules?: DOMPinnedWebIDLRule[];
99
}
1010

1111
export interface DOMPinnedWebIDLType {
1212
inheritance?: string;
13-
includes?: Array<string>;
13+
includes?: string[];
1414
props?: {
1515
[PropName: string]: DOMPinnedWebIDLProp,
1616
};
17-
rules?: Array<DOMPinnedWebIDLRule>;
17+
rules?: DOMPinnedWebIDLRule[];
1818
}
1919

2020
export interface DOMPinnedWebIDLRule {

front_end/core/common/Linkifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ export function getApplicableRegisteredlinkifiers(object: Object): LinkifierRegi
4848
}
4949
export interface LinkifierRegistration {
5050
loadLinkifier: () => Promise<Linkifier>;
51-
contextTypes?: (() => Array<Function>);
51+
contextTypes?: (() => Function[]);
5252
}

front_end/core/common/Revealer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ let revealerRegistry: RevealerRegistry|undefined;
7878
* @see Revealer
7979
*/
8080
export class RevealerRegistry {
81-
private readonly registeredRevealers: RevealerRegistration<unknown>[] = [];
81+
private readonly registeredRevealers: Array<RevealerRegistration<unknown>> = [];
8282

8383
/**
8484
* Yields the singleton instance, creating it on-demand when necessary.
@@ -126,7 +126,7 @@ export class RevealerRegistry {
126126
return await revealers[0].reveal(revealable, omitFocus);
127127
}
128128

129-
getApplicableRegisteredRevealers(revealable: unknown): RevealerRegistration<unknown>[] {
129+
getApplicableRegisteredRevealers(revealable: unknown): Array<RevealerRegistration<unknown>> {
130130
return this.registeredRevealers.filter(registration => {
131131
for (const contextType of registration.contextTypes()) {
132132
if (revealable instanceof contextType) {

front_end/core/common/Runnable.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ export function maybeRemoveLateInitializationRunnable(runnableId: string): boole
2626
return registeredLateInitializationRunnables.delete(runnableId);
2727
}
2828

29-
export function lateInitializationRunnables(): Array<LateInitializationLoader> {
29+
export function lateInitializationRunnables(): LateInitializationLoader[] {
3030
return [...registeredLateInitializationRunnables.values()];
3131
}
3232

33-
const registeredEarlyInitializationRunnables: (() => Runnable)[] = [];
33+
const registeredEarlyInitializationRunnables: Array<() => Runnable> = [];
3434

3535
export function registerEarlyInitializationRunnable(runnable: () => Runnable): void {
3636
registeredEarlyInitializationRunnables.push(runnable);
3737
}
3838

39-
export function earlyInitializationRunnables(): (() => Runnable)[] {
39+
export function earlyInitializationRunnables(): Array<() => Runnable> {
4040
return registeredEarlyInitializationRunnables;
4141
}

front_end/core/common/SegmentedRange.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Segment<T> {
2424
}
2525

2626
export class SegmentedRange<T> {
27-
#segmentsInternal: Segment<T>[];
27+
#segmentsInternal: Array<Segment<T>>;
2828
readonly #mergeCallback: ((arg0: Segment<T>, arg1: Segment<T>) => Segment<T>| null)|undefined;
2929

3030
constructor(mergeCallback?: ((arg0: Segment<T>, arg1: Segment<T>) => Segment<T>| null)) {
@@ -76,7 +76,7 @@ export class SegmentedRange<T> {
7676
that.segments().forEach(segment => this.append(segment));
7777
}
7878

79-
segments(): Segment<T>[] {
79+
segments(): Array<Segment<T>> {
8080
return this.#segmentsInternal;
8181
}
8282

front_end/core/common/SettingRegistration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const UIStrings = {
8181
};
8282
const str_ = i18n.i18n.registerUIStrings('core/common/SettingRegistration.ts', UIStrings);
8383
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
84-
let registeredSettings: Array<SettingRegistration> = [];
84+
let registeredSettings: SettingRegistration[] = [];
8585
const settingNameSet = new Set<string>();
8686

8787
export function registerSettingExtension(registration: SettingRegistration): void {
@@ -93,11 +93,11 @@ export function registerSettingExtension(registration: SettingRegistration): voi
9393
registeredSettings.push(registration);
9494
}
9595

96-
export function getRegisteredSettings(): Array<SettingRegistration> {
96+
export function getRegisteredSettings(): SettingRegistration[] {
9797
return registeredSettings.filter(setting => Root.Runtime.Runtime.isDescriptorEnabled(setting));
9898
}
9999

100-
export function registerSettingsForTest(settings: Array<SettingRegistration>, forceReset: boolean = false): void {
100+
export function registerSettingsForTest(settings: SettingRegistration[], forceReset: boolean = false): void {
101101
if (registeredSettings.length === 0 || forceReset) {
102102
registeredSettings = settings;
103103
settingNameSet.clear();
@@ -252,7 +252,7 @@ export interface SettingRegistration {
252252
/**
253253
* The possible values the setting can have, each with a description composed of a title and an optional text.
254254
*/
255-
options?: Array<SettingExtensionOption>;
255+
options?: SettingExtensionOption[];
256256
/**
257257
* Whether DevTools must be reloaded for a change in the setting to take effect.
258258
*/

0 commit comments

Comments
 (0)