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

Add JavaScript linting and GitHub workflow for testing #310

Merged
merged 3 commits into from
Nov 20, 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
5 changes: 4 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ We ask you to keep contributing, and feel free to open as many issues and PR as

## Developer commands

- `npm run test` - Run spelling check.
- `npm run lint` - Run linting checks.
- `npm run lint:fix` - Fix linting issues.
- `npm run test` - Run linting and formatter checks + Run spelling check.
- `npm run test:spelling` - Run spelling check.
30 changes: 30 additions & 0 deletions .github/workflows/automated-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Automated Tests
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]

permissions:
contents: read

jobs:
run-lint:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- run: echo "Starting automated tests for ${{ github.repository }} on ${{ github.ref }}"
- name: Check out repository code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Check spelling
run: npm run test:spelling
- name: Check linting
run: npm run lint
- run: echo "Test job status is ${{ job.status }}."
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ node_modules
# Default settings
settings.json

# Package Lock File
package-lock.json

2 changes: 1 addition & 1 deletion API/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

const path = require("path");
const url = require("url");
const fs = require("fs");

Check warning on line 10 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

'fs' is assigned a value but never used
const os = require("os");

Check warning on line 11 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

'os' is assigned a value but never used
const uuid = require("uuid/v4");
const bodyParser = require("body-parser");
const express = require("express");
Expand All @@ -20,7 +20,7 @@
*/
getApiKey() {
let thisConfig = this.configOnHd.modules.find(x => x.module === "MMM-Remote-Control");
if (typeof "thisConfig" !== "undefined" &&

Check warning on line 23 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

Unexpected constant truthiness on the left-hand side of a `&&` expression
"config" in thisConfig){
if ("apiKey" in thisConfig.config &&
thisConfig.config.apiKey !== '') {
Expand Down Expand Up @@ -48,8 +48,8 @@
if (!this.configOnHd) { return undefined; }

let getActions = function(content) {
let re = /notification \=\=\=? (?:"|')([A-Z_-]+?)(?:"|')|case (?:"|')([A-Z_-]+)(?:"|')/g;

Check warning on line 51 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

Unnecessary escape character: \=

Check warning on line 51 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

Unnecessary escape character: \=

Check warning on line 51 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

Unnecessary escape character: \=
let m;

Check warning on line 52 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

'm' is defined but never used
let availableActions = [];
if (re.test(content)) {
content.match(re).forEach((match) => {
Expand All @@ -72,7 +72,7 @@

this.configOnHd.modules.filter(mod => skippedModules.indexOf(mod.module) === -1).forEach(mod => {
try {
let modActions = getActions(Module.notificationHandler[mod.module]);

Check warning on line 75 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

'Module' is not defined

if (modActions.length > 0) {
let pathGuess = mod.module.replace(/MMM-/g, '').replace(/-/g, '').toLowerCase();
Expand Down Expand Up @@ -102,8 +102,8 @@
this.updateModuleApiMenu();
},

createApiRoutes() {

Check warning on line 105 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

Method 'createApiRoutes' has too many lines (204). Maximum allowed is 200
var self = this;

Check warning on line 106 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

Unexpected var, use let or const instead

this.getApiKey();

Expand Down Expand Up @@ -290,7 +290,7 @@
actionName = req.body.monitor.toUpperCase();
}
} else {
var actionName = req.params.action ? req.params.action.toUpperCase() : "STATUS";
actionName = req.params.action ? req.params.action.toUpperCase() : "STATUS";
}
this.executeQuery(this.checkDelay({ action: `MONITOR${actionName}` }, req), res);
});
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

### Added

- Added a spell checker and fixed problems that were found.
- Added a spell checker and fixed problems that were found (#308).
- Added JavaScript linting (for the start with soft rules).
- Added GitHub workflow for linting and spell checking on every push and pull request.

## [2.4.0] - 2024-10-08

Expand Down
61 changes: 61 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import eslintPluginImport from "eslint-plugin-import";
import eslintPluginJs from "@eslint/js";
import globals from "globals";

const config = [
eslintPluginImport.flatConfigs.recommended,
eslintPluginJs.configs.recommended,
{
"ignores": ["**/*.min.js"]
},
{
"files": ["**/*.js"],
"languageOptions": {
"globals": {
...globals.browser,
...globals.node
},
"sourceType": "commonjs"
},
"rules": {
"capitalized-comments": "off",
"consistent-this": "off",
"line-comment-position": "off",
"max-lines-per-function": ["warn", 200],
"max-statements": ["warn", 60],
"multiline-comment-style": "off",
"no-await-in-loop": "off",
"no-constant-binary-expression": "warn",
"no-inline-comments": "off",
"no-magic-numbers": "off",
"no-plusplus": "off",
"no-prototype-builtins": "warn",
"no-undef": "warn",
"no-unused-vars": "warn",
"no-useless-escape": "warn",
"no-var": "warn",
"one-var": "off",
"sort-keys": "off",
"strict": "off"
}
},
{
"files": ["**/*.mjs"],
"languageOptions": {
"ecmaVersion": "latest",
"globals": {
...globals.node
},
"sourceType": "module"
},
"rules": {
"func-style": "off",
"max-lines-per-function": ["error", 100],
"no-magic-numbers": "off",
"one-var": "off",
"prefer-destructuring": "off"
}
}
];

export default config;
Loading