Bug 1231963 - handle top-level "this.mumble" assignments in eslint; r=mikeratcliffe
authorTom Tromey <tom@tromey.com>
Tue, 19 Jan 2016 10:04:23 -0700
changeset 316068 cf165d1764d64d1267c0120a01be86c01da0b3d0
parent 316067 a7b909eabadf197c6b1988a793c329b6213db042
child 316069 f36a4a4ff73f1184f569fd9152b98fe8d8d3866a
push id5703
push userraliiev@mozilla.com
push dateMon, 07 Mar 2016 14:18:41 +0000
treeherdermozilla-beta@31e373ad5b5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikeratcliffe
bugs1231963
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1231963 - handle top-level "this.mumble" assignments in eslint; r=mikeratcliffe
.eslintrc
testing/eslint-plugin-mozilla/lib/index.js
testing/eslint-plugin-mozilla/lib/rules/this-top-level-scope.js
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,13 +1,14 @@
 {
   // When adding items to this file please check for effects on sub-directories.
   "plugins": [
     "mozilla"
   ],
   "rules": {
     "mozilla/components-imports": 1,
     "mozilla/import-globals-from": 1,
+    "mozilla/this-top-level-scope": 1,
   },
   "env": {
     "es6": true
   },
 }
--- a/testing/eslint-plugin-mozilla/lib/index.js
+++ b/testing/eslint-plugin-mozilla/lib/index.js
@@ -20,22 +20,24 @@ module.exports = {
     "balanced-listeners": require("../lib/rules/balanced-listeners"),
     "components-imports": require("../lib/rules/components-imports"),
     "import-globals-from": require("../lib/rules/import-globals-from"),
     "import-headjs-globals": require("../lib/rules/import-headjs-globals"),
     "import-browserjs-globals": require("../lib/rules/import-browserjs-globals"),
     "mark-test-function-used": require("../lib/rules/mark-test-function-used"),
     "no-aArgs": require("../lib/rules/no-aArgs"),
     "no-cpows-in-tests": require("../lib/rules/no-cpows-in-tests"),
+    "this-top-level-scope": require("../lib/rules/this-top-level-scope.js"),
     "var-only-at-top-level": require("../lib/rules/var-only-at-top-level")
   },
   rulesConfig: {
     "balanced-listeners": 0,
     "components-imports": 0,
     "import-globals-from": 0,
     "import-headjs-globals": 0,
     "import-browserjs-globals": 0,
     "mark-test-function-used": 0,
     "no-aArgs": 0,
     "no-cpows-in-tests": 0,
+    "this-top-level-scope": 0,
     "var-only-at-top-level": 0
   }
 };
new file mode 100644
--- /dev/null
+++ b/testing/eslint-plugin-mozilla/lib/rules/this-top-level-scope.js
@@ -0,0 +1,33 @@
+/**
+ * @fileoverview Marks "this.var = x" as top-level definition of "var".
+ *
+ * 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/.
+ */
+
+"use strict";
+
+// -----------------------------------------------------------------------------
+// Rule Definition
+// -----------------------------------------------------------------------------
+
+var helpers = require("../helpers");
+
+module.exports = function(context) {
+
+  // ---------------------------------------------------------------------------
+  // Public
+  //  --------------------------------------------------------------------------
+
+  return {
+    "AssignmentExpression": function(node) {
+      if (helpers.getIsGlobalScope(context) &&
+          node.left.type === "MemberExpression" &&
+          node.left.object.type === "ThisExpression" &&
+          node.left.property.type === "Identifier") {
+        helpers.addGlobals([node.left.property.name], context);
+      }
+    }
+  };
+};