Merge pull request #2007 from rejas/no_undef

Cleanup eslints no-undef warnings
This commit is contained in:
Michael Teeuw 2020-05-05 14:31:41 +02:00 committed by GitHub
commit 1e7ce8bb5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 84 additions and 91 deletions

View File

@ -6,6 +6,12 @@
"mocha": true,
"node": true
},
"globals": {
"config": true,
"Log": true,
"MM": true,
"moment": true
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2017,
@ -16,7 +22,6 @@
"rules": {
"eqeqeq": "error",
"no-prototype-builtins": "off",
"no-undef": "off",
"no-unused-vars": "off"
}
}

View File

@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- Replaced grunt-based linters with their non-grunt equivalents
- Switch to most of the eslint:recommended rules and fix warnings
- Replaced insecure links with https ones
- Cleaned up all "no-undef" warnings from eslint
### Deleted
- Removed truetype (ttf) fonts

View File

@ -1,9 +1,12 @@
/* global Class, xyz */
/* Simple JavaScript Inheritance
* By John Resig https://johnresig.com/
*
* Inspired by base2 and Prototype
*
* MIT Licensed.
*/
// Inspired by base2 and Prototype
(function () {
var initializing = false;
var fnTest = /xyz/.test(function () { xyz; }) ? /\b_super\b/ : /.*/;

View File

@ -1,4 +1,4 @@
/* exported defaults */
/* global mmPort */
/* Magic Mirror
* Config Defaults
@ -6,9 +6,8 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var port = 8080;
var address = "localhost";
var port = 8080;
if (typeof(mmPort) !== "undefined") {
port = mmPort;
}

View File

@ -1,4 +1,4 @@
/* global config, vendor, MM, Log, Module */
/* global defaultModules, Module, vendor */
/* Magic Mirror
* Module and File loaders.

View File

@ -1,16 +1,12 @@
/* exported Log */
/* Magic Mirror
* Logger
* This logger is very simple, but needs to be extended.
* This system can eventually be used to push the log messages to an external target.
*
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
// This logger is very simple, but needs to be extended.
// This system can eventually be used to push the log messages to an external target.
var Log = (function() {
const Log = (function() {
return {
info: Function.prototype.bind.call(console.info, console),
log: Function.prototype.bind.call(console.log, console),

View File

@ -1,4 +1,4 @@
/* global Log, Loader, Module, config, defaults */
/* global Loader, Module, defaults, Translator */
/* Magic Mirror
* Main System

View File

@ -1,4 +1,4 @@
/* exported Module */
/* global Class, cloneObject, Loader, MMSocket, nunjucks, Translator */
/* Magic Mirror
* Module Blueprint.
@ -6,7 +6,6 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var Module = Class.extend({
/*********************************************************
@ -237,7 +236,7 @@ var Module = Class.extend({
*/
socket: function () {
if (typeof this._socket === "undefined") {
this._socket = this._socket = new MMSocket(this.name);
this._socket = new MMSocket(this.name);
}
var self = this;
@ -467,8 +466,8 @@ function cmpVersions(a, b) {
Module.register = function (name, moduleDefinition) {
if (moduleDefinition.requiresVersion) {
Log.log("Check MagicMirror version for module '" + name + "' - Minimum version: " + moduleDefinition.requiresVersion + " - Current version: " + version);
if (cmpVersions(version, moduleDefinition.requiresVersion) >= 0) {
Log.log("Check MagicMirror version for module '" + name + "' - Minimum version: " + moduleDefinition.requiresVersion + " - Current version: " + global.version);
if (cmpVersions(global.version, moduleDefinition.requiresVersion) >= 0) {
Log.log("Version is ok!");
} else {
Log.log("Version is incorrect. Skip module: '" + name + "'");

View File

@ -4,12 +4,10 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
const Class = require("./class.js");
const express = require("express");
var Class = require("./class.js");
var express = require("express");
var path = require("path");
NodeHelper = Class.extend({
var NodeHelper = Class.extend({
init: function() {
console.log("Initializing new module helper ...");
},
@ -114,7 +112,6 @@ NodeHelper = Class.extend({
}
});
});
}
});
@ -122,4 +119,5 @@ NodeHelper.create = function(moduleDefinition) {
return NodeHelper.extend(moduleDefinition);
};
module.exports = NodeHelper;
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = NodeHelper;}

View File

@ -71,7 +71,7 @@ var Server = function(config, callback) {
var html = fs.readFileSync(path.resolve(global.root_path + "/index.html"), {encoding: "utf8"});
html = html.replace("#VERSION#", global.version);
configFile = "config/config.js";
var configFile = "config/config.js";
if (typeof(global.configuration_file) !== "undefined") {
configFile = global.configuration_file;
}

View File

@ -1,3 +1,11 @@
/* global io */
/* Magic Mirror
* TODO add description
*
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var MMSocket = function(moduleName) {
var self = this;

View File

@ -1,4 +1,4 @@
/* exported Translator */
/* global translations */
/* Magic Mirror
* Translator (l10n)

View File

@ -1,12 +1,9 @@
/* exported Utils */
/* Magic Mirror
* Utils
*
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed.
*/
var colors = require("colors/safe");
var Utils = {

View File

@ -1,4 +1,4 @@
/* global Module */
/* global Module, NotificationFx */
/* Magic Mirror
* Module: alert

View File

@ -1,4 +1,4 @@
/* global Module */
/* global cloneObject, Module */
/* Magic Mirror
* Module: Calendar

View File

@ -5,8 +5,8 @@
* MIT Licensed.
*/
var ical = require("./vendor/ical.js");
var moment = require("moment");
const ical = require("./vendor/ical.js");
const moment = require("moment");
var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents) {
var self = this;
@ -25,7 +25,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
clearTimeout(reloadTimer);
reloadTimer = null;
nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
var nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
var opts = {
headers: {
"User-Agent": "Mozilla/5.0 (Node.js "+ nodeVersion + ") MagicMirror/" + global.version + " (https://github.com/MichMich/MagicMirror/)"
@ -61,7 +61,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
}
// console.log(data);
newEvents = [];
var newEvents = [];
// limitFunction doesn't do much limiting, see comment re: the dates array in rrule section below as to why we need to do the filtering ourselves
var limitFunction = function(date, i) {return true;};
@ -97,7 +97,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
if (typeof event.end !== "undefined") {
endDate = eventDate(event, "end");
} else if(typeof event.duration !== "undefined") {
dur=moment.duration(event.duration);
var dur=moment.duration(event.duration);
endDate = startDate.clone().add(dur);
} else {
if (!isFacebookBirthday) {

View File

@ -15,8 +15,6 @@ var maximumEntries = 10;
var maximumNumberOfDays = 365;
var user = "magicmirror";
var pass = "MyStrongPass";
var broadcastPastEvents = false;
var auth = {
user: user,
pass: pass
@ -24,7 +22,7 @@ var auth = {
console.log("Create fetcher ...");
fetcher = new CalendarFetcher(url, fetchInterval, [], maximumEntries, maximumNumberOfDays, auth);
var fetcher = new CalendarFetcher(url, fetchInterval, [], maximumEntries, maximumNumberOfDays, auth);
fetcher.onReceive(function(fetcher) {
console.log(fetcher.events());

View File

@ -1,4 +1,4 @@
/* global Log, Module, moment, config */
/* global Module, SunCalc */
/* Magic Mirror
* Module: Clock
@ -289,11 +289,12 @@ Module.register("clock",{
// Both clocks have been configured, check position
var placement = this.config.analogPlacement;
analogWrapper = document.createElement("div");
var analogWrapper = document.createElement("div");
analogWrapper.id = "analog";
analogWrapper.style.cssFloat = "none";
analogWrapper.appendChild(clockCircle);
digitalWrapper = document.createElement("div");
var digitalWrapper = document.createElement("div");
digitalWrapper.id = "digital";
digitalWrapper.style.cssFloat = "none";
digitalWrapper.appendChild(dateWrapper);

View File

@ -1,4 +1,4 @@
/* global Log, Module, moment */
/* global Module */
/* Magic Mirror
* Module: Compliments
@ -127,7 +127,7 @@ Module.register("compliments", {
compliments.push.apply(compliments, this.config.compliments.anytime);
for (entry in this.config.compliments) {
for (var entry in this.config.compliments) {
if (new RegExp(entry).test(date)) {
compliments.push.apply(compliments, this.config.compliments[entry]);
}
@ -188,7 +188,7 @@ Module.register("compliments", {
// create a span to hold it all
var compliment = document.createElement("span");
// process all the parts of the compliment text
for (part of parts){
for (var part of parts){
// create a text element for each part
compliment.appendChild(document.createTextNode(part));
// add a break `

View File

@ -81,8 +81,8 @@ var Fetcher = function(url, reloadInterval, encoding, logFeedWarnings) {
scheduleTimer();
});
nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
headers = {"User-Agent": "Mozilla/5.0 (Node.js "+ nodeVersion + ") MagicMirror/" + global.version + " (https://github.com/MichMich/MagicMirror/)",
var nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
var headers = {"User-Agent": "Mozilla/5.0 (Node.js "+ nodeVersion + ") MagicMirror/" + global.version + " (https://github.com/MichMich/MagicMirror/)",
"Cache-Control": "max-age=0, no-cache, no-store, must-revalidate",
"Pragma": "no-cache"};

View File

@ -126,7 +126,7 @@ Module.register("newsfeed",{
if (this.config.removeStartTags === "title" || this.config.removeStartTags === "both") {
for (f=0; f<this.config.startTags.length;f++) {
for (let f=0; f<this.config.startTags.length;f++) {
if (this.newsItems[this.activeItem].title.slice(0,this.config.startTags[f].length) === this.config.startTags[f]) {
this.newsItems[this.activeItem].title = this.newsItems[this.activeItem].title.slice(this.config.startTags[f].length,this.newsItems[this.activeItem].title.length);
}
@ -137,7 +137,7 @@ Module.register("newsfeed",{
if (this.config.removeStartTags === "description" || this.config.removeStartTags === "both") {
if (this.isShowingDescription) {
for (f=0; f<this.config.startTags.length;f++) {
for (let f=0; f<this.config.startTags.length;f++) {
if (this.newsItems[this.activeItem].description.slice(0,this.config.startTags[f].length) === this.config.startTags[f]) {
this.newsItems[this.activeItem].description = this.newsItems[this.activeItem].description.slice(this.config.startTags[f].length,this.newsItems[this.activeItem].description.length);
}
@ -149,14 +149,14 @@ Module.register("newsfeed",{
//Remove selected tags from the end of rss feed items (title or description)
if (this.config.removeEndTags) {
for (f=0; f<this.config.endTags.length;f++) {
for (let f=0; f<this.config.endTags.length;f++) {
if (this.newsItems[this.activeItem].title.slice(-this.config.endTags[f].length)===this.config.endTags[f]) {
this.newsItems[this.activeItem].title = this.newsItems[this.activeItem].title.slice(0,-this.config.endTags[f].length);
}
}
if (this.isShowingDescription) {
for (f=0; f<this.config.endTags.length;f++) {
for (let f=0; f<this.config.endTags.length;f++) {
if (this.newsItems[this.activeItem].description.slice(-this.config.endTags[f].length)===this.config.endTags[f]) {
this.newsItems[this.activeItem].description = this.newsItems[this.activeItem].description.slice(0,-this.config.endTags[f].length);
}
@ -331,7 +331,7 @@ Module.register("newsfeed",{
self.sendNotification("NEWS_FEED", {items: self.newsItems});
}
timer = setInterval(function() {
this.timer = setInterval(function() {
self.activeItem++;
self.updateDom(self.config.animationSpeed);
@ -360,7 +360,7 @@ Module.register("newsfeed",{
// reset bottom bar alignment
document.getElementsByClassName("region bottom bar")[0].style.bottom = "0";
document.getElementsByClassName("region bottom bar")[0].style.top = "inherit";
if(!timer){
if(!this.timer){
this.scheduleUpdateInterval();
}
},
@ -433,10 +433,9 @@ Module.register("newsfeed",{
document.getElementsByClassName("region bottom bar")[0].style.bottom = "inherit";
document.getElementsByClassName("region bottom bar")[0].style.top = "-90px";
}
clearInterval(timer);
timer = null;
clearInterval(this.timer);
this.timer = null;
Log.info(this.name + " - showing " + this.isShowingDescription ? "article description" : "full article");
this.updateDom(100);
}
});

View File

@ -24,7 +24,7 @@ module.exports = NodeHelper.create({
var promises = [];
for (moduleName in modules) {
for (var moduleName in modules) {
if (!this.ignoreUpdateChecking(moduleName)) {
// Default modules are included in the main MagicMirror repo
var moduleFolder = path.normalize(__dirname + "/../../" + moduleName);

View File

@ -74,8 +74,8 @@ Module.register("updatenotification", {
var wrapper = document.createElement("div");
if(this.suspended === false){
// process the hash of module info found
for(key of Object.keys(this.moduleList)){
let m= this.moduleList[key];
for(var key of Object.keys(this.moduleList)){
let m = this.moduleList[key];
var message = document.createElement("div");
message.className = "small bright";

29
package-lock.json generated
View File

@ -2599,9 +2599,9 @@
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"fsevents": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.2.tgz",
"integrity": "sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA==",
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz",
"integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==",
"dev": true,
"optional": true
},
@ -4084,9 +4084,9 @@
}
},
"markdownlint": {
"version": "0.20.1",
"resolved": "https://registry.npmjs.org/markdownlint/-/markdownlint-0.20.1.tgz",
"integrity": "sha512-jq1qt0QkzY6AiN6O3tq+8SmUlvKfhx9GRKBn/IWEuN6RM5xBZG47rfW9Fn0eRvuozf5Xc59dRaLUZEO0XiyGOg==",
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/markdownlint/-/markdownlint-0.20.2.tgz",
"integrity": "sha512-TU/SgsylEzp9oAj9dGGZ6009yJq48GpEAeYIsREje5NuvadzO12qvl4wV21vHIerdPy/aSEyM2e9c+CzWq6Reg==",
"dev": true,
"requires": {
"markdown-it": "10.0.0"
@ -4325,9 +4325,9 @@
}
},
"mocha": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-7.1.1.tgz",
"integrity": "sha512-3qQsu3ijNS3GkWcccT5Zw0hf/rWvu1fTN9sPvEd81hlwsr30GX2GcDSSoBxo24IR8FelmrAydGC6/1J5QQP4WA==",
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-7.1.2.tgz",
"integrity": "sha512-o96kdRKMKI3E8U0bjnfqW4QMk12MwZ4mhdBTf+B5a1q9+aq2HRnj+3ZdJu0B/ZhJeK78MgYuv6L8d/rA5AeBJA==",
"dev": true,
"requires": {
"ansi-colors": "3.2.3",
@ -4343,7 +4343,7 @@
"js-yaml": "3.13.1",
"log-symbols": "3.0.0",
"minimatch": "3.0.4",
"mkdirp": "0.5.3",
"mkdirp": "0.5.5",
"ms": "2.1.1",
"node-environment-flags": "1.0.6",
"object.assign": "4.1.0",
@ -4431,15 +4431,6 @@
"path-exists": "^3.0.0"
}
},
"mkdirp": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.3.tgz",
"integrity": "sha512-P+2gwrFqx8lhew375MQHHeTlY8AuOJSrGf0R5ddkEndUkmwpgUob/vQuBD1V22/Cw1/lJr4x+EjllSezBThzBg==",
"dev": true,
"requires": {
"minimist": "^1.2.5"
}
},
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",

View File

@ -50,9 +50,9 @@
"danger": "^3.1.3",
"http-auth": "^3.2.3",
"jsdom": "^11.6.2",
"markdownlint": "^0.20.1",
"markdownlint": "^0.20.2",
"markdownlint-cli": "^0.22.0",
"mocha": "^7.1.1",
"mocha": "^7.1.2",
"mocha-each": "^2.0.1",
"mocha-logger": "^1.0.6",
"spectron": "^8.0.0",

View File

@ -8,6 +8,7 @@ const describe = global.describe;
describe("All font files from roboto.css should be downloadable", function() {
helpers.setupTimeout(this);
var app;
var fontFiles = [];
// Statements below filters out all 'url' lines in the CSS file
var fileContent = require("fs").readFileSync(__dirname + "/../../fonts/roboto.css", "utf8");

View File

@ -28,7 +28,7 @@ describe("Position of modules", function () {
var position;
var className;
for (idx in positions) {
for (var idx in positions) {
position = positions[idx];
className = position.replace("_", ".");
it("show text in " + position, function () {

View File

@ -6,7 +6,6 @@ const describe = global.describe;
const it = global.it;
const before = global.before;
const after = global.after;
const mlog = require("mocha-logger");
describe("Vendors", function () {
@ -30,7 +29,7 @@ describe("Vendors", function () {
var vendors = require(__dirname + "/../../vendor/vendor.js");
Object.keys(vendors).forEach(vendor => {
it(`should return 200 HTTP code for vendor "${vendor}"`, function () {
urlVendor = "http://localhost:8080/vendor/" + vendors[vendor];
var urlVendor = "http://localhost:8080/vendor/" + vendors[vendor];
request.get(urlVendor, function (err, res, body) {
expect(res.statusCode).to.equal(200);
});
@ -39,7 +38,7 @@ describe("Vendors", function () {
Object.keys(vendors).forEach(vendor => {
it(`should return 404 HTTP code for vendor https://localhost/"${vendor}"`, function() {
urlVendor = "http://localhost:8080/" + vendors[vendor];
var urlVendor = "http://localhost:8080/" + vendors[vendor];
request.get(urlVendor, function (err, res, body) {
expect(res.statusCode).to.equal(404);
});

View File

@ -19,7 +19,8 @@ app.use(auth.connect(basic));
// Set available directories
var directories = ["/tests/configs"];
var directory;
rootPath = path.resolve(__dirname + "/../../");
var rootPath = path.resolve(__dirname + "/../../");
for (var i in directories) {
directory = directories[i];
app.use(directory, express.static(path.resolve(rootPath + directory)));

3
vendor/vendor.js vendored
View File

@ -1,12 +1,9 @@
/* exported vendor */
/* Magic Mirror
* Vendor File Definition
*
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var vendor = {
"moment.js" : "node_modules/moment/min/moment-with-locales.js",
"moment-timezone.js" : "node_modules/moment-timezone/builds/moment-timezone-with-data.js",