Bug 1193390 - Add ESLint rule to check for single argument Cu.import. r=tromey

MozReview-Commit-ID: 1IRTa7kgdiF
This commit is contained in:
J. Ryan Stinnett 2016-06-03 14:18:27 -05:00
Родитель 2cb9715c8a
Коммит 66ea2b9a74
6 изменённых файлов: 96 добавлений и 34 удалений

Просмотреть файл

@ -22,14 +22,17 @@ avoids ESLint telling us that the function is never called.
``no-aArgs`` prevents using the hungarian notation in function arguments.
``no-cpows-in-tests`` This rule checks if the file is a browser mochitest and,
``no-cpows-in-tests`` checks if the file is a browser mochitest and,
if so, checks for possible CPOW usage.
``reject-importGlobalProperties`` This rule rejects calls to
``no-single-arg-cu-import`` rejects calls to "Cu.import" that do not supply a
second argument (meaning they add the exported properties into global scope).
``reject-importGlobalProperties`` rejects calls to
"Cu.importGlobalProperties". Use of this function is undesirable in
some parts of the tree.
``this-top-level-scope`` This rule treats top-level assignments like
``this-top-level-scope`` treats top-level assignments like
``this.mumble = value`` as declaring a global.
Note: These are string matches so we will miss situations where the parent

Просмотреть файл

@ -0,0 +1,11 @@
.. _no-single-arg-cu-import:
=======================
no-single-arg-cu-import
=======================
Rule Details
------------
Rejects calls to "Cu.import" that do not supply a second argument (meaning they
add the exported properties into global scope).

Просмотреть файл

@ -24,6 +24,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"),
"no-single-arg-cu-import": require("../lib/rules/no-single-arg-cu-import"),
"reject-importGlobalProperties": require("../lib/rules/reject-importGlobalProperties"),
"var-only-at-top-level": require("../lib/rules/var-only-at-top-level")
},
@ -35,6 +36,7 @@ module.exports = {
"mark-test-function-used": 0,
"no-aArgs": 0,
"no-cpows-in-tests": 0,
"no-single-arg-cu-import": 0,
"reject-importGlobalProperties": 0,
"var-only-at-top-level": 0
}

Просмотреть файл

@ -0,0 +1,39 @@
/**
* @fileoverview Reject use of single argument Cu.import
*
* 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 === "import" &&
node.arguments.length === 1) {
context.report(node, "Single argument Cu.import exposes new " +
"globals to all modules");
}
}
}
};
};

Просмотреть файл

@ -1,8 +1,8 @@
[
{
"size": 2218185,
"size": 2373126,
"visibility": "public",
"digest": "ea0065d8986ceffb2870fbc8489c1c2e06afc859df4d93ce8ea87c5accb10822a30e16dbde72c19c9a03fa434f136969089467e629a18c3e6d8601645436fff9",
"digest": "c37113493a8f638fd32b5926cdf4066d32ee65b9425465593233a19c3915e38c37463cae1cb229722a3b61a837d999cd7f6b0beee41ddcadedc22da85cd2a7cd",
"algorithm": "sha512",
"filename": "eslint.tar.gz"
}

65
tools/lint/eslint/npm-shrinkwrap.json сгенерированный
Просмотреть файл

@ -1,9 +1,9 @@
{
"dependencies": {
"acorn": {
"version": "3.1.0",
"version": "3.2.0",
"from": "acorn@>=3.1.0 <4.0.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-3.1.0.tgz"
"resolved": "https://registry.npmjs.org/acorn/-/acorn-3.2.0.tgz"
},
"acorn-jsx": {
"version": "3.0.1",
@ -51,9 +51,9 @@
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-0.4.1.tgz"
},
"bluebird": {
"version": "3.3.5",
"version": "3.4.0",
"from": "bluebird@>=3.1.1 <4.0.0",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.3.5.tgz"
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.4.0.tgz"
},
"brace-expansion": {
"version": "1.1.4",
@ -126,9 +126,9 @@
"resolved": "https://registry.npmjs.org/del/-/del-2.2.0.tgz"
},
"doctrine": {
"version": "1.2.1",
"version": "1.2.2",
"from": "doctrine@>=1.2.1 <2.0.0",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.2.1.tgz",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.2.2.tgz",
"dependencies": {
"esutils": {
"version": "1.1.6",
@ -171,8 +171,15 @@
},
"es5-ext": {
"version": "0.10.11",
"from": "es5-ext@>=0.10.8 <0.11.0",
"resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.11.tgz"
"from": "es5-ext@>=0.10.11 <0.11.0",
"resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.11.tgz",
"dependencies": {
"es6-symbol": {
"version": "3.0.2",
"from": "es6-symbol@>=3.0.2 <3.1.0",
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.0.2.tgz"
}
}
},
"es6-iterator": {
"version": "2.0.0",
@ -180,9 +187,9 @@
"resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.0.tgz"
},
"es6-map": {
"version": "0.1.3",
"version": "0.1.4",
"from": "es6-map@>=0.1.3 <0.2.0",
"resolved": "https://registry.npmjs.org/es6-map/-/es6-map-0.1.3.tgz"
"resolved": "https://registry.npmjs.org/es6-map/-/es6-map-0.1.4.tgz"
},
"es6-set": {
"version": "0.1.4",
@ -190,9 +197,9 @@
"resolved": "https://registry.npmjs.org/es6-set/-/es6-set-0.1.4.tgz"
},
"es6-symbol": {
"version": "3.0.2",
"from": "es6-symbol@>=3.0.1 <3.1.0",
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.0.2.tgz"
"version": "3.1.0",
"from": "es6-symbol@>=3.1.0 <3.2.0",
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.0.tgz"
},
"es6-weak-map": {
"version": "2.0.1",
@ -284,9 +291,9 @@
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-1.1.3.tgz"
},
"figures": {
"version": "1.5.0",
"version": "1.7.0",
"from": "figures@>=1.3.5 <2.0.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-1.5.0.tgz"
"resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz"
},
"file-entry-cache": {
"version": "1.2.4",
@ -314,14 +321,14 @@
"resolved": "https://registry.npmjs.org/glob/-/glob-7.0.3.tgz"
},
"globals": {
"version": "9.6.0",
"version": "9.8.0",
"from": "globals@>=9.2.0 <10.0.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-9.6.0.tgz"
"resolved": "https://registry.npmjs.org/globals/-/globals-9.8.0.tgz"
},
"globby": {
"version": "4.0.0",
"version": "4.1.0",
"from": "globby@>=4.0.0 <5.0.0",
"resolved": "https://registry.npmjs.org/globby/-/globby-4.0.0.tgz",
"resolved": "https://registry.npmjs.org/globby/-/globby-4.1.0.tgz",
"dependencies": {
"glob": {
"version": "6.0.4",
@ -356,9 +363,9 @@
"resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz"
},
"inflight": {
"version": "1.0.4",
"version": "1.0.5",
"from": "inflight@>=1.0.4 <2.0.0",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.4.tgz"
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.5.tgz"
},
"inherits": {
"version": "2.0.1",
@ -411,9 +418,9 @@
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
},
"js-yaml": {
"version": "3.6.0",
"version": "3.6.1",
"from": "js-yaml@>=3.5.1 <4.0.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.6.0.tgz"
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.6.1.tgz"
},
"json-stable-stringify": {
"version": "1.0.1",
@ -436,9 +443,9 @@
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz"
},
"lodash": {
"version": "4.12.0",
"version": "4.13.1",
"from": "lodash@>=4.0.0 <5.0.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.12.0.tgz"
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.13.1.tgz"
},
"minimatch": {
"version": "3.0.0",
@ -681,9 +688,9 @@
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz"
},
"wrappy": {
"version": "1.0.1",
"version": "1.0.2",
"from": "wrappy@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.1.tgz"
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz"
},
"write": {
"version": "0.2.1",
@ -691,9 +698,9 @@
"resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz"
},
"xregexp": {
"version": "3.1.0",
"version": "3.1.1",
"from": "xregexp@>=3.0.0 <4.0.0",
"resolved": "https://registry.npmjs.org/xregexp/-/xregexp-3.1.0.tgz"
"resolved": "https://registry.npmjs.org/xregexp/-/xregexp-3.1.1.tgz"
},
"xtend": {
"version": "4.0.1",