Skip to content

Commit

Permalink
Switch to ESLint flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
KristjanESPERANTO committed Apr 2, 2024
1 parent 16546f4 commit d3ebb4d
Show file tree
Hide file tree
Showing 7 changed files with 8,830 additions and 3,372 deletions.
31 changes: 0 additions & 31 deletions .eslintrc.json

This file was deleted.

2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js
*.mjs
36 changes: 18 additions & 18 deletions MMM-JsonTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ Module.register("MMM-JsonTable", {
descriptiveRow: null
},

start() {
start () {
this.getJson();
this.scheduleUpdate();
},

scheduleUpdate() {
scheduleUpdate () {
const self = this;
setInterval(() => {
self.getJson();
}, this.config.updateInterval);
},

// Request node_helper to get json from url
getJson() {
getJson () {
this.sendSocketNotification("MMM-JsonTable_GET_JSON", this.config.url);
},

socketNotificationReceived(notification, payload) {
socketNotificationReceived (notification, payload) {
if (notification === "MMM-JsonTable_JSON_RESULT") {
// Only continue if the notification came from the request we made
// This way we can load the module more than once
Expand All @@ -46,7 +46,7 @@ Module.register("MMM-JsonTable", {
},

// Override dom generator.
getDom() {
getDom () {
const wrapper = document.createElement("div");
wrapper.className = "xsmall";

Expand Down Expand Up @@ -87,7 +87,7 @@ Module.register("MMM-JsonTable", {
return wrapper;
},

getTableRow(jsonObject) {
getTableRow (jsonObject) {
const row = document.createElement("tr");
Object.entries(jsonObject).forEach(([key, value]) => {
const cell = document.createElement("td");
Expand All @@ -107,9 +107,9 @@ Module.register("MMM-JsonTable", {
const cellText = document.createTextNode(valueToDisplay);

if (this.config.size > 0 && this.config.size < 9) {
const h = document.createElement(`H${this.config.size}`);
h.appendChild(cellText);
cell.appendChild(h);
const heading = document.createElement(`H${this.config.size}`);
heading.appendChild(cellText);
cell.appendChild(heading);
} else {
cell.appendChild(cellText);
}
Expand All @@ -120,19 +120,19 @@ Module.register("MMM-JsonTable", {
},

// Format a date string or return the input
getFormattedValue(input) {
const m = moment(input);
if (typeof input === "string" && m.isValid()) {
getFormattedValue (input) {
const momentObj = moment(input);
if (typeof input === "string" && momentObj.isValid()) {
// Show a formatted time if it occures today
if (
m.isSame(new Date(Date.now()), "day") &&
m.hours() !== 0 &&
m.minutes() !== 0 &&
m.seconds() !== 0
momentObj.isSame(new Date(Date.now()), "day") &&
momentObj.hours() !== 0 &&
momentObj.minutes() !== 0 &&
momentObj.seconds() !== 0
) {
return m.format("HH:mm:ss");
return momentObj.format("HH:mm:ss");
}
return m.format("YYYY-MM-DD");
return momentObj.format("YYYY-MM-DD");
}
return input;
}
Expand Down
42 changes: 42 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import eslintPluginImport from "eslint-plugin-import";
import eslintPluginJs from "@eslint/js";
import eslintPluginJsonc from "eslint-plugin-jsonc";
import eslintPluginStylistic from "@stylistic/eslint-plugin";
import globals from "globals";

export default [
...eslintPluginJsonc.configs["flat/recommended-with-json"],
{
files: ["**/*.js", "**/*.mjs"],
languageOptions: {
globals: {
...globals.browser,
...globals.nodeBuiltin,
...globals.node
}
},
plugins: {
...eslintPluginStylistic.configs["all-flat"].plugins,
import: eslintPluginImport
},
rules: {
...eslintPluginJs.configs.all.rules,
...eslintPluginImport.configs.recommended.rules,
...eslintPluginStylistic.configs["all-flat"].rules,
"capitalized-comments": "off",
"consistent-this": "off",
"max-statements": ["error", 25],
"multiline-comment-style": "off",
"no-magic-numbers": "off",
"one-var": "off",
"sort-keys": "off",
"@stylistic/array-element-newline": ["error", "consistent"],
"@stylistic/dot-location": ["error", "property"],
"@stylistic/function-call-argument-newline": ["error", "consistent"],
"@stylistic/indent": ["error", 2],
"@stylistic/quote-props": ["error", "as-needed"],
"@stylistic/padded-blocks": ["error", "never"]
}
}
];

6 changes: 3 additions & 3 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const NodeHelper = require("node_helper");
const Log = require("logger");

module.exports = NodeHelper.create({
start() {
start () {
Log.log("MMM-JsonTable helper started...");
},

getJson(url) {
getJson (url) {
const self = this;

fetch(url)
Expand All @@ -21,7 +21,7 @@ module.exports = NodeHelper.create({
},

// Subclass socketNotificationReceived received.
socketNotificationReceived(notification, url) {
socketNotificationReceived (notification, url) {
if (notification === "MMM-JsonTable_GET_JSON") {
this.getJson(url);
}
Expand Down
Loading

0 comments on commit d3ebb4d

Please sign in to comment.