Bug 1549166 - Turn on ESLint in ldap; r=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 06 May 2019 16:30:15 +1200
changeset 35276 e344d6227471b1ef216a260cd1e8861b9ce59fb0
parent 35275 bcaa0061855c512d8947c107a59ed77fc68e3c6a
child 35277 230148914b48b705c2cb204240bbdc1064cf8e9d
push id391
push userclokep@gmail.com
push dateTue, 09 Jul 2019 00:57:56 +0000
reviewersjorgk
bugs1549166
Bug 1549166 - Turn on ESLint in ldap; r=jorgk
.eslintignore
ldap/xpcom/src/nsLDAPProtocolHandler.js
ldap/xpcom/tests/unit/.eslintrc.js
ldap/xpcom/tests/unit/test_nsLDAPURL.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -20,17 +20,16 @@ testing/**
 calendar/base/content/calendar-calendars-list.xul
 calendar/providers/gdata/content/gdata-calendar-creation.xul
 common/src/viewSource.xul
 
 # We ignore all these directories by default, until we get them enabled.
 # If you are enabling a directory, please add directory specific exclusions
 # below.
 build/**
-ldap/**
 suite/**
 
 # chat exclusions
 chat/chat-prefs.js
 # third-party code
 chat/modules/BigInteger.jsm
 chat/protocols/matrix/matrix-sdk/**
 chat/protocols/twitter/twitter-text.jsm
--- a/ldap/xpcom/src/nsLDAPProtocolHandler.js
+++ b/ldap/xpcom/src/nsLDAPProtocolHandler.js
@@ -13,42 +13,42 @@ function makeProtocolHandler(aCID, aProt
     QueryInterface: ChromeUtils.generateQI([nsIProtocolHandler]),
 
     scheme: aProtocol,
     defaultPort: aDefaultPort,
     protocolFlags: nsIProtocolHandler.URI_NORELATIVE |
                    nsIProtocolHandler.URI_DANGEROUS_TO_LOAD |
                    nsIProtocolHandler.ALLOWS_PROXY,
 
-    newURI: function (aSpec, aOriginCharset, aBaseURI) {
+    newURI(aSpec, aOriginCharset, aBaseURI) {
       var url = Cc["@mozilla.org/network/ldap-url;1"]
                   .createInstance(Ci.nsIURI);
 
       if (url instanceof Ci.nsILDAPURL)
         url.init(Ci.nsIStandardURL.URLTYPE_STANDARD,
           aDefaultPort, aSpec, aOriginCharset, aBaseURI);
 
       return url;
     },
 
-    newChannel: function (aURI, aLoadInfo) {
+    newChannel(aURI, aLoadInfo) {
       if ("@mozilla.org/network/ldap-channel;1" in Cc) {
         var channel = Cc["@mozilla.org/network/ldap-channel;1"]
                         .createInstance(Ci.nsIChannel);
         channel.init(aURI);
         channel.loadInfo = aLoadInfo;
         return channel;
       }
 
       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
     },
 
-    allowPort: function (port, scheme) {
+    allowPort(port, scheme) {
       return port == aDefaultPort;
-    }
+    },
   };
 }
 
 function nsLDAPProtocolHandler() {}
 
 nsLDAPProtocolHandler.prototype = makeProtocolHandler("{b3de9249-b0e5-4c12-8d91-c9a434fd80f5}", "ldap", 389);
 
 function nsLDAPSProtocolHandler() {}
new file mode 100644
--- /dev/null
+++ b/ldap/xpcom/tests/unit/.eslintrc.js
@@ -0,0 +1,14 @@
+"use strict";
+
+module.exports = {
+  "extends": "plugin:mozilla/xpcshell-test",
+
+  "rules": {
+    "func-names": "off",
+    "mozilla/import-headjs-globals": "error",
+    "no-unused-vars": ["error", {
+      "args": "none",
+      "vars": "all",
+    }],
+  },
+};
--- a/ldap/xpcom/tests/unit/test_nsLDAPURL.js
+++ b/ldap/xpcom/tests/unit/test_nsLDAPURL.js
@@ -1,112 +1,109 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Test suite for nsLDAPURL functions.
  */
 
+var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 // If we are still using the wallet service, then default port numbers
 // are still visible in the password manager, and therefore we need to have
 // them in the url. The toolkit login manager doesn't do this.
 const usingWallet = "nsIWalletService" in Ci;
 const portAdpt = usingWallet ? ":389" : "";
 
-const ldapURLs =
-  [ { url: "ldap://localhost/dc=test",
-      spec: "ldap://localhost/dc=test",
-      asciiSpec: "ldap://localhost/dc=test",
-      host: "localhost",
-      asciiHost: "localhost",
-      port: -1,
-      scheme: "ldap",
-      path: "/dc=test",
-      prePath: "ldap://localhost",
-      hostPort: "localhost",
-      displaySpec: "ldap://localhost/dc=test",
-      displayPrePath: "ldap://localhost",
-      displayHost: "localhost",
-      displayHostPort: "localhost",
-      dn: "dc=test",
-      scope: Ci.nsILDAPURL.SCOPE_BASE,
-      filter: "(objectclass=*)",
-      options: 0
-    },
-    { url: "ldap://localhost:389/dc=test,dc=abc??sub?(objectclass=*)",
-      spec: "ldap://localhost" + portAdpt + "/dc=test,dc=abc??sub?(objectclass=*)",
-      asciiSpec: "ldap://localhost" + portAdpt + "/dc=test,dc=abc??sub?(objectclass=*)",
-      host: "localhost",
-      asciiHost: "localhost",
-      port: usingWallet ? 389 : -1,
-      scheme: "ldap",
-      path: "/dc=test,dc=abc??sub?(objectclass=*)",
-      prePath: "ldap://localhost" + portAdpt,
-      hostPort: "localhost" + portAdpt,
-      displaySpec: "ldap://localhost" + portAdpt + "/dc=test,dc=abc??sub?(objectclass=*)",
-      displayPrePath: "ldap://localhost",
-      displayHost: "localhost",
-      displayHostPort: "localhost" + portAdpt,
-      dn: "dc=test,dc=abc",
-      scope: Ci.nsILDAPURL.SCOPE_SUBTREE,
-      filter: "(objectclass=*)",
-      options: 0
-    },
-    { url: "ldap://\u65e5\u672c\u8a93.jp:389/dc=tes\u65e5t??one?(oc=xyz)",
-      spec: "ldap://xn--wgv71a309e.jp" + portAdpt + "/dc=tes%E6%97%A5t??one?(oc=xyz)",
-      asciiSpec: "ldap://xn--wgv71a309e.jp" + portAdpt + "/dc=tes%E6%97%A5t??one?(oc=xyz)",
-      host: "xn--wgv71a309e.jp",
-      asciiHost: "xn--wgv71a309e.jp",
-      port: usingWallet ? 389 : -1,
-      scheme: "ldap",
-      path: "/dc=tes%E6%97%A5t??one?(oc=xyz)",
-      prePath: "ldap://xn--wgv71a309e.jp" + portAdpt,
-      hostPort: "xn--wgv71a309e.jp" + portAdpt,
-      displaySpec: "ldap://\u65e5\u672c\u8a93.jp" + portAdpt + "/dc=tes%E6%97%A5t??one?(oc=xyz)",
-      displayPrePath: "ldap://\u65e5\u672c\u8a93.jp" + portAdpt,
-      displayHost: "\u65e5\u672c\u8a93.jp",
-      displayHostPort: "\u65e5\u672c\u8a93.jp" + portAdpt,
-      dn: "dc=tes\u65e5t",
-      scope: Ci.nsILDAPURL.SCOPE_ONELEVEL,
-      filter: "(oc=xyz)",
-      options: 0
-    },
-    { url: "ldaps://localhost/dc=test",
-      spec: "ldaps://localhost/dc=test",
-      asciiSpec: "ldaps://localhost/dc=test",
-      host: "localhost",
-      asciiHost: "localhost",
-      port: -1,
-      scheme: "ldaps",
-      path: "/dc=test",
-      prePath: "ldaps://localhost",
-      hostPort: "localhost",
-      displaySpec: "ldaps://localhost/dc=test",
-      displayPrePath: "ldaps://localhost",
-      displayHost: "localhost",
-      displayHostPort: "localhost",
-      dn: "dc=test",
-      scope: Ci.nsILDAPURL.SCOPE_BASE,
-      filter: "(objectclass=*)",
-      options: Ci.nsILDAPURL.OPT_SECURE
-    }
-  ];
+const ldapURLs = [
+  {
+    url: "ldap://localhost/dc=test",
+    spec: "ldap://localhost/dc=test",
+    asciiSpec: "ldap://localhost/dc=test",
+    host: "localhost",
+    asciiHost: "localhost",
+    port: -1,
+    scheme: "ldap",
+    path: "/dc=test",
+    prePath: "ldap://localhost",
+    hostPort: "localhost",
+    displaySpec: "ldap://localhost/dc=test",
+    displayPrePath: "ldap://localhost",
+    displayHost: "localhost",
+    displayHostPort: "localhost",
+    dn: "dc=test",
+    scope: Ci.nsILDAPURL.SCOPE_BASE,
+    filter: "(objectclass=*)",
+    options: 0,
+  }, {
+    url: "ldap://localhost:389/dc=test,dc=abc??sub?(objectclass=*)",
+    spec: "ldap://localhost" + portAdpt + "/dc=test,dc=abc??sub?(objectclass=*)",
+    asciiSpec: "ldap://localhost" + portAdpt + "/dc=test,dc=abc??sub?(objectclass=*)",
+    host: "localhost",
+    asciiHost: "localhost",
+    port: usingWallet ? 389 : -1,
+    scheme: "ldap",
+    path: "/dc=test,dc=abc??sub?(objectclass=*)",
+    prePath: "ldap://localhost" + portAdpt,
+    hostPort: "localhost" + portAdpt,
+    displaySpec: "ldap://localhost" + portAdpt + "/dc=test,dc=abc??sub?(objectclass=*)",
+    displayPrePath: "ldap://localhost",
+    displayHost: "localhost",
+    displayHostPort: "localhost" + portAdpt,
+    dn: "dc=test,dc=abc",
+    scope: Ci.nsILDAPURL.SCOPE_SUBTREE,
+    filter: "(objectclass=*)",
+    options: 0,
+  }, {
+    url: "ldap://\u65e5\u672c\u8a93.jp:389/dc=tes\u65e5t??one?(oc=xyz)",
+    spec: "ldap://xn--wgv71a309e.jp" + portAdpt + "/dc=tes%E6%97%A5t??one?(oc=xyz)",
+    asciiSpec: "ldap://xn--wgv71a309e.jp" + portAdpt + "/dc=tes%E6%97%A5t??one?(oc=xyz)",
+    host: "xn--wgv71a309e.jp",
+    asciiHost: "xn--wgv71a309e.jp",
+    port: usingWallet ? 389 : -1,
+    scheme: "ldap",
+    path: "/dc=tes%E6%97%A5t??one?(oc=xyz)",
+    prePath: "ldap://xn--wgv71a309e.jp" + portAdpt,
+    hostPort: "xn--wgv71a309e.jp" + portAdpt,
+    displaySpec: "ldap://\u65e5\u672c\u8a93.jp" + portAdpt + "/dc=tes%E6%97%A5t??one?(oc=xyz)",
+    displayPrePath: "ldap://\u65e5\u672c\u8a93.jp" + portAdpt,
+    displayHost: "\u65e5\u672c\u8a93.jp",
+    displayHostPort: "\u65e5\u672c\u8a93.jp" + portAdpt,
+    dn: "dc=tes\u65e5t",
+    scope: Ci.nsILDAPURL.SCOPE_ONELEVEL,
+    filter: "(oc=xyz)",
+    options: 0,
+  }, {
+    url: "ldaps://localhost/dc=test",
+    spec: "ldaps://localhost/dc=test",
+    asciiSpec: "ldaps://localhost/dc=test",
+    host: "localhost",
+    asciiHost: "localhost",
+    port: -1,
+    scheme: "ldaps",
+    path: "/dc=test",
+    prePath: "ldaps://localhost",
+    hostPort: "localhost",
+    displaySpec: "ldaps://localhost/dc=test",
+    displayPrePath: "ldaps://localhost",
+    displayHost: "localhost",
+    displayHostPort: "localhost",
+    dn: "dc=test",
+    scope: Ci.nsILDAPURL.SCOPE_BASE,
+    filter: "(objectclass=*)",
+    options: Ci.nsILDAPURL.OPT_SECURE,
+  },
+];
 
 function run_test() {
   var url;
 
-  // Get the IO service;
-  var ioService = Cc["@mozilla.org/network/io-service;1"]
-                    .getService(Ci.nsIIOService);
-
   // Test - get and check urls.
 
-  var part = 0;
-  for (part = 0; part < ldapURLs.length; ++part)
-  {
+  for (let part = 0; part < ldapURLs.length; ++part) {
     dump("url: " + ldapURLs[part].url + "\n");
-    url = ioService.newURI(ldapURLs[part].url);
+    url = Services.io.newURI(ldapURLs[part].url);
 
     Assert.equal(url.spec, ldapURLs[part].spec);
     Assert.equal(url.asciiSpec, ldapURLs[part].asciiSpec);
     Assert.equal(url.scheme, ldapURLs[part].scheme);
     Assert.equal(url.host, ldapURLs[part].host);
     Assert.equal(url.asciiHost, ldapURLs[part].asciiHost);
     Assert.equal(url.port, ldapURLs[part].port);
     Assert.equal(url.pathQueryRef, ldapURLs[part].path);
@@ -125,18 +122,17 @@ function run_test() {
   }
 
   // Test - Check changing ldap values
   dump("Other Tests\n");
 
   // Start off with a base url
   const kBaseURL = "ldap://localhost:389/dc=test,dc=abc??sub?(objectclass=*)";
 
-  url = ioService.newURI(kBaseURL)
-                 .QueryInterface(Ci.nsILDAPURL);
+  url = Services.io.newURI(kBaseURL).QueryInterface(Ci.nsILDAPURL);
 
   // Test - dn
 
   url.dn = "dc=short";
 
   Assert.equal(url.dn, "dc=short");
   Assert.equal(url.spec, "ldap://localhost" + portAdpt + "/dc=short??sub?(objectclass=*)");
 
@@ -197,18 +193,18 @@ function run_test() {
 
   url.options = 0;
 
   Assert.equal(url.options, 0);
   Assert.equal(url.spec, "ldap://localhost" + portAdpt + "/dc=short??one?(objectclass=*)");
 
   // Test - Equals
 
-  var url2 = ioService.newURI("ldap://localhost" + portAdpt + "/dc=short??one?(objectclass=*)")
-                      .QueryInterface(Ci.nsILDAPURL);
+  var url2 = Services.io.newURI("ldap://localhost" + portAdpt + "/dc=short??one?(objectclass=*)")
+                        .QueryInterface(Ci.nsILDAPURL);
 
   Assert.ok(url.equals(url2));
 
   url2 = url2.mutate().setSpec("ldap://localhost:389/dc=short??sub?(objectclass=*)").finalize();
 
   Assert.ok(!url.equals(url2));
 
   // Test Attributes
@@ -229,18 +225,16 @@ function run_test() {
   url.removeAttribute("dn");
 
   Assert.equal(url.attributes.length, 0);
   Assert.equal(url.spec, "ldap://localhost" + portAdpt + "/dc=short??one?(objectclass=*)");
 
   var newAttrs = "abc,def,ghi,jkl";
   url.attributes = newAttrs;
 
-  var i;
-
   Assert.equal(url.attributes, newAttrs);
   Assert.equal(url.spec,
                "ldap://localhost" + portAdpt + "/dc=short?" +
                newAttrs + "?one?(objectclass=*)");
 
   // Try adding an existing attribute - should do nothing
   url.addAttribute("def");
   Assert.equal(url.attributes, newAttrs);