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

Upgrade ESlint v8 to v9 #235

Merged
merged 1 commit into from
Oct 6, 2024
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
20 changes: 10 additions & 10 deletions BvgFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const Log = require("logger");
const pjson = require("./package.json");

module.exports = class BvgFetcher {
constructor(config) {
constructor (config) {
this.config = config;
}

async init() {
async init () {
const {createClient} = await import("hafas-client");
const {profile} = await import("hafas-client/p/bvg/index.js");
this.hafasClient = createClient(
Expand All @@ -16,30 +16,30 @@ module.exports = class BvgFetcher {
);
}

getIdentifier() {
getIdentifier () {
return this.config.identifier;
}

getStationId() {
getStationId () {
return this.config.stationId;
}

async getStationName() {
async getStationName () {
const station = await this.hafasClient.stop(this.config.stationId);
return this.config.shortenStationNames
? shortenStationName(station.name)
: station.name;
}

async getDirectionDescriptor() {
async getDirectionDescriptor () {
if (typeof this.config.directionStationId === "undefined") {
return "all directions";
}
const station = await this.hafasClient.stop(this.config.directionStationId);
return station.name;
}

async fetchDepartures() {
async fetchDepartures () {
// when value for a request is calculated to be 5 minutes before travelTimeToStation time
// so we can also show the non-reachable departures in the module
let when;
Expand Down Expand Up @@ -81,7 +81,7 @@ module.exports = class BvgFetcher {
return processedDepartures;
}

processData(data) {
processData (data) {
const departuresData = {
fetcherId: this.config.identifier,
departuresArray: []
Expand Down Expand Up @@ -127,7 +127,7 @@ module.exports = class BvgFetcher {
return departuresData;
}

static compareTimes(a, b) {
static compareTimes (a, b) {
if (a.when < b.when) {
return -1;
}
Expand All @@ -138,7 +138,7 @@ module.exports = class BvgFetcher {
}

// helper function to print departure for debugging
static printDeparture(row) {
static printDeparture (row) {
const delayMinutes = Math.floor(
row.delay % 31536000 % 86400 % 3600 / 60
);
Expand Down
32 changes: 16 additions & 16 deletions MMM-PublicTransportBerlin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Module.register("MMM-PublicTransportBerlin", {
shortenStationNames: true // Shorten station names? See https://github.com/derhuerst/vbb-short-station-name
},

start() {
start () {
Log.info(
`Starting module: ${this.name} with identifier: ${this.identifier}`
);
Expand Down Expand Up @@ -93,7 +93,7 @@ Module.register("MMM-PublicTransportBerlin", {
}
},

getDom() {
getDom () {
const wrapper = document.createElement("div");
wrapper.className = "ptb-wrapper";

Expand Down Expand Up @@ -200,7 +200,7 @@ Module.register("MMM-PublicTransportBerlin", {
return wrapper;
},

getRowOpacity(i, reachableDeparturePos) {
getRowOpacity (i, reachableDeparturePos) {
// Per default, opacity is at 100%
let opacity = 1;

Expand Down Expand Up @@ -241,7 +241,7 @@ Module.register("MMM-PublicTransportBerlin", {
return opacity;
},

getRuleRow() {
getRuleRow () {
const ruleRow = document.createElement("tr");

const ruleTimeCell = document.createElement("td");
Expand All @@ -255,7 +255,7 @@ Module.register("MMM-PublicTransportBerlin", {
return ruleRow;
},

getTableHeaderRow() {
getTableHeaderRow () {
const headerRow = document.createElement("tr");

// Cell for departure time
Expand Down Expand Up @@ -309,7 +309,7 @@ Module.register("MMM-PublicTransportBerlin", {
return headerRow;
},

getNoDeparturesRow(message) {
getNoDeparturesRow (message) {
const row = document.createElement("tr");
const cell = document.createElement("td");

Expand All @@ -321,7 +321,7 @@ Module.register("MMM-PublicTransportBerlin", {
return row;
},

getRow(currentDeparture) {
getRow (currentDeparture) {
let currentWhen = moment(currentDeparture.when).tz(this.config.timezone);
const delay = this.convertDelayToMinutes(currentDeparture.delay);

Expand Down Expand Up @@ -395,7 +395,7 @@ Module.register("MMM-PublicTransportBerlin", {
return row;
},

getDepartureTimeWithoutDelay(departureTime, delay) {
getDepartureTimeWithoutDelay (departureTime, delay) {
if (delay > 0) {
departureTime.subtract(delay, "minutes");
} else if (delay < 0) {
Expand All @@ -405,7 +405,7 @@ Module.register("MMM-PublicTransportBerlin", {
return departureTime;
},

getFirstReachableDeparturePosition() {
getFirstReachableDeparturePosition () {
const now = moment();
const nowWithDelay = now.add(this.config.travelTimeToStation, "minutes");
let result = 0;
Expand All @@ -429,7 +429,7 @@ Module.register("MMM-PublicTransportBerlin", {
return result;
},

trimDirectionString(string) {
trimDirectionString (string) {
let dirString = string;

if (dirString.indexOf(",") > -1) {
Expand All @@ -444,7 +444,7 @@ Module.register("MMM-PublicTransportBerlin", {
return dirString;
},

getLineSymbol(product) {
getLineSymbol (product) {
const symbol = document.createElement("div");

if (product.type === "express") {
Expand All @@ -471,26 +471,26 @@ Module.register("MMM-PublicTransportBerlin", {
return symbol;
},

convertDelayToMinutes(delay) {
convertDelayToMinutes (delay) {
return Math.floor(delay % 31536000 % 86400 % 3600 / 60);
},

getTranslations() {
getTranslations () {
return {
en: "translations/en.json",
de: "translations/de.json"
};
},

getStyles() {
getStyles () {
return ["style.css", "font-awesome.css"];
},

getScripts() {
getScripts () {
return ["moment.js", "moment-timezone.js"];
},

socketNotificationReceived(notification, payload) {
socketNotificationReceived (notification, payload) {
if (payload.fetcherId === this.identifier) {
switch (notification) {
case "FETCHER_INITIALIZED":
Expand Down
21 changes: 11 additions & 10 deletions convenience/query_stations.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-console */
import * as readline from "node:readline";
// eslint-disable-next-line import-x/namespace
import {createClient} from "hafas-client";

let profileName = "";
Expand All @@ -11,7 +12,7 @@ const productMap = {};
* @param {array} array An array that could have duplicate values.
* @returns {array} An array without duplicate values.
*/
function arrayUnique(array) {
function arrayUnique (array) {
return [...new Set(array)];
}

Expand All @@ -21,7 +22,7 @@ function arrayUnique(array) {
* @param {object} products An object with the available transport products as a keys.
* @returns {string} A list of transport products as a string.
*/
function refineProducts(products) {
function refineProducts (products) {
if (!products) {
return "none";
}
Expand All @@ -42,7 +43,7 @@ function refineProducts(products) {
*
* @param {object} station The station it's about.
*/
function printStationInfo(station) {
function printStationInfo (station) {
if (station.id && station.name) {
console.info(
` > Stop: ${station.name}\n ID: ${
Expand All @@ -52,7 +53,7 @@ function printStationInfo(station) {
}
}

function query(profile) {
function query (profile) {
if (profile !== "" && profile !== undefined) {
const client = createClient(profile, "MMM-PublicTransportHafas");
const rl = readline.createInterface({
Expand All @@ -64,10 +65,10 @@ function query(profile) {
rl.close();

const opt = {
results: 10,
stations: true,
adresses: false,
poi: false
poi: false,
results: 10,
stations: true
};

client
Expand All @@ -92,7 +93,7 @@ if (process.argv.length === 3) {
profileName = "bvg";
}

async function importProfile() {
async function importProfile () {
const {profile} = await import(`hafas-client/p/${profileName}/index.js`);

Object.keys(profile.products).forEach((key) => {
Expand All @@ -106,6 +107,6 @@ async function importProfile() {

try {
importProfile();
} catch (e) {
console.error(`${e.message}\n\n Did you choose the right profile name? \n`);
} catch (error) {
console.error(`${error.message}\n\n Did you choose the right profile name? \n`);
}
49 changes: 40 additions & 9 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import eslintPluginImport from "eslint-plugin-import";
import eslintPluginImportX from "eslint-plugin-import-x";
import eslintPluginJs from "@eslint/js";
import eslintPluginJsonc from "eslint-plugin-jsonc";
import eslintPluginStylistic from "@stylistic/eslint-plugin";
import globals from "globals";

export default [
const config = [
eslintPluginJs.configs.all,
eslintPluginImport.flatConfigs.recommended,
eslintPluginImportX.flatConfigs.recommended,
...eslintPluginJsonc.configs["flat/recommended-with-json"],
{
files: ["**/*.js", "**/*.mjs"],
files: ["**/*.js"],
languageOptions: {
ecmaVersion: "latest",
globals: {
...globals.browser,
...globals.node,
config: "readonly"
}
},
sourceType: "commonjs"
},
plugins: {
...eslintPluginStylistic.configs["all-flat"].plugins
Expand All @@ -31,15 +32,13 @@ export default [
"@stylistic/multiline-comment-style": "off",
"@stylistic/multiline-ternary": "off",
"@stylistic/no-multi-spaces": "off",
"@stylistic/quote-props": ["error", "as-needed"],
"@stylistic/padded-blocks": ["error", "never"],
"@stylistic/space-before-function-paren": "off",
"@stylistic/quote-props": ["error", "as-needed"],
"capitalized-comments": "off",
"consistent-this": "off",
"default-case": "off",
"func-style": "off",
"id-length": "off",
"import/namespace": "off",
"init-declarations": "off",
"line-comment-position": "off",
"max-lines": "off",
Expand All @@ -56,10 +55,42 @@ export default [
"prefer-destructuring": "off",
"prefer-named-capture-group": "off",
"require-await": "warn",
"sort-keys": "off"
"sort-keys": "off",
strict: "off"
}
},
{
files: ["**/*.mjs"],
languageOptions: {
ecmaVersion: "latest",
globals: {
...globals.node
},
sourceType: "module"
},
plugins: {
...eslintPluginStylistic.configs["all-flat"].plugins
},
rules: {
...eslintPluginStylistic.configs["all-flat"].rules,
"@stylistic/array-element-newline": "off",
"@stylistic/dot-location": ["error", "property"],
"@stylistic/function-call-argument-newline": ["error", "consistent"],
"@stylistic/function-paren-newline": "off",
"@stylistic/indent": ["error", 2],
"@stylistic/padded-blocks": ["error", "never"],
"@stylistic/quote-props": ["error", "as-needed"],
"func-style": "off",
"max-lines-per-function": ["error", 100],
"no-magic-numbers": "off",
"no-undefined": "off",
"one-var": "off",
"prefer-destructuring": "off"
}
},
{
ignores: ["package-lock.json"]
}
];

export default config;
Loading