Bug 1378767 - Enable ESLint for extensions/pref/ r=standard8
authorHemant Singh Patwal <hemantsingh1612@gmail.com>
Fri, 07 Jul 2017 15:30:25 +0530
changeset 416534 d83718fd4da907e11f2e35185dec6ab392150d7f
parent 416533 dfe994f2c6706e7e83b4370ec28cfe08a877322f
child 416535 657ef58ae0353d196c6356855e5b996ef8d48a24
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8
bugs1378767
milestone56.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 1378767 - Enable ESLint for extensions/pref/ r=standard8 MozReview-Commit-ID: BJWBoD3lcTb
.eslintignore
extensions/pref/autoconfig/src/prefcalls.js
extensions/pref/autoconfig/test/unit/.eslintrc.js
extensions/pref/autoconfig/test/unit/autoconfig.js
extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -10,17 +10,19 @@ obj*/**
 addon-sdk/**
 build/**
 chrome/**
 config/**
 db/**
 docshell/**
 editor/**
 embedding/**
-extensions/**
+extensions/cookie/**
+extensions/spellcheck/**
+extensions/universalchardet/**
 gfx/**
 gradle/**
 hal/**
 image/**
 intl/**
 ipc/**
 layout/**
 media/**
--- a/extensions/pref/autoconfig/src/prefcalls.js
+++ b/extensions/pref/autoconfig/src/prefcalls.js
@@ -1,219 +1,208 @@
+/* global processLDAPValues */
 /* -*- tab-width: 4; indent-tabs-mode: nil; js-indent-level: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const nsILDAPURL = Components.interfaces.nsILDAPURL;
 const LDAPURLContractID = "@mozilla.org/network/ldap-url;1";
 const nsILDAPSyncQuery = Components.interfaces.nsILDAPSyncQuery;
 const LDAPSyncQueryContractID = "@mozilla.org/ldapsyncquery;1";
 const nsIPrefService = Components.interfaces.nsIPrefService;
 const PrefServiceContractID = "@mozilla.org/preferences-service;1";
 
 var gVersion;
 var gIsUTF8;
 
 function getPrefBranch() {
-    
+
     var prefService = Components.classes[PrefServiceContractID]
-                                .getService(nsIPrefService);    
+                                .getService(nsIPrefService);
     return prefService.getBranch(null);
 }
 
 function pref(prefName, value) {
 
-    try { 
+    try {
         var prefBranch = getPrefBranch();
 
         if (typeof value == "string") {
             if (gIsUTF8) {
                 prefBranch.setStringPref(prefName, value);
                 return;
             }
             prefBranch.setCharPref(prefName, value);
-        }
-        else if (typeof value == "number") {
+        } else if (typeof value == "number") {
             prefBranch.setIntPref(prefName, value);
-        }
-        else if (typeof value == "boolean") {
+        } else if (typeof value == "boolean") {
             prefBranch.setBoolPref(prefName, value);
         }
-    }
-    catch(e) {
+    } catch (e) {
         displayError("pref", e);
     }
 }
 
 function defaultPref(prefName, value) {
-    
+
     try {
         var prefService = Components.classes[PrefServiceContractID]
-                                    .getService(nsIPrefService);        
+                                    .getService(nsIPrefService);
         var prefBranch = prefService.getDefaultBranch(null);
         if (typeof value == "string") {
             if (gIsUTF8) {
                 prefBranch.setStringPref(prefName, value);
                 return;
             }
             prefBranch.setCharPref(prefName, value);
-        }
-        else if (typeof value == "number") {
+        } else if (typeof value == "number") {
             prefBranch.setIntPref(prefName, value);
-        }
-        else if (typeof value == "boolean") {
+        } else if (typeof value == "boolean") {
             prefBranch.setBoolPref(prefName, value);
         }
-    }
-    catch(e) {
+    } catch (e) {
         displayError("defaultPref", e);
     }
 }
 
 function lockPref(prefName, value) {
-    
+
     try {
         var prefBranch = getPrefBranch();
-        
+
         if (prefBranch.prefIsLocked(prefName))
             prefBranch.unlockPref(prefName);
-        
+
         defaultPref(prefName, value);
-        
+
         prefBranch.lockPref(prefName);
-    }
-    catch(e) {
+    } catch (e) {
         displayError("lockPref", e);
     }
 }
 
 function unlockPref(prefName) {
 
     try {
 
         var prefBranch = getPrefBranch();
         prefBranch.unlockPref(prefName);
-    }
-    catch(e) {
+    } catch (e) {
         displayError("unlockPref", e);
     }
 }
 
 function getPref(prefName) {
-    
+
     try {
         var prefBranch = getPrefBranch();
-        
+
         switch (prefBranch.getPrefType(prefName)) {
-            
+
         case prefBranch.PREF_STRING:
             if (gIsUTF8) {
                 return prefBranch.getStringPref(prefName);
             }
             return prefBranch.getCharPref(prefName);
-            
+
         case prefBranch.PREF_INT:
             return prefBranch.getIntPref(prefName);
-            
+
         case prefBranch.PREF_BOOL:
             return prefBranch.getBoolPref(prefName);
         default:
             return null;
         }
-    }
-    catch(e) {
+    } catch (e) {
         displayError("getPref", e);
     }
+    return undefined;
 }
 
 function clearPref(prefName) {
 
     try {
         var prefBranch = getPrefBranch();
             prefBranch.clearUserPref(prefName);
+    } catch (e) {
     }
-    catch(e) {
-    }
-        
+
 }
 
 function setLDAPVersion(version) {
     gVersion = version;
 }
 
 
 function getLDAPAttributes(host, base, filter, attribs, isSecure) {
-    
+
     try {
         var urlSpec = "ldap" + (isSecure ? "s" : "") + "://" + host + (isSecure ? ":636" : "") + "/" + base + "?" + attribs + "?sub?" +
                       filter;
 
         var url = Components.classes["@mozilla.org/network/io-service;1"]
                             .getService(Components.interfaces.nsIIOService)
                             .newURI(urlSpec)
                             .QueryInterface(Components.interfaces.nsILDAPURL);
 
         var ldapquery = Components.classes[LDAPSyncQueryContractID]
                                   .createInstance(nsILDAPSyncQuery);
         // default to LDAP v3
         if (!gVersion)
           gVersion = Components.interfaces.nsILDAPConnection.VERSION3
- 	// user supplied method
+        // user supplied method
         processLDAPValues(ldapquery.getQueryResults(url, gVersion));
-    }
-    catch(e) {
+    } catch (e) {
         displayError("getLDAPAttibutes", e);
     }
 }
 
 function getLDAPValue(str, key) {
 
     try {
         if (str == null || key == null)
             return null;
-        
+
         var search_key = "\n" + key + "=";
-        
+
         var start_pos = str.indexOf(search_key);
         if (start_pos == -1)
             return null;
-        
+
         start_pos += search_key.length;
-        
+
         var end_pos = str.indexOf("\n", start_pos);
         if (end_pos == -1)
             end_pos = str.length;
-        
+
         return str.substring(start_pos, end_pos);
-    }
-    catch(e) {
+    } catch (e) {
         displayError("getLDAPValue", e);
     }
+    return undefined;
 }
 
 function displayError(funcname, message) {
 
     try {
         var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                                       .getService(Components.interfaces.nsIPromptService);
         var bundle = Components.classes["@mozilla.org/intl/stringbundle;1"]
                                .getService(Components.interfaces.nsIStringBundleService)
                                .createBundle("chrome://autoconfig/locale/autoconfig.properties");
 
          var title = bundle.GetStringFromName("autoConfigTitle");
          var msg = bundle.formatStringFromName("autoConfigMsg", [funcname], 1);
          promptService.alert(null, title, msg + " " + message);
-    }
-    catch(e) { }
+    } catch (e) { }
 }
 
 function getenv(name) {
     try {
         var environment = Components.classes["@mozilla.org/process/environment;1"].
             getService(Components.interfaces.nsIEnvironment);
         return environment.get(name);
-    }
-    catch(e) {
+    } catch (e) {
         displayError("getEnvironment", e);
     }
+    return undefined;
 }
-
new file mode 100644
--- /dev/null
+++ b/extensions/pref/autoconfig/test/unit/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "plugin:mozilla/xpcshell-test"
+  ]
+};
\ No newline at end of file
--- a/extensions/pref/autoconfig/test/unit/autoconfig.js
+++ b/extensions/pref/autoconfig/test/unit/autoconfig.js
@@ -1,4 +1,5 @@
+/* global pref */
 pref("general.config.filename", "autoconfig.cfg");
 pref("general.config.vendor", "autoconfig");
 pref("general.config.obscure_value", 0);
 
--- a/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js
+++ b/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js
@@ -1,21 +1,23 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 var {classes: Cc, interfaces: Ci, results: Cr} = Components;
 
+/* eslint no-unsafe-finally: "off"*/
+/* Turning off this rule to allow control flow operations in finally block
+ * http://eslint.org/docs/rules/no-unsafe-finally  */
 function run_test() {
   let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
                getService(Ci.nsIProperties);
-  let obsvc = Cc['@mozilla.org/observer-service;1'].
+  let obsvc = Cc["@mozilla.org/observer-service;1"].
               getService(Ci.nsIObserverService);
   let ps = Cc["@mozilla.org/preferences-service;1"].
            getService(Ci.nsIPrefService);
-  let defaultPrefs = ps.getDefaultBranch(null);
   let prefs = ps.getBranch(null);
 
   let greD = dirSvc.get("GreD", Ci.nsIFile);
   let defaultPrefD = dirSvc.get("PrfDef", Ci.nsIFile);
   let testDir = do_get_cwd();
 
   try {
     let autoConfigJS = testDir.clone();
@@ -48,24 +50,24 @@ function run_test() {
       // Make sure pref values are unset.
       for (let prefName in test.prefs) {
         do_check_eq(Ci.nsIPrefBranch.PREF_INVALID, prefs.getPrefType(prefName));
       }
 
       let autoConfigCfg = testDir.clone();
       autoConfigCfg.append(test.filename);
       autoConfigCfg.copyTo(greD, "autoconfig.cfg");
-  
+
       obsvc.notifyObservers(ps, "prefservice:before-read-userprefs");
-  
+
       for (let prefName in test.prefs) {
         do_check_eq(test.prefs[prefName],
                     prefs.getStringPref(prefName));
       }
-  
+
       ps.resetPrefs();
       // Make sure pref values are reset.
       for (let prefName in test.prefs) {
         do_check_eq(Ci.nsIPrefBranch.PREF_INVALID, prefs.getPrefType(prefName));
       }
     }
 
     tests.forEach(testAutoConfig);
@@ -89,9 +91,8 @@ function run_test() {
       if (e.result != Cr.NS_ERROR_FILE_NOT_FOUND) {
         throw e;
       }
     }
 
     ps.resetPrefs();
   }
 }
-