Bug 1334261 - make the no-useless-parameters rule reject newURI call with an empty string as the last parameter, r=jaws.
authorFlorian Quèze <florian@queze.net>
Fri, 27 Jan 2017 10:51:02 +0100
changeset 331426 c0be583a19b635e94b3e7801497d09d03daa68b7
parent 331425 d02fd33024b876d9a5c7f4afa9bd103ed9d58e74
child 331427 a58d0d69502bbe43f2d468d08b2adeda458f630f
push id31269
push userkwierso@gmail.com
push dateSat, 28 Jan 2017 00:37:25 +0000
treeherdermozilla-central@dfb191cf6039 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1334261
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1334261 - make the no-useless-parameters rule reject newURI call with an empty string as the last parameter, r=jaws.
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-parameters.js
tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-parameters.js
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-parameters.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-parameters.js
@@ -59,17 +59,17 @@ module.exports = function(context) {
         let arg = node.arguments[1];
         if (arg.type === "Literal" && !arg.value) {
           context.report(node,
                          "getComputedStyle's second parameter can be omitted.");
         }
       }
 
       if (callee.property.name === "newURI" &&
-          node.arguments.length === 3) {
-        let arg = node.arguments[2];
-        if (arg.type === "Literal" && arg.value === null) {
-          context.report(node, "newURI's optional parameters passed as null.");
+          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.");
         }
       }
     }
   };
 };
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-parameters.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-parameters.js
@@ -57,21 +57,33 @@ exports.runTest = function(ruleTester) {
         errors: callError("removeObserver only takes 2 parameters.")
       },
       {
         code: "Services.removeObserver('notification name', {}, true);",
         errors: callError("removeObserver only takes 2 parameters.")
       },
       {
         code: "Services.io.newURI('http://example.com', null, null);",
-        errors: callError("newURI's optional parameters passed as null.")
+        errors: callError("newURI's last parameters are optional.")
       },
       {
         code: "Services.io.newURI('http://example.com', 'utf8', null);",
-        errors: callError("newURI's optional parameters passed as null.")
+        errors: callError("newURI's last parameters are optional.")
+      },
+      {
+        code: "Services.io.newURI('http://example.com', null);",
+        errors: callError("newURI's last parameters are optional.")
+      },
+      {
+        code: "Services.io.newURI('http://example.com', '', '');",
+        errors: callError("newURI's last parameters are optional.")
+      },
+      {
+        code: "Services.io.newURI('http://example.com', '');",
+        errors: callError("newURI's last parameters are optional.")
       },
       {
         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.")