Bug 1245649: Enable no-nested-ternary. r=mconley

--HG--
extra : commitid : 197imYXFNid
extra : rebase_source : ce71773fbd8f57118ba30ab395524d9200c42162
This commit is contained in:
Dave Townsend 2016-02-03 21:17:16 -08:00
Родитель 306183747d
Коммит aad445ae43
29 изменённых файлов: 215 добавлений и 106 удалений

Просмотреть файл

@ -426,9 +426,12 @@ var gGestureSupport = {
try {
// Determine what type of data to load based on default value's type
let type = typeof aDef;
let getFunc = "get" + (type == "boolean" ? "Bool" :
type == "number" ? "Int" : "Char") + "Pref";
return gPrefService[getFunc](branch + aPref);
let getFunc = "Char";
if (type == "boolean")
getFunc = "Bool";
else if (type == "number")
getFunc = "Int";
return gPrefService["get" + getFunc + "Pref"](branch + aPref);
}
catch (e) {
return aDef;

Просмотреть файл

@ -277,9 +277,13 @@ ContentSearchUIController.prototype = {
if (this.suggestionAtIndex(this.selectedIndex)) {
eventData.selection = {
index: this.selectedIndex,
kind: aEvent instanceof MouseEvent ? "mouse" :
aEvent instanceof KeyboardEvent ? "key" : undefined,
kind: undefined,
};
if (aEvent instanceof MouseEvent) {
eventData.selection.kind = "mouse";
} else if (aEvent instanceof KeyboardEvent) {
eventData.selection.kind = "key";
}
}
this._sendMsg("Search", eventData);

Просмотреть файл

@ -300,7 +300,7 @@ function initPluginsRow() {
let entries = Array.from(permissionMap, item => ({ name: item[1], permission: item[0] }));
entries.sort(function(a, b) {
return a.name < b.name ? -1 : (a.name == b.name ? 0 : 1);
return a.name.localeCompare(b.name);
});
let permissionEntries = entries.map(p => fillInPluginPermissionTemplate(p.name, p.permission));

Просмотреть файл

@ -916,8 +916,12 @@ CustomizeMode.prototype = {
let removable = aPlace == "palette" || CustomizableUI.isWidgetRemovable(aNode);
wrapper.setAttribute("removable", removable);
let contextMenuAttrName = aNode.getAttribute("context") ? "context" :
aNode.getAttribute("contextmenu") ? "contextmenu" : "";
let contextMenuAttrName = "";
if (aNode.getAttribute("context")) {
contextMenuAttrName = "context";
} else if (aNode.getAttribute("contextmenu")) {
contextMenuAttrName = "contextmenu";
}
let currentContextMenu = aNode.getAttribute(contextMenuAttrName);
let contextMenuForPlace = aPlace == "panel" ?
kPanelItemContextMenu :

Просмотреть файл

@ -417,8 +417,12 @@
// Autoscroll the popup strip if we drag over the scroll buttons.
let anonid = event.originalTarget.getAttribute('anonid');
let scrollDir = anonid == "scrollbutton-up" ? -1 :
anonid == "scrollbutton-down" ? 1 : 0;
let scrollDir = 0;
if (anonid == "scrollbutton-up") {
scrollDir = -1;
} else if (anonid == "scrollbutton-down") {
scrollDir = 1;
}
if (scrollDir != 0) {
this._scrollBox.scrollByIndex(scrollDir, false);
}

Просмотреть файл

@ -542,7 +542,7 @@ var pktApi = (function() {
usedTagsObjectArray.sort(function(usedTagA, usedTagB) {
var a = usedTagA.timestamp;
var b = usedTagB.timestamp;
return a < b ? -1 : a > b ? 1 : 0;
return a - b;
});
// Get all keys tags

Просмотреть файл

@ -110,7 +110,7 @@
"no-negated-in-lhs": 2,
// Nested ternary statements are confusing
// "no-nested-ternary": 2,
"no-nested-ternary": 2,
// Use {} instead of new Object()
// "no-new-object": 2,

Просмотреть файл

@ -1193,9 +1193,7 @@ TreeNode.compareAmounts = function(aA, aB) {
};
TreeNode.compareUnsafeNames = function(aA, aB) {
return aA._unsafeName < aB._unsafeName ? -1 :
aA._unsafeName > aB._unsafeName ? 1 :
0;
return aA._unsafeName.localeCompare(aB._unsafeName);
};

Просмотреть файл

@ -1593,12 +1593,13 @@ module.exports = function (chai, _) {
}
}
var actuallyGot = ''
, expectedThrown = name !== null
? name
: desiredError
? '#{exp}' //_.inspect(desiredError)
: 'an error';
var actuallyGot = '';
var expectedThrown = 'an error';
if (name !== null) {
expectedThrown = name;
} else if (desiredError) {
expectedThrown = '#{exp}'; //_.inspect(desiredError)
}
if (thrown) {
actuallyGot = ' but #{act} was thrown'

Просмотреть файл

@ -415,7 +415,13 @@ var JsDiff = (function() {
var ret = [], change;
for ( var i = 0; i < changes.length; i++) {
change = changes[i];
ret.push([(change.added ? 1 : change.removed ? -1 : 0), change.value]);
var order = 0;
if (change.added) {
order = 1;
} else if (change.removed) {
order = -1;
}
ret.push([order, change.value]);
}
return ret;
}
@ -2097,12 +2103,13 @@ var color = exports.color = function(type, str) {
*/
exports.window = {
width: isatty
? process.stdout.getWindowSize
? process.stdout.getWindowSize(1)[0]
: tty.getWindowSize()[1]
: 75
width: 75
};
if (isatty) {
exports.window.width = process.stdout.getWindowSize
? process.stdout.getWindowSize(1)[0]
: tty.getWindowSize()[1];
}
/**
* Expose some basic cursor interactions
@ -2240,11 +2247,13 @@ function Base(runner) {
stats.passes = stats.passes || 0;
var medium = test.slow() / 2;
test.speed = test.duration > test.slow()
? 'slow'
: test.duration > medium
? 'medium'
: 'fast';
if (test.duration > test.slow()) {
test.speed = 'slow';
} else if (test.duration > medium) {
test.speed = 'medium';
} else {
test.speed = 'fast';
}
stats.passes++;
});

Просмотреть файл

@ -581,11 +581,11 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
var wrapper = undefined;
for (var c = element.firstChild; c; c = c.nextSibling) {
var type = c.nodeType;
wrapper = (type === 1) // Element Node
? (wrapper ? element : c)
: (type === 3) // Text Node
? (notWs.test(c.nodeValue) ? element : wrapper)
: wrapper;
if (type === 1) {
wrapper = wrapper ? element : c;
} else if (type === 3) {
wrapper = notWs.test(c.nodeValue) ? element : wrapper;
}
}
return wrapper === element ? undefined : wrapper;
}
@ -1411,9 +1411,11 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
// Look for a class like linenums or linenums:<n> where <n> is the
// 1-indexed number of the first line.
var lineNums = cs.className.match(/\blinenums\b(?::(\d+))?/);
lineNums = lineNums
? lineNums[1] && lineNums[1].length ? +lineNums[1] : true
: false;
if (lineNums) {
lineNums = lineNums[1] && lineNums[1].length ? +lineNums[1] : true;
} else {
lineNums = false;
}
if (lineNums) { numberLines(cs, lineNums); }
// do the pretty printing

Просмотреть файл

@ -256,8 +256,11 @@ BookmarkImporter.prototype = {
} else {
// Ensure tag folder gets processed last
nodes[0].children.sort(function sortRoots(aNode, bNode) {
return (aNode.root && aNode.root == "tagsFolder") ? 1 :
(bNode.root && bNode.root == "tagsFolder") ? -1 : 0;
if (aNode.root && aNode.root == "tagsFolder")
return 1;
if (bNode.root && bNode.root == "tagsFolder")
return -1;
return 0;
});
let batch = {

Просмотреть файл

@ -977,8 +977,9 @@ function reorderChildren(parent, orderedChildrenGuids) {
let i = orderedChildrenGuids.indexOf(a.guid);
let j = orderedChildrenGuids.indexOf(b.guid);
// This works provided fetchBookmarksByParent returns sorted children.
return (i == -1 && j == -1) ? 0 :
(i != -1 && j != -1 && i < j) || (i != -1 && j == -1) ? -1 : 1;
if (i == -1 && j == -1)
return 0;
return (i != -1 && j != -1 && i < j) || (i != -1 && j == -1) ? -1 : 1;
});
// Update the bookmarks position now. If any unknown guid have been

Просмотреть файл

@ -173,7 +173,7 @@ this.PlacesBackups = {
this._entries.sort((a, b) => {
let aDate = this.getDateForFile(a);
let bDate = this.getDateForFile(b);
return aDate < bDate ? 1 : aDate > bDate ? -1 : 0;
return bDate - aDate;
});
return this._entries;
},
@ -215,7 +215,7 @@ this.PlacesBackups = {
this._backupFiles.sort((a, b) => {
let aDate = this.getDateForFile(a);
let bDate = this.getDateForFile(b);
return aDate < bDate ? 1 : aDate > bDate ? -1 : 0;
return bDate - aDate;
});
return this._backupFiles;

Просмотреть файл

@ -1751,16 +1751,21 @@ Search.prototype = {
let typed = Prefs.autofillTyped || this.hasBehavior("typed");
let bookmarked = this.hasBehavior("bookmark") && !this.hasBehavior("history");
return [
bookmarked ? typed ? SQL_BOOKMARKED_TYPED_HOST_QUERY
: SQL_BOOKMARKED_HOST_QUERY
: typed ? SQL_TYPED_HOST_QUERY
: SQL_HOST_QUERY,
{
query_type: QUERYTYPE_AUTOFILL_HOST,
searchString: this._searchString.toLowerCase()
}
];
let query = [];
if (bookmarked) {
query.push(typed ? SQL_BOOKMARKED_TYPED_HOST_QUERY
: SQL_BOOKMARKED_HOST_QUERY);
} else {
query.push(typed ? SQL_TYPED_HOST_QUERY
: SQL_HOST_QUERY);
}
query.push({
query_type: QUERYTYPE_AUTOFILL_HOST,
searchString: this._searchString.toLowerCase()
});
return query;
},
/**
@ -1780,17 +1785,22 @@ Search.prototype = {
let typed = Prefs.autofillTyped || this.hasBehavior("typed");
let bookmarked = this.hasBehavior("bookmark") && !this.hasBehavior("history");
return [
bookmarked ? typed ? SQL_BOOKMARKED_TYPED_URL_QUERY
: SQL_BOOKMARKED_URL_QUERY
: typed ? SQL_TYPED_URL_QUERY
: SQL_URL_QUERY,
{
query_type: QUERYTYPE_AUTOFILL_URL,
searchString: this._autofillUrlSearchString,
revHost
}
];
let query = [];
if (bookmarked) {
query.push(typed ? SQL_BOOKMARKED_TYPED_URL_QUERY
: SQL_BOOKMARKED_URL_QUERY);
} else {
query.push(typed ? SQL_TYPED_URL_QUERY
: SQL_URL_QUERY);
}
query.push({
query_type: QUERYTYPE_AUTOFILL_URL,
searchString: this._autofillUrlSearchString,
revHost
});
return query;
},
/**

Просмотреть файл

@ -534,9 +534,12 @@ function check_JSON_backup(aIsAutomaticBackup) {
*/
function frecencyForUrl(aURI)
{
let url = aURI instanceof Ci.nsIURI ? aURI.spec
: aURI instanceof URL ? aURI.href
: aURI;
let url = aURI;
if (aURI instanceof Ci.nsIURI) {
url = aURI.spec;
} else if (aURI instanceof URL) {
url = aURI.href;
}
let stmt = DBConn().createStatement(
"SELECT frecency FROM moz_places WHERE url = ?1"
);

Просмотреть файл

@ -72,8 +72,12 @@ var Readability = function(uri, doc, options) {
return rv + '("' + e.textContent + '")';
}
var classDesc = e.className && ("." + e.className.replace(/ /g, "."));
var elDesc = e.id ? "(#" + e.id + classDesc + ")" :
(classDesc ? "(" + classDesc + ")" : "");
var elDesc = "";
if (e.id) {
elDesc = "(#" + e.id + classDesc + ")";
} else if (classDesc) {
elDesc = "(" + classDesc + ")";
}
return rv + elDesc;
}
this.log = function () {
@ -743,7 +747,7 @@ Readability.prototype = {
// - parent: 1 (no division)
// - grandparent: 2
// - great grandparent+: ancestor level * 3
var scoreDivider = level === 0 ? 1 : level === 1 ? 2 : level * 3;
var scoreDivider = level < 2 ? level + 1 : level * 3;
ancestor.readability.contentScore += contentScore / scoreDivider;
});
});

Просмотреть файл

@ -481,8 +481,14 @@ function logTestInfo(aText, aCaller) {
let ms = now.getMilliseconds();
let time = (hh < 10 ? "0" + hh : hh) + ":" +
(mm < 10 ? "0" + mm : mm) + ":" +
(ss < 10 ? "0" + ss : ss) + ":" +
(ms < 10 ? "00" + ms : ms < 100 ? "0" + ms : ms);
(ss < 10 ? "0" + ss : ss) + ":";
if (ms < 10) {
time += "00";
}
else if (ms < 100) {
time += "0";
}
time += ms;
let msg = time + " | TEST-INFO | " + caller.filename + " | [" + caller.name +
" : " + caller.lineNumber + "] " + aText;
do_print(msg);

Просмотреть файл

@ -1241,7 +1241,10 @@ var Histogram = {
// - If it's 1 -> manually correct it to 0 (the 0..1 anomaly)
// - For the rest, set the label as the bottom value instead of the upper.
// --> so we'll end with the following (non dummy) labels: 0, 2, 4, 8, 16, ...
return !aIsBHR ? k : k == 1 ? 0 : (k + 1) / 2;
if (!aIsBHR) {
return k;
}
return k == 1 ? 0 : (k + 1) / 2;
}
const labelledValues = Object.keys(aHgram.values)

Просмотреть файл

@ -393,7 +393,11 @@ function testtag_tree_TreeSelection_UI(tree, testid, multiple)
// do this three times, one for each state of pageUpOrDownMovesSelection,
// and then once with the accel key pressed
for (let t = 0; t < 3; t++) {
let testidmod = (t == 2) ? " with accel" : (t == 1) ? " rev" : "";
let testidmod = "";
if (t == 2)
testidmod = " with accel"
else if (t == 1)
testidmod = " rev";
var keymod = (t == 2) ? { accelKey: true } : { };
var moveselection = tree.pageUpOrDownMovesSelection;
@ -1164,10 +1168,20 @@ function testtag_tree_wheel(aTree)
function helper(aStart, aDelta, aIntDelta, aDeltaMode)
{
aTree.treeBoxObject.scrollToRow(aStart);
var expected = !aIntDelta ? aStart :
aDeltaMode != WheelEvent.DOM_DELTA_PAGE ? aStart + aIntDelta :
aIntDelta > 0 ? aStart + aTree.treeBoxObject.getPageLength() :
aStart - aTree.treeBoxObject.getPageLength();
var expected;
if (!aIntDelta) {
expected = aStart;
}
else if (aDeltaMode != WheelEvent.DOM_DELTA_PAGE) {
expected = aStart + aIntDelta;
}
else if (aIntDelta > 0) {
expected = aStart + aTree.treeBoxObject.getPageLength();
}
else {
expected = aStart - aTree.treeBoxObject.getPageLength();
}
if (expected < 0) {
expected = 0;
}

Просмотреть файл

@ -63,8 +63,11 @@
var state = this.getAttribute("checkState");
if (state == "")
return this.checked ? 1 : 0;
else
return state == "0" ? 0 : (state == "2" ? 2 : 1);
if (state == "0")
return 0;
if (state == "2")
return 2;
return 1;
]]></getter>
<setter><![CDATA[
this.setAttribute("checkState", val);

Просмотреть файл

@ -778,24 +778,29 @@
var yi = 2, mi = 4, di = 6;
function fieldForNumber(i) {
if (i == 2)
return "input-one";
if (i == 4)
return "input-two";
return "input-three";
}
for (var i = 1; i < numberFields.length; i++) {
switch (Number(numberFields[i])) {
case 2:
twoDigitYear = true; // fall through
case 2002:
yi = i;
yfield = (i == 2 ? "input-one" :
(i == 4 ? "input-two" : "input-three"));
yfield = fieldForNumber(i);
break;
case 9, 10:
mi = i;
mfield = (i == 2 ? "input-one" :
(i == 4 ? "input-two" : "input-three"));
mfield = fieldForNumber(i);
break;
case 4:
di = i;
dfield = (i == 2 ? "input-one" :
(i == 4 ? "input-two" : "input-three"));
dfield = fieldForNumber(i);
break;
}
}

Просмотреть файл

@ -465,10 +465,18 @@
// set fading
var fade = this.getAttribute("fade");
var fadeDelay = (fade == "fast") ? 1 : fade == "slow" ? 4000 : 0;
if (fadeDelay) {
this._fadeTimer = setTimeout(() => this.hidePopup(true), fadeDelay, this);
var fadeDelay = 0;
if (fade == "fast") {
fadeDelay = 1;
}
else if (fade == "slow") {
fadeDelay = 4000;
}
else {
return;
}
this._fadeTimer = setTimeout(() => this.hidePopup(true), fadeDelay, this);
]]>
</handler>
<handler event="popuphiding" phase="target">

Просмотреть файл

@ -443,7 +443,9 @@
Components.utils.reportError(e);
}
}
var val = rv !== undefined ? rv : (this.instantApply ? this.valueFromPreferences : this.value);
var val = rv;
if (val === undefined)
val = this.instantApply ? this.valueFromPreferences : this.value;
// if the preference is marked for reset, show default value in UI
if (val === undefined)
val = this.defaultValue;

Просмотреть файл

@ -1237,7 +1237,10 @@
<property name="ordinal">
<getter><![CDATA[
var val = this.getAttribute("ordinal");
return "" + (val == "" ? 1 : (val == "0" ? 0 : parseInt(val)));
if (val == "")
return "1";
return "" + (val == "0" ? 0 : parseInt(val));
]]></getter>
<setter><![CDATA[
this.setAttribute("ordinal", val);

Просмотреть файл

@ -262,10 +262,18 @@ Rect.prototype = {
/** Ensure this rectangle is inside the other, if possible. Preserves w, h. */
translateInside: function translateInside(other) {
let offsetX = (this.left <= other.left ? other.left - this.left :
(this.right > other.right ? other.right - this.right : 0));
let offsetY = (this.top <= other.top ? other.top - this.top :
(this.bottom > other.bottom ? other.bottom - this.bottom : 0));
let offsetX = 0;
if (this.left <= other.left)
offsetX = other.left - this.left;
else if (this.right > other.right)
offsetX = other.right - this.right;
let offsetY = 0;
if (this.top <= other.top)
offsetY = other.top - this.top;
else if (this.bottom > other.bottom)
offsetY = other.bottom - this.bottom;
return this.translate(offsetX, offsetY);
},

Просмотреть файл

@ -80,9 +80,11 @@ this.XPathGenerator = {
* @returns a properly quoted string to insert into an XPath query
*/
quoteArgument: function sss_xph_quoteArgument(aArg) {
return !/'/.test(aArg) ? "'" + aArg + "'" :
!/"/.test(aArg) ? '"' + aArg + '"' :
"concat('" + aArg.replace(/'+/g, "',\"$&\",'") + "')";
if (!/'/.test(aArg))
return "'" + aArg + "'";
if (!/"/.test(aArg))
return '"' + aArg + '"';
return "concat('" + aArg.replace(/'+/g, "',\"$&\",'") + "')";
},
/**

Просмотреть файл

@ -320,9 +320,13 @@ function parseRDFManifest(aId, aUpdateKey, aRequest, aManifestData) {
let extensionRes = gRDF.GetResource(PREFIX_EXTENSION + aId);
let themeRes = gRDF.GetResource(PREFIX_THEME + aId);
let itemRes = gRDF.GetResource(PREFIX_ITEM + aId);
let addonRes = ds.ArcLabelsOut(extensionRes).hasMoreElements() ? extensionRes
: ds.ArcLabelsOut(themeRes).hasMoreElements() ? themeRes
: itemRes;
let addonRes;
if (ds.ArcLabelsOut(extensionRes).hasMoreElements())
addonRes = extensionRes;
else if (ds.ArcLabelsOut(themeRes).hasMoreElements())
addonRes = themeRes;
else
addonRes = itemRes;
// If we have an update key then the update manifest must be signed
if (aUpdateKey) {

Просмотреть файл

@ -609,8 +609,13 @@ function logTestInfo(aText, aCaller) {
let ms = now.getMilliseconds();
let time = (hh < 10 ? "0" + hh : hh) + ":" +
(mm < 10 ? "0" + mm : mm) + ":" +
(ss < 10 ? "0" + ss : ss) + ":" +
(ms < 10 ? "00" + ms : ms < 100 ? "0" + ms : ms);
(ss < 10 ? "0" + ss : ss) + ":";
if (ms < 10) {
time += "00";
} else if (ms < 100) {
time += "0";
}
time += ms;
let msg = time + " | TEST-INFO | " + caller.filename + " | [" + caller.name +
" : " + caller.lineNumber + "] " + aText;
LOG_FUNCTION(msg);