imported patch eslint-ldap draft
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 03 May 2019 17:03:33 +1200
changeset 73393 6a50a9de6a372394bbdb29f1227f3ed51de911de
parent 73392 ca40d2a5e64434a8790473f7371e221bf91f0a88
child 73394 db8bf0c428c9dafd28ac512b83f6d35add2c7fd6
push id8378
push usergeoff@darktrojan.net
push dateFri, 03 May 2019 05:04:15 +0000
treeherdertry-comm-central@404997bfbacf [default view] [failures only]
imported patch eslint-ldap
.eslintignore
ldap/xpcom/src/nsLDAPProtocolHandler.js
ldap/xpcom/tests/unit/.eslintrc.js
ldap/xpcom/tests/unit/test_nsLDAPURL.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -2,35 +2,24 @@
 **/node_modules/**/*.*
 
 # lint eslint config files which are excluded by default
 !**/.eslintrc.js
 
 # Exclude expected objdirs.
 obj*/**
 
-# Exclude mozilla directory, this one is checked separately
-mozilla/**
-
-# These directories don't contain any js and are not meant to
-config/**
-db/**
-other-licenses/**
-testing/**
-
 # Temporarily disabled until the XUL parser is fixed.
 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,110 @@
 /* -*- 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",
+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=*)",
+      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)",
+      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",
+      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
-    }
+      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 (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 +123,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 +194,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 +226,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);