Bug 1311349 - Enable eslint of browser/components/translation/; r?flo
MozReview-Commit-ID: 4hIAnfs3qL0
--- a/.eslintignore
+++ b/.eslintignore
@@ -63,17 +63,16 @@ browser/base/content/sanitizeDialog.js
browser/base/content/test/general/file_csp_block_all_mixedcontent.html
browser/base/content/test/urlbar/file_blank_but_not_blank.html
browser/base/content/newtab/**
browser/components/downloads/**
browser/components/feeds/**
browser/components/privatebrowsing/**
browser/components/sessionstore/**
browser/components/tabview/**
-browser/components/translation/**
# generated files in cld2
browser/components/translation/cld2/cld-worker.js
browser/extensions/pdfjs/**
# generated or library files in pocket
browser/extensions/pocket/content/panels/js/tmpl.js
browser/extensions/pocket/content/panels/js/vendor/**
browser/locales/**
--- a/browser/components/translation/BingTranslator.jsm
+++ b/browser/components/translation/BingTranslator.jsm
@@ -281,17 +281,17 @@ function BingRequest(translationData, so
this.characterCount = 0;
}
BingRequest.prototype = {
/**
* Initiates the request
*/
fireRequest: function() {
- return Task.spawn(function *(){
+ return Task.spawn(function *() {
// Prepare authentication.
let token = yield BingTokenManager.getToken();
let auth = "Bearer " + token;
// Prepare URL.
let url = getUrlParam("https://api.microsofttranslator.com/v2/Http.svc/TranslateArray",
"browser.translation.bing.translateArrayURL");
--- a/browser/components/translation/TranslationDocument.jsm
+++ b/browser/components/translation/TranslationDocument.jsm
@@ -161,29 +161,27 @@ this.TranslationDocument.prototype = {
// it's a translation node: it has useful content for translation.
// In this case, we need to stringify this node.
// However, if this item is a root, we should skip it here in this
// object's child list (and just add a placeholder for it), because
// it will be stringfied separately for being a root.
item.original.push(objInMap);
str += this.generateTextForItem(objInMap);
wasLastItemPlaceholder = false;
- } else {
+ } else if (!wasLastItemPlaceholder) {
// Otherwise, if this node doesn't contain any useful content,
// or if it is a root itself, we can replace it with a placeholder node.
// We can't simply eliminate this node from our string representation
// because that could change the HTML structure (e.g., it would
// probably merge two separate text nodes).
// It's not necessary to add more than one placeholder in sequence;
// we can optimize them away.
- if (!wasLastItemPlaceholder) {
- item.original.push(TranslationItem_NodePlaceholder);
- str += '<br>';
- wasLastItemPlaceholder = true;
- }
+ item.original.push(TranslationItem_NodePlaceholder);
+ str += '<br>';
+ wasLastItemPlaceholder = true;
}
}
return generateTranslationHtmlForItem(item, str);
},
/**
* Changes the document to display its translated
@@ -272,19 +270,25 @@ function TranslationItem(node, id, isRoo
this.children = [];
}
TranslationItem.prototype = {
isRoot: false,
isSimpleRoot: false,
toString: function() {
- let rootType = this.isRoot
- ? (this.isSimpleRoot ? ' (simple root)' : ' (non simple root)')
- : '';
+ let rootType = "";
+ if (this.isRoot) {
+ if (this.isSimpleRoot) {
+ rootType = " (simple root)";
+ }
+ else {
+ rootType = " (non simple root)";
+ }
+ }
return "[object TranslationItem: <" + this.nodeRef.localName + ">"
+ rootType + "]";
},
/**
* This function will parse the result of the translation of one translation
* item. If this item was a simple root, all we sent was a plain-text version
* of it, so the result is also straightforward text.
--- a/browser/components/translation/YandexTranslator.jsm
+++ b/browser/components/translation/YandexTranslator.jsm
@@ -288,17 +288,17 @@ function YandexRequest(translationData,
this.characterCount = 0;
}
YandexRequest.prototype = {
/**
* Initiates the request
*/
fireRequest: function() {
- return Task.spawn(function *(){
+ return Task.spawn(function *() {
// Prepare URL.
let url = getUrlParam("https://translate.yandex.net/api/v1.5/tr.json/translate",
"browser.translation.yandex.translateURLOverride");
// Prepare the request body.
let apiKey = getUrlParam("%YANDEX_API_KEY%", "browser.translation.yandex.apiKeyOverride");
let params = [
["key", apiKey],
--- a/browser/components/translation/cld2/post.js
+++ b/browser/components/translation/cld2/post.js
@@ -120,17 +120,17 @@ var Encodings = {
// Accept forms both with and without underscores/hypens.
for (let code of Object.keys(Encodings)) {
if (code['includes']("_"))
Encodings[code.replace(/_/g, "")] = Encodings[code];
}
addOnPreMain(function() {
- onmessage = function(aMsg){
+ onmessage = function(aMsg) {
let data = aMsg['data'];
let langInfo;
if (data['tld'] == undefined && data['encoding'] == undefined && data['language'] == undefined) {
langInfo = LanguageInfo.detectLanguage(data['text'], !data['isHTML']);
} else {
// Do our best to find the given encoding in the encodings table.
// Otherwise, just fall back to unknown.
--- a/browser/components/translation/test/browser_translation_bing.js
+++ b/browser/components/translation/test/browser_translation_bing.js
@@ -98,17 +98,17 @@ add_task(function* test_handling_out_of_
});
/**
* A helper function for constructing a URL to a page stored in the
* local fixture folder.
*
* @param filename Name of a fixture file.
*/
-function constructFixtureURL(filename){
+function constructFixtureURL(filename) {
// Deduce the Mochitest server address in use from a pref that was pre-processed.
let server = Services.prefs.getCharPref("browser.translation.bing.authURL")
.replace("http://", "");
server = server.substr(0, server.indexOf("/"));
let url = "http://" + server +
"/browser/browser/components/translation/test/fixtures/" + filename;
return url;
}
--- a/browser/components/translation/test/browser_translation_telemetry.js
+++ b/browser/components/translation/test/browser_translation_telemetry.js
@@ -19,17 +19,17 @@ var MetricsChecker = {
AUTO_REJECTED : Services.telemetry.getHistogramById("AUTO_REJECTED_TRANSLATION_OFFERS"),
SHOW_ORIGINAL : Services.telemetry.getHistogramById("REQUESTS_OF_ORIGINAL_CONTENT"),
TARGET_CHANGES : Services.telemetry.getHistogramById("CHANGES_OF_TARGET_LANGUAGE"),
DETECTION_CHANGES : Services.telemetry.getHistogramById("CHANGES_OF_DETECTED_LANGUAGE"),
SHOW_UI : Services.telemetry.getHistogramById("SHOULD_TRANSLATION_UI_APPEAR"),
DETECT_LANG : Services.telemetry.getHistogramById("SHOULD_AUTO_DETECT_LANGUAGE"),
},
- reset: function(){
+ reset: function() {
for (let i of Object.keys(this.HISTOGRAMS)) {
this.HISTOGRAMS[i].clear();
}
this.updateMetrics();
},
updateMetrics: function () {
this._metrics = {
@@ -60,17 +60,17 @@ var MetricsChecker = {
this._metrics.pageCountByLang[key] = pages[key] ? pages[key].sum : 0;
}
}
},
/**
* A recurrent loop for making assertions about collected metrics.
*/
- _assertionLoop: function (prevMetrics, metrics, additions){
+ _assertionLoop: function (prevMetrics, metrics, additions) {
for (let metric of Object.keys(additions)) {
let addition = additions[metric];
// Allows nesting metrics. Useful for keyed histograms.
if (typeof addition === 'object') {
this._assertionLoop(prevMetrics[metric], metrics[metric], addition);
continue;
}
Assert.equal(prevMetrics[metric] + addition, metrics[metric]);
@@ -112,19 +112,19 @@ var acceptTranslationOffer = Task.async(
yield waitForMessage(browser, "Translation:Finished");
});
var translate = Task.async(function*(text, from, closeTab = true) {
let tab = yield offerTranslationFor(text, from);
yield acceptTranslationOffer(tab);
if (closeTab) {
gBrowser.removeTab(tab);
- } else {
- return tab;
+ return null;
}
+ return tab;
});
function waitForMessage({messageManager}, name) {
return new Promise(resolve => {
messageManager.addMessageListener(name, function onMessage() {
messageManager.removeMessageListener(name, onMessage);
resolve();
});
--- a/browser/components/translation/test/browser_translation_yandex.js
+++ b/browser/components/translation/test/browser_translation_yandex.js
@@ -86,17 +86,17 @@ add_task(function* test_preference_attri
});
/**
* A helper function for constructing a URL to a page stored in the
* local fixture folder.
*
* @param filename Name of a fixture file.
*/
-function constructFixtureURL(filename){
+function constructFixtureURL(filename) {
// Deduce the Mochitest server address in use from a pref that was pre-processed.
let server = Services.prefs.getCharPref("browser.translation.yandex.translateURLOverride")
.replace("http://", "");
server = server.substr(0, server.indexOf("/"));
let url = "http://" + server +
"/browser/browser/components/translation/test/fixtures/" + filename;
return url;
}