Bug 1224289 - add eslint rule to reject Cu.importGlobalProperties; r=mikeratcliffe

This commit is contained in:
Tom Tromey 2016-01-21 10:20:13 -07:00
parent 9811f3937d
commit 23cd180d68
5 changed files with 56 additions and 0 deletions

View File

@ -26,6 +26,8 @@
"mozilla/mark-test-function-used": 1,
"mozilla/no-aArgs": 1,
"mozilla/no-cpows-in-tests": 1,
// See bug 1224289.
"mozilla/reject-importGlobalProperties": 1,
"mozilla/var-only-at-top-level": 1,
// Disallow using variables outside the blocks they are defined (especially

View File

@ -25,6 +25,10 @@ avoids ESLint telling us that the function is never called.
``no-cpows-in-tests`` This rule checks if the file is a browser mochitest and,
if so, checks for possible CPOW usage.
``reject-importGlobalProperties`` This rule rejects calls to
"Cu.importGlobalProperties". Use of this function is undesirable in
some parts of the tree.
Note: These are string matches so we will miss situations where the parent
object is assigned to another variable e.g.::
@ -68,4 +72,5 @@ Example configuration::
mark-test-function-used
no-aArgs
no-cpows-in-tests
reject-importGlobalProperties
var-only-at-top-level

View File

@ -0,0 +1,10 @@
.. _reject-importGlobalProperties:
=============================
reject-importGlobalProperties
=============================
Rule Details
------------
Reject calls to Cu.importGlobalProperties.

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"),
"reject-importGlobalProperties": require("../lib/rules/reject-importGlobalProperties"),
"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")
},
@ -37,6 +38,7 @@ module.exports = {
"mark-test-function-used": 0,
"no-aArgs": 0,
"no-cpows-in-tests": 0,
"reject-importGlobalProperties": 0,
"this-top-level-scope": 0,
"var-only-at-top-level": 0
}

View File

@ -0,0 +1,37 @@
/**
* @fileoverview Reject use of Cu.importGlobalProperties
*
* 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 {
"CallExpression": function(node) {
if (node.callee.type === "MemberExpression") {
let memexp = node.callee;
if (memexp.object.type === "Identifier" &&
// Only Cu, not Components.utils; see bug 1230369.
memexp.object.name === "Cu" &&
memexp.property.type === "Identifier" &&
memexp.property.name === "importGlobalProperties") {
context.report(node, "Unexpected call to Cu.importGlobalProperties");
}
}
}
};
};