From 502efefbe5ef97afb0f5cf9306abf33a81dfc332 Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Wed, 18 Sep 2024 23:27:31 +0200 Subject: [PATCH] Handle linter issues --- BvgFetcher.js | 8 ++++---- MMM-PublicTransportBerlin.js | 27 +++++++++++++++------------ convenience/query_stations.mjs | 10 +++++++--- node_helper.js | 4 +--- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/BvgFetcher.js b/BvgFetcher.js index 7ad8017..8dae35a 100644 --- a/BvgFetcher.js +++ b/BvgFetcher.js @@ -8,8 +8,8 @@ module.exports = class BvgFetcher { } async init() { - const { createClient } = await import("hafas-client"); - const { profile } = await import(`hafas-client/p/bvg/index.js`); + const {createClient} = await import("hafas-client"); + const {profile} = await import("hafas-client/p/bvg/index.js"); this.hafasClient = createClient( profile, `MMM-PublicTransportBerlin v${pjson.version}` @@ -95,7 +95,7 @@ module.exports = class BvgFetcher { // TODO: Make real stop/station handling here // Quick fix to work around missing station objects if (!row.station) { - row.station = row.stop; // eslint-disable-line no-param-reassign + row.station = row.stop; } // If log level is set to debug print infos about departures @@ -140,7 +140,7 @@ module.exports = class BvgFetcher { // helper function to print departure for debugging static printDeparture(row) { const delayMinutes = Math.floor( - (((row.delay % 31536000) % 86400) % 3600) / 60 + row.delay % 31536000 % 86400 % 3600 / 60 ); const time = new Date(row.when).toLocaleTimeString([], { diff --git a/MMM-PublicTransportBerlin.js b/MMM-PublicTransportBerlin.js index 62fbc13..a66623f 100644 --- a/MMM-PublicTransportBerlin.js +++ b/MMM-PublicTransportBerlin.js @@ -163,8 +163,8 @@ Module.register("MMM-PublicTransportBerlin", { this.departuresArray.forEach((currentDeparture, i) => { if ( i >= - reachableDeparturePos - - this.config.maxUnreachableDepartures && + reachableDeparturePos - + this.config.maxUnreachableDepartures && i < reachableDeparturePos + this.config.maxReachableDepartures ) { // Insert rule to separate reachable from unreachable departures @@ -213,7 +213,7 @@ Module.register("MMM-PublicTransportBerlin", { if (i >= reachableDeparturePos - steps && i < reachableDeparturePos) { const currentStep = reachableDeparturePos - i; - opacity = 1 - ((1 / steps) * currentStep - 0.2); + opacity = 1 - (1 / steps * currentStep - 0.2); } } @@ -234,7 +234,7 @@ Module.register("MMM-PublicTransportBerlin", { const steps = this.config.maxReachableDepartures - startingPoint; if (i >= startingPoint) { const currentStep = i - reachableDeparturePos - startingPoint; - opacity = 1 - (1 / steps) * currentStep; + opacity = 1 - 1 / steps * currentStep; } } @@ -420,9 +420,9 @@ Module.register("MMM-PublicTransportBerlin", { if (depArray.length > 1 && i < depArray.length - 1) { const nextWhen = moment(depArray[i + 1].when); if ( - (currentWhen.isBefore(nowWithDelay) && - nextWhen.isSameOrAfter(nowWithDelay)) || - (i === 0 && nextWhen.isSameOrAfter(nowWithDelay)) + currentWhen.isBefore(nowWithDelay) && + nextWhen.isSameOrAfter(nowWithDelay) || + i === 0 && nextWhen.isSameOrAfter(nowWithDelay) ) { resolve(i); } @@ -445,9 +445,9 @@ Module.register("MMM-PublicTransportBerlin", { dirString = dirString.split(",")[0]; } - const viaIndex = dirString.search(/( via )/g); + const viaIndex = dirString.search(/( via )/gu); if (viaIndex > -1) { - dirString = dirString.split(/( via )/g)[0]; + dirString = dirString.split(/( via )/gu)[0]; } return dirString; @@ -457,8 +457,11 @@ Module.register("MMM-PublicTransportBerlin", { const symbol = document.createElement("div"); if (product.type === "express") { - if (product.name === "LOCOMORE") symbol.innerHTML = "LOC"; - else symbol.innerHTML = "ICE"; + if (product.name === "LOCOMORE") { + symbol.innerHTML = "LOC"; + } else { + symbol.innerHTML = "ICE"; + } } else { symbol.innerHTML = product.name; } @@ -478,7 +481,7 @@ Module.register("MMM-PublicTransportBerlin", { }, convertDelayToMinutes(delay) { - return Math.floor((((delay % 31536000) % 86400) % 3600) / 60); + return Math.floor(delay % 31536000 % 86400 % 3600 / 60); }, getTranslations() { diff --git a/convenience/query_stations.mjs b/convenience/query_stations.mjs index 9f8ef95..d57ced9 100755 --- a/convenience/query_stations.mjs +++ b/convenience/query_stations.mjs @@ -1,6 +1,6 @@ /* eslint-disable no-console */ -import { createClient } from "hafas-client"; import * as readline from "node:readline"; +import {createClient} from "hafas-client"; let profileName = ""; const productMap = {}; @@ -92,8 +92,8 @@ if (process.argv.length === 3) { profileName = "bvg"; } -try { - const { profile } = await import(`hafas-client/p/${profileName}/index.js`); +async function importProfile() { + const {profile} = await import(`hafas-client/p/${profileName}/index.js`); Object.keys(profile.products).forEach((key) => { const productMapKey = profile.products[key].id; @@ -102,6 +102,10 @@ try { }); query(profile); +} + +try { + importProfile(); } catch (e) { console.error(`${e.message}\n\n Did you choose the right profile name? \n`); } diff --git a/node_helper.js b/node_helper.js index 7daf3ea..3a90303 100644 --- a/node_helper.js +++ b/node_helper.js @@ -78,9 +78,7 @@ module.exports = NodeHelper.create({ this.pimpDeparturesArray(departuresData.departuresArray); this.sendSocketNotification("DEPARTURES_FETCHED", departuresData); } catch (error) { - Log.log( - `Error while fetching departures (for module instance ${fetcherId}): ${error}` - ); + Log.log(`Error while fetching departures (for module instance ${fetcherId}): ${error}`); // Add stationId to error for identification in the main instance error.fetcherId = fetcherId; error.message = error;