Skip to content

Commit cdab7a7

Browse files
refactor: use const instead of let for variable declarations (#4196)
This replaces `let` with `const` for variable declarations where it was possible. Using `const` [is considered best practice](https://www.xjavascript.com/blog/in-javascript-why-should-i-usually-prefer-const-to-let/#5-best-practices-const-first-let-second). I have enabled the corresponding ESLint rule and let the ESLint auto-fix the "wrong" usages of `let`.
1 parent 3e223b7 commit cdab7a7

127 files changed

Lines changed: 175 additions & 175 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config/config.js.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* which will be converted to `config.js` while starting. For more information
99
* see https://docs.magicmirror.builders/configuration/introduction.html#enviromnent-variables
1010
*/
11-
let config = {
11+
const config = {
1212
address: "localhost", // Address to listen on, can be:
1313
// - "localhost", "127.0.0.1", "::1" to listen on loopback interface
1414
// - another specific IPv4/6 to listen on a specific interface

defaultmodules/alert/notificationFx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @returns {object} The merged object
2121
*/
2222
function extend (a, b) {
23-
for (let key in b) {
23+
for (const key in b) {
2424
if (b.hasOwnProperty(key)) {
2525
a[key] = b[key];
2626
}

defaultmodules/calendar/calendar.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Module.register("calendar", {
215215
return;
216216
}
217217
} else if (notification === "CALENDAR_ERROR") {
218-
let error_message = this.translate(payload.error_type);
218+
const error_message = this.translate(payload.error_type);
219219
this.error = this.translate("MODULE_CONFIG_ERROR", { MODULE_NAME: this.name, ERROR: error_message });
220220
this.loaded = true;
221221
}
@@ -350,8 +350,8 @@ Module.register("calendar", {
350350

351351
// Color events if custom color or eventClass are specified, transform title if required
352352
if (this.config.customEvents.length > 0) {
353-
for (let ev in this.config.customEvents) {
354-
let needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
353+
for (const ev in this.config.customEvents) {
354+
const needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
355355
if (needle.test(event.title)) {
356356
if (typeof this.config.customEvents[ev].transform === "object") {
357357
transformedTitle = CalendarUtils.titleTransform(transformedTitle, [this.config.customEvents[ev].transform]);
@@ -471,16 +471,16 @@ Module.register("calendar", {
471471
* @returns {object[]} Array with events.
472472
*/
473473
createEventList (limitNumberOfEntries) {
474-
let now = moment();
475-
let future = now.clone().startOf("day").add(this.config.maximumNumberOfDays, "days");
474+
const now = moment();
475+
const future = now.clone().startOf("day").add(this.config.maximumNumberOfDays, "days");
476476

477477
let events = [];
478478

479479
for (const calendarUrl in this.calendarData) {
480480
const calendar = this.calendarData[calendarUrl].events;
481-
let remainingEntries = this.maximumEntriesForUrl(calendarUrl);
482-
let maxPastDaysCompare = now.clone().subtract(this.maximumPastDaysForUrl(calendarUrl), "days");
483-
let by_url_calevents = [];
481+
const remainingEntries = this.maximumEntriesForUrl(calendarUrl);
482+
const maxPastDaysCompare = now.clone().subtract(this.maximumPastDaysForUrl(calendarUrl), "days");
483+
const by_url_calevents = [];
484484
for (const e in calendar) {
485485
const event = JSON.parse(JSON.stringify(calendar[e])); // clone object
486486
const eventStartDateMoment = this.timestampToMoment(event.startDate);
@@ -541,7 +541,7 @@ Module.register("calendar", {
541541
event.tomorrow = this.timestampToMoment(event.startDate).isSame(now.clone().add(1, "days"), "d");
542542
splitEvents.push(event);
543543

544-
for (let splitEvent of splitEvents) {
544+
for (const splitEvent of splitEvents) {
545545
if (this.timestampToMoment(splitEvent.endDate).isAfter(now) && this.timestampToMoment(splitEvent.endDate).isSameOrBefore(future)) {
546546
by_url_calevents.push(splitEvent);
547547
}
@@ -579,7 +579,7 @@ Module.register("calendar", {
579579
// Group all events by date, events on the same date will be in a list with the key being the date.
580580
const eventsByDate = Object.groupBy(events, (ev) => this.timestampToMoment(ev.startDate).format("YYYY-MM-DD"));
581581
const newEvents = [];
582-
let currentDate = moment();
582+
const currentDate = moment();
583583
let daysCollected = 0;
584584

585585
while (daysCollected < this.config.limitDays) {
@@ -650,9 +650,9 @@ Module.register("calendar", {
650650
}
651651

652652
// If custom symbol is set, replace event symbol
653-
for (let ev of this.config.customEvents) {
653+
for (const ev of this.config.customEvents) {
654654
if (typeof ev.symbol !== "undefined" && ev.symbol !== "") {
655-
let needle = new RegExp(ev.keyword, "gi");
655+
const needle = new RegExp(ev.keyword, "gi");
656656
if (needle.test(event.title)) {
657657
// Get the default prefix for this class name and add to the custom symbol provided
658658
const className = this.getCalendarProperty(event.url, "symbolClassName", this.config.defaultSymbolClassName);
@@ -988,7 +988,7 @@ Module.register("calendar", {
988988
if (property === "symbol" || property === "recurringSymbol" || property === "fullDaySymbol") {
989989
const className = this.getCalendarProperty(url, "symbolClassName", this.config.defaultSymbolClassName);
990990
if (p instanceof Array) {
991-
let t = [];
991+
const t = [];
992992
p.forEach((n) => { t.push(className + n); });
993993
p = t;
994994
}

defaultmodules/calendar/calendarutils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ const CalendarUtils = {
9595
*/
9696
titleTransform (title, titleReplace) {
9797
let transformedTitle = title;
98-
for (let tr in titleReplace) {
99-
let transform = titleReplace[tr];
98+
for (const tr in titleReplace) {
99+
const transform = titleReplace[tr];
100100
if (typeof transform === "object") {
101101
if (typeof transform.search !== "undefined" && transform.search !== "" && typeof transform.replace !== "undefined") {
102-
let regParts = transform.search.match(/^\/(.+)\/([gim]*)$/);
102+
const regParts = transform.search.match(/^\/(.+)\/([gim]*)$/);
103103
let needle = new RegExp(transform.search, "g");
104104
if (regParts) {
105105
// the parsed pattern is a regexp with flags.
@@ -110,8 +110,8 @@ const CalendarUtils = {
110110
if (typeof transform.yearmatchgroup !== "undefined" && transform.yearmatchgroup !== "") {
111111
const yearmatch = [...title.matchAll(needle)];
112112
if (yearmatch[0].length >= transform.yearmatchgroup + 1 && yearmatch[0][transform.yearmatchgroup] * 1 >= 1900) {
113-
let calcage = new Date().getFullYear() - yearmatch[0][transform.yearmatchgroup] * 1;
114-
let searchstr = `$${transform.yearmatchgroup}`;
113+
const calcage = new Date().getFullYear() - yearmatch[0][transform.yearmatchgroup] * 1;
114+
const searchstr = `$${transform.yearmatchgroup}`;
115115
replacement = replacement.replace(searchstr, calcage);
116116
}
117117
}

defaultmodules/compliments/compliments.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Module.register("compliments", {
6363
}
6464
let minute_sync_delay = 1;
6565
// loop thru all the configured when events
66-
for (let m of Object.keys(this.config.compliments)) {
66+
for (const m of Object.keys(this.config.compliments)) {
6767
// if it is a cron entry
6868
if (this.isCronEntry(m)) {
6969
// we need to synch our interval cycle to the minute
@@ -165,14 +165,14 @@ Module.register("compliments", {
165165
Array.prototype.push.apply(compliments, this.config.compliments.anytime);
166166

167167
// get the list of just date entry keys
168-
let temp_list = Object.keys(this.config.compliments).filter((k) => {
168+
const temp_list = Object.keys(this.config.compliments).filter((k) => {
169169
if (this.pre_defined_types.includes(k)) return false;
170170
else return true;
171171
});
172172

173-
let date_compliments = [];
173+
const date_compliments = [];
174174
// Add compliments for special day/times
175-
for (let entry of temp_list) {
175+
for (const entry of temp_list) {
176176
// check if this could be a cron type entry
177177
if (this.isCronEntry(entry)) {
178178
// make sure the regex is valid

defaultmodules/newsfeed/newsfeed.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Module.register("newsfeed", {
212212
* Registers the feeds to be used by the backend.
213213
*/
214214
registerFeeds () {
215-
for (let feed of this.config.feeds) {
215+
for (const feed of this.config.feeds) {
216216
this.sendSocketNotification("ADD_FEED", {
217217
feed: feed,
218218
config: this.config
@@ -239,10 +239,10 @@ Module.register("newsfeed", {
239239
*/
240240
generateFeed (feeds) {
241241
let newsItems = [];
242-
for (let feed in feeds) {
242+
for (const feed in feeds) {
243243
const feedItems = feeds[feed];
244244
if (this.subscribedToFeed(feed)) {
245-
for (let item of feedItems) {
245+
for (const item of feedItems) {
246246
item.sourceTitle = this.titleForFeed(feed);
247247
if (!(this.getFeedProperty(feed, "ignoreOldItems") && Date.now() - new Date(item.pubdate) > this.getFeedProperty(feed, "ignoreOlderThan"))) {
248248
newsItems.push(item);
@@ -262,7 +262,7 @@ Module.register("newsfeed", {
262262

263263
if (this.config.prohibitedWords.length > 0) {
264264
newsItems = newsItems.filter(function (item) {
265-
for (let word of this.config.prohibitedWords) {
265+
for (const word of this.config.prohibitedWords) {
266266
if (item.title.toLowerCase().indexOf(word.toLowerCase()) > -1) {
267267
return false;
268268
}
@@ -273,7 +273,7 @@ Module.register("newsfeed", {
273273
newsItems.forEach((item) => {
274274
//Remove selected tags from the beginning of rss feed items (title or description)
275275
if (this.config.removeStartTags === "title" || this.config.removeStartTags === "both") {
276-
for (let startTag of this.config.startTags) {
276+
for (const startTag of this.config.startTags) {
277277
if (item.title.slice(0, startTag.length) === startTag) {
278278
item.title = item.title.slice(startTag.length, item.title.length);
279279
}
@@ -282,7 +282,7 @@ Module.register("newsfeed", {
282282

283283
if (this.config.removeStartTags === "description" || this.config.removeStartTags === "both") {
284284
if (this.isShowingDescription) {
285-
for (let startTag of this.config.startTags) {
285+
for (const startTag of this.config.startTags) {
286286
if (item.description.slice(0, startTag.length) === startTag) {
287287
item.description = item.description.slice(startTag.length, item.description.length);
288288
}
@@ -292,14 +292,14 @@ Module.register("newsfeed", {
292292

293293
//Remove selected tags from the end of rss feed items (title or description)
294294
if (this.config.removeEndTags) {
295-
for (let endTag of this.config.endTags) {
295+
for (const endTag of this.config.endTags) {
296296
if (item.title.slice(-endTag.length) === endTag) {
297297
item.title = item.title.slice(0, -endTag.length);
298298
}
299299
}
300300

301301
if (this.isShowingDescription) {
302-
for (let endTag of this.config.endTags) {
302+
for (const endTag of this.config.endTags) {
303303
if (item.description.slice(-endTag.length) === endTag) {
304304
item.description = item.description.slice(0, -endTag.length);
305305
}
@@ -331,7 +331,7 @@ Module.register("newsfeed", {
331331
* @returns {boolean} True if it is subscribed, false otherwise
332332
*/
333333
subscribedToFeed (feedUrl) {
334-
for (let feed of this.config.feeds) {
334+
for (const feed of this.config.feeds) {
335335
if (feed.url === feedUrl) {
336336
return true;
337337
}
@@ -345,7 +345,7 @@ Module.register("newsfeed", {
345345
* @returns {string} The title of the feed
346346
*/
347347
titleForFeed (feedUrl) {
348-
for (let feed of this.config.feeds) {
348+
for (const feed of this.config.feeds) {
349349
if (feed.url === feedUrl) {
350350
return feed.title || "";
351351
}

defaultmodules/updatenotification/git_helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class GitHelper {
7676
}
7777

7878
async getStatusInfo (repo) {
79-
let gitInfo = {
79+
const gitInfo = {
8080
module: repo.module,
8181
behind: 0, // commits behind
8282
current: "", // branch name

defaultmodules/updatenotification/update_helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Updater {
7777
});
7878

7979
await Promise.all(parser);
80-
let updater = Object.values(this.moduleList);
80+
const updater = Object.values(this.moduleList);
8181
Log.debug("Update Result:", updater);
8282
return updater;
8383
}
@@ -92,7 +92,7 @@ class Updater {
9292
* };
9393
*/
9494
updateProcess (module) {
95-
let Result = {
95+
const Result = {
9696
error: false,
9797
updated: false,
9898
needRestart: false

defaultmodules/weather/providers/envcanada.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class EnvCanadaProvider {
252252
// Check if first forecast is Today or Tonight
253253
const isToday = forecasts[0].includes("textForecastName=\"Today\"");
254254

255-
let nextDay = isToday ? 2 : 1;
255+
const nextDay = isToday ? 2 : 1;
256256
const lastDay = isToday ? 12 : 11;
257257

258258
// Process first day

defaultmodules/weather/weather.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Module.register("weather", {
144144
const senderClasses = sender.data.classes.toLowerCase().split(" ");
145145
if (senderClasses.indexOf(this.config.calendarClass.toLowerCase()) !== -1) {
146146
this.firstEvent = null;
147-
for (let event of payload) {
147+
for (const event of payload) {
148148
if (event.location || event.geo) {
149149
this.firstEvent = event;
150150
Log.debug("[weather] First upcoming event with location: ", event);

0 commit comments

Comments
 (0)