Skip to content

Commit 7226765

Browse files
[docs] add README best practice (#57)
Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com>
1 parent 709e7d5 commit 7226765

3 files changed

Lines changed: 85 additions & 6 deletions

File tree

guides/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,24 @@ Please help use to improve this guide. If you have any suggestions, please creat
1010

1111
## Hint "No ESLint configuration was found. ESLint is very helpful, it is worth using it even for small projects."
1212

13-
To get started with ESLint checkout [ESLint](eslint.md).
13+
To get started with ESLint, check out [ESLint](eslint.md).
14+
15+
## Hint "Recommendation: The README seems not to have a config example. Please add one."
16+
17+
For information on best practices for a README config section, check out [Config Instructions](readme_bestpractices.md#Config-Instructions).
18+
19+
## Hint "Recommendation: The README seems not to have an install section (like ## Installation). Please add one."
20+
21+
For information on best practices for a README installation section, check out [Installation Instructions](readme_bestpractices.md#Installation-Instructions).
22+
23+
## Hint "Recommendation: The README seems not to have an update section (like ## Update). Please add one."
24+
25+
For information on best practices for a README update section, check out [Update Instructions](readme_bestpractices.md#Update-Instructions).
26+
27+
## Hint "Recommendation: The README seems to have a config example without a trailing comma. Please add one."
28+
29+
For information on best practices for a README config section, check out [Config Instructions](readme_bestpractices.md#Config-Instructions).
30+
31+
## Hint "Recommendation: The README seems to have a modules array (Found modules: [). This is usually not necessary. Please remove it if it is not needed."
32+
33+
For information on best practices for a README config section, check out [Config Instructions](readme_bestpractices.md#Config-Instructions).

guides/readme_bestpractices.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
This file contains suggested best practices for creating a README file for your MagicMirror² module.
2+
3+
# Installation Instructions
4+
5+
Your README file should have an "Installation" section that includes a code block that can be pasted into a user's terminal to fully install your module. Here is a good example of an install code block:
6+
7+
## Example if your module has no dependencies
8+
9+
````
10+
```bash
11+
cd ~/MagicMirror/modules
12+
git clone https://github.com/MyUsername/MMM-MyModule
13+
```
14+
````
15+
16+
## Example if your module has dependencies
17+
18+
````
19+
```bash
20+
cd ~/MagicMirror/modules
21+
git clone https://github.com/MyUsername/MMM-MyModule
22+
cd MMM-MyModule
23+
npm ci --omit=dev
24+
```
25+
````
26+
27+
## Tips
28+
29+
* The code block should not be broken up into multiple separate blocks for each line of code so that users can copy and paste the entire block into their terminal and execute the install with one click.
30+
* The opening `` ``` `` of your code block should be followed by "`sh`" or "`bash`" so that the code block is styled as shell script.
31+
* If your module has required dependencies, `npm ci` is preferable to `npm install` in many circumstances because it will repeatably instruct users' machines not to recreate the `package-lock.json` file.
32+
* Adding `--omit=dev` to the `npm ci` or `npm install` command will instruct users' machines not to install developer dependencies that are unneeded by most users, which will save on install time and disk space.
33+
34+
# Update Instructions
35+
36+
Your README file should have an "Update" section that includes a code block that can be pasted into a user's terminal to update your module.
37+
38+
# Config Instructions
39+
40+
Your README file should have a "Config" or "Configuration" section that includes an example config block that can be pasted into user's `config.js` files. Here is a good example of a config code block:
41+
42+
````
43+
```js
44+
{
45+
module: MMM-MyModule,
46+
position: bottom_bar,
47+
config: {
48+
myCustomVariable: 400,
49+
MySecondCustomVariable: false
50+
}
51+
},
52+
```
53+
````
54+
55+
## Tips
56+
57+
* The opening `` ``` `` of your code block should be followed by "`js`" or "`javascript`" so that the code block is styled as javasript.
58+
* The final `}` should be followed by a `,` so that the block can be copied and pasted straight into users' `config.js` files without throwing errors.
59+
* The example config should provide a minimal demo configuration that will get your module working if pasted directly into a user's `config.js` file.

scripts/check_modules.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,15 @@ def check_modules():
359359
file_path, "## Updat")
360360
if not found_update_section:
361361
module["issues"].append(
362-
"Recommendation: The README seems not to have an update section (like `## Update`). Please add one."
362+
"Recommendation: The README seems not to have an update section (like `## Update`). Please add one ([basic instructions](https://github.com/MagicMirrorOrg/MagicMirror-3rd-Party-Modules/blob/main/guides/readme_bestpractices.md#Update-Instructions))."
363363
)
364364

365365
# Search for an install section in README
366366
found_install_section = search_in_file(
367367
file_path, "## Install")
368368
if not found_install_section:
369369
module["issues"].append(
370-
"Recommendation: The README seems not to have an install section (like `## Installation`). Please add one."
370+
"Recommendation: The README seems not to have an install section (like `## Installation`). Please add one ([basic instructions](https://github.com/MagicMirrorOrg/MagicMirror-3rd-Party-Modules/blob/main/guides/readme_bestpractices.md#Installation-Instructions))."
371371
)
372372

373373
# Search for "modules: [" in README
@@ -377,7 +377,7 @@ def check_modules():
377377

378378
if found_modules_string and module["name"] not in false_positive_modules:
379379
module["issues"].append(
380-
"Recommendation: The README seems to have a modules array (Found `modules: [`). This is usually not necessary. Please remove it if it is not needed."
380+
"Recommendation: The README seems to have a modules array (Found `modules: [`). This is usually not necessary. Please remove it if it is not needed ([basic instructions](https://github.com/MagicMirrorOrg/MagicMirror-3rd-Party-Modules/blob/main/guides/readme_bestpractices.md#Config-Instructions))."
381381
)
382382

383383
# Search for config example with regex "\{\s*[^}]*?\s*config:\s*\{\s*[^}]*\}(?!\s*,\s*\})\s*\}"
@@ -389,7 +389,7 @@ def check_modules():
389389
false_positive_modules = ["MMM-CalendarExt2"]
390390
if not found_modules_string and module["name"] not in false_positive_modules:
391391
module["issues"].append(
392-
"Recommendation: The README seems not to have a config example. Please add one."
392+
"Recommendation: The README seems not to have a config example. Please add one ([basic instructions](https://github.com/MagicMirrorOrg/MagicMirror-3rd-Party-Modules/blob/main/guides/readme_bestpractices.md#Config-Instructions))."
393393
)
394394
else:
395395
# Check if the config example has an trailing comma
@@ -398,7 +398,7 @@ def check_modules():
398398
false_positive_modules = ["MMM-MealieMenu", "MMM-Remote-Control"]
399399
if not found_trailing_comma and module["name"] not in false_positive_modules:
400400
module["issues"].append(
401-
"Recommendation: The README seems to have a config example without a trailing comma. Please add one."
401+
"Recommendation: The README seems to have a config example without a trailing comma. Please add one ([basic instructions](https://github.com/MagicMirrorOrg/MagicMirror-3rd-Party-Modules/blob/main/guides/readme_bestpractices.md#Config-Instructions))."
402402
)
403403

404404
if len(module["issues"]) < 1:

0 commit comments

Comments
 (0)