Merge pull request #287 from nhubbard/v2-beta

Close #281: ESLint and using the force, Luke
This commit is contained in:
Michael Teeuw 2016-05-04 07:19:56 +02:00
commit 06a471033c
14 changed files with 129 additions and 62 deletions

7
.eslintignore Normal file
View File

@ -0,0 +1,7 @@
vendor/
!/vendor/vendor.js
/modules/**
!/modules/default/**
!/modules/node_helper
!/modules/node_helper/**
!/modules/default/defaultmodules.js

14
.eslintrc.json Normal file
View File

@ -0,0 +1,14 @@
{
"rules": {
"indent": ["error", "tab"],
"quotes": ["error", "double"],
"max-len": ["error", 250],
"curly": "error",
"camelcase": ["error", {"properties": "never"}]
},
"env": {
"browser": true,
"node": true,
"es6": true
}
}

View File

@ -1,9 +0,0 @@
{
"preset": "google",
"validateIndentation": "\t",
"validateQuoteMarks": "\"",
"maximumLineLength": 250,
"requireCurlyBraces": [],
"requireCamelCaseOrUpperCaseIdentifiers": false,
"excludeFiles": [".jscsrc"],
}

9
.travis.yml Normal file
View File

@ -0,0 +1,9 @@
language: node_js
node_js:
- "6"
- "5.1"
- "4"
- "0.12"
before_script:
- npm install grunt-cli -g
script: grunt

28
Gruntfile.js Normal file
View File

@ -0,0 +1,28 @@
module.exports = function(grunt) {
require("time-grunt")(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
eslint: {
options: {
configFile: ".eslintrc.json"
},
target: ["js/*.js", "modules/default/*.js", "serveronly/*.js", "*.js"]
},
postcss: {
lint: {
options: {
processors: [
require("stylelint")({"extends": "stylelint-config-standard", "font-family-name-quotes": "double-where-recommended"}),
require("postcss-reporter")({ clearMessages: true })
]
},
dist: {
src: "**/**/**/**/**/**/**/**.css"
}
}
}
});
grunt.loadNpmTasks("grunt-eslint");
grunt.loadNpmTasks("grunt-postcss");
grunt.registerTask("default", ["eslint", "postcss:lint"]);
};

View File

@ -127,3 +127,4 @@ Please keep the following in mind:
- **New Features**: please please discuss in a GitHub issue before you start to alter a big part of the code. Without discussion upfront, the pull request will not be accepted / merged.
Thanks for your help in making MagicMirror² better!

View File

@ -12,7 +12,7 @@ var path = require("path");
// The next part is here to prevent a major exception when there
// is no internet connection. This could probable be solved better.
process.on('uncaughtException', function (err) {
process.on("uncaughtException", function (err) {
console.log("Whoops! There was an uncaught exception...");
console.error(err);
console.log("MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?");
@ -41,7 +41,7 @@ var App = function() {
var config = Object.assign(defaults, c);
callback(config);
} catch (e) {
console.error('WARNING! Could not find config. Please create one.');
console.error("WARNING! Could not find config. Please create one.");
callback(defaults);
}
};
@ -98,7 +98,7 @@ var App = function() {
/* start(callback)
* This methods starts the core app.
* It loads the config, then it loads all modules.
* When it's done it executs the callback with the config as argument.
* When it"s done it executs the callback with the config as argument.
*
* argument callback function - The callback function.
*/
@ -130,7 +130,7 @@ var App = function() {
console.log("Sockets connected & modules started ...");
if (typeof callback === 'function') {
if (typeof callback === "function") {
callback(config);
}

View File

@ -48,9 +48,10 @@
// The dummy class constructor
function Class() {
// All construction is actually done in the init method
if (!initializing && this.init)
if (!initializing && this.init) {
this.init.apply(this, arguments);
}
}
// Populate our constructed prototype object
Class.prototype = prototype;

View File

@ -1,7 +1,4 @@
/* global config, vendor, MM, Log, Module */
/* jshint unused:false */
/* jshint -W061 */
/* Magic Mirror
* Module and File loaders.
*
@ -175,20 +172,16 @@ var Loader = (function() {
switch (extension.toLowerCase()) {
case "js":
Log.log("Load script: " + fileName);
var script = document.createElement("script");
script.type = "text/javascript";
script.src = fileName;
script.onload = function() {
if (typeof callback === "function") {callback();}
};
document.getElementsByTagName("body")[0].appendChild(script);
break;
case "css":
Log.log("Load stylesheet: " + fileName);
var stylesheet = document.createElement("link");
stylesheet.rel = "stylesheet";
stylesheet.type = "text/css";
@ -196,7 +189,6 @@ var Loader = (function() {
stylesheet.onload = function() {
if (typeof callback === "function") {callback();}
};
document.getElementsByTagName("head")[0].appendChild(stylesheet);
break;
}

View File

@ -1,5 +1,4 @@
/* global Log, Loader, Module, config, defaults */
/* jshint -W020 */
/* Magic Mirror
* Main System
@ -165,7 +164,7 @@ var MM = (function() {
clearTimeout(module.showHideTimer);
module.showHideTimer = setTimeout(function() {
// To not take up any space, we just make the position absolute.
// since it's fade out anyway, we can see it lay above or
// since it"s fade out anyway, we can see it lay above or
// below other modules. This works way better than adjusting
// the .display property.
moduleWrapper.style.position = "absolute";
@ -434,7 +433,27 @@ var MM = (function() {
})();
// Add polyfill for Object.assign.
if (typeof Object.assign != 'function') { (function () { Object.assign = function (target) { 'use strict'; if (target === undefined || target === null) { throw new TypeError('Cannot convert undefined or null to object'); } var output = Object(target); for (var index = 1; index < arguments.length; index++) { var source = arguments[index]; if (source !== undefined && source !== null) { for (var nextKey in source) { if (source.hasOwnProperty(nextKey)) { output[nextKey] = source[nextKey]; } } } } return output; }; })(); }
if (typeof Object.assign != "function") {
(function() {
Object.assign = function(target) {
"use strict";
if (target === undefined || target === null) {
throw new TypeError("Cannot convert undefined or null to object");
}
var output = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source !== undefined && source !== null) {
for (var nextKey in source) {
if (source.hasOwnProperty(nextKey)) {
output[nextKey] = source[nextKey];
}
}
}
}
return output;
};
})();
}
MM.init();

View File

@ -111,7 +111,7 @@ var Module = Class.extend({
},
/*********************************************
* The methods below don't need subclassing. *
* The methods below don"t need subclassing. *
*********************************************/
/* setData(data)
@ -138,7 +138,7 @@ var Module = Class.extend({
},
/* socket()
* Returns a socket object. If it doesn't exsist, it's created.
* Returns a socket object. If it doesn"t exsist, it"s created.
* It also registers the notification callback.
*/
socket: function() {
@ -236,7 +236,7 @@ var Module = Class.extend({
* argument defaultValue string - The default value if no translation was found. (Optional)
*/
translate: function(key, defaultValue) {
return Translator.translate(this, key) || defaultValue || '';
return Translator.translate(this, key) || defaultValue || "";
},
/* updateDom(speed)
@ -299,7 +299,7 @@ Module.create = function(name) {
return obj;
}
var temp = obj.constructor(); // give temp the original obj's constructor
var temp = obj.constructor(); // give temp the original obj"s constructor
for (var key in obj) {
temp[key] = cloneObject(obj[key]);
}

View File

@ -47,7 +47,7 @@ var Translator = (function() {
_loadJSON: function(file, callback) {
var xhr = new XMLHttpRequest();
xhr.overrideMimeType("application/json");
xhr.open('GET', file, true);
xhr.open("GET", file, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == "200") {
callback(JSON.parse(xhr.responseText));

View File

@ -29,8 +29,13 @@
"homepage": "https://github.com/MichMich/MagicMirror#readme",
"devDependencies": {
"electron-prebuilt": "latest",
"grunt": "latest",
"grunt-eslint": "latest",
"grunt-postcss": "latest",
"postcss-reporter": "latest",
"stylelint": "latest",
"stylelint-config-standard": "latest"
"stylelint-config-standard": "latest",
"time-grunt": "latest"
},
"dependencies": {
"express": "latest",
@ -38,7 +43,7 @@
"iconv-lite": "latest",
"moment": "latest",
"request": "latest",
"snyk": "^1.13.2",
"snyk": "latest",
"socket.io": "latest",
"valid-url": "latest",
"walk": "latest",

View File

@ -1,5 +1,5 @@
var app = require('../js/app.js');
var app = require("../js/app.js");
app.start(function(config) {
console.log('');
console.log('Ready to go! Please point your browser to: http://localhost:' + config.port);
console.log("");
console.log("Ready to go! Please point your browser to: http://localhost:" + config.port);
});