Skip to content

Commit 057c075

Browse files
chore: add eslint-plugin-jsdoc and improve documentation
1 parent 8462322 commit 057c075

8 files changed

Lines changed: 226 additions & 12 deletions

File tree

MMM-Remote-Control.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Module.register("MMM-Remote-Control", {
167167

168168
/**
169169
* Handle DEFAULT_SETTINGS notification - manage module visibility
170-
* @param {Object} payload - Settings data
170+
* @param {object} payload - Settings data
171171
*/
172172
handleDefaultSettings (payload) {
173173
let {settingsVersion} = payload;
@@ -208,7 +208,7 @@ Module.register("MMM-Remote-Control", {
208208
/**
209209
* Handle HIDE/SHOW/TOGGLE notifications - manage module visibility
210210
* @param {string} notification - Type of visibility action
211-
* @param {Object} payload - Notification data with module info
211+
* @param {object} payload - Notification data with module info
212212
*/
213213
handleModuleVisibility (notification, payload) {
214214
const options = {lockString: this.identifier};

eslint.config.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {flatConfigs as importX} from "eslint-plugin-import-x";
55
import js from "@eslint/js";
66
import json from "@eslint/json";
77
import markdown from "@eslint/markdown";
8+
import pluginJsdoc from "eslint-plugin-jsdoc";
89
import stylistic from "@stylistic/eslint-plugin";
910
import unicorn from "eslint-plugin-unicorn";
1011

@@ -22,8 +23,8 @@ export default defineConfig([
2223
"$node": "writable"
2324
}
2425
},
25-
"plugins": {js, stylistic},
26-
"extends": [importX.recommended, "js/recommended", "stylistic/all", unicorn.configs.recommended],
26+
"plugins": {js, "jsdoc": pluginJsdoc, stylistic},
27+
"extends": [importX.recommended, pluginJsdoc.configs["flat/recommended"], "js/recommended", "stylistic/all", unicorn.configs.recommended],
2728
"rules": {
2829
"@stylistic/array-element-newline": ["error", "consistent"],
2930
"@stylistic/brace-style": ["error", "1tbs", {"allowSingleLine": true}],
@@ -51,6 +52,12 @@ export default defineConfig([
5152
"unicorn/switch-case-braces": ["error", "avoid"]
5253
}
5354
},
55+
{
56+
"files": ["**/*.test.js"],
57+
"rules": {
58+
"jsdoc/require-jsdoc": "off"
59+
}
60+
},
5461
{
5562
"files": ["**/*.mjs"],
5663
"languageOptions": {

lib/configUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
* cleanConfig removes keys from the full MagicMirror config object that equal their defaults.
33
* It mirrors the logic inside removeDefaultValues in node_helper.js but is pure and testable.
44
* Mutates and also returns the provided config object.
5-
*
6-
* @param {object} params
5+
* @param {object} params - Configuration cleaning parameters
76
* @param {object} params.config - The full runtime config (will be mutated)
87
* @param {object} params.defaultConfig - Global MagicMirror default config
9-
* @param {Object.<string,object>} params.moduleDefaultsMap - Map moduleName -> defaults
8+
* @param {Record<string, object>} params.moduleDefaultsMap - Map moduleName -> defaults
109
* @param {Array<object>} [params.moduleDataFromBrowser] - Optional list providing defaults for bundled modules
10+
* @returns {object} The cleaned config object (same reference as input)
1111
*/
1212
function cleanConfig ({config, defaultConfig, moduleDefaultsMap, moduleDataFromBrowser = []}) {
1313
if (!config || typeof config !== "object") return config;

lib/utils.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,33 @@
33
* Pure functions – no side effects.
44
*/
55

6+
/**
7+
* Capitalizes the first character of a string.
8+
* @param {string} string - The string to capitalize
9+
* @returns {string} String with first character capitalized
10+
*/
611
function capitalizeFirst (string) {
712
if (!string) return string;
813
return string.charAt(0).toUpperCase() + string.slice(1);
914
}
1015

16+
/**
17+
* Formats a module name by removing MMM- prefix and converting to title case.
18+
* @param {string} string - The module name to format
19+
* @returns {string} Formatted module name with spaces and title case
20+
*/
1121
function formatName (string) {
1222
if (!string) return string;
1323
// Original logic: strip MMM-, split camelCase, convert delimiters to spaces & capitalize
1424
return string.replaceAll("MMM-", "").replaceAll(/([a-z])([A-Z])/g, "$1 $2").replaceAll(/(^|[-_])(\w)/g, ($0, $1, $2) => ($1 && " ") + $2.toUpperCase());
1525
}
1626

27+
/**
28+
* Checks if a string contains a pattern (null-safe).
29+
* @param {string} pattern - The pattern to search for
30+
* @param {string} string - The string to search in
31+
* @returns {boolean} True if pattern is found in string
32+
*/
1733
function includes (pattern, string) {
1834
if (string == undefined) return false;
1935
return string.includes(pattern);

node_helper.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,10 +817,10 @@ module.exports = NodeHelper.create({
817817
/**
818818
* Sends custom notification to MagicMirror modules.
819819
* Attempts to parse JSON string payloads, falls back to raw string on error.
820-
* @param {Object} query - Query with notification name and optional payload
820+
* @param {object} query - Query with notification name and optional payload
821821
* @param {string} query.notification - Notification name to broadcast
822-
* @param {*} query.payload - Payload (object, JSON string, or primitive)
823-
* @param {Object} res - Express response object
822+
* @param {object|string|number|boolean|null} query.payload - Payload (object, JSON string, or primitive)
823+
* @param {object} res - Express response object
824824
* @returns {boolean} Always true (errors are handled internally)
825825
*/
826826
handleNotification (query, res) {
@@ -928,8 +928,8 @@ module.exports = NodeHelper.create({
928928
/**
929929
* Forwards action to frontend without validation.
930930
* Used for SHOW/HIDE/TOGGLE - frontend filters invalid/missing module parameters.
931-
* @param {Object} query - Query object containing action and optional module identifier
932-
* @param {Object} res - Express response object or socket placeholder
931+
* @param {object} query - Query object containing action and optional module identifier
932+
* @param {object} res - Express response object or socket placeholder
933933
*/
934934
handleSimpleSocketNotification (query, res) {
935935
this.sendSocketNotification(query.action, query);

package-lock.json

Lines changed: 186 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)