Skip to content

Commit

Permalink
Lint codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
JHWelch committed Oct 20, 2024
1 parent e21e0b6 commit 02b3349
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 71 deletions.
44 changes: 22 additions & 22 deletions MMM-CTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Module.register('MMM-CTA', {

loading: true,

start() {
start () {
Log.info(`Starting module: ${this.name}`);
const self = this;

Expand All @@ -35,7 +35,7 @@ Module.register('MMM-CTA', {
}, this.config.updateInterval);
},

getData() {
getData () {
this.sendSocketNotification('MMM-CTA-FETCH', {
trainApiKey: this.config.trainApiKey,
busApiKey: this.config.busApiKey,
Expand All @@ -45,11 +45,11 @@ Module.register('MMM-CTA', {
});
},

getTemplate() {
getTemplate () {
return 'templates/MMM-CTA.njk';
},

getTemplateData() {
getTemplateData () {
return {
loading: this.loading,
routeIcons: this.config.routeIcons,
Expand All @@ -67,25 +67,25 @@ Module.register('MMM-CTA', {
};
},

getScripts() {
getScripts () {
return [];
},

getStyles() {
getStyles () {
return [
'font-awesome.css',
'MMM-CTA.css',
];
},

getTranslations() {
getTranslations () {
return {
en: 'translations/en.json',
es: 'translations/es.json',
};
},

socketNotificationReceived(notification, payload) {
socketNotificationReceived (notification, payload) {
if (notification !== 'MMM-CTA-DATA') {
return;
}
Expand All @@ -95,15 +95,15 @@ Module.register('MMM-CTA', {
this.updateDom(300);
},

getMinutesUntil(arrivalTime) {
getMinutesUntil (arrivalTime) {
const now = new Date();
const diffInMilliseconds = new Date(arrivalTime) - now;
const diffInMinutes = Math.floor(diffInMilliseconds / 1000 / 60);

return this.formatMinutes(diffInMinutes);
},

formatMinutes(minutes) {
formatMinutes (minutes) {
const minutesInt = parseInt(minutes, 10);

if (Number.isNaN(minutesInt)) {
Expand All @@ -115,19 +115,19 @@ Module.register('MMM-CTA', {
return this.minutesWithSuffix(minutesInt);
},

minutesWithSuffix(minutes) {
minutesWithSuffix (minutes) {
switch (this.config.suffixStyle) {
case 'none':
return minutes.toString();
case 'short':
return `${minutes.toString()}m`;
case 'long':
default:
if (minutes === 1) {
return `${minutes.toString()} min`;
}

return `${minutes.toString()} mins`;
case 'none':
return minutes.toString();
case 'short':
return `${minutes.toString()}m`;
case 'long':
default:
if (minutes === 1) {
return `${minutes.toString()} min`;
}

return `${minutes.toString()} mins`;
}
},
});
36 changes: 18 additions & 18 deletions __mocks__/Module.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable no-param-reassign */
global.Module = {
definitions: {},

create(name) {
create (name) {
return this.definitions[name];
},

register(name, overrides) {
register (name, overrides) {
const base = {
requiresVersion: '2.0.0',

Expand All @@ -18,33 +18,33 @@ global.Module = {

_nunjucksEnvironment: { addFilter: jest.fn() },

init() {
init () {
Log.log(this.defaults);
},

start() {
start () {
Log.info(`Starting module: ${this.name}`);
},

getScripts() {
getScripts () {
return [];
},

getStyles() {
getStyles () {
return [];
},

getTranslations() {
getTranslations () {
return false;
},

getDom: jest.fn(),

getHeader() {
getHeader () {
return this.data.header;
},

getTemplate() {
getTemplate () {
return (
`<div class="normal">${
this.name
Expand All @@ -54,11 +54,11 @@ global.Module = {
);
},

getTemplateData() {
getTemplateData () {
return {};
},

notificationReceived(notification, payload, sender) {
notificationReceived (notification, payload, sender) {
if (sender) {
Log.log(
`${this.name
Expand All @@ -74,11 +74,11 @@ global.Module = {
}
},

nunjucksEnvironment() {
nunjucksEnvironment () {
return this._nunjucksEnvironment;
},

socketNotificationReceived(notification, payload) {
socketNotificationReceived (notification, payload) {
Log.log(
`${this.name
} received a socket notification: ${
Expand All @@ -88,15 +88,15 @@ global.Module = {
);
},

suspend() {
suspend () {
Log.log(`${this.name} is suspended.`);
},

resume() {
resume () {
Log.log(`${this.name} is resumed.`);
},

setData(data) {
setData (data) {
this.data = data;
this.name = data.name;
this.identifier = data.identifier;
Expand All @@ -105,7 +105,7 @@ global.Module = {
this.setConfig(data.config, data.configDeepMerge);
},

setConfig(config) {
setConfig (config) {
this.config = { ...this.defaults, ...config };
},

Expand Down
16 changes: 8 additions & 8 deletions __mocks__/node_helper.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/* eslint-disable no-unused-vars */
module.exports = {
create(overrides) {
create (overrides) {
const base = {
init() {},
init () {},

loaded(callback) {
loaded (callback) {
callback();
},

start() {},
start () {},

stop() {},
stop () {},

socketNotificationReceived(notification, payload) {},
socketNotificationReceived (notification, payload) {},

setName(name) {
setName (name) {
this.name = name;
},

setPath(path) {
setPath (path) {
this.path = path;
},

Expand Down
13 changes: 5 additions & 8 deletions __tests__/MMM-CTA.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/* eslint-disable global-require */
beforeAll(() => {
require('../__mocks__/Module');
require('../__mocks__/globalLogger');
});
require('../__mocks__/Module');
require('../__mocks__/globalLogger');

const name = 'MMM-CTA';

Expand Down Expand Up @@ -176,11 +173,11 @@ describe('getTemplateData', () => {

describe('train information', () => {
beforeEach(() => {
now = new Date();
const now = new Date();
jest.useFakeTimers().setSystemTime(now); // Ensures time is consistent
threeMinutes = new Date();
const threeMinutes = new Date();
threeMinutes.setMinutes(threeMinutes.getMinutes() + 1);
twelveMinutes = new Date();
const twelveMinutes = new Date();
twelveMinutes.setMinutes(twelveMinutes.getMinutes() + 12);

stops = [{
Expand Down
3 changes: 0 additions & 3 deletions __tests__/node_helper.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { default: fetchMock } = require('fetch-mock');

/* eslint-disable global-require */
beforeAll(() => {
require('../__mocks__/logger');
});
Expand Down Expand Up @@ -131,8 +130,6 @@ let fetch;

beforeEach(() => {
helper = require('../node_helper');
Log = require('logger'); // eslint-disable-line import/no-unresolved

helper.setName('MMM-CTA');
});

Expand Down
Loading

0 comments on commit 02b3349

Please sign in to comment.