Skip to content

Commit 143dfd6

Browse files
Add some ESLint rules + minor changes (#3665)
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.
1 parent d41ce81 commit 143dfd6

File tree

11 files changed

+31
-26
lines changed

11 files changed

+31
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ _This release is scheduled to be released on 2025-01-01._
2222
- [linter] Re-add `eslint-plugin-import`now that it supports ESLint v9 (#3586)
2323
- [linter] Re-activate `eslint-plugin-package-json` to lint `package.json` (#3643)
2424
- [linter] Add linting for markdown files (#3646)
25+
- [linter] Add some handy ESLint rules.
2526
- [calendar] Add ability to display end date for full date events, where end is not same day (showEnd=true) (#3650)
2627
- [core] Add text to the config.js.sample file about the locale variable (#3654, #3655)
2728
- [core] Add fetch timeout for all node_helpers (thru undici, forces node 20.18.1 minimum) to help on slower systems. (#3660) (3661)

clientonly/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
});
2929

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

3434
/**

cspell.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
"newsitems",
153153
"nfogal",
154154
"njwilliams",
155+
"nonrepeating",
155156
"Norsk",
156157
"nunjuck",
157158
"odroid",

eslint.config.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ const config = [
5555
"@stylistic/semi": ["error", "always"],
5656
"@stylistic/space-before-function-paren": ["error", "always"],
5757
"@stylistic/spaced-comment": "off",
58+
"dot-notation": "error",
5859
eqeqeq: "error",
5960
"id-length": "off",
60-
"import/order": "error",
6161
"import/extensions": "error",
6262
"import/newline-after-import": "error",
63+
"import/order": "error",
6364
"init-declarations": "off",
6465
"jest/consistent-test-it": "warn",
6566
"jest/no-done-callback": "warn",
@@ -78,6 +79,7 @@ const config = [
7879
"no-ternary": "off",
7980
"no-throw-literal": "error",
8081
"no-undefined": "off",
82+
"no-unneeded-ternary": "error",
8183
"no-unused-vars": "off",
8284
"no-useless-return": "error",
8385
"no-warning-comments": "off",
@@ -112,7 +114,8 @@ const config = [
112114
"max-lines-per-function": ["error", 100],
113115
"no-magic-numbers": "off",
114116
"one-var": "off",
115-
"prefer-destructuring": "off"
117+
"prefer-destructuring": "off",
118+
"sort-keys": "error"
116119
}
117120
},
118121
{

js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const fetch_timeout = process.env.mmFetchTimeout !== undefined ? process.env.mmF
1818

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

2424
// Log system information.

js/electron.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function createWindow () {
102102
*/
103103

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

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

js/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ module.exports = {
2424
versions: "kernel, node, npm, pm2"
2525
});
2626
let systemDataString = "System information:";
27-
systemDataString += `\n### SYSTEM: manufacturer: ${staticData["system"]["manufacturer"]}; model: ${staticData["system"]["model"]}; virtual: ${staticData["system"]["virtual"]}`;
28-
systemDataString += `\n### OS: platform: ${staticData["osInfo"]["platform"]}; distro: ${staticData["osInfo"]["distro"]}; release: ${staticData["osInfo"]["release"]}; arch: ${staticData["osInfo"]["arch"]}; kernel: ${staticData["versions"]["kernel"]}`;
29-
systemDataString += `\n### VERSIONS: electron: ${process.versions.electron}; used node: ${staticData["versions"]["node"]}; installed node: ${installedNodeVersion}; npm: ${staticData["versions"]["npm"]}; pm2: ${staticData["versions"]["pm2"]}`;
27+
systemDataString += `\n### SYSTEM: manufacturer: ${staticData.system.manufacturer}; model: ${staticData.system.model}; virtual: ${staticData.system.virtual}`;
28+
systemDataString += `\n### OS: platform: ${staticData.osInfo.platform}; distro: ${staticData.osInfo.distro}; release: ${staticData.osInfo.release}; arch: ${staticData.osInfo.arch}; kernel: ${staticData.versions.kernel}`;
29+
systemDataString += `\n### VERSIONS: electron: ${process.versions.electron}; used node: ${staticData.versions.node}; installed node: ${installedNodeVersion}; npm: ${staticData.versions.npm}; pm2: ${staticData.versions.pm2}`;
3030
systemDataString += `\n### OTHER: timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`;
3131
Log.info(systemDataString);
3232

modules/default/weather/providers/openmeteo.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,25 +244,25 @@ WeatherProvider.register("openmeteo", {
244244
.add(Math.max(0, Math.min(7, this.config.maxNumberOfDays)), "days")
245245
.endOf("day");
246246

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

249249
switch (this.config.type) {
250250
case "hourly":
251251
case "daily":
252252
case "forecast":
253-
params["end_date"] = endDate.format("YYYY-MM-DD");
253+
params.end_date = endDate.format("YYYY-MM-DD");
254254
break;
255255
case "current":
256-
params["current_weather"] = true;
257-
params["end_date"] = params["start_date"];
256+
params.current_weather = true;
257+
params.end_date = params.start_date;
258258
break;
259259
default:
260260
// Failsafe
261261
return "";
262262
}
263263

264264
return Object.keys(params)
265-
.filter((key) => (params[key] ? true : false))
265+
.filter((key) => (!!params[key]))
266266
.map((key) => {
267267
switch (key) {
268268
case "hourly":

modules/default/weather/providers/openweathermap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,12 @@ WeatherProvider.register("openweathermap", {
285285
current.weatherType = this.convertWeatherType(data.current.weather[0].icon);
286286
current.humidity = data.current.humidity;
287287
current.uv_index = data.current.uvi;
288-
if (data.current.hasOwnProperty("rain") && !isNaN(data.current["rain"]["1h"])) {
289-
current.rain = data.current["rain"]["1h"];
288+
if (data.current.hasOwnProperty("rain") && !isNaN(data.current.rain["1h"])) {
289+
current.rain = data.current.rain["1h"];
290290
precip = true;
291291
}
292-
if (data.current.hasOwnProperty("snow") && !isNaN(data.current["snow"]["1h"])) {
293-
current.snow = data.current["snow"]["1h"];
292+
if (data.current.hasOwnProperty("snow") && !isNaN(data.current.snow["1h"])) {
293+
current.snow = data.current.snow["1h"];
294294
precip = true;
295295
}
296296
if (precip) {

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)