Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add prefer interfaces rule #3011

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const compat = new FlatCompat({
*/
export default [
{
name: 'Ignored files',
ignores: [
'**/.mypy_cache/',
'**/.pytest_cache/',
Expand Down Expand Up @@ -151,6 +152,7 @@ export default [
'plugin:@typescript-eslint/recommended-requiring-type-checking',
)
.map((config) => ({
name: 'Plugin rules',
...config,
files: ['**/*.ts'],
})),
Expand Down Expand Up @@ -238,6 +240,8 @@ export default [

'no-throw-literal': 'off',
'@typescript-eslint/only-throw-error': 'error',

'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
},
},
{
Expand Down
8 changes: 4 additions & 4 deletions src/bidiMapper/BidiServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ import {
} from './modules/session/EventManager.js';
import type {OutgoingMessage} from './OutgoingMessage.js';

type BidiServerEvent = {
interface BidiServerEvent extends Record<string | symbol, unknown> {
message: ChromiumBidi.Command;
};
}

export type MapperOptions = {
export interface MapperOptions {
acceptInsecureCerts?: boolean;
unhandledPromptBehavior?: Session.UserPromptHandler;
'goog:prerenderingDisabled'?: boolean;
};
}

export class BidiServer extends EventEmitter<BidiServerEvent> {
#messageQueue: ProcessingQueue<OutgoingMessage>;
Expand Down
4 changes: 2 additions & 2 deletions src/bidiMapper/CommandProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export const enum CommandProcessorEvents {
Response = 'response',
}

type CommandProcessorEventsMap = {
interface CommandProcessorEventsMap extends Record<string | symbol, unknown> {
[CommandProcessorEvents.Response]: {
message: Promise<Result<OutgoingMessage>>;
event: string;
};
};
}

export class CommandProcessor extends EventEmitter<CommandProcessorEventsMap> {
// keep-sorted start
Expand Down
2 changes: 1 addition & 1 deletion src/bidiMapper/modules/browser/BrowserProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
NoSuchUserContextException,
} from '../../../protocol/protocol.js';
import type {CdpClient} from '../../BidiMapper.js';
import type {BrowsingContextStorage} from '../context/BrowsingContextStorage';
import type {BrowsingContextStorage} from '../context/BrowsingContextStorage.js';

export class BrowserProcessor {
readonly #browserCdpClient: CdpClient;
Expand Down
4 changes: 2 additions & 2 deletions src/bidiMapper/modules/cdp/TargetEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export const enum TargetEvents {
FrameStartedNavigating = 'frameStartedNavigating',
}

export type TargetEventMap = {
export interface TargetEventMap extends Record<string | symbol, unknown> {
[TargetEvents.FrameStartedNavigating]: {
loaderId: string;
url: string;
frameId: string | undefined;
};
};
}
2 changes: 1 addition & 1 deletion src/bidiMapper/modules/context/BrowsingContextImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {type LoggerFn, LogType} from '../../../utils/log.js';
import {getTimestamp} from '../../../utils/time.js';
import {inchesFromCm} from '../../../utils/unitConversions.js';
import type {CdpTarget} from '../cdp/CdpTarget.js';
import {TargetEvents} from '../cdp/TargetEvents';
import {TargetEvents} from '../cdp/TargetEvents.js';
import type {Realm} from '../script/Realm.js';
import type {RealmStorage} from '../script/RealmStorage.js';
import {WindowRealm} from '../script/WindowRealm.js';
Expand Down
2 changes: 1 addition & 1 deletion src/bidiMapper/modules/context/BrowsingContextProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
NoSuchUserContextException,
NoSuchAlertException,
} from '../../../protocol/protocol.js';
import {CdpErrorConstants} from '../../../utils/CdpErrorConstants.js';
import {CdpErrorConstants} from '../../../utils/cdpErrorConstants.js';
import type {EventManager} from '../session/EventManager.js';

import type {BrowsingContextImpl} from './BrowsingContextImpl.js';
Expand Down
4 changes: 2 additions & 2 deletions src/bidiMapper/modules/context/BrowsingContextStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const enum BrowsingContextStorageEvents {
Added = 'added',
}

type BrowsingContextStorageEvent = {
interface BrowsingContextStorageEvent extends Record<string | symbol, unknown> {
[BrowsingContextStorageEvents.Added]: {browsingContext: BrowsingContextImpl};
};
}

/** Container class for browsing contexts. */
export class BrowsingContextStorage {
Expand Down
2 changes: 1 addition & 1 deletion src/bidiMapper/modules/context/NavigationTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import {Deferred} from '../../../utils/Deferred.js';
import {type LoggerFn, LogType} from '../../../utils/log.js';
import {getTimestamp} from '../../../utils/time.js';
import {urlMatchesAboutBlank} from '../../../utils/UrlHelpers.js';
import {urlMatchesAboutBlank} from '../../../utils/urlHelpers.js';
import {uuidv4} from '../../../utils/uuid.js';
import type {EventManager} from '../session/EventManager.js';

Expand Down
2 changes: 1 addition & 1 deletion src/bidiMapper/modules/input/ActionDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {assert} from '../../../utils/assert.js';
import {
isSingleComplexGrapheme,
isSingleGrapheme,
} from '../../../utils/GraphemeTools.js';
} from '../../../utils/graphemeTools.js';
import type {BrowsingContextImpl} from '../context/BrowsingContextImpl.js';
import type {BrowsingContextStorage} from '../context/BrowsingContextStorage.js';

Expand Down
6 changes: 3 additions & 3 deletions src/bidiMapper/modules/network/NetworkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {Protocol} from 'devtools-protocol';

import {InvalidArgumentException} from '../../../protocol/ErrorResponse.js';
import {Network, type Storage} from '../../../protocol/protocol.js';
import {base64ToString} from '../../../utils/Base64.js';
import {base64ToString} from '../../../utils/base64.js';

export function computeHeadersSize(headers: Network.Header[]): number {
const requestHeaders = headers.reduce((acc, header) => {
Expand Down Expand Up @@ -302,13 +302,13 @@ export function isSpecialScheme(protocol: string): boolean {
);
}

export type ParsedUrlPattern = {
export interface ParsedUrlPattern {
protocol?: string;
hostname?: string;
port?: string;
pathname?: string;
search?: string;
};
}

function getScheme(url: URL) {
return url.protocol.replace(/:$/, '');
Expand Down
4 changes: 2 additions & 2 deletions src/bidiMapper/modules/script/PreloadScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import type {CdpTarget} from '../cdp/CdpTarget.js';

import {ChannelProxy} from './ChannelProxy.js';

type CdpPreloadScript = {
interface CdpPreloadScript {
/** CDP target. Includes session ID and target ID. */
target: CdpTarget;
/** CDP preload script ID. */
preloadScriptId: Script.PreloadScript;
};
}

/**
* BiDi IDs are generated by the server and are unique within contexts.
Expand Down
2 changes: 1 addition & 1 deletion src/bidiMapper/modules/script/Realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
NoSuchHandleException,
Script,
} from '../../../protocol/protocol.js';
import {CdpErrorConstants} from '../../../utils/CdpErrorConstants.js';
import {CdpErrorConstants} from '../../../utils/cdpErrorConstants.js';
import {LogType, type LoggerFn} from '../../../utils/log.js';
import {uuidv4} from '../../../utils/uuid.js';
import type {BrowsingContextImpl} from '../context/BrowsingContextImpl.js';
Expand Down
4 changes: 2 additions & 2 deletions src/bidiMapper/modules/script/RealmStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import {
import type {Realm} from './Realm.js';
import {WindowRealm} from './WindowRealm.js';

type RealmFilter = {
interface RealmFilter {
realmId?: Script.Realm;
browsingContextId?: BrowsingContext.BrowsingContext;
executionContextId?: Protocol.Runtime.ExecutionContextId;
origin?: string;
type?: Script.RealmType;
sandbox?: string;
cdpSessionId?: Protocol.Target.SessionID;
};
}

/** Container class for browsing realms. */
export class RealmStorage {
Expand Down
2 changes: 1 addition & 1 deletion src/bidiMapper/modules/script/WindowRealm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
type BrowsingContext,
type Script,
} from '../../../protocol/protocol.js';
import {CdpErrorConstants} from '../../../utils/CdpErrorConstants.js';
import {CdpErrorConstants} from '../../../utils/cdpErrorConstants.js';
import type {LoggerFn} from '../../../utils/log.js';
import type {BrowsingContextImpl} from '../context/BrowsingContextImpl.js';
import type {BrowsingContextStorage} from '../context/BrowsingContextStorage.js';
Expand Down
8 changes: 4 additions & 4 deletions src/bidiMapper/modules/session/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ export const enum EventManagerEvents {
Event = 'event',
}

type EventManagerEventsMap = {
interface EventManagerEventsMap extends Record<string | symbol, unknown> {
[EventManagerEvents.Event]: {
message: Promise<Result<OutgoingMessage>>;
event: string;
};
};
}
/**
* Maps event name to a desired buffer length.
*/
Expand All @@ -82,10 +82,10 @@ const eventBufferLength: ReadonlyMap<ChromiumBidi.EventNames, number> = new Map(
/**
* Subscription item is a pair of event name and context id.
*/
export type SubscriptionItem = {
export interface SubscriptionItem {
contextId: BrowsingContext.BrowsingContext;
event: ChromiumBidi.EventNames;
};
}

export class EventManager extends EventEmitter<EventManagerEventsMap> {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/bidiMapper/modules/session/SubscriptionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ export function unrollEvents(
return [...allEvents.values()];
}

export type Subscription = {
export interface Subscription {
id: string;
// Empty set means a global subscription.
topLevelTraversableIds: Set<BrowsingContext.BrowsingContext>;
// Never empty.
eventNames: Set<ChromiumBidi.EventNames>;
channel: BidiPlusChannel;
};
}

export class SubscriptionManager {
#subscriptions: Subscription[] = [];
Expand Down
4 changes: 2 additions & 2 deletions src/bidiServer/BrowserInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ import type {SimpleTransport} from './SimpleTransport.js';

const debugInternal = debug('bidi:mapper:internal');

export type ChromeOptions = {
export interface ChromeOptions {
chromeArgs: string[];
chromeBinary?: string;
};
}

/**
* BrowserProcess is responsible for running the browser and BiDi Mapper within
Expand Down
8 changes: 4 additions & 4 deletions src/bidiServer/WebSocketServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ const debugInternal = debug('bidi:server:internal');
const debugSend = debug('bidi:server:SEND ▸');
const debugRecv = debug('bidi:server:RECV ◂');

type Session = {
interface Session {
sessionId: string;
// Promise is used to decrease WebSocket handshake latency. If session is set via
// WebDriver Classic, we need to launch Browser instance for each new WebSocket
// connection before processing BiDi commands.
// TODO: replace with BrowserInstance, make readonly, remove promise and undefined.
browserInstancePromise: Promise<BrowserInstance> | undefined;
sessionOptions: Readonly<SessionOptions>;
};
}

type SessionOptions = {
interface SessionOptions {
readonly chromeOptions: ChromeOptions;
readonly verbose: boolean;
readonly sessionNewBody: string;
};
}

export class WebSocketServer {
#sessions = new Map<string, Session>();
Expand Down
Loading
Loading