mirror of
https://github.com/edward-shen/MMM-pages.git
synced 2024-12-21 16:25:09 -08:00
Switch to recommended stylistic rules
This commit is contained in:
parent
6db5efe2c8
commit
90a7651f40
2 changed files with 17 additions and 30 deletions
27
MMM-pages.js
27
MMM-pages.js
|
@ -22,18 +22,17 @@ Module.register('MMM-pages', {
|
||||||
/**
|
/**
|
||||||
* Apply any styles, if we have any.
|
* Apply any styles, if we have any.
|
||||||
*/
|
*/
|
||||||
getStyles () {
|
getStyles() {
|
||||||
return ['pages.css'];
|
return ['pages.css'];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modulo that also works with negative numbers.
|
* Modulo that also works with negative numbers.
|
||||||
*
|
*
|
||||||
* @param {number} x The dividend
|
* @param {number} x The dividend
|
||||||
* @param {number} n The divisor
|
* @param {number} n The divisor
|
||||||
*/
|
*/
|
||||||
mod (x, n) {
|
mod(x, n) {
|
||||||
return ((x % n) + n) % n;
|
return ((x % n) + n) % n;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -41,7 +40,7 @@ Module.register('MMM-pages', {
|
||||||
* Pseudo-constructor for our module. Makes sure that values aren't negative,
|
* Pseudo-constructor for our module. Makes sure that values aren't negative,
|
||||||
* and sets the default current page to 0.
|
* and sets the default current page to 0.
|
||||||
*/
|
*/
|
||||||
start () {
|
start() {
|
||||||
// Clamp homePage value to [0, num pages).
|
// Clamp homePage value to [0, num pages).
|
||||||
if (this.config.homePage >= this.config.modules.length || this.config.homePage < 0) {
|
if (this.config.homePage >= this.config.modules.length || this.config.homePage < 0) {
|
||||||
this.config.homePage = 0;
|
this.config.homePage = 0;
|
||||||
|
@ -88,7 +87,7 @@ Module.register('MMM-pages', {
|
||||||
* @param {string} notification the notification ID
|
* @param {string} notification the notification ID
|
||||||
* @param {number|string} payload the page to change to/by
|
* @param {number|string} payload the page to change to/by
|
||||||
*/
|
*/
|
||||||
notificationReceived (notification, payload) {
|
notificationReceived(notification, payload) {
|
||||||
switch (notification) {
|
switch (notification) {
|
||||||
case 'PAGE_CHANGED':
|
case 'PAGE_CHANGED':
|
||||||
Log.log(`[MMM-pages] received a notification to change to page ${payload} of type ${typeof payload}.`);
|
Log.log(`[MMM-pages] received a notification to change to page ${payload} of type ${typeof payload}.`);
|
||||||
|
@ -150,7 +149,7 @@ Module.register('MMM-pages', {
|
||||||
* @param {number} fallback the fallback value to use. Accepts negative
|
* @param {number} fallback the fallback value to use. Accepts negative
|
||||||
* numbers.
|
* numbers.
|
||||||
*/
|
*/
|
||||||
changePageBy (amt, fallback) {
|
changePageBy(amt, fallback) {
|
||||||
if (typeof amt !== 'number' && typeof fallback === 'undefined') {
|
if (typeof amt !== 'number' && typeof fallback === 'undefined') {
|
||||||
Log.warn(`[MMM-pages] ${amt} is not a number!`);
|
Log.warn(`[MMM-pages] ${amt} is not a number!`);
|
||||||
}
|
}
|
||||||
|
@ -172,7 +171,7 @@ Module.register('MMM-pages', {
|
||||||
* Handles hiding the current page's elements and showing the next page's
|
* Handles hiding the current page's elements and showing the next page's
|
||||||
* elements.
|
* elements.
|
||||||
*/
|
*/
|
||||||
updatePages () {
|
updatePages() {
|
||||||
// Update if there's at least one page.
|
// Update if there's at least one page.
|
||||||
if (this.config.modules.length !== 0) {
|
if (this.config.modules.length !== 0) {
|
||||||
this.animatePageChange();
|
this.animatePageChange();
|
||||||
|
@ -191,8 +190,8 @@ Module.register('MMM-pages', {
|
||||||
* @param {string} [targetPageName] the name of the hiddenPage we want to show.
|
* @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
|
* Optional and only used when we want to switch to a hidden page
|
||||||
*/
|
*/
|
||||||
animatePageChange (targetPageName) {
|
animatePageChange(targetPageName) {
|
||||||
let lockStringObj = {lockString: this.identifier};
|
let lockStringObj = { lockString: this.identifier };
|
||||||
if (!this.config.useLockString) {
|
if (!this.config.useLockString) {
|
||||||
// Passing in an undefined object is equivalent to not passing it in at
|
// Passing in an undefined object is equivalent to not passing it in at
|
||||||
// all, effectively providing only one arg to the hide and show calls
|
// all, effectively providing only one arg to the hide and show calls
|
||||||
|
@ -213,13 +212,13 @@ Module.register('MMM-pages', {
|
||||||
|
|
||||||
MM.getModules()
|
MM.getModules()
|
||||||
.exceptWithClass(modulesToShow)
|
.exceptWithClass(modulesToShow)
|
||||||
.enumerate((module) => module.hide(animationTime, lockStringObj));
|
.enumerate(module => module.hide(animationTime, lockStringObj));
|
||||||
|
|
||||||
// Shows all modules meant to be on the current page, after a small delay.
|
// Shows all modules meant to be on the current page, after a small delay.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
MM.getModules()
|
MM.getModules()
|
||||||
.withClass(modulesToShow)
|
.withClass(modulesToShow)
|
||||||
.enumerate((module) => module.show(animationTime, lockStringObj));
|
.enumerate(module => module.show(animationTime, lockStringObj));
|
||||||
}, animationTime);
|
}, animationTime);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -228,7 +227,7 @@ Module.register('MMM-pages', {
|
||||||
*
|
*
|
||||||
* @param {number} delay the delay, in milliseconds.
|
* @param {number} delay the delay, in milliseconds.
|
||||||
*/
|
*/
|
||||||
resetTimerWithDelay (delay) {
|
resetTimerWithDelay(delay) {
|
||||||
if (this.config.rotationTime > 0) {
|
if (this.config.rotationTime > 0) {
|
||||||
// This timer is the auto rotate function.
|
// This timer is the auto rotate function.
|
||||||
clearInterval(this.timer);
|
clearInterval(this.timer);
|
||||||
|
@ -272,7 +271,7 @@ Module.register('MMM-pages', {
|
||||||
*
|
*
|
||||||
* @param {boolean} isRotating the parameter, if you want to pause or resume.
|
* @param {boolean} isRotating the parameter, if you want to pause or resume.
|
||||||
*/
|
*/
|
||||||
setRotation (isRotating) {
|
setRotation(isRotating) {
|
||||||
const stateBaseString = isRotating ? 'resum' : 'paus';
|
const stateBaseString = isRotating ? 'resum' : 'paus';
|
||||||
if (isRotating === this.rotationPaused) {
|
if (isRotating === this.rotationPaused) {
|
||||||
Log.warn(`[MMM-pages] was asked to ${stateBaseString}e but rotation is already ${stateBaseString}ed!`);
|
Log.warn(`[MMM-pages] was asked to ${stateBaseString}e but rotation is already ${stateBaseString}ed!`);
|
||||||
|
@ -293,7 +292,7 @@ Module.register('MMM-pages', {
|
||||||
*
|
*
|
||||||
* @param {string} name the name of the hiddenPage we want to show
|
* @param {string} name the name of the hiddenPage we want to show
|
||||||
*/
|
*/
|
||||||
showHiddenPage (name) {
|
showHiddenPage(name) {
|
||||||
// Only proceed if the named hidden page actually exists
|
// Only proceed if the named hidden page actually exists
|
||||||
if (name in this.config.hiddenPages) {
|
if (name in this.config.hiddenPages) {
|
||||||
this.animatePageChange(name);
|
this.animatePageChange(name);
|
||||||
|
|
|
@ -3,6 +3,8 @@ import eslintPluginStylistic from '@stylistic/eslint-plugin';
|
||||||
import globals from 'globals';
|
import globals from 'globals';
|
||||||
|
|
||||||
const config = [
|
const config = [
|
||||||
|
eslintPluginJs.configs.recommended,
|
||||||
|
eslintPluginStylistic.configs['recommended-flat'],
|
||||||
{
|
{
|
||||||
files: ['**/*.js', '**/*.mjs'],
|
files: ['**/*.js', '**/*.mjs'],
|
||||||
},
|
},
|
||||||
|
@ -16,24 +18,10 @@ const config = [
|
||||||
Module: 'readonly',
|
Module: 'readonly',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: {
|
|
||||||
...eslintPluginStylistic.configs['all-flat'].plugins,
|
|
||||||
},
|
|
||||||
rules: {
|
rules: {
|
||||||
...eslintPluginJs.configs.recommended.rules,
|
'@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
||||||
...eslintPluginStylistic.configs['all-flat'].rules,
|
|
||||||
'@stylistic/array-element-newline': 'off',
|
|
||||||
'@stylistic/brace-style': ['error', '1tbs', {allowSingleLine: true}],
|
|
||||||
'@stylistic/comma-dangle': ['error', 'only-multiline'],
|
'@stylistic/comma-dangle': ['error', 'only-multiline'],
|
||||||
'@stylistic/dot-location': ['error', 'property'],
|
'@stylistic/semi': ['error', 'always'],
|
||||||
'@stylistic/function-call-argument-newline': 'off',
|
|
||||||
'@stylistic/indent': ['error', 2],
|
|
||||||
'@stylistic/padded-blocks': 'off',
|
|
||||||
'@stylistic/quote-props': ['error', 'consistent-as-needed'],
|
|
||||||
'@stylistic/quotes': ['error', 'single'],
|
|
||||||
'@stylistic/multiline-comment-style': 'off',
|
|
||||||
'@stylistic/multiline-ternary': 'off',
|
|
||||||
'@stylistic/no-extra-parens': 'off',
|
|
||||||
'object-shorthand': ['error', 'always']
|
'object-shorthand': ['error', 'always']
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue