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

introduce eslint along with prettier for stylecheck #930 #974

Merged
merged 1 commit into from
Dec 20, 2019
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
19 changes: 11 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
"mocha": true,
"jest/globals": true
},
"extends": "eslint:recommended",
"ignorePatterns": [".local-chromium", "node_modules/", "test/functional-tests/reports/"],
"extends": ["eslint:recommended", "prettier"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
"plugins": ["jest"],
"plugins": ["jest", "prettier"],
"rules": {
"no-control-regex" : 0,
"indent": [
"error",
4
"prettier/prettier": [
"error"
],
"no-control-regex" : 0,
"quotes": [
"error",
"single"
"single",
"avoid-escape"
],
"no-constant-condition": [
"error",
Expand All @@ -38,6 +39,8 @@
"error",
"always"
],
"no-console": 0
"no-console": 0,
"curly": 2,
"require-atomic-updates": 0
}
}
26 changes: 0 additions & 26 deletions .eslintrc.json

This file was deleted.

7 changes: 5 additions & 2 deletions bin/runFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ module.exports = async (
global[func] = function() {
return realFuncs[func].apply(this, arguments);
};
} else global[func] = taiko[func];
} else {
global[func] = taiko[func];
}
if (continueRepl) {
recorder.repl = async () => {
console.log(
Expand All @@ -68,8 +70,9 @@ module.exports = async (
if (
process.env.TAIKO_DISABLE_LOGOUT &&
process.env.TAIKO_DISABLE_LOGOUT.toLowerCase() !== 'false'
)
) {
return;
}
desc = symbols.pass + desc;
desc = removeQuotes(util.inspect(desc, { colors: true }), desc);
console.log(desc);
Expand Down
11 changes: 7 additions & 4 deletions bin/taiko.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ let taiko;
function printVersion() {
const packageJson = require('../package.json');
let hash = 'RELEASE';
if (packageJson._resolved && packageJson._resolved.includes('#'))
if (packageJson._resolved && packageJson._resolved.includes('#')) {
hash = packageJson._resolved.split('#')[1];
}
return `Version: ${packageJson.version} (Chromium: ${packageJson.taiko.chromium_version}) ${hash}`;
}

async function exitOnUnhandledFailures(e) {
if (!repl_mode) {
console.error(e);
if (taiko && (await taiko.client())) await taiko.closeBrowser();
if (taiko && (await taiko.client())) {
await taiko.closeBrowser();
}
process.exit(1);
}
}
Expand All @@ -46,9 +49,9 @@ function validate(file) {
}

function setupEmulateDevice(device) {
if (Object.prototype.hasOwnProperty.call(devices, device))
if (Object.prototype.hasOwnProperty.call(devices, device)) {
process.env['TAIKO_EMULATE_DEVICE'] = device;
else {
} else {
console.log(`Invalid value ${device} for --emulate-device`);
console.log(
`Available devices: ${Object.keys(devices).join(', ')}`,
Expand Down
8 changes: 6 additions & 2 deletions docs/layout/assets/js/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* eslint-env jquery */
/* global algoliaSearch*/
/* global hljs*/

$(document).ready(function() {
init();
algoliaSearch();
Expand Down Expand Up @@ -28,7 +32,7 @@ $(document).ready(function() {
}
});

$sidebar = $('.sidebar');
const $sidebar = $('.sidebar');
$window
.resize(function resize() {
if ($window.width() < 991) {
Expand Down Expand Up @@ -116,7 +120,7 @@ function copyCode(element) {
.prev()
.text();
var $copied_text = $(this).nextAll('.copied-text');
codeBox = $(this).next();
const codeBox = $(this).next();
codeBox.val(value);
codeBox.select();
document.execCommand('copy');
Expand Down
8 changes: 6 additions & 2 deletions examples/browserLauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ const screenCastEnabled =

module.exports.openBrowserAndStartScreencast = async outFile => {
await openBrowser({ args: ['--no-first-run', '--no-sandbox'] });
if (screenCastEnabled) await startScreencast(outFile);
if (screenCastEnabled) {
await startScreencast(outFile);
}
};

module.exports.closeBrowserAndStopScreencast = async () => {
if (screenCastEnabled) await stopScreencast();
if (screenCastEnabled) {
await stopScreencast();
}
await closeBrowser();
};
4 changes: 3 additions & 1 deletion examples/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ var server = app.listen(3000, async () => {
failed = true;
}
});
if (failed) process.exit(1);
if (failed) {
process.exit(1);
}
});
77 changes: 55 additions & 22 deletions lib/browserFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ function existsAsync(filePath) {
}

function archiveName(platform, revision) {
if (platform === 'linux') return 'chrome-linux';
if (platform === 'mac') return 'chrome-mac';
if (platform === 'linux') {
return 'chrome-linux';
}
if (platform === 'mac') {
return 'chrome-mac';
}
if (platform === 'win32' || platform === 'win64') {
// Windows archive name changed at r591479.
return parseInt(revision, 10) > 591479
Expand Down Expand Up @@ -87,10 +91,13 @@ class BrowserFetcher {
this._platform = options.platform || '';
if (!this._platform) {
const platform = os.platform();
if (platform === 'darwin') this._platform = 'mac';
else if (platform === 'linux') this._platform = 'linux';
else if (platform === 'win32')
if (platform === 'darwin') {
this._platform = 'mac';
} else if (platform === 'linux') {
this._platform = 'linux';
} else if (platform === 'win32') {
this._platform = os.arch() === 'x64' ? 'win64' : 'win32';
}
assert(
this._platform,
'Unsupported platform: ' + os.platform(),
Expand Down Expand Up @@ -148,27 +155,34 @@ class BrowserFetcher {
`download-${this._platform}-${revision}.zip`,
);
const folderPath = this._getFolderPath(revision);
if (await existsAsync(folderPath))
if (await existsAsync(folderPath)) {
return this.revisionInfo(revision);
if (!(await existsAsync(this._downloadsFolder)))
}
if (!(await existsAsync(this._downloadsFolder))) {
await mkdirAsync(this._downloadsFolder);
}
try {
await downloadFile(url, zipPath, progressCallback);
await extractZip(zipPath, folderPath);
} finally {
if (await existsAsync(zipPath)) await unlinkAsync(zipPath);
if (await existsAsync(zipPath)) {
await unlinkAsync(zipPath);
}
}
const revisionInfo = this.revisionInfo(revision);
if (revisionInfo)
if (revisionInfo) {
await chmodAsync(revisionInfo.executablePath, 0o755);
}
return revisionInfo;
}

/**
* @return {!Promise<!Array<string>>}
*/
async localRevisions() {
if (!(await existsAsync(this._downloadsFolder))) return [];
if (!(await existsAsync(this._downloadsFolder))) {
return [];
}
const fileNames = await readdirAsync(this._downloadsFolder);
return fileNames
.map(fileName => parseFolderPath(fileName))
Expand Down Expand Up @@ -196,7 +210,7 @@ class BrowserFetcher {
revisionInfo(revision) {
const folderPath = this._getFolderPath(revision);
let executablePath = '';
if (this._platform === 'mac')
if (this._platform === 'mac') {
executablePath = path.join(
folderPath,
archiveName(this._platform, revision),
Expand All @@ -205,19 +219,24 @@ class BrowserFetcher {
'MacOS',
'Chromium',
);
else if (this._platform === 'linux')
} else if (this._platform === 'linux') {
executablePath = path.join(
folderPath,
archiveName(this._platform, revision),
'chrome',
);
else if (this._platform === 'win32' || this._platform === 'win64')
} else if (
this._platform === 'win32' ||
this._platform === 'win64'
) {
executablePath = path.join(
folderPath,
archiveName(this._platform, revision),
'chrome.exe',
);
else throw 'Unsupported platform: ' + this._platform;
} else {
throw 'Unsupported platform: ' + this._platform;
}
const url = downloadURL(
this._platform,
this._downloadHost,
Expand Down Expand Up @@ -251,7 +270,9 @@ class BrowserFetcher {
missingText,
executablePath,
} = this._resolveExecutablePath();
if (missingText) throw new Error(missingText);
if (missingText) {
throw new Error(missingText);
}
return executablePath;
}

Expand Down Expand Up @@ -305,7 +326,9 @@ class BrowserFetcher {
const match = line.match(
/^DevTools listening on (ws:\/\/.*)$/,
);
if (!match) return;
if (!match) {
return;
}
cleanup();
const endpoint = {
host: url.parse(match[1]).hostname,
Expand All @@ -315,7 +338,9 @@ class BrowserFetcher {
}

function cleanup() {
if (timeoutId) clearTimeout(timeoutId);
if (timeoutId) {
clearTimeout(timeoutId);
}
helper.removeEventListeners(listeners);
}
});
Expand All @@ -342,9 +367,13 @@ module.exports = BrowserFetcher;
function parseFolderPath(folderPath) {
const name = path.basename(folderPath);
const splits = name.split('-');
if (splits.length !== 2) return null;
if (splits.length !== 2) {
return null;
}
const [platform, revision] = splits;
if (!supportedPlatforms.includes(platform)) return null;
if (!supportedPlatforms.includes(platform)) {
return null;
}
return { platform, revision };
}

Expand Down Expand Up @@ -382,7 +411,9 @@ function downloadFile(url, destinationPath, progressCallback) {
/** @type {string} */ (response.headers['content-length']),
10,
);
if (progressCallback) response.on('data', onData);
if (progressCallback) {
response.on('data', onData);
}
});
request.on('error', error => reject(error));
return promise;
Expand Down Expand Up @@ -425,9 +456,11 @@ function httpRequest(url, method, response) {
res.statusCode >= 300 &&
res.statusCode < 400 &&
res.headers.location
)
) {
httpRequest(res.headers.location, method, response);
else response(res);
} else {
response(res);
}
});
request.end();
return request;
Expand Down
3 changes: 2 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ const defaultConfig = {
const setConfig = options => {
for (const key in options) {
if (Object.prototype.hasOwnProperty.call(defaultConfig, key)) {
if (typeof defaultConfig[key] !== typeof options[key])
if (typeof defaultConfig[key] !== typeof options[key]) {
throw new Error(
`Invalid value for ${key}. Expected ${typeof defaultConfig[
key
]} received ${typeof options[key]}`,
);
}
defaultConfig[key] = options[key];
} else {
throw new Error(
Expand Down
Loading