forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1328565 - Prevent cases of Cu.import importing into variables and…
… global scope at the same time. r=mossop MozReview-Commit-ID: CXly2RhNpRP --HG-- extra : rebase_source : 9b9a8542bbd437aa0160c122b1b826e08de03009
- Loading branch information
Showing
9 changed files
with
77 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-import-into-var-and-global.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @fileoverview Reject use of Cu.import where it attempts to import into | ||
* a var and into the global scope, e.g. | ||
* var foo = Cu.import("path.jsm", this); | ||
* | ||
* This is considered bad practice as it is confusing as to what | ||
* is actually being imported. | ||
* | ||
* 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" && | ||
node.parent.type === "VariableDeclarator" && | ||
node.arguments.length === 2) { | ||
let memexp = node.callee; | ||
if (((memexp.object.type === "Identifier" && | ||
memexp.object.name === "Cu") || | ||
(memexp.object.type === "MemberExpression" && | ||
memexp.object.object && memexp.object.property && | ||
memexp.object.object.name === "Components" && | ||
memexp.object.property.name === "utils")) && | ||
memexp.property.type === "Identifier" && | ||
memexp.property.name === "import" && | ||
node.arguments[1].type === "ThisExpression") { | ||
context.report(node, "Cu.import imports into variables and into " + | ||
"global scope."); | ||
} | ||
} | ||
} | ||
}; | ||
}; |