mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: fix eslint warnings around type defs (#7230)
This PR updates some code to remove constant ESLint warnings. It also upgrades those warnings to errors - so that they have to be resolved as part of the PR, rather than landing as a warning and causing noise. Fixes #7229.
This commit is contained in:
parent
523aa0aafa
commit
3204f2780f
@ -166,6 +166,8 @@ module.exports = {
|
||||
default: 'array-simple',
|
||||
},
|
||||
],
|
||||
// By default this is a warning but we want it to error.
|
||||
'@typescript-eslint/explicit-module-boundary-types': 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -72,7 +72,7 @@
|
||||
"@commitlint/cli": "^11.0.0",
|
||||
"@commitlint/config-conventional": "^11.0.0",
|
||||
"@microsoft/api-documenter": "^7.12.7",
|
||||
"@microsoft/api-extractor": "^7.13.1",
|
||||
"@microsoft/api-extractor": "7.15.1",
|
||||
"@types/debug": "0.0.31",
|
||||
"@types/mime": "^2.0.0",
|
||||
"@types/mocha": "^7.0.2",
|
||||
@ -82,8 +82,8 @@
|
||||
"@types/sinon": "^9.0.4",
|
||||
"@types/tar-fs": "^1.16.2",
|
||||
"@types/ws": "^7.2.4",
|
||||
"@typescript-eslint/eslint-plugin": "^4.4.0",
|
||||
"@typescript-eslint/parser": "^4.4.0",
|
||||
"@typescript-eslint/eslint-plugin": "4.23.0",
|
||||
"@typescript-eslint/parser": "4.23.0",
|
||||
"@web/test-runner": "^0.12.15",
|
||||
"commonmark": "^0.28.1",
|
||||
"cross-env": "^7.0.2",
|
||||
@ -109,7 +109,7 @@
|
||||
"standard-version": "^9.0.0",
|
||||
"text-diff": "^1.0.1",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.1.5"
|
||||
"typescript": "4.2.4"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
|
@ -21,7 +21,7 @@ export interface CommonEventEmitter {
|
||||
*/
|
||||
addListener(event: EventType, handler: Handler): CommonEventEmitter;
|
||||
removeListener(event: EventType, handler: Handler): CommonEventEmitter;
|
||||
emit(event: EventType, eventData?: any): boolean;
|
||||
emit(event: EventType, eventData?: unknown): boolean;
|
||||
once(event: EventType, handler: Handler): CommonEventEmitter;
|
||||
listenerCount(event: string): number;
|
||||
|
||||
@ -98,7 +98,7 @@ export class EventEmitter implements CommonEventEmitter {
|
||||
* @param eventData - any data you'd like to emit with the event
|
||||
* @returns `true` if there are any listeners, `false` if there are not.
|
||||
*/
|
||||
emit(event: EventType, eventData?: any): boolean {
|
||||
emit(event: EventType, eventData?: unknown): boolean {
|
||||
this.emitter.emit(event, eventData);
|
||||
return this.eventListenersCount(event) > 0;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ export class FileChooser {
|
||||
/**
|
||||
* Closes the file chooser without selecting any files.
|
||||
*/
|
||||
cancel() {
|
||||
cancel(): void {
|
||||
assert(
|
||||
!this._handled,
|
||||
'Cannot cancel FileChooser which is already handled!'
|
||||
|
@ -26,7 +26,7 @@ const supportedProducts = {
|
||||
firefox: 'Firefox Nightly',
|
||||
} as const;
|
||||
|
||||
export async function downloadBrowser() {
|
||||
export async function downloadBrowser(): Promise<void> {
|
||||
const downloadHost =
|
||||
process.env.PUPPETEER_DOWNLOAD_HOST ||
|
||||
process.env.npm_config_puppeteer_download_host ||
|
||||
@ -178,7 +178,7 @@ export async function downloadBrowser() {
|
||||
}
|
||||
}
|
||||
|
||||
export function logPolitely(toBeLogged) {
|
||||
export function logPolitely(toBeLogged: unknown): void {
|
||||
const logLevel = process.env.npm_config_loglevel;
|
||||
const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1;
|
||||
|
||||
|
@ -231,13 +231,12 @@ describe('Cookie specs', () => {
|
||||
value: 'bar',
|
||||
}
|
||||
);
|
||||
expectCookieEquals(
|
||||
await page.evaluate(() => {
|
||||
const cookies = document.cookie.split(';');
|
||||
return cookies.map((cookie) => cookie.trim()).sort();
|
||||
}),
|
||||
['foo=bar', 'password=123456']
|
||||
);
|
||||
const cookieStrings = await page.evaluate(() => {
|
||||
const cookies = document.cookie.split(';');
|
||||
return cookies.map((cookie) => cookie.trim()).sort();
|
||||
});
|
||||
|
||||
expect(cookieStrings).toEqual(['foo=bar', 'password=123456']);
|
||||
});
|
||||
it('should have |expires| set to |-1| for session cookies', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
@ -31,6 +31,7 @@ import rimraf from 'rimraf';
|
||||
import expect from 'expect';
|
||||
|
||||
import { trackCoverage } from './coverage-utils.js';
|
||||
import Protocol from 'devtools-protocol';
|
||||
|
||||
const setupServer = async () => {
|
||||
const assetsPath = path.join(__dirname, 'assets');
|
||||
@ -177,7 +178,10 @@ export const itFailsWindowsUntilDate = (
|
||||
return it(description, body);
|
||||
};
|
||||
|
||||
export const itFailsWindows = (description: string, body: Mocha.Func) => {
|
||||
export const itFailsWindows = (
|
||||
description: string,
|
||||
body: Mocha.Func
|
||||
): Mocha.Test => {
|
||||
if (os.platform() === 'win32') {
|
||||
return xit(description, body);
|
||||
}
|
||||
@ -217,7 +221,7 @@ console.log(
|
||||
}`
|
||||
);
|
||||
|
||||
export const setupTestBrowserHooks = () => {
|
||||
export const setupTestBrowserHooks = (): void => {
|
||||
before(async () => {
|
||||
const browser = await puppeteer.launch(defaultBrowserOptions);
|
||||
state.browser = browser;
|
||||
@ -229,7 +233,7 @@ export const setupTestBrowserHooks = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const setupTestPageAndContextHooks = () => {
|
||||
export const setupTestPageAndContextHooks = (): void => {
|
||||
beforeEach(async () => {
|
||||
state.context = await state.browser.createIncognitoBrowserContext();
|
||||
state.page = await state.context.newPage();
|
||||
@ -244,7 +248,7 @@ export const setupTestPageAndContextHooks = () => {
|
||||
|
||||
export const mochaHooks = {
|
||||
beforeAll: [
|
||||
async () => {
|
||||
async (): Promise<void> => {
|
||||
const { server, httpsServer } = await setupServer();
|
||||
|
||||
state.puppeteer = puppeteer;
|
||||
@ -259,13 +263,13 @@ export const mochaHooks = {
|
||||
coverageHooks.beforeAll,
|
||||
],
|
||||
|
||||
beforeEach: async () => {
|
||||
beforeEach: async (): Promise<void> => {
|
||||
state.server.reset();
|
||||
state.httpsServer.reset();
|
||||
},
|
||||
|
||||
afterAll: [
|
||||
async () => {
|
||||
async (): Promise<void> => {
|
||||
await state.server.stop();
|
||||
state.server = null;
|
||||
await state.httpsServer.stop();
|
||||
@ -274,12 +278,15 @@ export const mochaHooks = {
|
||||
coverageHooks.afterAll,
|
||||
],
|
||||
|
||||
afterEach: () => {
|
||||
afterEach: (): void => {
|
||||
sinon.restore();
|
||||
},
|
||||
};
|
||||
|
||||
export const expectCookieEquals = (cookies, expectedCookies) => {
|
||||
export const expectCookieEquals = (
|
||||
cookies: Protocol.Network.Cookie[],
|
||||
expectedCookies: Array<Partial<Protocol.Network.Cookie>>
|
||||
): void => {
|
||||
const { isChrome } = getTestState();
|
||||
if (!isChrome) {
|
||||
// Only keep standard properties when testing on a browser other than Chrome.
|
||||
|
@ -685,7 +685,8 @@ function compareDocumentations(actual, expected) {
|
||||
'Method Page.emulateVisionDeficiency() type',
|
||||
{
|
||||
actualName: 'string',
|
||||
expectedName: 'Object',
|
||||
expectedName:
|
||||
'"none"|"achromatopsia"|"blurredVision"|"deuteranopia"|"protanopia"|"tritanopia"',
|
||||
},
|
||||
],
|
||||
[
|
||||
@ -849,14 +850,6 @@ function compareDocumentations(actual, expected) {
|
||||
expectedName: '...DeleteCookiesRequest',
|
||||
},
|
||||
],
|
||||
[
|
||||
'Method Page.emulateVisionDeficiency() type',
|
||||
{
|
||||
actualName: 'string',
|
||||
expectedName:
|
||||
'"none"|"achromatopsia"|"blurredVision"|"deuteranopia"|"protanopia"|"tritanopia"',
|
||||
},
|
||||
],
|
||||
[
|
||||
'Method BrowserContext.overridePermissions() permissions',
|
||||
{
|
||||
@ -885,6 +878,13 @@ function compareDocumentations(actual, expected) {
|
||||
expectedName: 'Object',
|
||||
},
|
||||
],
|
||||
[
|
||||
'Method EventEmitter.emit() eventData',
|
||||
{
|
||||
actualName: 'Object',
|
||||
expectedName: 'unknown',
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
const expectedForSource = expectedNamingMismatches.get(source);
|
||||
|
Loading…
Reference in New Issue
Block a user