Bug 1378767 - Enable ESLint for extensions/pref/ r=standard8

MozReview-Commit-ID: BJWBoD3lcTb

--HG--
extra : rebase_source : b3ee9d94abdbe19a355c85da2b5abf148fe43689
This commit is contained in:
Hemant Singh Patwal 2017-07-07 15:30:25 +05:30
parent aeaad5857f
commit 53e34790cc
5 changed files with 58 additions and 58 deletions

View File

@ -15,7 +15,9 @@ db/**
docshell/**
editor/**
embedding/**
extensions/**
extensions/cookie/**
extensions/spellcheck/**
extensions/universalchardet/**
gfx/**
gradle/**
hal/**

View File

@ -1,3 +1,4 @@
/* 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
@ -14,15 +15,15 @@ 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") {
@ -31,24 +32,21 @@ function pref(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) {
@ -56,32 +54,28 @@ function defaultPref(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);
}
}
@ -92,37 +86,36 @@ function unlockPref(prefName) {
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) {
@ -130,10 +123,9 @@ function clearPref(prefName) {
try {
var prefBranch = getPrefBranch();
prefBranch.clearUserPref(prefName);
} catch (e) {
}
catch(e) {
}
}
function setLDAPVersion(version) {
@ -142,7 +134,7 @@ function setLDAPVersion(version) {
function getLDAPAttributes(host, base, filter, attribs, isSecure) {
try {
var urlSpec = "ldap" + (isSecure ? "s" : "") + "://" + host + (isSecure ? ":636" : "") + "/" + base + "?" + attribs + "?sub?" +
filter;
@ -157,10 +149,9 @@ function getLDAPAttributes(host, base, filter, attribs, isSecure) {
// 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);
}
}
@ -170,24 +161,24 @@ 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) {
@ -202,8 +193,7 @@ function displayError(funcname, message) {
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) {
@ -211,9 +201,8 @@ function getenv(name) {
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;
}

View File

@ -0,0 +1,7 @@
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/xpcshell-test"
]
};

View File

@ -1,3 +1,4 @@
/* global pref */
pref("general.config.filename", "autoconfig.cfg");
pref("general.config.vendor", "autoconfig");
pref("general.config.obscure_value", 0);

View File

@ -3,14 +3,16 @@
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);
@ -53,14 +55,14 @@ function run_test() {
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) {
@ -94,4 +96,3 @@ function run_test() {
ps.resetPrefs();
}
}