Bug 1231963 - handle top-level "this.mumble" assignments in eslint; r=mikeratcliffe

This commit is contained in:
Tom Tromey 2016-01-19 10:04:23 -07:00
parent 8fbd12a804
commit 5dccd728ef
3 changed files with 36 additions and 0 deletions

View File

@ -6,6 +6,7 @@
"rules": {
"mozilla/components-imports": 1,
"mozilla/import-globals-from": 1,
"mozilla/this-top-level-scope": 1,
},
"env": {
"es6": true

View File

@ -25,6 +25,7 @@ module.exports = {
"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: {
@ -36,6 +37,7 @@ module.exports = {
"mark-test-function-used": 0,
"no-aArgs": 0,
"no-cpows-in-tests": 0,
"this-top-level-scope": 0,
"var-only-at-top-level": 0
}
};

View File

@ -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);
}
}
};
};