From 5f38c532600a257e7c92079e58014e23bf21d787 Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Wed, 22 Mar 2023 23:53:10 +0100 Subject: [PATCH] Revise require imports (#3071) - order (external first) - remove superfluous file extensions - new line after imports - deconstruct (only one time (in `check_config.js`)) - fix path (only one time (in `global-setup.js`)) --- .eslintrc.json | 3 +- CHANGELOG.md | 3 +- js/app.js | 2 +- js/check_config.js | 6 +- js/electron.js | 4 +- js/node_helper.js | 4 +- js/server.js | 14 +- js/server_functions.js | 2 +- modules/default/calendar/calendarfetcher.js | 11 +- modules/default/calendar/calendarutils.js | 4 +- modules/default/calendar/debug.js | 2 +- modules/default/calendar/node_helper.js | 2 +- modules/default/newsfeed/newsfeedfetcher.js | 11 +- modules/default/newsfeed/node_helper.js | 2 +- .../default/updatenotification/node_helper.js | 4 +- package-lock.json | 394 ++++++++++++++++++ package.json | 1 + serveronly/index.js | 2 +- tests/e2e/helpers/global-setup.js | 2 +- tests/e2e/helpers/weather-functions.js | 2 +- tests/e2e/modules/calendar_spec.js | 2 +- tests/e2e/modules/clock_spec.js | 2 +- tests/e2e/translations_spec.js | 2 +- tests/electron/env_spec.js | 2 +- tests/electron/helpers/weather-setup.js | 2 +- tests/unit/classes/translator_spec.js | 1 + tests/unit/classes/utils_spec.js | 2 +- tests/unit/functions/calendar_spec.js | 2 +- tests/unit/functions/weather_object_spec.js | 4 +- tests/unit/modules/default/utils_spec.js | 3 +- .../default/weather/weather_utils_spec.js | 2 +- tests/utils/weather_mocker.js | 2 +- 32 files changed, 451 insertions(+), 50 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 4460b034..c1bf1cb5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,6 @@ { "extends": ["eslint:recommended", "plugin:prettier/recommended", "plugin:jsdoc/recommended"], - "plugins": ["prettier", "jsdoc", "jest"], + "plugins": ["prettier", "import", "jsdoc", "jest"], "env": { "browser": true, "es2022": true, @@ -23,6 +23,7 @@ }, "rules": { "eqeqeq": "error", + "import/order": "error", "no-prototype-builtins": "off", "no-throw-literal": "error", "no-unused-vars": "off", diff --git a/CHANGELOG.md b/CHANGELOG.md index 15d3c1b3..3aeb8914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,7 @@ _This release is scheduled to be released on 2023-04-01._ - Update `stylelint` dependencies, switch to `stylelint-config-standard` and handle `stylelint` issues, update `main.css` matching new rules - Update Eslint config, add new rule and handle issue - Convert lots of callbacks to async/await -- Fixed Open-Meteo wind speed units +- Revise require imports ### Fixed @@ -58,6 +58,7 @@ _This release is scheduled to be released on 2023-04-01._ - Fix e2e tests (failed after async changes) by running calendar and newsfeed tests last - Lint: Use template literals instead of string concatenation - Fix default alert module to render HTML for title and message +- Fixed Open-Meteo wind speed units ## [2.22.0] - 2023-01-01 diff --git a/js/app.js b/js/app.js index dbd299e5..22127b66 100644 --- a/js/app.js +++ b/js/app.js @@ -10,11 +10,11 @@ require("module-alias/register"); const fs = require("fs"); const path = require("path"); +const envsub = require("envsub"); const Log = require("logger"); const Server = require(`${__dirname}/server`); const Utils = require(`${__dirname}/utils`); const defaultModules = require(`${__dirname}/../modules/default/defaultmodules`); -const envsub = require("envsub"); // Get version number. global.version = require(`${__dirname}/../package.json`).version; diff --git a/js/check_config.js b/js/check_config.js index abc0940b..24368734 100644 --- a/js/check_config.js +++ b/js/check_config.js @@ -5,11 +5,11 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ -const Linter = require("eslint").Linter; -const linter = new Linter(); - const path = require("path"); const fs = require("fs"); +const { Linter } = require("eslint"); + +const linter = new Linter(); const rootPath = path.resolve(`${__dirname}/../`); const Log = require(`${rootPath}/js/logger.js`); diff --git a/js/electron.js b/js/electron.js index 13247cea..8a474bb3 100644 --- a/js/electron.js +++ b/js/electron.js @@ -1,8 +1,8 @@ "use strict"; const electron = require("electron"); -const core = require("./app.js"); -const Log = require("logger"); +const core = require("./app"); +const Log = require("./logger"); // Config let config = process.env.config ? JSON.parse(process.env.config) : {}; diff --git a/js/node_helper.js b/js/node_helper.js index 31c87e30..03c6dca7 100644 --- a/js/node_helper.js +++ b/js/node_helper.js @@ -4,9 +4,9 @@ * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. */ -const Class = require("./class.js"); -const Log = require("logger"); const express = require("express"); +const Log = require("logger"); +const Class = require("./class"); const NodeHelper = Class.extend({ init() { diff --git a/js/server.js b/js/server.js index 515a1a1f..14546217 100644 --- a/js/server.js +++ b/js/server.js @@ -4,18 +4,18 @@ * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. */ -const express = require("express"); -const path = require("path"); -const ipfilter = require("express-ipfilter").IpFilter; const fs = require("fs"); -const helmet = require("helmet"); -const socketio = require("socket.io"); const http = require("http"); const https = require("https"); +const path = require("path"); +const express = require("express"); +const ipfilter = require("express-ipfilter").IpFilter; +const helmet = require("helmet"); +const socketio = require("socket.io"); const Log = require("logger"); -const Utils = require("./utils.js"); -const { cors, getConfig, getHtml, getVersion } = require("./server_functions.js"); +const Utils = require("./utils"); +const { cors, getConfig, getHtml, getVersion } = require("./server_functions"); /** * Server diff --git a/js/server_functions.js b/js/server_functions.js index 9a70e664..6ecc6cae 100644 --- a/js/server_functions.js +++ b/js/server_functions.js @@ -1,7 +1,7 @@ -const fetch = require("./fetch"); const fs = require("fs"); const path = require("path"); const Log = require("logger"); +const fetch = require("./fetch"); /** * Gets the config. diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 0a032d73..00688ee2 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -4,13 +4,14 @@ * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. */ -const CalendarUtils = require("./calendarutils"); -const Log = require("logger"); -const NodeHelper = require("node_helper"); + +const https = require("https"); +const digest = require("digest-fetch"); const ical = require("node-ical"); const fetch = require("fetch"); -const digest = require("digest-fetch"); -const https = require("https"); +const Log = require("logger"); +const NodeHelper = require("node_helper"); +const CalendarUtils = require("./calendarutils"); /** * diff --git a/modules/default/calendar/calendarutils.js b/modules/default/calendar/calendarutils.js index 4ccb827e..64a7b9f4 100644 --- a/modules/default/calendar/calendarutils.js +++ b/modules/default/calendar/calendarutils.js @@ -8,10 +8,10 @@ /** * @external Moment */ -const moment = require("moment"); const path = require("path"); +const moment = require("moment"); const zoneTable = require(path.join(__dirname, "windowsZones.json")); -const Log = require("../../../js/logger.js"); +const Log = require("../../../js/logger"); const CalendarUtils = { /** diff --git a/modules/default/calendar/debug.js b/modules/default/calendar/debug.js index 08cd3770..5e19e131 100644 --- a/modules/default/calendar/debug.js +++ b/modules/default/calendar/debug.js @@ -8,7 +8,7 @@ // Alias modules mentioned in package.js under _moduleAliases. require("module-alias/register"); -const CalendarFetcher = require("./calendarfetcher.js"); +const CalendarFetcher = require("./calendarfetcher"); const url = "https://calendar.google.com/calendar/ical/pkm1t2uedjbp0uvq1o7oj1jouo%40group.calendar.google.com/private-08ba559f89eec70dd74bbd887d0a3598/basic.ics"; // Standard test URL //const url = "https://www.googleapis.com/calendar/v3/calendars/primary/events/"; // URL for Bearer auth (must be configured in Google OAuth2 first) diff --git a/modules/default/calendar/node_helper.js b/modules/default/calendar/node_helper.js index 437d279e..08e6158b 100644 --- a/modules/default/calendar/node_helper.js +++ b/modules/default/calendar/node_helper.js @@ -5,8 +5,8 @@ * MIT Licensed. */ const NodeHelper = require("node_helper"); -const CalendarFetcher = require("./calendarfetcher.js"); const Log = require("logger"); +const CalendarFetcher = require("./calendarfetcher"); module.exports = NodeHelper.create({ // Override start method. diff --git a/modules/default/newsfeed/newsfeedfetcher.js b/modules/default/newsfeed/newsfeedfetcher.js index f5e088f9..039a3ea5 100644 --- a/modules/default/newsfeed/newsfeedfetcher.js +++ b/modules/default/newsfeed/newsfeedfetcher.js @@ -4,12 +4,13 @@ * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. */ -const Log = require("logger"); -const FeedMe = require("feedme"); -const NodeHelper = require("node_helper"); -const fetch = require("fetch"); -const iconv = require("iconv-lite"); + const stream = require("stream"); +const FeedMe = require("feedme"); +const iconv = require("iconv-lite"); +const fetch = require("fetch"); +const Log = require("logger"); +const NodeHelper = require("node_helper"); /** * Responsible for requesting an update on the set interval and broadcasting the data. diff --git a/modules/default/newsfeed/node_helper.js b/modules/default/newsfeed/node_helper.js index 4e6594ee..534b7020 100644 --- a/modules/default/newsfeed/node_helper.js +++ b/modules/default/newsfeed/node_helper.js @@ -6,8 +6,8 @@ */ const NodeHelper = require("node_helper"); -const NewsfeedFetcher = require("./newsfeedfetcher.js"); const Log = require("logger"); +const NewsfeedFetcher = require("./newsfeedfetcher"); module.exports = NodeHelper.create({ // Override start method. diff --git a/modules/default/updatenotification/node_helper.js b/modules/default/updatenotification/node_helper.js index 9db4354f..ae3e0375 100644 --- a/modules/default/updatenotification/node_helper.js +++ b/modules/default/updatenotification/node_helper.js @@ -1,6 +1,6 @@ -const GitHelper = require("./git_helper"); -const defaultModules = require("../defaultmodules"); const NodeHelper = require("node_helper"); +const defaultModules = require("../defaultmodules"); +const GitHelper = require("./git_helper"); const ONE_MINUTE = 60 * 1000; diff --git a/package-lock.json b/package-lock.json index 185d001d..be572de5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ }, "devDependencies": { "eslint-config-prettier": "^8.7.0", + "eslint-plugin-import": "^2.27.5", "eslint-plugin-jest": "^27.2.1", "eslint-plugin-jsdoc": "^40.1.0", "eslint-plugin-prettier": "^4.2.1", @@ -1489,6 +1490,12 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "node_modules/@types/json5": { + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", + "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", + "dev": true + }, "node_modules/@types/keyv": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.4.tgz", @@ -1936,6 +1943,25 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, + "node_modules/array-includes": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.6.tgz", + "integrity": "sha512-sgTbLvL6cNnw24FnbaDyjmvddQ2ML8arZsgaJhoABMoplz/4QRhtrYS+alr1BUM1Bwp6dhx8vVCBSLG+StwOFw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4", + "get-intrinsic": "^1.1.3", + "is-string": "^1.0.7" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/array-union": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", @@ -1945,6 +1971,42 @@ "node": ">=8" } }, + "node_modules/array.prototype.flat": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.1.tgz", + "integrity": "sha512-roTU0KWIOmJ4DRLmwKd19Otg0/mT3qPNt0Qb3GWW8iObuZXxrjB/pzn0R3hqpRSWg4HCwqx+0vwOnWnvlOyeIA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4", + "es-shim-unscopables": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/array.prototype.flatmap": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/array.prototype.flatmap/-/array.prototype.flatmap-1.3.1.tgz", + "integrity": "sha512-8UGn9O1FDVvMNB0UlLv4voxRMze7+FpHyF5mSMRjWHUMlpoDViniy05870VlxhfgTnLbpuwTzvD76MTtWxB/mQ==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4", + "es-shim-unscopables": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/arrify": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-2.0.1.tgz", @@ -3161,6 +3223,15 @@ "node": ">= 0.4" } }, + "node_modules/es-shim-unscopables": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-shim-unscopables/-/es-shim-unscopables-1.0.0.tgz", + "integrity": "sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w==", + "dev": true, + "dependencies": { + "has": "^1.0.3" + } + }, "node_modules/es-to-primitive": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", @@ -3349,6 +3420,102 @@ "eslint": ">=7.0.0" } }, + "node_modules/eslint-import-resolver-node": { + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.7.tgz", + "integrity": "sha512-gozW2blMLJCeFpBwugLTGyvVjNoeo1knonXAcatC6bjPBZitotxdWf7Gimr25N4c0AAOo4eOUfaG82IJPDpqCA==", + "dev": true, + "dependencies": { + "debug": "^3.2.7", + "is-core-module": "^2.11.0", + "resolve": "^1.22.1" + } + }, + "node_modules/eslint-import-resolver-node/node_modules/debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "dependencies": { + "ms": "^2.1.1" + } + }, + "node_modules/eslint-module-utils": { + "version": "2.7.4", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.7.4.tgz", + "integrity": "sha512-j4GT+rqzCoRKHwURX7pddtIPGySnX9Si/cgMI5ztrcqOPtk5dDEeZ34CQVPphnqkJytlc97Vuk05Um2mJ3gEQA==", + "dev": true, + "dependencies": { + "debug": "^3.2.7" + }, + "engines": { + "node": ">=4" + }, + "peerDependenciesMeta": { + "eslint": { + "optional": true + } + } + }, + "node_modules/eslint-module-utils/node_modules/debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "dependencies": { + "ms": "^2.1.1" + } + }, + "node_modules/eslint-plugin-import": { + "version": "2.27.5", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.27.5.tgz", + "integrity": "sha512-LmEt3GVofgiGuiE+ORpnvP+kAm3h6MLZJ4Q5HCyHADofsb4VzXFsRiWj3c0OFiV+3DWFh0qg3v9gcPlfc3zRow==", + "dev": true, + "dependencies": { + "array-includes": "^3.1.6", + "array.prototype.flat": "^1.3.1", + "array.prototype.flatmap": "^1.3.1", + "debug": "^3.2.7", + "doctrine": "^2.1.0", + "eslint-import-resolver-node": "^0.3.7", + "eslint-module-utils": "^2.7.4", + "has": "^1.0.3", + "is-core-module": "^2.11.0", + "is-glob": "^4.0.3", + "minimatch": "^3.1.2", + "object.values": "^1.1.6", + "resolve": "^1.22.1", + "semver": "^6.3.0", + "tsconfig-paths": "^3.14.1" + }, + "engines": { + "node": ">=4" + }, + "peerDependencies": { + "eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" + } + }, + "node_modules/eslint-plugin-import/node_modules/debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "dependencies": { + "ms": "^2.1.1" + } + }, + "node_modules/eslint-plugin-import/node_modules/doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "dependencies": { + "esutils": "^2.0.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/eslint-plugin-jest": { "version": "27.2.1", "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.2.1.tgz", @@ -6465,6 +6632,23 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/object.values": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.6.tgz", + "integrity": "sha512-FVVTkD1vENCsAcwNs9k6jea2uHC/X0+JcjG8YA60FN5CMaJmG95wT9jek/xX9nornqGRrBkKtzuAu2wuHpKqvw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/on-finished": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", @@ -8439,6 +8623,39 @@ "node": ">=8" } }, + "node_modules/tsconfig-paths": { + "version": "3.14.2", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz", + "integrity": "sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g==", + "dev": true, + "dependencies": { + "@types/json5": "^0.0.29", + "json5": "^1.0.2", + "minimist": "^1.2.6", + "strip-bom": "^3.0.0" + } + }, + "node_modules/tsconfig-paths/node_modules/json5": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", + "dev": true, + "dependencies": { + "minimist": "^1.2.0" + }, + "bin": { + "json5": "lib/cli.js" + } + }, + "node_modules/tsconfig-paths/node_modules/strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -10060,6 +10277,12 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "@types/json5": { + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", + "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", + "dev": true + }, "@types/keyv": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.4.tgz", @@ -10395,12 +10618,49 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, + "array-includes": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.6.tgz", + "integrity": "sha512-sgTbLvL6cNnw24FnbaDyjmvddQ2ML8arZsgaJhoABMoplz/4QRhtrYS+alr1BUM1Bwp6dhx8vVCBSLG+StwOFw==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4", + "get-intrinsic": "^1.1.3", + "is-string": "^1.0.7" + } + }, "array-union": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", "dev": true }, + "array.prototype.flat": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.1.tgz", + "integrity": "sha512-roTU0KWIOmJ4DRLmwKd19Otg0/mT3qPNt0Qb3GWW8iObuZXxrjB/pzn0R3hqpRSWg4HCwqx+0vwOnWnvlOyeIA==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4", + "es-shim-unscopables": "^1.0.0" + } + }, + "array.prototype.flatmap": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/array.prototype.flatmap/-/array.prototype.flatmap-1.3.1.tgz", + "integrity": "sha512-8UGn9O1FDVvMNB0UlLv4voxRMze7+FpHyF5mSMRjWHUMlpoDViniy05870VlxhfgTnLbpuwTzvD76MTtWxB/mQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4", + "es-shim-unscopables": "^1.0.0" + } + }, "arrify": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-2.0.1.tgz", @@ -11291,6 +11551,15 @@ "has-tostringtag": "^1.0.0" } }, + "es-shim-unscopables": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-shim-unscopables/-/es-shim-unscopables-1.0.0.tgz", + "integrity": "sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w==", + "dev": true, + "requires": { + "has": "^1.0.3" + } + }, "es-to-primitive": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", @@ -11431,6 +11700,91 @@ "dev": true, "requires": {} }, + "eslint-import-resolver-node": { + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.7.tgz", + "integrity": "sha512-gozW2blMLJCeFpBwugLTGyvVjNoeo1knonXAcatC6bjPBZitotxdWf7Gimr25N4c0AAOo4eOUfaG82IJPDpqCA==", + "dev": true, + "requires": { + "debug": "^3.2.7", + "is-core-module": "^2.11.0", + "resolve": "^1.22.1" + }, + "dependencies": { + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + } + } + }, + "eslint-module-utils": { + "version": "2.7.4", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.7.4.tgz", + "integrity": "sha512-j4GT+rqzCoRKHwURX7pddtIPGySnX9Si/cgMI5ztrcqOPtk5dDEeZ34CQVPphnqkJytlc97Vuk05Um2mJ3gEQA==", + "dev": true, + "requires": { + "debug": "^3.2.7" + }, + "dependencies": { + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + } + } + }, + "eslint-plugin-import": { + "version": "2.27.5", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.27.5.tgz", + "integrity": "sha512-LmEt3GVofgiGuiE+ORpnvP+kAm3h6MLZJ4Q5HCyHADofsb4VzXFsRiWj3c0OFiV+3DWFh0qg3v9gcPlfc3zRow==", + "dev": true, + "requires": { + "array-includes": "^3.1.6", + "array.prototype.flat": "^1.3.1", + "array.prototype.flatmap": "^1.3.1", + "debug": "^3.2.7", + "doctrine": "^2.1.0", + "eslint-import-resolver-node": "^0.3.7", + "eslint-module-utils": "^2.7.4", + "has": "^1.0.3", + "is-core-module": "^2.11.0", + "is-glob": "^4.0.3", + "minimatch": "^3.1.2", + "object.values": "^1.1.6", + "resolve": "^1.22.1", + "semver": "^6.3.0", + "tsconfig-paths": "^3.14.1" + }, + "dependencies": { + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + } + } + }, "eslint-plugin-jest": { "version": "27.2.1", "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.2.1.tgz", @@ -13736,6 +14090,17 @@ "object-keys": "^1.1.1" } }, + "object.values": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.6.tgz", + "integrity": "sha512-FVVTkD1vENCsAcwNs9k6jea2uHC/X0+JcjG8YA60FN5CMaJmG95wT9jek/xX9nornqGRrBkKtzuAu2wuHpKqvw==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.20.4" + } + }, "on-finished": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", @@ -15185,6 +15550,35 @@ "integrity": "sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==", "dev": true }, + "tsconfig-paths": { + "version": "3.14.2", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz", + "integrity": "sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g==", + "dev": true, + "requires": { + "@types/json5": "^0.0.29", + "json5": "^1.0.2", + "minimist": "^1.2.6", + "strip-bom": "^3.0.0" + }, + "dependencies": { + "json5": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", + "dev": true, + "requires": { + "minimist": "^1.2.0" + } + }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "dev": true + } + } + }, "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", diff --git a/package.json b/package.json index 40611843..480d0052 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "homepage": "https://magicmirror.builders", "devDependencies": { "eslint-config-prettier": "^8.7.0", + "eslint-plugin-import": "^2.27.5", "eslint-plugin-jest": "^27.2.1", "eslint-plugin-jsdoc": "^40.1.0", "eslint-plugin-prettier": "^4.2.1", diff --git a/serveronly/index.js b/serveronly/index.js index 62f0619a..7f81dc11 100644 --- a/serveronly/index.js +++ b/serveronly/index.js @@ -1,5 +1,5 @@ -const app = require("../js/app.js"); const Log = require("logger"); +const app = require("../js/app"); app.start().then((config) => { const bindAddress = config.address ? config.address : "localhost"; diff --git a/tests/e2e/helpers/global-setup.js b/tests/e2e/helpers/global-setup.js index cc84431e..b79c1f1f 100644 --- a/tests/e2e/helpers/global-setup.js +++ b/tests/e2e/helpers/global-setup.js @@ -13,7 +13,7 @@ exports.startApplication = async (configFilename, exec) => { process.env.MM_CONFIG_FILE = configFilename; } if (exec) exec; - global.app = require("app.js"); + global.app = require("../../../js/app"); return global.app.start(); }; diff --git a/tests/e2e/helpers/weather-functions.js b/tests/e2e/helpers/weather-functions.js index b3fe2280..e28eb9de 100644 --- a/tests/e2e/helpers/weather-functions.js +++ b/tests/e2e/helpers/weather-functions.js @@ -1,5 +1,5 @@ -const helpers = require("./global-setup"); const { injectMockData } = require("../../utils/weather_mocker"); +const helpers = require("./global-setup"); exports.getText = async (element, result) => { const elem = await helpers.waitForElement(element); diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index f4fed1d4..6932f124 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -1,5 +1,5 @@ const helpers = require("../helpers/global-setup"); -const serverBasicAuth = require("../helpers/basic-auth.js"); +const serverBasicAuth = require("../helpers/basic-auth"); describe("Calendar module", () => { /** diff --git a/tests/e2e/modules/clock_spec.js b/tests/e2e/modules/clock_spec.js index 9867b077..1ffa74a1 100644 --- a/tests/e2e/modules/clock_spec.js +++ b/tests/e2e/modules/clock_spec.js @@ -1,5 +1,5 @@ -const helpers = require("../helpers/global-setup"); const moment = require("moment"); +const helpers = require("../helpers/global-setup"); describe("Clock module", () => { afterAll(async () => { diff --git a/tests/e2e/translations_spec.js b/tests/e2e/translations_spec.js index f389f9a4..ec138757 100644 --- a/tests/e2e/translations_spec.js +++ b/tests/e2e/translations_spec.js @@ -1,10 +1,10 @@ const fs = require("fs"); const path = require("path"); -const translations = require("../../translations/translations.js"); const helmet = require("helmet"); const { JSDOM } = require("jsdom"); const express = require("express"); const sinon = require("sinon"); +const translations = require("../../translations/translations"); describe("Translations", () => { let server; diff --git a/tests/electron/env_spec.js b/tests/electron/env_spec.js index 1b51a3c2..32b9f6fc 100644 --- a/tests/electron/env_spec.js +++ b/tests/electron/env_spec.js @@ -1,5 +1,5 @@ -const helpers = require("./helpers/global-setup"); const events = require("events"); +const helpers = require("./helpers/global-setup"); describe("Electron app environment", () => { beforeEach(async () => { diff --git a/tests/electron/helpers/weather-setup.js b/tests/electron/helpers/weather-setup.js index 8adf2b1d..4dd3cdb2 100644 --- a/tests/electron/helpers/weather-setup.js +++ b/tests/electron/helpers/weather-setup.js @@ -1,5 +1,5 @@ -const helpers = require("./global-setup"); const { injectMockData } = require("../../utils/weather_mocker"); +const helpers = require("./global-setup"); exports.getText = async (element, result) => { const elem = await helpers.getElement(element); diff --git a/tests/unit/classes/translator_spec.js b/tests/unit/classes/translator_spec.js index 31f8fa7d..410234ac 100644 --- a/tests/unit/classes/translator_spec.js +++ b/tests/unit/classes/translator_spec.js @@ -2,6 +2,7 @@ const path = require("path"); const helmet = require("helmet"); const { JSDOM } = require("jsdom"); const express = require("express"); + const sockets = new Set(); describe("Translator", () => { diff --git a/tests/unit/classes/utils_spec.js b/tests/unit/classes/utils_spec.js index 771f51b7..bf7a5c59 100644 --- a/tests/unit/classes/utils_spec.js +++ b/tests/unit/classes/utils_spec.js @@ -1,5 +1,5 @@ -const Utils = require("../../../js/utils.js"); const colors = require("colors/safe"); +const Utils = require("../../../js/utils"); describe("Utils", () => { describe("colors", () => { diff --git a/tests/unit/functions/calendar_spec.js b/tests/unit/functions/calendar_spec.js index bcd5eb5c..34e16dd3 100644 --- a/tests/unit/functions/calendar_spec.js +++ b/tests/unit/functions/calendar_spec.js @@ -10,7 +10,7 @@ describe("Functions into modules/default/calendar/calendar.js", () => { beforeAll(() => { // load calendar.js - require("../../../modules/default/calendar/calendar.js"); + require("../../../modules/default/calendar/calendar"); }); describe("capFirst", () => { diff --git a/tests/unit/functions/weather_object_spec.js b/tests/unit/functions/weather_object_spec.js index 0b24737b..5f9444e4 100644 --- a/tests/unit/functions/weather_object_spec.js +++ b/tests/unit/functions/weather_object_spec.js @@ -1,5 +1,5 @@ -const WeatherObject = require("../../../modules/default/weather/weatherobject.js"); -const WeatherUtils = require("../../../modules/default/weather/weatherutils.js"); +const WeatherObject = require("../../../modules/default/weather/weatherobject"); +const WeatherUtils = require("../../../modules/default/weather/weatherutils"); global.moment = require("moment-timezone"); global.SunCalc = require("suncalc"); diff --git a/tests/unit/modules/default/utils_spec.js b/tests/unit/modules/default/utils_spec.js index a384cd8e..f9c9390a 100644 --- a/tests/unit/modules/default/utils_spec.js +++ b/tests/unit/modules/default/utils_spec.js @@ -1,4 +1,5 @@ -const { performWebRequest } = require("../../../../modules/default/utils.js"); +const { performWebRequest } = require("../../../../modules/default/utils"); + const nodeVersion = process.version.match(/^v(\d+)\.*/)[1]; describe("Utils tests", () => { diff --git a/tests/unit/modules/default/weather/weather_utils_spec.js b/tests/unit/modules/default/weather/weather_utils_spec.js index 6d26f8fa..8aefd3c9 100644 --- a/tests/unit/modules/default/weather/weather_utils_spec.js +++ b/tests/unit/modules/default/weather/weather_utils_spec.js @@ -1,4 +1,4 @@ -const weather = require("../../../../../modules/default/weather/weatherutils.js"); +const weather = require("../../../../../modules/default/weather/weatherutils"); describe("Weather utils tests", () => { describe("convertPrecipitationUnit tests", () => { diff --git a/tests/utils/weather_mocker.js b/tests/utils/weather_mocker.js index 612f98f5..81e91245 100644 --- a/tests/utils/weather_mocker.js +++ b/tests/utils/weather_mocker.js @@ -1,6 +1,6 @@ -const _ = require("lodash"); const fs = require("fs"); const path = require("path"); +const _ = require("lodash"); /** * @param {string} type what data to read, can be "current" "forecast" or "hourly