From 361f55bec16e6fc0174205de1b9dea59f7a30112 Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Fri, 6 Dec 2024 09:38:56 +0100 Subject: [PATCH] Use object shorthand syntax --- MMM-pages.js | 23 ++++++++++------------- eslint.config.mjs | 1 + 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/MMM-pages.js b/MMM-pages.js index f89ef40..4e182a1 100644 --- a/MMM-pages.js +++ b/MMM-pages.js @@ -1,8 +1,5 @@ Module.register('MMM-pages', { - // We require the older style of function declaration for compatibility - // reasons. - /** * By default, we have don't pseudo-paginate any modules. We also exclude * the page indicator by default, in case people actually want to use the @@ -25,7 +22,7 @@ Module.register('MMM-pages', { /** * Apply any styles, if we have any. */ - getStyles: function () { + getStyles () { return ['pages.css']; }, @@ -36,7 +33,7 @@ Module.register('MMM-pages', { * @param {number} x The dividend * @param {number} n The divisor */ - mod: function (x, n) { + mod (x, n) { return (x % n + n) % n; }, @@ -44,7 +41,7 @@ Module.register('MMM-pages', { * Pseudo-constructor for our module. Makes sure that values aren't negative, * and sets the default current page to 0. */ - start: function () { + start () { // Clamp homePage value to [0, num pages). if (this.config.homePage >= this.config.modules.length || this.config.homePage < 0) { this.config.homePage = 0; @@ -91,7 +88,7 @@ Module.register('MMM-pages', { * @param {string} notification the notification ID * @param {number|string} payload the page to change to/by */ - notificationReceived: function (notification, payload) { + notificationReceived (notification, payload) { switch (notification) { case 'PAGE_CHANGED': Log.log(`[MMM-pages] received a notification to change to page ${payload} of type ${typeof payload}.`); @@ -153,7 +150,7 @@ Module.register('MMM-pages', { * @param {number} fallback the fallback value to use. Accepts negative * numbers. */ - changePageBy: function (amt, fallback) { + changePageBy (amt, fallback) { if (typeof amt !== 'number' && typeof fallback === 'undefined') { Log.warn(`[MMM-pages] ${amt} is not a number!`); } @@ -175,7 +172,7 @@ Module.register('MMM-pages', { * Handles hiding the current page's elements and showing the next page's * elements. */ - updatePages: function () { + updatePages () { // Update if there's at least one page. if (this.config.modules.length !== 0) { this.animatePageChange(); @@ -194,7 +191,7 @@ Module.register('MMM-pages', { * @param {string} [targetPageName] the name of the hiddenPage we want to show. * Optional and only used when we want to switch to a hidden page */ - animatePageChange: function (targetPageName) { + animatePageChange (targetPageName) { let lockStringObj = {lockString: this.identifier}; if (!this.config.useLockString) { // Passing in an undefined object is equivalent to not passing it in at @@ -231,7 +228,7 @@ Module.register('MMM-pages', { * * @param {number} delay the delay, in milliseconds. */ - resetTimerWithDelay: function (delay) { + resetTimerWithDelay (delay) { if (this.config.rotationTime > 0) { // This timer is the auto rotate function. clearInterval(this.timer); @@ -275,7 +272,7 @@ Module.register('MMM-pages', { * * @param {boolean} isRotating the parameter, if you want to pause or resume. */ - setRotation: function (isRotating) { + setRotation (isRotating) { const stateBaseString = isRotating ? 'resum' : 'paus'; if (isRotating === this.rotationPaused) { Log.warn(`[MMM-pages] was asked to ${stateBaseString}e but rotation is already ${stateBaseString}ed!`); @@ -296,7 +293,7 @@ Module.register('MMM-pages', { * * @param {string} name the name of the hiddenPage we want to show */ - showHiddenPage: function (name) { + showHiddenPage (name) { // Only proceed if the named hidden page actually exists if (name in this.config.hiddenPages) { this.animatePageChange(name); diff --git a/eslint.config.mjs b/eslint.config.mjs index fcbd88a..95d1bf9 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -33,6 +33,7 @@ const config = [ '@stylistic/quotes': ['error', 'single'], '@stylistic/multiline-comment-style': 'off', '@stylistic/multiline-ternary': 'off', + 'object-shorthand': ['error', 'always'] }, } ];