mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-22 13:09:26 +00:00
Replace prettier by stylistic to lint JavaScript (#3303)
In the latest versions of ESLint, more and more formatting rules were removed or declared deprecated. These rules have been integrated into the new Stylistic package (https://eslint.style/guide/why) and expanded. Stylistic acts as a better formatter for JavaScript as Prettier. With this PR there are many changes that make the code more uniform, but it may be difficult to review due to the large amount. Even if I have no worries about the changes, perhaps this would be something for the release after next. Let me know what you think.
This commit is contained in:
committed by
GitHub
parent
4e7b68a69d
commit
0b70274a1a
@@ -7,22 +7,22 @@ const Log = require("logger");
|
||||
const BASE_DIR = path.normalize(`${__dirname}/../../../`);
|
||||
|
||||
class GitHelper {
|
||||
constructor() {
|
||||
constructor () {
|
||||
this.gitRepos = [];
|
||||
this.gitResultList = [];
|
||||
}
|
||||
|
||||
getRefRegex(branch) {
|
||||
getRefRegex (branch) {
|
||||
return new RegExp(`s*([a-z,0-9]+[.][.][a-z,0-9]+) ${branch}`, "g");
|
||||
}
|
||||
|
||||
async execShell(command) {
|
||||
async execShell (command) {
|
||||
const { stdout = "", stderr = "" } = await exec(command);
|
||||
|
||||
return { stdout, stderr };
|
||||
}
|
||||
|
||||
async isGitRepo(moduleFolder) {
|
||||
async isGitRepo (moduleFolder) {
|
||||
const { stderr } = await this.execShell(`cd ${moduleFolder} && git remote -v`);
|
||||
|
||||
if (stderr) {
|
||||
@@ -34,7 +34,7 @@ class GitHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
async add(moduleName) {
|
||||
async add (moduleName) {
|
||||
let moduleFolder = BASE_DIR;
|
||||
|
||||
if (moduleName !== "MagicMirror") {
|
||||
@@ -59,7 +59,7 @@ class GitHelper {
|
||||
}
|
||||
}
|
||||
|
||||
async getStatusInfo(repo) {
|
||||
async getStatusInfo (repo) {
|
||||
let gitInfo = {
|
||||
module: repo.module,
|
||||
behind: 0, // commits behind
|
||||
@@ -114,7 +114,7 @@ class GitHelper {
|
||||
return gitInfo;
|
||||
}
|
||||
|
||||
async getRepoInfo(repo) {
|
||||
async getRepoInfo (repo) {
|
||||
const gitInfo = await this.getStatusInfo(repo);
|
||||
|
||||
if (!gitInfo || !gitInfo.current) {
|
||||
@@ -174,7 +174,7 @@ class GitHelper {
|
||||
}
|
||||
}
|
||||
|
||||
async getRepos() {
|
||||
async getRepos () {
|
||||
this.gitResultList = [];
|
||||
|
||||
for (const repo of this.gitRepos) {
|
||||
@@ -192,7 +192,7 @@ class GitHelper {
|
||||
return this.gitResultList;
|
||||
}
|
||||
|
||||
async checkUpdates() {
|
||||
async checkUpdates () {
|
||||
var updates = [];
|
||||
|
||||
const allRepos = await this.gitResultList.map((module) => {
|
||||
|
@@ -14,7 +14,7 @@ module.exports = NodeHelper.create({
|
||||
gitHelper: new GitHelper(),
|
||||
updateHelper: null,
|
||||
|
||||
async configureModules(modules) {
|
||||
async configureModules (modules) {
|
||||
for (const moduleName of modules) {
|
||||
if (!this.ignoreUpdateChecking(moduleName)) {
|
||||
await this.gitHelper.add(moduleName);
|
||||
@@ -26,7 +26,7 @@ module.exports = NodeHelper.create({
|
||||
}
|
||||
},
|
||||
|
||||
async socketNotificationReceived(notification, payload) {
|
||||
async socketNotificationReceived (notification, payload) {
|
||||
switch (notification) {
|
||||
case "CONFIG":
|
||||
this.config = payload;
|
||||
@@ -51,7 +51,7 @@ module.exports = NodeHelper.create({
|
||||
}
|
||||
},
|
||||
|
||||
async performFetch() {
|
||||
async performFetch () {
|
||||
const repos = await this.gitHelper.getRepos();
|
||||
|
||||
for (const repo of repos) {
|
||||
@@ -76,7 +76,7 @@ module.exports = NodeHelper.create({
|
||||
this.scheduleNextFetch(this.config.updateInterval);
|
||||
},
|
||||
|
||||
scheduleNextFetch(delay) {
|
||||
scheduleNextFetch (delay) {
|
||||
clearTimeout(this.updateTimer);
|
||||
|
||||
this.updateTimer = setTimeout(
|
||||
@@ -87,7 +87,7 @@ module.exports = NodeHelper.create({
|
||||
);
|
||||
},
|
||||
|
||||
ignoreUpdateChecking(moduleName) {
|
||||
ignoreUpdateChecking (moduleName) {
|
||||
// Should not check for updates for default modules
|
||||
if (defaultModules.includes(moduleName)) {
|
||||
return true;
|
||||
|
@@ -39,7 +39,7 @@ const Log = require("logger");
|
||||
*/
|
||||
|
||||
class Updater {
|
||||
constructor(config) {
|
||||
constructor (config) {
|
||||
this.updates = config.updates;
|
||||
this.timeout = config.updateTimeout;
|
||||
this.autoRestart = config.updateAutorestart;
|
||||
@@ -53,7 +53,7 @@ class Updater {
|
||||
}
|
||||
|
||||
// [main command] parse if module update is needed
|
||||
async parse(modules) {
|
||||
async parse (modules) {
|
||||
var parser = modules.map(async (module) => {
|
||||
if (this.moduleList[module.module] === undefined) {
|
||||
this.moduleList[module.module] = {};
|
||||
@@ -90,7 +90,7 @@ class Updater {
|
||||
// updated: <boolean>, // if updated successfully
|
||||
// needRestart: <boolean> // if magicmirror restart required
|
||||
//};
|
||||
updateProcess(module) {
|
||||
updateProcess (module) {
|
||||
let Result = {
|
||||
error: false,
|
||||
updated: false,
|
||||
@@ -130,13 +130,13 @@ class Updater {
|
||||
}
|
||||
|
||||
// restart rules (pm2 or npm start)
|
||||
restart() {
|
||||
restart () {
|
||||
if (this.usePM2) this.pm2Restart();
|
||||
else this.npmRestart();
|
||||
}
|
||||
|
||||
// restart MagicMiror with "pm2"
|
||||
pm2Restart() {
|
||||
pm2Restart () {
|
||||
Log.info("updatenotification: PM2 will restarting MagicMirror...");
|
||||
Exec(`pm2 restart ${this.PM2}`, (err, std, sde) => {
|
||||
if (err) {
|
||||
@@ -146,7 +146,7 @@ class Updater {
|
||||
}
|
||||
|
||||
// restart MagicMiror with "npm start"
|
||||
npmRestart() {
|
||||
npmRestart () {
|
||||
Log.info("updatenotification: Restarting MagicMirror...");
|
||||
const out = process.stdout;
|
||||
const err = process.stderr;
|
||||
@@ -156,7 +156,7 @@ class Updater {
|
||||
}
|
||||
|
||||
// Check using pm2
|
||||
check_PM2_Process() {
|
||||
check_PM2_Process () {
|
||||
Log.info("updatenotification: Checking PM2 using...");
|
||||
return new Promise((resolve) => {
|
||||
commandExists("pm2")
|
||||
@@ -191,7 +191,7 @@ class Updater {
|
||||
}
|
||||
|
||||
// Get the list of pm2 process
|
||||
PM2_GetList() {
|
||||
PM2_GetList () {
|
||||
return new Promise((resolve) => {
|
||||
Exec("pm2 jlist", (err, std, sde) => {
|
||||
if (err) {
|
||||
@@ -211,13 +211,13 @@ class Updater {
|
||||
}
|
||||
|
||||
// check if module is MagicMirror
|
||||
isMagicMirror(module) {
|
||||
isMagicMirror (module) {
|
||||
if (module === "MagicMirror") return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// search update module command
|
||||
applyCommand(module) {
|
||||
applyCommand (module) {
|
||||
if (this.isMagicMirror(module.module)) return null;
|
||||
let command = null;
|
||||
this.updates.forEach((updater) => {
|
||||
|
@@ -20,7 +20,7 @@ Module.register("updatenotification", {
|
||||
needRestart: false,
|
||||
updates: {},
|
||||
|
||||
start() {
|
||||
start () {
|
||||
Log.info(`Starting module: ${this.name}`);
|
||||
this.addFilters();
|
||||
setInterval(() => {
|
||||
@@ -29,16 +29,16 @@ Module.register("updatenotification", {
|
||||
}, this.config.refreshInterval);
|
||||
},
|
||||
|
||||
suspend() {
|
||||
suspend () {
|
||||
this.suspended = true;
|
||||
},
|
||||
|
||||
resume() {
|
||||
resume () {
|
||||
this.suspended = false;
|
||||
this.updateDom(2);
|
||||
},
|
||||
|
||||
notificationReceived(notification) {
|
||||
notificationReceived (notification) {
|
||||
switch (notification) {
|
||||
case "DOM_OBJECTS_CREATED":
|
||||
this.sendSocketNotification("CONFIG", this.config);
|
||||
@@ -50,7 +50,7 @@ Module.register("updatenotification", {
|
||||
}
|
||||
},
|
||||
|
||||
socketNotificationReceived(notification, payload) {
|
||||
socketNotificationReceived (notification, payload) {
|
||||
switch (notification) {
|
||||
case "REPO_STATUS":
|
||||
this.updateUI(payload);
|
||||
@@ -64,19 +64,19 @@ Module.register("updatenotification", {
|
||||
}
|
||||
},
|
||||
|
||||
getStyles() {
|
||||
getStyles () {
|
||||
return [`${this.name}.css`];
|
||||
},
|
||||
|
||||
getTemplate() {
|
||||
getTemplate () {
|
||||
return `${this.name}.njk`;
|
||||
},
|
||||
|
||||
getTemplateData() {
|
||||
getTemplateData () {
|
||||
return { moduleList: this.moduleList, updatesList: this.updates, suspended: this.suspended, needRestart: this.needRestart };
|
||||
},
|
||||
|
||||
updateUI(payload) {
|
||||
updateUI (payload) {
|
||||
if (payload && payload.behind > 0) {
|
||||
// if we haven't seen info for this module
|
||||
if (this.moduleList[payload.module] === undefined) {
|
||||
@@ -94,7 +94,7 @@ Module.register("updatenotification", {
|
||||
}
|
||||
},
|
||||
|
||||
addFilters() {
|
||||
addFilters () {
|
||||
this.nunjucksEnvironment().addFilter("diffLink", (text, status) => {
|
||||
if (status.module !== "MagicMirror") {
|
||||
return text;
|
||||
@@ -106,7 +106,7 @@ Module.register("updatenotification", {
|
||||
});
|
||||
},
|
||||
|
||||
updatesNotifier(payload, done = true) {
|
||||
updatesNotifier (payload, done = true) {
|
||||
if (this.updates[payload.name] === undefined) {
|
||||
this.updates[payload.name] = {
|
||||
name: payload.name,
|
||||
|
Reference in New Issue
Block a user