Skip to content

Commit

Permalink
Generic linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zabil committed Aug 12, 2024
1 parent 94e6e87 commit 52dddf9
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 64 deletions.
18 changes: 9 additions & 9 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const defaultConfig = {
: false,
criConnectionRetries: process.env.TAIKO_CRI_CONNECTION_RETRIES || 50,
firefox:
(process.env.TAIKO_BROWSER_PATH?.toLowerCase().includes("firefox")) ||
false,
highlightOnAction:
process.env.TAIKO_BROWSER_PATH?.toLowerCase().includes("firefox")
? false
: process.env.TAIKO_HIGHLIGHT_ON_ACTION
? process.env.TAIKO_HIGHLIGHT_ON_ACTION.toLowerCase() === "true"
: true,
process.env.TAIKO_BROWSER_PATH?.toLowerCase().includes("firefox") || false,
highlightOnAction: process.env.TAIKO_BROWSER_PATH?.toLowerCase().includes(
"firefox",
)
? false
: process.env.TAIKO_HIGHLIGHT_ON_ACTION
? process.env.TAIKO_HIGHLIGHT_ON_ACTION.toLowerCase() === "true"
: true,
blockAlignment: "nearest",
inlineAlignment: "nearest",
useHostName: false,
Expand All @@ -33,7 +33,7 @@ const setConfig = (options) => {
if (typeof defaultConfig[key] !== typeof options[key]) {
throw new Error(
`Invalid value for ${key}. Expected ${typeof defaultConfig[
key
key
]} received ${typeof options[key]}`,
);
}
Expand Down
21 changes: 12 additions & 9 deletions lib/elementSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ function match(text, options = {}, ...args) {
nodeFilter,
);

const exactMatches = [],
containsMatches = [];
const exactMatches = [];
const containsMatches = [];

function checkIfRegexMatch(text, searchText, exactMatch) {
return exactMatch
Expand Down Expand Up @@ -141,7 +141,8 @@ function match(text, options = {}, ...args) {
) {
exactMatches.push(node);
continue;
} else if (
}
if (
// Contains match of values and types
!args.exactMatch &&
(checkIfRegexMatch(node.value, searchText, false) ||
Expand Down Expand Up @@ -218,16 +219,16 @@ const $$ = async (selector) => {

const $$xpath = async (selector) => {
logQuery(`xpath - ${selector}`);
var xpathFunc = (selector) => {
var result = [];
var nodesSnapshot = document.evaluate(
const xpathFunc = (selector) => {
const result = [];
const nodesSnapshot = document.evaluate(
selector,
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null,
);
for (var i = 0; i < nodesSnapshot.snapshotLength; i++) {
for (let i = 0; i < nodesSnapshot.snapshotLength; i++) {
result.push(nodesSnapshot.snapshotItem(i));
}
return result;
Expand Down Expand Up @@ -284,9 +285,11 @@ const findElements = async (selector, tag) => {
const elements = await (async () => {
if (isString(selector)) {
return match(selector).elements(tag);
} else if (isSelector(selector)) {
}
if (isSelector(selector)) {
return selector.elements();
} else if (isElement(selector)) {
}
if (isElement(selector)) {
return [selector];
}
return null;
Expand Down
4 changes: 2 additions & 2 deletions lib/eventBus.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const EventEmitter = require("events");
const util = require("util");
const EventEmitter = require("node:events");
const util = require("node:util");
const { removeQuotes, symbols } = require("../lib/util");

const eventHandler = new EventEmitter();
Expand Down
38 changes: 18 additions & 20 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* Few modifications are done on the file.
*/

const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
let projectRoot = null;
const descEvent = require("./eventBus").descEvent;

Expand Down Expand Up @@ -96,7 +96,7 @@ const isStrictObject = (obj) =>
(obj.constructor === Object || obj.constructor.name === "Object");

function wait(time) {
var promise = new Promise((resolve) =>
const promise = new Promise((resolve) =>
setTimeout(() => {
resolve();
}, time),
Expand All @@ -116,8 +116,8 @@ const commandlineArgs = () => {
};

const sleep = (milliseconds) => {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
const start = new Date().getTime();
for (let i = 0; i < 1e7; i++) {
if (new Date().getTime() - start > milliseconds) {
break;
}
Expand All @@ -128,7 +128,7 @@ const waitUntil = async (condition, retryInterval, retryTimeout, message) => {
if (!retryTimeout) {
return;
}
var start = new Date().getTime();
const start = new Date().getTime();
while (true) {
let actualError;
try {
Expand All @@ -154,20 +154,18 @@ const waitUntil = async (condition, retryInterval, retryTimeout, message) => {
};

const xpath = (s) =>
`concat(${
s
.match(/[^'"]+|['"]/g)
.map((part) => {
if (part === "'") {
return '"\'"';
}
if (part === '"') {
return "'\"'";
}
return "'" + part + "'";
})
.join(",") + ', ""'
})`;
`concat(${`${s
.match(/[^'"]+|['"]/g)
.map((part) => {
if (part === "'") {
return '"\'"';
}
if (part === '"') {
return "'\"'";
}
return `'${part}'`;
})
.join(",")}, ""`})`;

const handleUrlRedirection = (url) => {
if (url.substr(-1) === "/") {
Expand Down
2 changes: 1 addition & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let lastDownloadedBytes = 0;
* @return {!Promise}
*/
function onSuccess(localRevisions) {
console.log("Chromium downloaded to " + revisionInfo.folderPath);
console.log(`Chromium downloaded to ${revisionInfo.folderPath}`);
localRevisions = localRevisions.filter(
(revision) => revision !== revisionInfo.revision,
);
Expand Down
10 changes: 4 additions & 6 deletions lib/plugins.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const childProcess = require("child_process");
const path = require("path");
const fs = require("node:fs");
const childProcess = require("node:child_process");
const path = require("node:path");

const pluginHooks = {
preConnectionHook: (target, options) => {
Expand Down Expand Up @@ -91,9 +91,7 @@ function filterExecutablePlugin(plugins, pluginsPath) {
return plugins
.filter((npmModule) => {
const packageJson = getPackageJsonForPlugin(pluginsPath, npmModule);
return (
packageJson.capability && packageJson.capability.includes("subcommands")
);
return packageJson.capability?.includes("subcommands");
})
.reduce((plugins, plugin) => {
plugins[plugin.replace(/^taiko-/, "")] = path.join(pluginsPath, plugin);
Expand Down
4 changes: 2 additions & 2 deletions lib/proximityElementSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class RelativeSearchElement {
}

async validNodes(objectId) {
let matchingNode,
minDiff = Number.POSITIVE_INFINITY;
let matchingNode;
let minDiff = Number.POSITIVE_INFINITY;
this.calculatedRects = this.calculatedRects.length
? this.calculatedRects
: await this.findProximityElementRects();
Expand Down
10 changes: 6 additions & 4 deletions lib/repl/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ function displayUsageFor(name) {
if (e.returns) {
e.returns.map((e) => {
console.log(
`Returns: ${type(e.type)} ${e.description.type ? desc(e.description) : e.description
`Returns: ${type(e.type)} ${
e.description.type ? desc(e.description) : e.description
}${EOL}`,
);
});
Expand Down Expand Up @@ -442,9 +443,10 @@ const params = (p) => {
return p
.map(
(p) =>
`* ${param(p)}${p.properties
? p.properties.map((p) => ` * ${param(p)}`).join("")
: ""
`* ${param(p)}${
p.properties
? p.properties.map((p) => ` * ${param(p)}`).join("")
: ""
}`,
)
.join("");
Expand Down
22 changes: 11 additions & 11 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const isWin = require("os").platform() === "win32";
const Module = require("module");
const nodeURL = require("url");
const path = require("path");
const { spawnSync } = require("child_process");
const { readFileSync, existsSync, realpathSync } = require("fs");
const isWin = require("node:os").platform() === "win32";
const Module = require("node:module");
const nodeURL = require("node:url");
const path = require("node:path");
const { spawnSync } = require("node:child_process");
const { readFileSync, existsSync, realpathSync } = require("node:fs");

module.exports.removeQuotes = (textWithQuotes, textWithoutQuotes) => {
return textWithQuotes
Expand All @@ -21,12 +21,12 @@ module.exports.isTaikoRunner = (path) => {
try {
if (!path.includes("taiko.js")) {
const link = realpathSync(path);
return link && link.includes("taiko.js");
return link?.includes("taiko.js");
}
return path && path.includes("taiko.js");
return path?.includes("taiko.js");
} catch (e) {
return Module._nodeModulePaths("taiko").some(
(val) => path === val + ".bin/taiko",
(val) => path === `${val}.bin/taiko`,
);
}
};
Expand Down Expand Up @@ -58,7 +58,7 @@ module.exports.isSameUrl = (url1, url2) => {
};

module.exports.escapeHtml = (str) => {
var chars = {
const chars = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
Expand All @@ -78,7 +78,7 @@ module.exports.taikoInstallationLocation = () => {
}
let installLocation = "";
const jsonData = JSON.parse(readFileSync(packageJSONFilePath, "utf-8"));
if (jsonData.dependencies && jsonData.dependencies.taiko) {
if (jsonData.dependencies?.taiko) {
installLocation = path.join(
spawnSync("npm", ["root"]).output[1].toString().trim(),
"taiko",
Expand Down

0 comments on commit 52dddf9

Please sign in to comment.