Skip to content

Commit

Permalink
Add some ESLint rules + minor changes (#3665)
Browse files Browse the repository at this point in the history
Main point was to enable ESLint `dot-notation` and `no-unneeded-ternary`
rules for more code consistency.

I took the occasion to add two minor commits:
- Fix a problem found by running `test:spelling
- Minor dependency update

It wouldn't be a problem if the PR didn't arrive in the next release,
the changes are cosmetic.
  • Loading branch information
KristjanESPERANTO authored Dec 30, 2024
1 parent d41ce81 commit 143dfd6
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ _This release is scheduled to be released on 2025-01-01._
- [linter] Re-add `eslint-plugin-import`now that it supports ESLint v9 (#3586)
- [linter] Re-activate `eslint-plugin-package-json` to lint `package.json` (#3643)
- [linter] Add linting for markdown files (#3646)
- [linter] Add some handy ESLint rules.
- [calendar] Add ability to display end date for full date events, where end is not same day (showEnd=true) (#3650)
- [core] Add text to the config.js.sample file about the locale variable (#3654, #3655)
- [core] Add fetch timeout for all node_helpers (thru undici, forces node 20.18.1 minimum) to help on slower systems. (#3660) (3661)
Expand Down
2 changes: 1 addition & 1 deletion clientonly/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
});

// determine if "--use-tls"-flag was provided
config["tls"] = process.argv.indexOf("--use-tls") > 0;
config.tls = process.argv.indexOf("--use-tls") > 0;
}

/**
Expand Down
1 change: 1 addition & 0 deletions cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"newsitems",
"nfogal",
"njwilliams",
"nonrepeating",
"Norsk",
"nunjuck",
"odroid",
Expand Down
7 changes: 5 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ const config = [
"@stylistic/semi": ["error", "always"],
"@stylistic/space-before-function-paren": ["error", "always"],
"@stylistic/spaced-comment": "off",
"dot-notation": "error",
eqeqeq: "error",
"id-length": "off",
"import/order": "error",
"import/extensions": "error",
"import/newline-after-import": "error",
"import/order": "error",
"init-declarations": "off",
"jest/consistent-test-it": "warn",
"jest/no-done-callback": "warn",
Expand All @@ -78,6 +79,7 @@ const config = [
"no-ternary": "off",
"no-throw-literal": "error",
"no-undefined": "off",
"no-unneeded-ternary": "error",
"no-unused-vars": "off",
"no-useless-return": "error",
"no-warning-comments": "off",
Expand Down Expand Up @@ -112,7 +114,8 @@ const config = [
"max-lines-per-function": ["error", 100],
"no-magic-numbers": "off",
"one-var": "off",
"prefer-destructuring": "off"
"prefer-destructuring": "off",
"sort-keys": "error"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const fetch_timeout = process.env.mmFetchTimeout !== undefined ? process.env.mmF

// Get version number.
global.version = require(`${__dirname}/../package.json`).version;
global.mmTestMode = process.env.mmTestMode === "true" ? true : false;
global.mmTestMode = process.env.mmTestMode === "true";
Log.log(`Starting MagicMirror: v${global.version}`);

// Log system information.
Expand Down
6 changes: 3 additions & 3 deletions js/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function createWindow () {
*/

let prefix;
if ((config["tls"] !== null && config["tls"]) || config.useHttps) {
if ((config.tls !== null && config.tls) || config.useHttps) {
prefix = "https://";
} else {
prefix = "http://";
Expand Down Expand Up @@ -151,11 +151,11 @@ function createWindow () {
//remove response headers that prevent sites of being embedded into iframes if configured
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
let curHeaders = details.responseHeaders;
if (config["ignoreXOriginHeader"] || false) {
if (config.ignoreXOriginHeader || false) {
curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !(/x-frame-options/i).test(header[0])));
}

if (config["ignoreContentSecurityPolicy"] || false) {
if (config.ignoreContentSecurityPolicy || false) {
curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !(/content-security-policy/i).test(header[0])));
}

Expand Down
6 changes: 3 additions & 3 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module.exports = {
versions: "kernel, node, npm, pm2"
});
let systemDataString = "System information:";
systemDataString += `\n### SYSTEM: manufacturer: ${staticData["system"]["manufacturer"]}; model: ${staticData["system"]["model"]}; virtual: ${staticData["system"]["virtual"]}`;
systemDataString += `\n### OS: platform: ${staticData["osInfo"]["platform"]}; distro: ${staticData["osInfo"]["distro"]}; release: ${staticData["osInfo"]["release"]}; arch: ${staticData["osInfo"]["arch"]}; kernel: ${staticData["versions"]["kernel"]}`;
systemDataString += `\n### VERSIONS: electron: ${process.versions.electron}; used node: ${staticData["versions"]["node"]}; installed node: ${installedNodeVersion}; npm: ${staticData["versions"]["npm"]}; pm2: ${staticData["versions"]["pm2"]}`;
systemDataString += `\n### SYSTEM: manufacturer: ${staticData.system.manufacturer}; model: ${staticData.system.model}; virtual: ${staticData.system.virtual}`;
systemDataString += `\n### OS: platform: ${staticData.osInfo.platform}; distro: ${staticData.osInfo.distro}; release: ${staticData.osInfo.release}; arch: ${staticData.osInfo.arch}; kernel: ${staticData.versions.kernel}`;
systemDataString += `\n### VERSIONS: electron: ${process.versions.electron}; used node: ${staticData.versions.node}; installed node: ${installedNodeVersion}; npm: ${staticData.versions.npm}; pm2: ${staticData.versions.pm2}`;
systemDataString += `\n### OTHER: timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`;
Log.info(systemDataString);

Expand Down
10 changes: 5 additions & 5 deletions modules/default/weather/providers/openmeteo.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,25 @@ WeatherProvider.register("openmeteo", {
.add(Math.max(0, Math.min(7, this.config.maxNumberOfDays)), "days")
.endOf("day");

params["start_date"] = startDate.format("YYYY-MM-DD");
params.start_date = startDate.format("YYYY-MM-DD");

switch (this.config.type) {
case "hourly":
case "daily":
case "forecast":
params["end_date"] = endDate.format("YYYY-MM-DD");
params.end_date = endDate.format("YYYY-MM-DD");
break;
case "current":
params["current_weather"] = true;
params["end_date"] = params["start_date"];
params.current_weather = true;
params.end_date = params.start_date;
break;
default:
// Failsafe
return "";
}

return Object.keys(params)
.filter((key) => (params[key] ? true : false))
.filter((key) => (!!params[key]))
.map((key) => {
switch (key) {
case "hourly":
Expand Down
8 changes: 4 additions & 4 deletions modules/default/weather/providers/openweathermap.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ WeatherProvider.register("openweathermap", {
current.weatherType = this.convertWeatherType(data.current.weather[0].icon);
current.humidity = data.current.humidity;
current.uv_index = data.current.uvi;
if (data.current.hasOwnProperty("rain") && !isNaN(data.current["rain"]["1h"])) {
current.rain = data.current["rain"]["1h"];
if (data.current.hasOwnProperty("rain") && !isNaN(data.current.rain["1h"])) {
current.rain = data.current.rain["1h"];
precip = true;
}
if (data.current.hasOwnProperty("snow") && !isNaN(data.current["snow"]["1h"])) {
current.snow = data.current["snow"]["1h"];
if (data.current.hasOwnProperty("snow") && !isNaN(data.current.snow["1h"])) {
current.snow = data.current.snow["1h"];
precip = true;
}
if (precip) {
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@
"module-alias": "^2.2.3",
"moment": "^2.30.1",
"node-ical": "^0.20.1",
"pm2": "^5.4.2",
"pm2": "^5.4.3",
"socket.io": "^4.8.1",
"suncalc": "^1.9.0",
"systeminformation": "^5.23.23",
"systeminformation": "^5.23.24",
"undici": "^7.2.0"
},
"devDependencies": {
Expand Down

0 comments on commit 143dfd6

Please sign in to comment.