зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset c724e1485608 (bug 1356569)
This commit is contained in:
Родитель
9890c46407
Коммит
608dc9589d
|
@ -181,7 +181,7 @@
|
|||
.removeObserver(this.name, this.preferences);
|
||||
this.setAttribute("name", val);
|
||||
this.preferences.rootBranchInternal
|
||||
.addObserver(val, this.preferences);
|
||||
.addObserver(val, this.preferences, false);
|
||||
|
||||
return val;
|
||||
</setter>
|
||||
|
|
|
@ -27,47 +27,45 @@ module.exports = function(context) {
|
|||
return;
|
||||
}
|
||||
|
||||
let isFalse = arg => arg.type === "Literal" && arg.value === false;
|
||||
let isFalsy = arg => arg.type === "Literal" && !arg.value;
|
||||
let isBool = arg => arg.type === "Literal" && (arg.value === false ||
|
||||
arg.value === true);
|
||||
let name = callee.property.name;
|
||||
let args = node.arguments;
|
||||
|
||||
if (["addEventListener", "removeEventListener", "addObserver"]
|
||||
.includes(name) && args.length === 3 && isFalse(args[2])) {
|
||||
context.report(node, name +
|
||||
"'s third parameter can be omitted when it's false.");
|
||||
if ((callee.property.name === "addEventListener" ||
|
||||
callee.property.name === "removeEventListener") &&
|
||||
node.arguments.length === 3) {
|
||||
let arg = node.arguments[2];
|
||||
if (arg.type === "Literal" && arg.value === false) {
|
||||
context.report(node, callee.property.name +
|
||||
"'s third parameter can be omitted when it's false.");
|
||||
}
|
||||
}
|
||||
|
||||
if (name === "clearUserPref" && args.length > 1) {
|
||||
context.report(node, name + " takes only 1 parameter.");
|
||||
if (callee.property.name == "clearUserPref" &&
|
||||
node.arguments.length > 1) {
|
||||
context.report(node, callee.property.name + " takes only 1 parameter.");
|
||||
}
|
||||
|
||||
if (name === "removeObserver" && args.length === 3 && isBool(args[2])) {
|
||||
context.report(node, "removeObserver only takes 2 parameters.");
|
||||
if (callee.property.name === "removeObserver" &&
|
||||
node.arguments.length === 3) {
|
||||
let arg = node.arguments[2];
|
||||
if (arg.type === "Literal" && (arg.value === false ||
|
||||
arg.value === true)) {
|
||||
context.report(node, "removeObserver only takes 2 parameters.");
|
||||
}
|
||||
}
|
||||
|
||||
if (name === "appendElement" && args.length === 2 && isFalse(args[1])) {
|
||||
context.report(node, name +
|
||||
"'s second parameter can be omitted when it's false.");
|
||||
if (callee.property.name === "getComputedStyle" &&
|
||||
node.arguments.length === 2) {
|
||||
let arg = node.arguments[1];
|
||||
if (arg.type === "Literal" && !arg.value) {
|
||||
context.report(node,
|
||||
"getComputedStyle's second parameter can be omitted.");
|
||||
}
|
||||
}
|
||||
|
||||
if (name === "notifyObservers" && args.length === 3 &&
|
||||
isFalsy(args[2])) {
|
||||
context.report(node, name +
|
||||
"'s third parameter can be omitted.");
|
||||
}
|
||||
|
||||
if (name === "getComputedStyle" && args.length === 2 &&
|
||||
isFalsy(args[1])) {
|
||||
context.report(node,
|
||||
"getComputedStyle's second parameter can be omitted.");
|
||||
}
|
||||
|
||||
if (name === "newURI" && args.length > 1 &&
|
||||
isFalsy(args[args.length - 1])) {
|
||||
context.report(node, "newURI's last parameters are optional.");
|
||||
if (callee.property.name === "newURI" &&
|
||||
node.arguments.length > 1) {
|
||||
let arg = node.arguments[node.arguments.length - 1];
|
||||
if (arg.type === "Literal" && !arg.value) {
|
||||
context.report(node, "newURI's last parameters are optional.");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eslint-plugin-mozilla",
|
||||
"version": "0.2.38",
|
||||
"version": "0.2.37",
|
||||
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
|
||||
"keywords": [
|
||||
"eslint",
|
||||
|
|
|
@ -29,13 +29,6 @@ exports.runTest = function(ruleTester) {
|
|||
"elt.addEventListener('click', handler, {once: true});",
|
||||
"elt.removeEventListener('click', handler);",
|
||||
"elt.removeEventListener('click', handler, true);",
|
||||
"Services.obs.addObserver(this, 'topic', true);",
|
||||
"Services.obs.addObserver(this, 'topic');",
|
||||
"Services.prefs.addObserver('branch', this, true);",
|
||||
"Services.prefs.addObserver('branch', this);",
|
||||
"array.appendElement(elt);",
|
||||
"Services.obs.notifyObservers(obj, 'topic', 'data');",
|
||||
"Services.obs.notifyObservers(obj, 'topic');",
|
||||
"window.getComputedStyle(elt);",
|
||||
"window.getComputedStyle(elt, ':before');"
|
||||
],
|
||||
|
@ -83,34 +76,6 @@ exports.runTest = function(ruleTester) {
|
|||
"removeEventListener's third parameter can be omitted when it's" +
|
||||
" false.")
|
||||
},
|
||||
{
|
||||
code: "Services.obs.addObserver(this, 'topic', false);",
|
||||
errors: callError(
|
||||
"addObserver's third parameter can be omitted when it's" +
|
||||
" false.")
|
||||
},
|
||||
{
|
||||
code: "Services.prefs.addObserver('branch', this, false);",
|
||||
errors: callError(
|
||||
"addObserver's third parameter can be omitted when it's" +
|
||||
" false.")
|
||||
},
|
||||
{
|
||||
code: "array.appendElement(elt, false);",
|
||||
errors: callError(
|
||||
"appendElement's second parameter can be omitted when it's" +
|
||||
" false.")
|
||||
},
|
||||
{
|
||||
code: "Services.obs.notifyObservers(obj, 'topic', null);",
|
||||
errors: callError(
|
||||
"notifyObservers's third parameter can be omitted.")
|
||||
},
|
||||
{
|
||||
code: "Services.obs.notifyObservers(obj, 'topic', '');",
|
||||
errors: callError(
|
||||
"notifyObservers's third parameter can be omitted.")
|
||||
},
|
||||
{
|
||||
code: "window.getComputedStyle(elt, null);",
|
||||
errors: callError("getComputedStyle's second parameter can be omitted.")
|
||||
|
|
Загрузка…
Ссылка в новой задаче