Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ESLint flat config #96

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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