зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1331081
- make the no-useless-parameters eslint rule report useless addEventListener false third parameter, r=jaws.
--HG-- extra : rebase_source : 9b2b156afacff5d1309c60a3620d061706cc303c
This commit is contained in:
Родитель
6c4ca071b5
Коммит
d422907f57
|
@ -29,6 +29,16 @@ module.exports = function(context) {
|
|||
return;
|
||||
}
|
||||
|
||||
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 ((["getCharPref", "getBoolPref", "getIntPref", "clearUserPref"]
|
||||
.indexOf(callee.property.name) != -1) &&
|
||||
node.arguments.length > 1) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eslint-plugin-mozilla",
|
||||
"version": "0.2.10",
|
||||
"version": "0.2.11",
|
||||
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
|
||||
"keywords": [
|
||||
"eslint",
|
||||
|
|
|
@ -27,6 +27,11 @@ exports.runTest = function(ruleTester) {
|
|||
"Services.removeObserver('notification name', {});",
|
||||
"Services.io.newURI('http://example.com');",
|
||||
"Services.io.newURI('http://example.com', 'utf8');",
|
||||
"elt.addEventListener('click', handler);",
|
||||
"elt.addEventListener('click', handler, true);",
|
||||
"elt.addEventListener('click', handler, {once: true});",
|
||||
"elt.removeEventListener('click', handler);",
|
||||
"elt.removeEventListener('click', handler, true);",
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
|
@ -60,6 +65,14 @@ exports.runTest = function(ruleTester) {
|
|||
{
|
||||
code: "Services.io.newURI('http://example.com', 'utf8', null);",
|
||||
errors: callError("newURI's optional parameters passed as null.")
|
||||
},
|
||||
{
|
||||
code: "elt.addEventListener('click', handler, false);",
|
||||
errors: callError("addEventListener's third parameter can be omitted when it's false.")
|
||||
},
|
||||
{
|
||||
code: "elt.removeEventListener('click', handler, false);",
|
||||
errors: callError("removeEventListener's third parameter can be omitted when it's false.")
|
||||
}
|
||||
]
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче