Skip to content

Commit

Permalink
Revert "[eslint] Prefer TypeScript interface over type aliases."
Browse files Browse the repository at this point in the history
This reverts commit af6c633.

Reason for revert: The latest version of EsLint v9 does not work with the plugin added here, also the rule does more that just change shape objects from type to interface.

Original change's description:
> [eslint] Prefer TypeScript `interface` over type aliases.
>
> We have a mix of `type` and `interface` usage throughout our codebase,
> that is sometimes difficult to follow and reason about. We should follow
> the suggestion from the TypeScript PM and use `interface` consistently
> where possible. This leads to better type display in errors and makes
> our codebase easier to read (b/c consistency).
>
> This CL adds the `etc/prefer-interface` ESLint rule to accomplish this.
>
> Fixed: 387237537
> Change-Id: Idd6775094ba94b8397f626191788437f6b156dc6
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6135001
> Commit-Queue: Nikolay Vitkov <[email protected]>
> Reviewed-by: Nikolay Vitkov <[email protected]>
> Commit-Queue: Benedikt Meurer <[email protected]>

Bug: 387237537
Change-Id: I6ecf18bfdaa4ad9efb17f0801def528035f9e703
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6140555
Commit-Queue: Benedikt Meurer <[email protected]>
Reviewed-by: Benedikt Meurer <[email protected]>
Auto-Submit: Nikolay Vitkov <[email protected]>
  • Loading branch information
Lightning00Blade authored and Devtools-frontend LUCI CQ committed Jan 3, 2025
1 parent ef61624 commit 937f463
Show file tree
Hide file tree
Showing 1,801 changed files with 1,666 additions and 55,202 deletions.
4 changes: 0 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import importPlugin from 'eslint-plugin-import';
import jsdocPlugin from 'eslint-plugin-jsdoc';
import globals from 'globals';
import tsParser from '@typescript-eslint/parser';
import etcPlugin from 'eslint-plugin-etc';
import { join } from 'path';

rulesdirPlugin.RULES_DIR = join(
Expand Down Expand Up @@ -65,7 +64,6 @@ export default [
rulesdir: rulesdirPlugin,
import: importPlugin,
jsdoc: jsdocPlugin,
etc: etcPlugin,
},

languageOptions: {
Expand Down Expand Up @@ -234,8 +232,6 @@ export default [
'no-implicit-globals': 'off',
'no-unused-private-class-members': 'error',

// Forbids type aliases where interfaces can be used.
'etc/prefer-interface': 'error',
// Closure does not properly typecheck default exports
'import/no-default-export': 'error',
/**
Expand Down
6 changes: 3 additions & 3 deletions front_end/core/common/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export const enum Events {
MESSAGE_ADDED = 'messageAdded',
}

export interface EventTypes {
[Events.MESSAGE_ADDED]: Message;
}
export type EventTypes = {
[Events.MESSAGE_ADDED]: Message,
};

export const enum MessageLevel {
INFO = 'info',
Expand Down
14 changes: 7 additions & 7 deletions front_end/core/common/EventTarget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ const enum Events {
UNION_EVENT = 'UnionEvent',
}

interface TestEvents {
[Events.VOID_EVENT]: void;
[Events.NUMBER_EVENT]: number;
[Events.KEY_VALUE_EVENT]: {key: string, value: number};
[Events.BOOLEAN_EVENT]: boolean;
[Events.UNION_EVENT]: string|null;
}
type TestEvents = {
[Events.VOID_EVENT]: void,
[Events.NUMBER_EVENT]: number,
[Events.KEY_VALUE_EVENT]: {key: string, value: number},
[Events.BOOLEAN_EVENT]: boolean,
[Events.UNION_EVENT]: string|null,
};

class TypedEventEmitter extends Common.ObjectWrapper.ObjectWrapper<TestEvents> {
testValidArgumentTypes() {
Expand Down
10 changes: 4 additions & 6 deletions front_end/core/common/EventTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ export function removeEventListeners(eventList: EventDescriptor[]): void {

// This type can be used as the type parameter for `EventTarget`/`ObjectWrapper`
// when the set of events is not known at compile time.
export interface GenericEvents {
export type GenericEvents = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[eventName: string]: any;
}
[eventName: string]: any,
};

export type EventPayloadToRestParameters<Events, T extends keyof Events> = Events[T] extends void ? [] : [Events[T]];
export interface EventListener<Events, T extends keyof Events> {
(arg0: EventTargetEvent<Events[T], Events>): void;
}
export type EventListener<Events, T extends keyof Events> = (arg0: EventTargetEvent<Events[T], Events>) => void;

export interface EventTarget<Events> {
addEventListener<T extends keyof Events>(eventType: T, listener: EventListener<Events, T>, thisObject?: Object):
Expand Down
4 changes: 1 addition & 3 deletions front_end/core/common/Mutex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

interface ReleaseFunction {
(): void;
}
type ReleaseFunction = () => void;

/**
* Use Mutex class to coordinate local concurrent operations.
Expand Down
4 changes: 1 addition & 3 deletions front_end/core/common/Revealer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,4 @@ export const RevealerDestination = {
ANIMATIONS_PANEL: i18nLazyString(UIStrings.animationsPanel),
};

export interface RevealerDestination {
(): Platform.UIString.LocalizedString;
}
export type RevealerDestination = () => Platform.UIString.LocalizedString;
4 changes: 1 addition & 3 deletions front_end/core/common/Runnable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export interface Runnable {
run(): Promise<void>;
}

interface LateInitializationLoader {
(): Promise<Runnable>;
}
type LateInitializationLoader = () => Promise<Runnable>;
export interface LateInitializableRunnableSetting {
id: string;
loadRunnable: LateInitializationLoader;
Expand Down
4 changes: 1 addition & 3 deletions front_end/core/common/Throttler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export interface FinishCallback {
(err: Error): void;
}
export type FinishCallback = (err: Error) => void;

export class Throttler {
readonly #timeout: number;
Expand Down
6 changes: 3 additions & 3 deletions front_end/core/host/AidaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,6 @@ export const enum Events {
AIDA_AVAILABILITY_CHANGED = 'aidaAvailabilityChanged',
}

export interface EventTypes {
[Events.AIDA_AVAILABILITY_CHANGED]: void;
}
export type EventTypes = {
[Events.AIDA_AVAILABILITY_CHANGED]: void,
};
60 changes: 30 additions & 30 deletions front_end/core/host/InspectorFrontendHostAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,36 +204,36 @@ export interface KeyDownEvent {
// `EventTypes` is not used at runtime.
// Please note that the "dispatch" side can't be type-checked as the dispatch is
// done dynamically.
export interface EventTypes {
[Events.AppendedToURL]: Platform.DevToolsPath.RawPathString|Platform.DevToolsPath.UrlString;
[Events.CanceledSaveURL]: Platform.DevToolsPath.UrlString;
[Events.ColorThemeChanged]: void;
[Events.ContextMenuCleared]: void;
[Events.ContextMenuItemSelected]: number;
[Events.DeviceCountUpdated]: number;
[Events.DevicesDiscoveryConfigChanged]: Adb.Config;
[Events.DevicesPortForwardingStatusChanged]: void;
[Events.DevicesUpdated]: void;
[Events.DispatchMessage]: string;
[Events.DispatchMessageChunk]: DispatchMessageChunkEvent;
[Events.EnterInspectElementMode]: void;
[Events.EyeDropperPickedColor]: EyeDropperPickedColorEvent;
[Events.FileSystemsLoaded]: DevToolsFileSystem[];
[Events.FileSystemRemoved]: Platform.DevToolsPath.RawPathString;
[Events.FileSystemAdded]: FileSystemAddedEvent;
[Events.FileSystemFilesChangedAddedRemoved]: FilesChangedEvent;
[Events.IndexingTotalWorkCalculated]: IndexingTotalWorkCalculatedEvent;
[Events.IndexingWorked]: IndexingWorkedEvent;
[Events.IndexingDone]: IndexingEvent;
[Events.KeyEventUnhandled]: KeyEventUnhandledEvent;
[Events.ReloadInspectedPage]: boolean;
[Events.RevealSourceLine]: RevealSourceLineEvent;
[Events.SavedURL]: SavedURLEvent;
[Events.SearchCompleted]: SearchCompletedEvent;
[Events.SetInspectedTabId]: string;
[Events.SetUseSoftMenu]: boolean;
[Events.ShowPanel]: string;
}
export type EventTypes = {
[Events.AppendedToURL]: Platform.DevToolsPath.RawPathString|Platform.DevToolsPath.UrlString,
[Events.CanceledSaveURL]: Platform.DevToolsPath.UrlString,
[Events.ColorThemeChanged]: void,
[Events.ContextMenuCleared]: void,
[Events.ContextMenuItemSelected]: number,
[Events.DeviceCountUpdated]: number,
[Events.DevicesDiscoveryConfigChanged]: Adb.Config,
[Events.DevicesPortForwardingStatusChanged]: void,
[Events.DevicesUpdated]: void,
[Events.DispatchMessage]: string,
[Events.DispatchMessageChunk]: DispatchMessageChunkEvent,
[Events.EnterInspectElementMode]: void,
[Events.EyeDropperPickedColor]: EyeDropperPickedColorEvent,
[Events.FileSystemsLoaded]: DevToolsFileSystem[],
[Events.FileSystemRemoved]: Platform.DevToolsPath.RawPathString,
[Events.FileSystemAdded]: FileSystemAddedEvent,
[Events.FileSystemFilesChangedAddedRemoved]: FilesChangedEvent,
[Events.IndexingTotalWorkCalculated]: IndexingTotalWorkCalculatedEvent,
[Events.IndexingWorked]: IndexingWorkedEvent,
[Events.IndexingDone]: IndexingEvent,
[Events.KeyEventUnhandled]: KeyEventUnhandledEvent,
[Events.ReloadInspectedPage]: boolean,
[Events.RevealSourceLine]: RevealSourceLineEvent,
[Events.SavedURL]: SavedURLEvent,
[Events.SearchCompleted]: SearchCompletedEvent,
[Events.SetInspectedTabId]: string,
[Events.SetUseSoftMenu]: boolean,
[Events.ShowPanel]: string,
};

export interface InspectorFrontendHostAPI {
addFileSystem(type?: string): void;
Expand Down
6 changes: 3 additions & 3 deletions front_end/core/i18n/i18nTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export interface Values {
[key: string]: string|boolean|number;
}
export type Values = {
[key: string]: string|boolean|number,
};

export interface SerializedMessage {
string: string;
Expand Down
4 changes: 1 addition & 3 deletions front_end/core/platform/ArrayUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export const removeElement = <T>(array: T[], element: T, firstOnly?: boolean): b
return true;
};

interface NumberComparator {
(a: number, b: number): number;
}
type NumberComparator = (a: number, b: number) => number;

function swap(array: number[], i1: number, i2: number): void {
const temp = array[i1];
Expand Down
16 changes: 8 additions & 8 deletions front_end/core/platform/ServerTiming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const defaultWarningMessages: ServerTimingParsingWarningMessage = {
},
};

export interface ServerTimingParsingWarningMessage {
deprecratedSyntax: () => string;
duplicateParameter: (parameter: string) => string;
noValueFoundForParameter: (parameter: string) => string;
unrecognizedParameter: (parameter: string) => string;
extraneousTrailingCharacters: () => string;
unableToParseValue: (parameter: string, value: string) => string;
}
export type ServerTimingParsingWarningMessage = {
deprecratedSyntax: () => string,
duplicateParameter: (parameter: string) => string,
noValueFoundForParameter: (parameter: string) => string,
unrecognizedParameter: (parameter: string) => string,
extraneousTrailingCharacters: () => string,
unableToParseValue: (parameter: string, value: string) => string,
};

export class ServerTiming {
metric: string;
Expand Down
32 changes: 14 additions & 18 deletions front_end/core/protocol_client/InspectorBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export const DevToolsStubErrorCode = -32015;
const GenericErrorCode = -32000;
const ConnectionClosedErrorCode = -32001;

interface MessageParams {
type MessageParams = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[x: string]: any;
}
[x: string]: any,
};

type ProtocolDomainName = ProtocolProxyApi.ProtocolDomainName;

Expand All @@ -52,15 +52,15 @@ export interface MessageError {
data?: string|null;
}

export interface Message {
sessionId?: string;
url?: Platform.DevToolsPath.UrlString;
id?: number;
error?: MessageError|null;
result?: Object|null;
method?: QualifiedName;
params?: MessageParams|null;
}
export type Message = {
sessionId?: string,
url?: Platform.DevToolsPath.UrlString,
id?: number,
error?: MessageError|null,
result?: Object|null,
method?: QualifiedName,
params?: MessageParams|null,
};

interface EventMessage extends Message {
method: QualifiedName;
Expand Down Expand Up @@ -91,9 +91,7 @@ interface CommandParameter {
description: string;
}

interface Callback {
(error: MessageError|null, arg1: Object|null): void;
}
type Callback = (error: MessageError|null, arg1: Object|null) => void;

interface CallbackWithDebugInfo {
callback: Callback;
Expand Down Expand Up @@ -208,9 +206,7 @@ export class Connection {
}
}

interface SendRawMessageCallback {
(...args: unknown[]): void;
}
type SendRawMessageCallback = (...args: unknown[]) => void;

export const test = {
/**
Expand Down
4 changes: 1 addition & 3 deletions front_end/core/root/Runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,7 @@ export type HostConfig = Platform.TypeScriptUtilities.RecursivePartial<{
* When defining conditions make sure that objects used by the function have
* been instantiated.
*/
export interface Condition {
(config?: HostConfig): boolean;
}
export type Condition = (config?: HostConfig) => boolean;

export const conditions = {
canDock: () => Boolean(Runtime.queryParam('can_dock')),
Expand Down
6 changes: 3 additions & 3 deletions front_end/core/sdk/AccessibilityModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ export const enum Events {
TREE_UPDATED = 'TreeUpdated',
}

export interface EventTypes {
[Events.TREE_UPDATED]: {root?: AccessibilityNode};
}
export type EventTypes = {
[Events.TREE_UPDATED]: {root?: AccessibilityNode},
};

export class AccessibilityModel extends SDKModel<EventTypes> implements ProtocolProxyApi.AccessibilityDispatcher {
agent: ProtocolProxyApi.AccessibilityApi;
Expand Down
19 changes: 8 additions & 11 deletions front_end/core/sdk/AnimationModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ const REPORT_SCROLL_POSITION_BINDING_NAME = '__devtools_report_scroll_position__

const getScrollListenerNameInPage = (id: number): string => `__devtools_scroll_listener_${id}__`;

interface ScrollListener {
(param: {scrollLeft: number, scrollTop: number}): void;
}
interface BindingListener {
(ev: Common.EventTarget.EventTargetEvent<Protocol.Runtime.BindingCalledEvent, RuntimeModelEventTypes>): void;
}
type ScrollListener = (param: {scrollLeft: number, scrollTop: number}) => void;
type BindingListener =
(ev: Common.EventTarget.EventTargetEvent<Protocol.Runtime.BindingCalledEvent, RuntimeModelEventTypes>) => void;

async function resolveToObjectInWorld(domNode: DOMNode, worldName: string): Promise<RemoteObject|null> {
const resourceTreeModel = domNode.domModel().target().model(ResourceTreeModel) as ResourceTreeModel;
Expand Down Expand Up @@ -481,11 +478,11 @@ export enum Events {
/* eslint-enable @typescript-eslint/naming-convention */
}

export interface EventTypes {
[Events.AnimationGroupStarted]: AnimationGroup;
[Events.AnimationGroupUpdated]: AnimationGroup;
[Events.ModelReset]: void;
}
export type EventTypes = {
[Events.AnimationGroupStarted]: AnimationGroup,
[Events.AnimationGroupUpdated]: AnimationGroup,
[Events.ModelReset]: void,
};

export class AnimationImpl {
readonly #animationModel: AnimationModel;
Expand Down
6 changes: 3 additions & 3 deletions front_end/core/sdk/AutofillModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ export interface AddressFormFilledEvent {
event: Protocol.Autofill.AddressFormFilledEvent;
}

export interface EventTypes {
[Events.ADDRESS_FORM_FILLED]: AddressFormFilledEvent;
}
export type EventTypes = {
[Events.ADDRESS_FORM_FILLED]: AddressFormFilledEvent,
};
8 changes: 4 additions & 4 deletions front_end/core/sdk/CPUProfilerModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ export const enum Events {
CONSOLE_PROFILE_FINISHED = 'ConsoleProfileFinished',
}

export interface EventTypes {
[Events.CONSOLE_PROFILE_STARTED]: EventData;
[Events.CONSOLE_PROFILE_FINISHED]: ProfileFinishedData;
}
export type EventTypes = {
[Events.CONSOLE_PROFILE_STARTED]: EventData,
[Events.CONSOLE_PROFILE_FINISHED]: ProfileFinishedData,
};

SDKModel.register(CPUProfilerModel, {capabilities: Capability.JS, autostart: true});

Expand Down
Loading

0 comments on commit 937f463

Please sign in to comment.