Bug 999737-bootstrap eslint for loop content JS, fix a found bug, rs=MattN
authorDan Mosedale <dmose@meer.net>
Tue, 31 Mar 2015 17:28:36 -0700
changeset 255785 91b6a396bf7c6496b4b2f5dc8bfea60b3ba4197a
parent 255784 0d5114f9b9d9340331f09d8a90b411865eba9787
child 255786 ae9a28f9f7368c13df2a0d587db114e37b2f5f06
push id8007
push userraliiev@mozilla.com
push dateMon, 11 May 2015 19:23:16 +0000
treeherdermozilla-aurora@e2ce1aac996e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs999737
milestone40.0a1
Bug 999737-bootstrap eslint for loop content JS, fix a found bug, rs=MattN
browser/components/loop/.eslintignore
browser/components/loop/.eslintrc
browser/components/loop/content/.eslintrc
browser/components/loop/content/shared/js/mixins.js
browser/components/loop/run-all-loop-tests.sh
browser/components/loop/standalone/Makefile
browser/components/loop/standalone/package.json
browser/components/loop/standalone/server.js
browser/components/loop/test/desktop-local/.eslintrc
new file mode 100644
--- /dev/null
+++ b/browser/components/loop/.eslintignore
@@ -0,0 +1,9 @@
+MozLoopWorker.js
+content/libs
+content/shared/libs
+standalone/content/libs
+standalone/node_modules
+test/xpcshell
+test/mochitest
+test/shared/vendor
+
new file mode 100644
--- /dev/null
+++ b/browser/components/loop/.eslintrc
@@ -0,0 +1,71 @@
+{
+  "plugins": [
+    "react"
+  ],
+  "ecmaFeatures": {
+    "forOf": true,
+    "jsx": true
+  },
+  "env": {
+    "browser": true,
+    "mocha": true
+  },
+  "globals": {
+    "_": false,
+    "$": false,
+    "Backbone": false,
+    "chai": false,
+    "console": false,
+    "jQuery": false,
+    "loop": false,
+    "MozActivity": false,
+    "OT": false,
+    "Promise": false,
+    "React": false,
+    "sinon": false
+  },
+  "rules": {
+    // turn off all kinds of stuff that we actually do want, because
+    // right now, we're bootstrapping the linting infrastructure.  We'll
+    // want to audit these rules, and start turning them on and fixing the
+    // problems they find, one at a time.
+
+    // Eslint built-in rules are documented at <http://eslint.org/docs/rules/>
+    "camelcase": 0,
+    "comma-dangle": 0,
+    "comma-spacing": 0,
+    "consistent-return": 0,
+    "curly": 0,
+    "dot-notation": 0,
+    "eol-last": 0,
+    "eqeqeq": 0,
+    "key-spacing": 0,
+    "new-cap": 0,
+    "no-catch-shadow": 0,
+    "no-console": 0,
+    "no-empty": 0,
+    "no-extra-bind": 0,
+    "no-extra-boolean-cast": 0,
+    "no-extra-semi": 0,
+    "no-multi-spaces": 0,
+    "no-new": 0,
+    "no-redeclare": 0,
+    "no-return-assign": 0,
+    "no-shadow": 0,
+    "no-spaced-func": 0,
+    "no-trailing-spaces": 0,
+    "no-undef": 0,
+    "no-underscore-dangle": 0,
+    "no-unused-expressions": 0,
+    "no-unused-vars": 0,
+    "no-use-before-define": 0,
+    "no-wrap-func": 0,
+    "quotes": 0,
+    "semi": 0,
+    "semi-spacing": 0,
+    "space-infix-ops": 0,
+    "space-return-throw-case": 0,
+    "strict": 0,
+    "yoda": 0
+  }
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/loop/content/.eslintrc
@@ -0,0 +1,10 @@
+{
+  "ecmaFeatures": {
+    // since the code here is running only on known versions of
+    // Firefox, we can use newer ECMAscript features
+    "arrowFunctions": true,
+    "blockBindings": true,
+    "destructuring": true,
+    "forOf": true
+  }
+}
--- a/browser/components/loop/content/shared/js/mixins.js
+++ b/browser/components/loop/content/shared/js/mixins.js
@@ -436,17 +436,17 @@ loop.shared.mixins = (function() {
     /**
      * Returns the default configuration for publishing media on the sdk.
      *
      * @param {Object} options An options object containing:
      * - publishVideo A boolean set to true to publish video when the stream is initiated.
      */
     getDefaultPublisherConfig: function(options) {
       options = options || {};
-      if (!"publishVideo" in options) {
+      if (!("publishVideo" in options)) {
         throw new Error("missing option publishVideo");
       }
 
       // height set to 100%" to fix video layout on Google Chrome
       // @see https://bugzilla.mozilla.org/show_bug.cgi?id=1020445
       return {
         insertMode: "append",
         fitMode: "contain",
--- a/browser/components/loop/run-all-loop-tests.sh
+++ b/browser/components/loop/run-all-loop-tests.sh
@@ -5,27 +5,36 @@ if [ "$1" == "--help" ]; then
   echo "Usage: ./run-all-loop-tests.sh [options]"
   echo "    --skip-e10s  Skips the e10s tests"
   exit 0;
 fi
 
 set -e
 
 # Main tests
-./mach xpcshell-test browser/components/loop/
-./mach marionette-test browser/components/loop/manifest.ini
+
+LOOPDIR=browser/components/loop
+#ESLINT=standalone/node_modules/.bin/eslint
+#if [ -x "${LOOPDIR}/${ESLINT}" ]; then
+#  echo 'running eslint; see http://eslint.org/docs/rules/ for error info'
+#  (cd ${LOOPDIR} && ./${ESLINT} .)
+#  echo 'eslint run finished.'
+#fi
+
+./mach xpcshell-test ${LOOPDIR}/
+./mach marionette-test ${LOOPDIR}/manifest.ini
 
 # The browser_parsable_css.js can fail if we add some css that isn't parsable.
 #
 # The check to make sure that the media devices can be used in Loop without
 # prompting is in browser_devices_get_user_media_about_urls.js. It's possible
 # to mess this up with CSP handling, and probably other changes, too.
 
 TESTS="
-  browser/components/loop/test/mochitest
+  ${LOOPDIR}/test/mochitest
   browser/modules/test/browser_UITour_loop.js
   browser/base/content/test/general/browser_devices_get_user_media_about_urls.js
 "
 
 ./mach mochitest $TESTS
 
 if [ "$1" != "--skip-e10s" ]; then
   ./mach mochitest --e10s $TESTS
--- a/browser/components/loop/standalone/Makefile
+++ b/browser/components/loop/standalone/Makefile
@@ -19,19 +19,16 @@ NODE_LOCAL_BIN=./node_modules/.bin
 install: npm_install
 
 npm_install:
 	@npm install
 
 test:
 	@echo "Not implemented yet."
 
-lint:
-	@$(NODE_LOCAL_BIN)/jshint *.js content test
-
 runserver: remove_old_config
 	node server.js
 
 frontend:
 	@echo "Not implemented yet."
 
 # Try hg first, if not fall back to git.
 SOURCE_STAMP := $(shell hg parent --template '{node|short}\n' 2> /dev/null)
--- a/browser/components/loop/standalone/package.json
+++ b/browser/components/loop/standalone/package.json
@@ -7,16 +7,18 @@
     "url": "git@github.com:mozilla/loop-client.git"
   },
   "engines": {
     "node": "0.10.x",
     "npm": "1.3.x"
   },
   "dependencies": {},
   "devDependencies": {
+    "eslint": "0.18.x",
+    "eslint-plugin-react": "2.0.x",
     "express": "3.x"
   },
   "scripts": {
     "test": "make test",
     "start": "make runserver"
   },
   "license": "MPL-2.0"
 }
--- a/browser/components/loop/standalone/server.js
+++ b/browser/components/loop/standalone/server.js
@@ -1,12 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/* eslint-env node */
+
+/* XXX We should enable these and fix the warnings, but at the time of this
+ * writing, we're just bootstrapping the linting infrastructure.
+ */
+/* eslint-disable no-path-concat,no-process-exit */
+
 var express = require('express');
 var app = express();
 
 var port = process.env.PORT || 3000;
 var loopServerPort = process.env.LOOP_SERVER_PORT || 5000;
 var feedbackApiUrl = process.env.LOOP_FEEDBACK_API_URL ||
                      "https://input.allizom.org/api/v1/feedback";
 var feedbackProductName = process.env.LOOP_FEEDBACK_PRODUCT_NAME || "Loop";
new file mode 100644
--- /dev/null
+++ b/browser/components/loop/test/desktop-local/.eslintrc
@@ -0,0 +1,10 @@
+{
+  "ecmaFeatures": {
+    // since the code here is running only on known versions of
+    // Firefox, we can use newer ECMAscript features here
+    "arrowFunctions": true,
+    "blockBindings": true,
+    "destructuring": true,
+    "forOf": true
+  },
+}