Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(lint): add @typescript-eslint/type-annotation-spacing rule (#897)

Joel Einbinder487d394f3b34
diff --git a/.eslintrc.js b/.eslintrc.js
index 7f9cf61c72..a2ce4a0218 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -41,7 +41,6 @@ module.exports = {
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"curly": [2, "multi-or-nest", "consistent"],
"new-parens": 2,
- "func-call-spacing": 2,
"arrow-parens": [2, "as-needed"],
"prefer-const": 2,
"quote-props": [2, "consistent"],
@@ -96,6 +95,8 @@ module.exports = {
"after": true,
"before": true
}],
+ "@typescript-eslint/func-call-spacing": 2,
+ "@typescript-eslint/type-annotation-spacing": 2,
// file whitespace
"no-multiple-empty-lines": [2, {"max": 2}],
diff --git a/src/.eslintrc.js b/src/.eslintrc.js
index 1d9df6e7f9..91f49549f9 100644
--- a/src/.eslintrc.js
+++ b/src/.eslintrc.js
@@ -11,6 +11,6 @@ module.exports = {
*/
"rules": {
"no-console": [2, { "allow": ["warn", "error", "assert", "timeStamp", "time", "timeEnd"] }],
- "no-debugger": 0,
+ "no-debugger": 0
}
};
diff --git a/src/chromium/crAccessibility.ts b/src/chromium/crAccessibility.ts
index 591dde0009..52866fcb7c 100644
--- a/src/chromium/crAccessibility.ts
+++ b/src/chromium/crAccessibility.ts
@@ -20,7 +20,7 @@ import { Protocol } from './protocol';
import * as dom from '../dom';
import * as accessibility from '../accessibility';
-export async function getAccessibilityTree(client: CRSession, needle?: dom.ElementHandle) : Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
+export async function getAccessibilityTree(client: CRSession, needle?: dom.ElementHandle): Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
const {nodes} = await client.send('Accessibility.getFullAXTree');
const tree = CRAXNode.createTree(client, nodes);
return {
diff --git a/src/chromium/crConnection.ts b/src/chromium/crConnection.ts
index 55aae2ccfd..2931d28162 100644
--- a/src/chromium/crConnection.ts
+++ b/src/chromium/crConnection.ts
@@ -118,7 +118,7 @@ export const CRSessionEvents = {
export class CRSession extends platform.EventEmitter {
_connection: CRConnection | null;
- private _callbacks = new Map<number, {resolve:(o: any) => void, reject: (e: Error) => void, error: Error, method: string}>();
+ private _callbacks = new Map<number, {resolve: (o: any) => void, reject: (e: Error) => void, error: Error, method: string}>();
private _targetType: string;
private _sessionId: string;
on: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
diff --git a/src/chromium/crCoverage.ts b/src/chromium/crCoverage.ts
index fcc8e789a1..d17735f505 100644
--- a/src/chromium/crCoverage.ts
+++ b/src/chromium/crCoverage.ts
@@ -26,7 +26,7 @@ import * as types from '../types';
type CoverageEntry = {
url: string,
text: string,
- ranges : {start: number, end: number}[]
+ ranges: {start: number, end: number}[]
};
export class CRCoverage implements Coverage {
diff --git a/src/chromium/crPage.ts b/src/chromium/crPage.ts
index bcb5b79173..2d2fdbe9cb 100644
--- a/src/chromium/crPage.ts
+++ b/src/chromium/crPage.ts
@@ -280,7 +280,7 @@ export class CRPage implements PageDelegate {
this._page._onBindingCalled(event.payload, context);
}
- _onDialog(event : Protocol.Page.javascriptDialogOpeningPayload) {
+ _onDialog(event: Protocol.Page.javascriptDialogOpeningPayload) {
this._page.emit(Events.Page.Dialog, new dialog.Dialog(
event.type as dialog.DialogType,
event.message,
@@ -367,7 +367,7 @@ export class CRPage implements PageDelegate {
await this._client.send('Page.setInterceptFileChooserDialog', { enabled }).catch(e => {}); // target can be closed.
}
- async opener() : Promise<Page | null> {
+ async opener(): Promise<Page | null> {
const openerTarget = CRTarget.fromPage(this._page).opener();
if (!openerTarget)
return null;
diff --git a/src/firefox/ffAccessibility.ts b/src/firefox/ffAccessibility.ts
index a83b7bf5ce..3d7fcb0762 100644
--- a/src/firefox/ffAccessibility.ts
+++ b/src/firefox/ffAccessibility.ts
@@ -20,7 +20,7 @@ import { FFSession } from './ffConnection';
import { Protocol } from './protocol';
import * as dom from '../dom';
-export async function getAccessibilityTree(session: FFSession, needle?: dom.ElementHandle) : Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
+export async function getAccessibilityTree(session: FFSession, needle?: dom.ElementHandle): Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
const objectId = needle ? needle._remoteObject.objectId : undefined;
const { tree } = await session.send('Accessibility.getFullAXTree', { objectId });
const axNode = new FFAXNode(tree);
diff --git a/src/firefox/ffPage.ts b/src/firefox/ffPage.ts
index 3eacd0d9d8..9331706900 100644
--- a/src/firefox/ffPage.ts
+++ b/src/firefox/ffPage.ts
@@ -315,7 +315,7 @@ export class FFPage implements PageDelegate {
await this._session.send('Page.setInterceptFileChooserDialog', { enabled }).catch(e => {}); // target can be closed.
}
- async opener() : Promise<Page | null> {
+ async opener(): Promise<Page | null> {
return await this._openerResolver();
}
diff --git a/src/platform.ts b/src/platform.ts
index 8572f20a14..69009191ba 100644
--- a/src/platform.ts
+++ b/src/platform.ts
@@ -332,7 +332,7 @@ export class WebSocketTransport implements ConnectionTransport {
// In Web, all IO callbacks (e.g. WebSocket callbacks)
// are dispatched into separate tasks, so there's no need
// to do anything extra.
- const messageWrap: (cb :() => void) => void = isNode ? makeWaitForNextTask() : cb => cb();
+ const messageWrap: (cb: () => void) => void = isNode ? makeWaitForNextTask() : cb => cb();
this._ws.addEventListener('message', event => {
messageWrap(() => {
diff --git a/src/types.ts b/src/types.ts
index ad0f11964a..006d077c55 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -118,7 +118,7 @@ export type PDFOptions = {
export type CoverageEntry = {
url: string,
text: string,
- ranges : {start: number, end: number}[]
+ ranges: {start: number, end: number}[]
};
export type CSSCoverageOptions = {
diff --git a/src/webkit/wkAccessibility.ts b/src/webkit/wkAccessibility.ts
index f0454737dd..4c7e7e362d 100644
--- a/src/webkit/wkAccessibility.ts
+++ b/src/webkit/wkAccessibility.ts
@@ -56,7 +56,7 @@ class WKAXNode implements accessibility.AXNode {
private _payload: Protocol.Page.AXNode;
private _children: WKAXNode[];
- constructor(payload : Protocol.Page.AXNode) {
+ constructor(payload: Protocol.Page.AXNode) {
this._payload = payload;
this._children = [];
@@ -68,7 +68,7 @@ class WKAXNode implements accessibility.AXNode {
return this._children;
}
- _findNeedle() : WKAXNode | null {
+ _findNeedle(): WKAXNode | null {
if (this._payload.found)
return this;
for (const child of this._children) {
@@ -79,7 +79,7 @@ class WKAXNode implements accessibility.AXNode {
return null;
}
- isControl() : boolean {
+ isControl(): boolean {
switch (this._payload.role) {
case 'button':
case 'checkbox':
@@ -108,7 +108,7 @@ class WKAXNode implements accessibility.AXNode {
}
}
- _isTextControl() : boolean {
+ _isTextControl(): boolean {
switch (this._payload.role) {
case 'combobox':
case 'searchfield':
@@ -119,13 +119,13 @@ class WKAXNode implements accessibility.AXNode {
return false;
}
- _name() : string {
+ _name(): string {
if (this._payload.role === 'text')
return this._payload.value || '';
return this._payload.name || '';
}
- isInteresting(insideControl: boolean) : boolean {
+ isInteresting(insideControl: boolean): boolean {
const {role, focusable} = this._payload;
const name = this._name();
if (role === 'ScrollArea')
@@ -154,7 +154,7 @@ class WKAXNode implements accessibility.AXNode {
return child._payload.role === 'text' && this._payload.name === child._payload.value;
}
- isLeafNode() : boolean {
+ isLeafNode(): boolean {
if (!this._children.length)
return true;
// WebKit on Linux ignores everything inside text controls, normalize this behavior
@@ -167,7 +167,7 @@ class WKAXNode implements accessibility.AXNode {
}
serialize(): accessibility.SerializedAXNode {
- const node : accessibility.SerializedAXNode = {
+ const node: accessibility.SerializedAXNode = {
role: WKRoleToARIARole.get(this._payload.role) || this._payload.role,
name: this._name(),
};
diff --git a/src/webkit/wkConnection.ts b/src/webkit/wkConnection.ts
index 27a6550594..1a557d5596 100644
--- a/src/webkit/wkConnection.ts
+++ b/src/webkit/wkConnection.ts
@@ -97,7 +97,7 @@ export class WKSession extends platform.EventEmitter {
private _disposed = false;
private readonly _rawSend: (message: any) => void;
- private readonly _callbacks = new Map<number, {resolve:(o: any) => void, reject: (e: Error) => void, error: Error, method: string}>();
+ private readonly _callbacks = new Map<number, {resolve: (o: any) => void, reject: (e: Error) => void, error: Error, method: string}>();
on: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
addListener: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
diff --git a/src/webkit/wkExecutionContext.ts b/src/webkit/wkExecutionContext.ts
index 17f75bd3f4..0de2a1f491 100644
--- a/src/webkit/wkExecutionContext.ts
+++ b/src/webkit/wkExecutionContext.ts
@@ -177,7 +177,7 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
}
}
- private _contextGlobalObjectId() : Promise<Protocol.Runtime.RemoteObjectId> {
+ private _contextGlobalObjectId(): Promise<Protocol.Runtime.RemoteObjectId> {
if (!this._globalObjectIdPromise) {
this._globalObjectIdPromise = this._session.send('Runtime.evaluate', {
expression: 'this',
@@ -189,7 +189,7 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
return this._globalObjectIdPromise;
}
- private async _returnObjectByValue(objectId: Protocol.Runtime.RemoteObjectId) : Promise<any> {
+ private async _returnObjectByValue(objectId: Protocol.Runtime.RemoteObjectId): Promise<any> {
try {
const serializeResponse = await this._session.send('Runtime.callFunctionOn', {
// Serialize object using standard JSON implementation to correctly pass 'undefined'.
@@ -253,7 +253,7 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
return (includeType ? 'JSHandle:' : '') + valueFromRemoteObject(object);
}
- private _convertArgument(arg: js.JSHandle | any) : Protocol.Runtime.CallArgument {
+ private _convertArgument(arg: js.JSHandle | any): Protocol.Runtime.CallArgument {
const objectHandle = arg && (arg instanceof js.JSHandle) ? arg : null;
if (objectHandle) {
if (objectHandle._context._delegate !== this)
diff --git a/src/webkit/wkPage.ts b/src/webkit/wkPage.ts
index b12f39f7d7..ad46607141 100644
--- a/src/webkit/wkPage.ts
+++ b/src/webkit/wkPage.ts
@@ -66,7 +66,7 @@ export class WKPage implements PageDelegate {
}
private async _initializePageProxySession() {
- const promises : Promise<any>[] = [
+ const promises: Promise<any>[] = [
this._pageProxySession.send('Dialog.enable'),
this.authenticate(this._page._state.credentials)
];
@@ -114,7 +114,7 @@ export class WKPage implements PageDelegate {
session.send('Page.getResourceTree'),
] as const);
resourceTreeHandler(frameTree);
- const promises : Promise<any>[] = [
+ const promises: Promise<any>[] = [
// Resource tree should be received before first execution context.
session.send('Runtime.enable'),
session.send('Page.createUserWorld', { name: UTILITY_WORLD_NAME }).catch(_ => {}), // Worlds are per-process
@@ -148,7 +148,7 @@ export class WKPage implements PageDelegate {
await Promise.all(promises);
}
- initializeProvisionalPage(provisionalSession: WKSession) : Promise<void> {
+ initializeProvisionalPage(provisionalSession: WKSession): Promise<void> {
assert(!this._provisionalPage);
this._provisionalPage = new WKProvisionalPage(provisionalSession, this);
return this._provisionalPage.initializationPromise;
@@ -285,7 +285,7 @@ export class WKPage implements PageDelegate {
}
}
- private _onExecutionContextCreated(contextPayload : Protocol.Runtime.ExecutionContextDescription) {
+ private _onExecutionContextCreated(contextPayload: Protocol.Runtime.ExecutionContextDescription) {
if (this._contextIdToContext.has(contextPayload.id))
return;
const frame = this._page._frameManager.frame(contextPayload.frameId);
@@ -578,7 +578,7 @@ export class WKPage implements PageDelegate {
return to._createHandle(result.object) as dom.ElementHandle<T>;
}
- async getAccessibilityTree(needle?: dom.ElementHandle) : Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
+ async getAccessibilityTree(needle?: dom.ElementHandle): Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
return getAccessibilityTree(this._session, needle);
}
diff --git a/src/webkit/wkPageProxy.ts b/src/webkit/wkPageProxy.ts
index 5124e5499e..bbaf621d4b 100644
--- a/src/webkit/wkPageProxy.ts
+++ b/src/webkit/wkPageProxy.ts
@@ -69,7 +69,7 @@ export class WKPageProxy {
this._pageProxySession.dispatchMessage(message);
}
- private _isProvisionalCrossProcessLoadInProgress() : boolean {
+ private _isProvisionalCrossProcessLoadInProgress(): boolean {
for (const anySession of this._sessions.values()) {
if ((anySession as any)[isPovisionalSymbol])
return true;