From 611729a761798aa0f53a8afe1a8324a690d07be5 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 21 Oct 2020 13:33:08 +0000 Subject: [PATCH 1/2] Replace variables with const --- app/index.js | 4 ++-- app/scripts/url-helper.js | 2 +- test/index-test.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/index.js b/app/index.js index 9c1add9..f1ce2cc 100644 --- a/app/index.js +++ b/app/index.js @@ -498,13 +498,13 @@ async function loginF95(browser, username, password) { let message = ""; // Check if the user is logged in - let success = await page.evaluate( + const success = await page.evaluate( /* istanbul ignore next */ (selector) => document.querySelector(selector) !== null, selectorK.AVATAR_INFO ); - let errorMessageExists = await page.evaluate( + const errorMessageExists = await page.evaluate( /* istanbul ignore next */ (selector) => document.querySelector(selector) !== null, diff --git a/app/scripts/url-helper.js b/app/scripts/url-helper.js index 5669ac3..221a56c 100644 --- a/app/scripts/url-helper.js +++ b/app/scripts/url-helper.js @@ -52,7 +52,7 @@ module.exports.urlExists = async function (url, checkRedirect) { if (!valid) return false; if (checkRedirect) { - let redirectUrl = await exports.getUrlRedirect(url); + const redirectUrl = await exports.getUrlRedirect(url); if (redirectUrl === url) valid = true; else valid = false; } diff --git a/test/index-test.js b/test/index-test.js index b8ce53e..d406f4e 100644 --- a/test/index-test.js +++ b/test/index-test.js @@ -172,8 +172,8 @@ describe("Search game data", function () { expect(result, "Without being logged should return null").to.be.null; }); it("Test game serialization", function() { - let json = JSON.stringify(testGame); - let parsedGameInfo = JSON.parse(json); + const json = JSON.stringify(testGame); + const parsedGameInfo = JSON.parse(json); expect(parsedGameInfo).to.be.equal(testGame); }); }); From c789b1f4abcaf8ba007d943221e71b42696fe0df Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 21 Oct 2020 13:33:20 +0000 Subject: [PATCH 2/2] Format code with prettier This commit fixes the style issues introduced in 611729a according to the output from prettier. Details: https://deepsource.io/gh/MillenniumEarl/F95API/transform/e85ee086-383c-4d69-b8e4-1d96a62a2790/ --- app/index.js | 21 ++++++++++++++------- test/index-test.js | 15 +++++++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/index.js b/app/index.js index f1ce2cc..403781d 100644 --- a/app/index.js +++ b/app/index.js @@ -114,7 +114,9 @@ module.exports.login = async function (username, password) { } // Else, log in throught browser - shared.logger.info("No saved sessions or expired session, login on the platform"); + shared.logger.info( + "No saved sessions or expired session, login on the platform" + ); if (_browser === null && !shared.isolation) _browser = await prepareBrowser(); const browser = shared.isolation ? await prepareBrowser() : _browser; @@ -267,7 +269,8 @@ module.exports.getGameDataFromURL = async function (url) { // Check URL const exists = await urlHelper.urlExists(url); if (!exists) throw new URIError(url + " is not a valid URL"); - if (!urlHelper.isF95URL(url)) throw new Error(url + " is not a valid F95Zone URL"); + if (!urlHelper.isF95URL(url)) + throw new Error(url + " is not a valid F95Zone URL"); // Gets the search results of the game being searched for if (_browser === null && !shared.isolation) _browser = await prepareBrowser(); @@ -393,7 +396,9 @@ function isCookieExpired(cookie) { const expirationDate = new Date(expirationUnixTimestamp * 1000); if (expirationDate < Date.now()) { - shared.logger.warn("Cookie " + cookie.name + " expired, you need to re-authenticate"); + shared.logger.warn( + "Cookie " + cookie.name + " expired, you need to re-authenticate" + ); expiredCookies = true; } } @@ -506,10 +511,9 @@ async function loginF95(browser, username, password) { const errorMessageExists = await page.evaluate( /* istanbul ignore next */ - (selector) => - document.querySelector(selector) !== null, + (selector) => document.querySelector(selector) !== null, selectorK.LOGIN_MESSAGE_ERROR - ) + ); // Save cookies to avoid re-auth if (success) { @@ -525,7 +529,10 @@ async function loginF95(browser, username, password) { if (errorMessage === "Incorrect password. Please try again.") { message = "Incorrect password"; - } else if (errorMessage ==='The requested user \'' + username + '\' could not be found.') { + } else if ( + errorMessage === + "The requested user '" + username + "' could not be found." + ) { // The escaped quotes are important! message = "Incorrect username"; } else message = errorMessage; diff --git a/test/index-test.js b/test/index-test.js index d406f4e..31bdecb 100644 --- a/test/index-test.js +++ b/test/index-test.js @@ -171,7 +171,7 @@ describe("Search game data", function () { const result = await F95API.getGameData("Kingdom of Deception", false); expect(result, "Without being logged should return null").to.be.null; }); - it("Test game serialization", function() { + it("Test game serialization", function () { const json = JSON.stringify(testGame); const parsedGameInfo = JSON.parse(json); expect(parsedGameInfo).to.be.equal(testGame); @@ -257,15 +257,22 @@ describe("Test url-helper", function () { expect(exists).to.be.false; // Now check for more specific URLs (with redirect)... - exists = urlHelper.urlExists("https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/"); + exists = urlHelper.urlExists( + "https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/" + ); expect(exists).to.be.true; - exists = urlHelper.urlExists("https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/", true); + exists = urlHelper.urlExists( + "https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/", + true + ); expect(exists).to.be.false; }); it("Check if URL belong to the platform", async function () { - let belong = urlHelper.isF95URL("https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/"); + let belong = urlHelper.isF95URL( + "https://f95zone.to/threads/perverted-education-v0-9601-april-ryan.1854/" + ); expect(belong).to.be.true; belong = urlHelper.isF95URL("https://www.google/");