Skip to content

Commit

Permalink
Merge pull request #18 from JHWelch/update-eslint
Browse files Browse the repository at this point in the history
Update eslint
  • Loading branch information
JHWelch authored Oct 20, 2024
2 parents a7b0985 + 02b3349 commit ea5fb9f
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 91 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
50 changes: 50 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import stylisticJs from '@stylistic/eslint-plugin-js';

export default [
{files: ['**/*.js'], languageOptions: {sourceType: 'commonjs'}},
{languageOptions: { globals: globals.browser }},
pluginJs.configs.recommended,
{
languageOptions: {
globals: {
...globals.jest,
Log: 'readonly',
nunjucks: 'writable',
translate: 'writable',
},
},
plugins: {
'@stylistic': stylisticJs,
},
rules: {
// Stylistic rules
'@stylistic/comma-dangle': ['error', 'always-multiline'],
'@stylistic/indent': ['error', 2],
'@stylistic/max-len': ['error', {
ignoreStrings: true,
ignoreTrailingComments: true,
ignoreUrls: true,
tabWidth: 2,
}],
'@stylistic/no-multi-spaces': 'error',
'@stylistic/no-multiple-empty-lines': ['error', { max: 1 }],
'@stylistic/quote-props': ['error', 'as-needed'],
'@stylistic/quotes': ['error', 'single', {
avoidEscape: true,
}],
'@stylistic/semi': ['error', 'always'],
'@stylistic/space-before-function-paren': ['error', 'always'],

// ESLint rules
'no-console': ['error', {
allow: ['warn', 'error'],
}],
'no-unused-vars': ['error', {
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
}],
},
},
];
Loading

0 comments on commit ea5fb9f

Please sign in to comment.