chore: align lint w/ playwright (#729)

This commit is contained in:
Pavel Feldman 2025-07-21 17:07:13 -07:00 committed by GitHub
parent eeeab4f042
commit f1826b96b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 46 additions and 19 deletions

View File

@ -192,6 +192,31 @@ const languageOptions = {
} }
}; };
const importOrderRules = {
"import/order": [
2,
{
groups: [
"builtin",
"external",
"internal",
["parent", "sibling"],
"index",
"type",
],
},
],
"import/consistent-type-specifier-style": [2, "prefer-top-level"],
};
const noFloatingPromisesRules = {
"@typescript-eslint/no-floating-promises": "error",
};
const noBooleanCompareRules = {
"@typescript-eslint/no-unnecessary-boolean-literal-compare": 2,
};
export default [ export default [
{ {
ignores: ["**/*.js"], ignores: ["**/*.js"],
@ -200,6 +225,11 @@ export default [
files: ["**/*.ts", "**/*.tsx"], files: ["**/*.ts", "**/*.tsx"],
plugins, plugins,
languageOptions, languageOptions,
rules: baseRules, rules: {
...baseRules,
...importOrderRules,
...noFloatingPromisesRules,
...noBooleanCompareRules,
},
}, },
]; ];

View File

@ -18,10 +18,9 @@ import fs from 'fs';
import os from 'os'; import os from 'os';
import path from 'path'; import path from 'path';
import { devices } from 'playwright'; import { devices } from 'playwright';
import { sanitizeForFilePath } from './tools/utils.js';
import type { Config, ToolCapability } from '../config.js'; import type { Config, ToolCapability } from '../config.js';
import type { BrowserContextOptions, LaunchOptions } from 'playwright'; import type { BrowserContextOptions, LaunchOptions } from 'playwright';
import { sanitizeForFilePath } from './tools/utils.js';
export type CLIOptions = { export type CLIOptions = {
allowedOrigins?: string[]; allowedOrigins?: string[];

View File

@ -22,15 +22,15 @@
* - /extension/guid - Extension connection for chrome.debugger forwarding * - /extension/guid - Extension connection for chrome.debugger forwarding
*/ */
import http from 'http';
import { promisify } from 'util';
import { exec } from 'child_process';
import { WebSocket, WebSocketServer } from 'ws'; import { WebSocket, WebSocketServer } from 'ws';
import type websocket from 'ws';
import http from 'node:http';
import debug from 'debug'; import debug from 'debug';
import { promisify } from 'node:util'; import * as playwright from 'playwright';
import { exec } from 'node:child_process';
import { httpAddressToString, startHttpServer } from '../transport.js'; import { httpAddressToString, startHttpServer } from '../transport.js';
import { BrowserContextFactory } from '../browserContextFactory.js'; import { BrowserContextFactory } from '../browserContextFactory.js';
import { Browser, chromium, type BrowserContext } from 'playwright'; import type websocket from 'ws';
const debugLogger = debug('pw:mcp:relay'); const debugLogger = debug('pw:mcp:relay');
@ -284,13 +284,13 @@ export class CDPRelayServer {
class ExtensionContextFactory implements BrowserContextFactory { class ExtensionContextFactory implements BrowserContextFactory {
private _relay: CDPRelayServer; private _relay: CDPRelayServer;
private _browserPromise: Promise<Browser> | undefined; private _browserPromise: Promise<playwright.Browser> | undefined;
constructor(relay: CDPRelayServer) { constructor(relay: CDPRelayServer) {
this._relay = relay; this._relay = relay;
} }
async createContext(clientInfo: { name: string, version: string }): Promise<{ browserContext: BrowserContext, close: () => Promise<void> }> { async createContext(clientInfo: { name: string, version: string }): Promise<{ browserContext: playwright.BrowserContext, close: () => Promise<void> }> {
// First call will establish the connection to the extension. // First call will establish the connection to the extension.
if (!this._browserPromise) if (!this._browserPromise)
this._browserPromise = this._obtainBrowser(clientInfo); this._browserPromise = this._obtainBrowser(clientInfo);
@ -301,9 +301,9 @@ class ExtensionContextFactory implements BrowserContextFactory {
}; };
} }
private async _obtainBrowser(clientInfo: { name: string, version: string }): Promise<Browser> { private async _obtainBrowser(clientInfo: { name: string, version: string }): Promise<playwright.Browser> {
await this._relay.ensureExtensionConnectionForMCPContext(clientInfo); await this._relay.ensureExtensionConnectionForMCPContext(clientInfo);
return await chromium.connectOverCDP(this._relay.cdpEndpoint()); return await playwright.chromium.connectOverCDP(this._relay.cdpEndpoint());
} }
} }

View File

@ -15,10 +15,9 @@
*/ */
import { createConnection as createConnectionImpl } from './connection.js'; import { createConnection as createConnectionImpl } from './connection.js';
import type { Connection } from '../index.js';
import { resolveConfig } from './config.js'; import { resolveConfig } from './config.js';
import { contextFactory } from './browserContextFactory.js'; import { contextFactory } from './browserContextFactory.js';
import type { Connection } from '../index.js';
import type { Config } from '../config.js'; import type { Config } from '../config.js';
import type { BrowserContext } from 'playwright'; import type { BrowserContext } from 'playwright';
import type { BrowserContextFactory } from './browserContextFactory.js'; import type { BrowserContextFactory } from './browserContextFactory.js';

View File

@ -16,11 +16,10 @@
import { fork } from 'child_process'; import { fork } from 'child_process';
import path from 'path'; import path from 'path';
import { fileURLToPath } from 'url';
import { z } from 'zod'; import { z } from 'zod';
import { defineTool } from './tool.js'; import { defineTool } from './tool.js';
import { fileURLToPath } from 'node:url';
const install = defineTool({ const install = defineTool({
capability: 'core-install', capability: 'core-install',

View File

@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { test, expect } from './fixtures.js';
import fs from 'fs/promises'; import fs from 'fs/promises';
import { test, expect } from './fixtures.js';
test('browser_file_upload', async ({ client, server }, testInfo) => { test('browser_file_upload', async ({ client, server }, testInfo) => {
server.setContent('/', ` server.setContent('/', `

View File

@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import child_process from 'child_process';
import fs from 'fs/promises';
import { test, expect } from './fixtures.js'; import { test, expect } from './fixtures.js';
import fs from 'node:fs/promises';
import child_process from 'node:child_process';
test('library can be used from CommonJS', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright-mcp/issues/456' } }, async ({}, testInfo) => { test('library can be used from CommonJS', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright-mcp/issues/456' } }, async ({}, testInfo) => {
const file = testInfo.outputPath('main.cjs'); const file = testInfo.outputPath('main.cjs');