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: enforce spacing around braces #5700

Merged
merged 1 commit into from Apr 21, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -33,6 +33,7 @@ module.exports = {
}],
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"curly": [2, "multi-or-nest", "consistent"],
"object-curly-spacing": [2, "never"],
"new-parens": 2,
"func-call-spacing": 2,
"arrow-parens": [2, "as-needed"],
Expand Down
2 changes: 1 addition & 1 deletion install.js
Expand Up @@ -37,7 +37,7 @@ async function download() {
const downloadHost = process.env.PUPPETEER_DOWNLOAD_HOST || process.env.npm_config_puppeteer_download_host || process.env.npm_package_config_puppeteer_download_host;
const puppeteer = require('./index');
const product = process.env.PUPPETEER_PRODUCT || process.env.npm_config_puppeteer_product || process.env.npm_package_config_puppeteer_product || 'chrome';
const browserFetcher = puppeteer.createBrowserFetcher({ product, host: downloadHost });
const browserFetcher = puppeteer.createBrowserFetcher({product, host: downloadHost});
const revision = await getRevision();
await fetchBinary(revision);

Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -22,7 +22,8 @@
"prepublishOnly": "npm run tsc",
"dev-install": "npm run tsc && node install.js",
"install": "node install.js",
"lint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet -f codeframe . || eslint --ext js --ext ts .) && npm run tsc && npm run doc",
"eslint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet -f codeframe . || eslint --ext js --ext ts .)",
"lint": "npm run eslint && npm run tsc && npm run doc",
"doc": "node utils/doclint/cli.js",
"tsc": "tsc --version && tsc -p . && cp src/protocol.d.ts lib/ && cp src/externs.d.ts lib/",
"apply-next-version": "node utils/apply_next_version.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Browser.js
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const { helper, assert } = require('./helper');
const {helper, assert} = require('./helper');
const {Target} = require('./Target');
const EventEmitter = require('events');
const {TaskQueue} = require('./TaskQueue');
Expand Down
4 changes: 2 additions & 2 deletions src/Coverage.js
Expand Up @@ -273,8 +273,8 @@ class CSSCoverage {
function convertToDisjointRanges(nestedRanges) {
const points = [];
for (const range of nestedRanges) {
points.push({ offset: range.startOffset, type: 0, range });
points.push({ offset: range.endOffset, type: 1, range });
points.push({offset: range.startOffset, type: 0, range});
points.push({offset: range.endOffset, type: 1, range});
}
// Sort points to form a valid parenthesis sequence.
points.sort((a, b) => {
Expand Down
4 changes: 2 additions & 2 deletions src/EmulationManager.js
Expand Up @@ -38,11 +38,11 @@ class EmulationManager {
const height = viewport.height;
const deviceScaleFactor = viewport.deviceScaleFactor || 1;
/** @type {Protocol.Emulation.ScreenOrientation} */
const screenOrientation = viewport.isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' };
const screenOrientation = viewport.isLandscape ? {angle: 90, type: 'landscapePrimary'} : {angle: 0, type: 'portraitPrimary'};
const hasTouch = viewport.hasTouch || false;

await Promise.all([
this._client.send('Emulation.setDeviceMetricsOverride', { mobile, width, height, deviceScaleFactor, screenOrientation }),
this._client.send('Emulation.setDeviceMetricsOverride', {mobile, width, height, deviceScaleFactor, screenOrientation}),
this._client.send('Emulation.setTouchEmulationEnabled', {
enabled: hasTouch
})
Expand Down
2 changes: 1 addition & 1 deletion src/Events.js
Expand Up @@ -77,4 +77,4 @@ const Events = {
},
};

module.exports = { Events };
module.exports = {Events};
20 changes: 10 additions & 10 deletions src/ExecutionContext.js
Expand Up @@ -120,7 +120,7 @@ class ExecutionContext {
err.message += ' Are you passing a nested JSHandle?';
throw err;
}
const { exceptionDetails, result: remoteObject } = await callFunctionOnPromise.catch(rewriteError);
const {exceptionDetails, result: remoteObject} = await callFunctionOnPromise.catch(rewriteError);
if (exceptionDetails)
throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails));
return returnByValue ? helper.valueFromRemoteObject(remoteObject) : createJSHandle(this, remoteObject);
Expand All @@ -132,28 +132,28 @@ class ExecutionContext {
*/
function convertArgument(arg) {
if (typeof arg === 'bigint') // eslint-disable-line valid-typeof
return { unserializableValue: `${arg.toString()}n` };
return {unserializableValue: `${arg.toString()}n`};
if (Object.is(arg, -0))
return { unserializableValue: '-0' };
return {unserializableValue: '-0'};
if (Object.is(arg, Infinity))
return { unserializableValue: 'Infinity' };
return {unserializableValue: 'Infinity'};
if (Object.is(arg, -Infinity))
return { unserializableValue: '-Infinity' };
return {unserializableValue: '-Infinity'};
if (Object.is(arg, NaN))
return { unserializableValue: 'NaN' };
return {unserializableValue: 'NaN'};
const objectHandle = arg && (arg instanceof JSHandle) ? arg : null;
if (objectHandle) {
if (objectHandle._context !== this)
throw new Error('JSHandles can be evaluated only in the context they were created!');
if (objectHandle._disposed)
throw new Error('JSHandle is disposed!');
if (objectHandle._remoteObject.unserializableValue)
return { unserializableValue: objectHandle._remoteObject.unserializableValue };
return {unserializableValue: objectHandle._remoteObject.unserializableValue};
if (!objectHandle._remoteObject.objectId)
return { value: objectHandle._remoteObject.value };
return { objectId: objectHandle._remoteObject.objectId };
return {value: objectHandle._remoteObject.value};
return {objectId: objectHandle._remoteObject.objectId};
}
return { value: arg };
return {value: arg};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/FrameManager.js
Expand Up @@ -70,7 +70,7 @@ class FrameManager extends EventEmitter {
const {frameTree} = /** @type Protocol.Page.getFrameTreeReturnValue*/ (result[1]);
this._handleFrameTree(frameTree);
await Promise.all([
this._client.send('Page.setLifecycleEventsEnabled', { enabled: true }),
this._client.send('Page.setLifecycleEventsEnabled', {enabled: true}),
this._client.send('Runtime.enable', {}).then(() => this._ensureIsolatedWorld(UTILITY_WORLD_NAME)),
this._networkManager.initialize(),
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Input.js
Expand Up @@ -43,7 +43,7 @@ class Keyboard {
* @param {string} key
* @param {{text?: string}=} options
*/
async down(key, options = { text: undefined }) {
async down(key, options = {text: undefined}) {
const description = this._keyDescriptionForString(key);

const autoRepeat = this._pressedKeys.has(description.code);
Expand Down Expand Up @@ -312,4 +312,4 @@ class Touchscreen {
}
}

module.exports = { Keyboard, Mouse, Touchscreen};
module.exports = {Keyboard, Mouse, Touchscreen};
18 changes: 9 additions & 9 deletions src/JSHandle.js
Expand Up @@ -304,8 +304,8 @@ class ElementHandle extends JSHandle {
if (option.selected && !element.multiple)
break;
}
element.dispatchEvent(new Event('input', { bubbles: true }));
element.dispatchEvent(new Event('change', { bubbles: true }));
element.dispatchEvent(new Event('input', {bubbles: true}));
element.dispatchEvent(new Event('change', {bubbles: true}));
return options.filter(option => option.selected).map(option => option.value);
}, values);
}
Expand All @@ -321,9 +321,9 @@ class ElementHandle extends JSHandle {
// the cost unnecessarily.
const path = require('path');
const files = filePaths.map(filePath => path.resolve(filePath));
const { objectId } = this._remoteObject;
const { node } = await this._client.send('DOM.describeNode', { objectId });
const { backendNodeId } = node;
const {objectId} = this._remoteObject;
const {node} = await this._client.send('DOM.describeNode', {objectId});
const {backendNodeId} = node;

// The zero-length array is a special case, it seems that DOM.setFileInputFiles does
// not actually update the files in that case, so the solution is to eval the element
Expand All @@ -333,11 +333,11 @@ class ElementHandle extends JSHandle {
element.files = new DataTransfer().files;

// Dispatch events for this case because it should behave akin to a user action.
element.dispatchEvent(new Event('input', { bubbles: true }));
element.dispatchEvent(new Event('change', { bubbles: true }));
element.dispatchEvent(new Event('input', {bubbles: true}));
element.dispatchEvent(new Event('change', {bubbles: true}));
});
} else {
await this._client.send('DOM.setFileInputFiles', { objectId, files, backendNodeId });
await this._client.send('DOM.setFileInputFiles', {objectId, files, backendNodeId});
}
}

Expand Down Expand Up @@ -437,7 +437,7 @@ class ElementHandle extends JSHandle {
assert(boundingBox.width !== 0, 'Node has 0 width.');
assert(boundingBox.height !== 0, 'Node has 0 height.');

const { layoutViewport: { pageX, pageY } } = await this._client.send('Page.getLayoutMetrics');
const {layoutViewport: {pageX, pageY}} = await this._client.send('Page.getLayoutMetrics');

const clip = Object.assign({}, boundingBox);
clip.x += pageX;
Expand Down
10 changes: 5 additions & 5 deletions src/Launcher.js
Expand Up @@ -169,7 +169,7 @@ class BrowserRunner {
this.connection = new Connection(browserWSEndpoint, transport, slowMo);
} else {
// stdio was assigned during start(), and the 'pipe' option there adds the 4th and 5th items to stdio array
const { 3: pipeWrite, 4: pipeRead } = /** @type {!Array<any>} */ (this.proc.stdio);
const {3: pipeWrite, 4: pipeRead} = /** @type {!Array<any>} */ (this.proc.stdio);
const transport = new PipeTransport(/** @type {!NodeJS.WritableStream} */ pipeWrite, /** @type {!NodeJS.ReadableStream} */ pipeRead);
this.connection = new Connection('', transport, slowMo);
}
Expand Down Expand Up @@ -476,7 +476,7 @@ class FirefoxLauncher {
async _updateRevision() {
// replace 'latest' placeholder with actual downloaded revision
if (this._preferredRevision === 'latest') {
const browserFetcher = new BrowserFetcher(this._projectRoot, { product: this.product });
const browserFetcher = new BrowserFetcher(this._projectRoot, {product: this.product});
const localRevisions = await browserFetcher.localRevisions();
if (localRevisions[0])
this._preferredRevision = localRevisions[0];
Expand Down Expand Up @@ -743,7 +743,7 @@ class FirefoxLauncher {
*/
function waitForWSEndpoint(browserProcess, timeout, preferredRevision) {
return new Promise((resolve, reject) => {
const rl = readline.createInterface({ input: browserProcess.stderr });
const rl = readline.createInterface({input: browserProcess.stderr});
let stderr = '';
const listeners = [
helper.addEventListener(rl, 'line', onLine),
Expand Down Expand Up @@ -802,7 +802,7 @@ function getWSEndpoint(browserURL) {

const endpointURL = URL.resolve(browserURL, '/json/version');
const protocol = endpointURL.startsWith('https') ? https : http;
const requestOptions = Object.assign(URL.parse(endpointURL), { method: 'GET' });
const requestOptions = Object.assign(URL.parse(endpointURL), {method: 'GET'});
const request = protocol.request(requestOptions, res => {
let data = '';
if (res.statusCode !== 200) {
Expand Down Expand Up @@ -836,7 +836,7 @@ function resolveExecutablePath(launcher) {
const executablePath = process.env.PUPPETEER_EXECUTABLE_PATH || process.env.npm_config_puppeteer_executable_path || process.env.npm_package_config_puppeteer_executable_path;
if (executablePath) {
const missingText = !fs.existsSync(executablePath) ? 'Tried to use PUPPETEER_EXECUTABLE_PATH env variable to launch browser but did not find any executable at: ' + executablePath : null;
return { executablePath, missingText };
return {executablePath, missingText};
}
}
const browserFetcher = new BrowserFetcher(launcher._projectRoot, {product: launcher.product});
Expand Down
6 changes: 3 additions & 3 deletions src/NetworkManager.js
Expand Up @@ -82,7 +82,7 @@ class NetworkManager extends EventEmitter {
assert(helper.isString(value), `Expected value of header "${key}" to be String, but "${typeof value}" is found.`);
this._extraHTTPHeaders[key.toLowerCase()] = value;
}
await this._client.send('Network.setExtraHTTPHeaders', { headers: this._extraHTTPHeaders });
await this._client.send('Network.setExtraHTTPHeaders', {headers: this._extraHTTPHeaders});
}

/**
Expand Down Expand Up @@ -112,7 +112,7 @@ class NetworkManager extends EventEmitter {
* @param {string} userAgent
*/
async setUserAgent(userAgent) {
await this._client.send('Network.setUserAgentOverride', { userAgent });
await this._client.send('Network.setUserAgentOverride', {userAgent});
}

/**
Expand Down Expand Up @@ -192,7 +192,7 @@ class NetworkManager extends EventEmitter {
const {username, password} = this._credentials || {username: undefined, password: undefined};
this._client.send('Fetch.continueWithAuth', {
requestId: event.requestId,
authChallengeResponse: { response, username, password },
authChallengeResponse: {response, username, password},
}).catch(debugError);
}

Expand Down
38 changes: 19 additions & 19 deletions src/Page.js
Expand Up @@ -184,7 +184,7 @@ class Page extends EventEmitter {
* @param {!{longitude: number, latitude: number, accuracy: (number|undefined)}} options
*/
async setGeolocation(options) {
const { longitude, latitude, accuracy = 0} = options;
const {longitude, latitude, accuracy = 0} = options;
if (longitude < -180 || longitude > 180)
throw new Error(`Invalid longitude "${longitude}": precondition -180 <= LONGITUDE <= 180 failed.`);
if (latitude < -90 || latitude > 90)
Expand Down Expand Up @@ -424,7 +424,7 @@ class Page extends EventEmitter {
});
await this.deleteCookie(...items);
if (items.length)
await this._client.send('Network.setCookies', { cookies: items });
await this._client.send('Network.setCookies', {cookies: items});
}

/**
Expand Down Expand Up @@ -579,7 +579,7 @@ class Page extends EventEmitter {
else
expression = helper.evaluationString(deliverErrorValue, name, seq, error);
}
this._client.send('Runtime.evaluate', { expression, contextId: event.executionContextId }).catch(debugError);
this._client.send('Runtime.evaluate', {expression, contextId: event.executionContextId}).catch(debugError);

/**
* @param {string} name
Expand Down Expand Up @@ -806,14 +806,14 @@ class Page extends EventEmitter {
if (this._javascriptEnabled === enabled)
return;
this._javascriptEnabled = enabled;
await this._client.send('Emulation.setScriptExecutionDisabled', { value: !enabled });
await this._client.send('Emulation.setScriptExecutionDisabled', {value: !enabled});
}

/**
* @param {boolean} enabled
*/
async setBypassCSP(enabled) {
await this._client.send('Page.setBypassCSP', { enabled });
await this._client.send('Page.setBypassCSP', {enabled});
}

/**
Expand Down Expand Up @@ -885,7 +885,7 @@ class Page extends EventEmitter {
*/
async evaluateOnNewDocument(pageFunction, ...args) {
const source = helper.evaluationString(pageFunction, ...args);
await this._client.send('Page.addScriptToEvaluateOnNewDocument', { source });
await this._client.send('Page.addScriptToEvaluateOnNewDocument', {source});
}

/**
Expand Down Expand Up @@ -951,20 +951,20 @@ class Page extends EventEmitter {
const height = Math.ceil(metrics.contentSize.height);

// Overwrite clip for full page at all times.
clip = { x: 0, y: 0, width, height, scale: 1 };
clip = {x: 0, y: 0, width, height, scale: 1};
const {
isMobile = false,
deviceScaleFactor = 1,
isLandscape = false
} = this._viewport || {};
/** @type {!Protocol.Emulation.ScreenOrientation} */
const screenOrientation = isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' };
await this._client.send('Emulation.setDeviceMetricsOverride', { mobile: isMobile, width, height, deviceScaleFactor, screenOrientation });
const screenOrientation = isLandscape ? {angle: 90, type: 'landscapePrimary'} : {angle: 0, type: 'portraitPrimary'};
await this._client.send('Emulation.setDeviceMetricsOverride', {mobile: isMobile, width, height, deviceScaleFactor, screenOrientation});
}
const shouldSetDefaultBackground = options.omitBackground && format === 'png';
if (shouldSetDefaultBackground)
await this._client.send('Emulation.setDefaultBackgroundColorOverride', { color: { r: 0, g: 0, b: 0, a: 0 } });
const result = await this._client.send('Page.captureScreenshot', { format, quality: options.quality, clip });
await this._client.send('Emulation.setDefaultBackgroundColorOverride', {color: {r: 0, g: 0, b: 0, a: 0}});
const result = await this._client.send('Page.captureScreenshot', {format, quality: options.quality, clip});
if (shouldSetDefaultBackground)
await this._client.send('Emulation.setDefaultBackgroundColorOverride');

Expand Down Expand Up @@ -1056,7 +1056,7 @@ class Page extends EventEmitter {
if (runBeforeUnload) {
await this._client.send('Page.close');
} else {
await this._client._connection.send('Target.closeTarget', { targetId: this._target._targetId });
await this._client._connection.send('Target.closeTarget', {targetId: this._target._targetId});
await this._target._isClosedPromise;
}
}
Expand Down Expand Up @@ -1235,13 +1235,13 @@ Page.PaperFormats = {
legal: {width: 8.5, height: 14},
tabloid: {width: 11, height: 17},
ledger: {width: 17, height: 11},
a0: {width: 33.1, height: 46.8 },
a1: {width: 23.4, height: 33.1 },
a2: {width: 16.54, height: 23.4 },
a3: {width: 11.7, height: 16.54 },
a4: {width: 8.27, height: 11.7 },
a5: {width: 5.83, height: 8.27 },
a6: {width: 4.13, height: 5.83 },
a0: {width: 33.1, height: 46.8},
a1: {width: 23.4, height: 33.1},
a2: {width: 16.54, height: 23.4},
a3: {width: 11.7, height: 16.54},
a4: {width: 8.27, height: 11.7},
a5: {width: 5.83, height: 8.27},
a6: {width: 4.13, height: 5.83},
};

const unitToPixels = {
Expand Down
2 changes: 1 addition & 1 deletion src/Target.js
Expand Up @@ -132,7 +132,7 @@ class Target {
* @return {?Puppeteer.Target}
*/
opener() {
const { openerId } = this._targetInfo;
const {openerId} = this._targetInfo;
if (!openerId)
return null;
return this.browser()._targets.get(openerId);
Expand Down
2 changes: 1 addition & 1 deletion src/TaskQueue.ts
Expand Up @@ -33,4 +33,4 @@ class TaskQueue {
}
}

export = { TaskQueue };
export = {TaskQueue};
2 changes: 1 addition & 1 deletion src/helper.ts
Expand Up @@ -112,7 +112,7 @@ export interface PuppeteerEventListener {

function addEventListener(emitter: NodeJS.EventEmitter, eventName: string|symbol, handler: (...args: any[]) => void): PuppeteerEventListener {
emitter.on(eventName, handler);
return { emitter, eventName, handler };
return {emitter, eventName, handler};
}

function removeEventListeners(listeners: Array<{emitter: NodeJS.EventEmitter; eventName: string|symbol; handler: (...args: any[]) => void}>): void {
Expand Down