Skip to content

Commit

Permalink
Bug 1489980 - Enable ESLint for editor/ - Manual fixes. r=masayuki
Browse files Browse the repository at this point in the history
This enables the editor directory to be linted, and fixes the remaining issues raised by ESLint. Various rules were fixed here including, no-shadow, no-undef, no-unused-vars and others.

I've generally gone conservative, disabling rules where it doesn't make sense to fix them (e.g. sometimes suggests use-services for tests, but it is only used once, or within a Chrome script).

Depends on D5585

Differential Revision: https://phabricator.services.mozilla.com/D5587
  • Loading branch information
Standard8 committed Sep 13, 2018
1 parent a8c93f0 commit 475e2a9
Show file tree
Hide file tree
Showing 76 changed files with 249 additions and 238 deletions.
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
**/crashtests/**
# Also ignore reftest - specially crafted to produce expected output.
**/reftest/**
**/reftests/**

# Exclude expected objdirs.
obj*/**
Expand All @@ -14,7 +15,6 @@ obj*/**
# If you are enabling a directory, please add directory specific exclusions
# below.
docshell/**
editor/**
extensions/cookie/**
extensions/spellcheck/**
extensions/universalchardet/**
Expand Down Expand Up @@ -258,6 +258,9 @@ dom/xul/**
# Third-party
dom/media/webvtt/**

# Third-party
editor/libeditor/tests/browserscope/**

# Third-party
gfx/ots/**
gfx/skia/**
Expand Down
1 change: 1 addition & 0 deletions editor/AsyncSpellCheckTestHelper.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function onSpellCheck(editableElement, callback) {
waitingForEnded = !waitingForEnded;
}

// eslint-disable-next-line mozilla/use-services
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.addObserver(observe, SPELL_CHECK_STARTED_TOPIC);
Expand Down
8 changes: 6 additions & 2 deletions editor/composer/test/test_bug519928.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
-->
<head>
<title>Test for Bug 519928</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=519928">Mozilla Bug 519928</a>
<p id="display"></p>
<div id="content">
<iframe id="load-frame"></iframe>
<iframe id="load-frame"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
Expand All @@ -38,11 +38,13 @@
is(self_.ICanRunMyJS, allowed, msg);
callback();
}, {once: true});
// eslint-disable-next-line no-useless-concat
var iframeSrc = "<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
innerFrame.srcdoc = iframeSrc;
}

SimpleTest.waitForExplicitFinish();
/* eslint-disable max-nested-callbacks */
addLoadEvent(function() {
var enterDesignMode = function() { document.designMode = "on"; };
var leaveDesignMode = function() { document.designMode = "off"; };
Expand Down Expand Up @@ -82,6 +84,7 @@
});
});
});
/* eslint-enable max-nested-callbacks */

function testDocumentDisabledJS() {
window.ICanRunMyJS = false;
Expand All @@ -105,6 +108,7 @@
is(self_.ICanRunMyJS, false, msg);
SimpleTest.finish();
}, {once: true});
// eslint-disable-next-line no-useless-concat
var iframeSrc = "<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
innerFrame.srcdoc = iframeSrc;
}
Expand Down
10 changes: 9 additions & 1 deletion editor/libeditor/tests/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ module.exports = {
"extends": [
"plugin:mozilla/browser-test",
"plugin:mozilla/mochitest-test",
]
],

"plugins": [
"no-unsanitized",
],

"rules": {
"no-unsanitized/property": "off",
},
};
16 changes: 8 additions & 8 deletions editor/libeditor/tests/browser_bug629172.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ add_task(async function() {
await BrowserTestUtils.withNewTab({
gBrowser,
url: kPageURL,
}, async function(aBrowser) {
await ContentTask.spawn(aBrowser, {}, async function() {
}, async function(browser) {
await ContentTask.spawn(browser, {}, async function() {
var window = content.window.wrappedJSObject;
var document = window.document;

Expand Down Expand Up @@ -50,8 +50,8 @@ add_task(async function() {
return Promise.resolve();
}

async function testDirection(initialDir, aBrowser) {
await ContentTask.spawn(aBrowser, {initialDir}, function({initialDir}) {
async function testDirection(initDir, aBrowser) {
await ContentTask.spawn(aBrowser, {initialDir: initDir}, function({initialDir}) {
var window = content.window.wrappedJSObject;
var document = window.document;

Expand All @@ -74,7 +74,7 @@ add_task(async function() {
is(window.inputEventCount, 0, "input event count must be 0 before");
});
await simulateCtrlShiftX(aBrowser);
await ContentTask.spawn(aBrowser, {initialDir}, function({initialDir}) {
await ContentTask.spawn(aBrowser, {initialDir: initDir}, function({initialDir}) {
var window = content.window.wrappedJSObject;
var expectedDir = initialDir == "ltr" ? "rtl" : "ltr";
is(window.t.getAttribute("dir"), expectedDir,
Expand All @@ -93,7 +93,7 @@ add_task(async function() {
is(window.inputEventCount, 1, "input event count must be 1 before");
});
await simulateCtrlShiftX(aBrowser);
await ContentTask.spawn(aBrowser, {initialDir}, function({initialDir}) {
await ContentTask.spawn(aBrowser, {initialDir: initDir}, function({initialDir}) {
var window = content.window.wrappedJSObject;

is(window.inputEventCount, 2, "input event count must be 2 after");
Expand All @@ -111,7 +111,7 @@ add_task(async function() {
});
}

await testDirection("ltr", aBrowser);
await testDirection("rtl", aBrowser);
await testDirection("ltr", browser);
await testDirection("rtl", browser);
});
});
2 changes: 1 addition & 1 deletion editor/libeditor/tests/file_select_all_without_body.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
root.appendChild(document.createTextNode("Mozilla"));
root.focus();
cespan = document.createElementNS("http://www.w3.org/1999/xhtml", "span");
let cespan = document.createElementNS("http://www.w3.org/1999/xhtml", "span");
cespan.setAttributeNS(null, "contenteditable", "true");
root.appendChild(cespan);
try {
Expand Down
9 changes: 4 additions & 5 deletions editor/libeditor/tests/test_CF_HTML_clipboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@
.QueryInterface(Ci.nsILoadContext);
}

var cb = Cc["@mozilla.org/widget/clipboard;1"].
getService(Ci.nsIClipboard);
var cb = SpecialPowers.Services.clipboard;

var counter = 0;
function copyCF_HTML_worker(success, failure) {
function copyCF_HTML_worker(successFn, failureFn) {
if (++counter > 50) {
ok(false, "Timed out while polling clipboard for pasted data");
failure();
Expand All @@ -45,7 +44,7 @@

var flavors = [CF_HTML];
if (!cb.hasDataMatchingFlavors(flavors, flavors.length, cb.kGlobalClipboard)) {
setTimeout(function() { copyCF_HTML_worker(success, failure); }, 100);
setTimeout(function() { copyCF_HTML_worker(successFn, failureFn); }, 100);
return;
}

Expand All @@ -59,7 +58,7 @@
trans.getTransferData(CF_HTML, data, {});
data = SpecialPowers.wrap(data).value.QueryInterface(Ci.nsISupportsCString).data;
} catch (e) {
setTimeout(function() { copyCF_HTML_worker(success, failure); }, 100);
setTimeout(function() { copyCF_HTML_worker(successFn, failureFn); }, 100);
return;
}
success();
Expand Down
4 changes: 2 additions & 2 deletions editor/libeditor/tests/test_backspace_vs.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
edit.focus();
var sel = window.getSelection();
sel.collapse(edit.childNodes[0], edit.textContent.length - 1);
for (i = 0; i < bsCount; ++i) {
for (let i = 0; i < bsCount; ++i) {
synthesizeKey("KEY_Backspace");
}
is(edit.textContent, "ab", "The backspace key should delete the characters correctly");
Expand Down Expand Up @@ -92,7 +92,7 @@
* Once the Firefox Emoji font is ready, we can load that via @font-face
* and expect these tests to work across all platforms.
*/
hasEmojiFont =
let hasEmojiFont =
(navigator.platform.indexOf("Mac") == 0 &&
/10\.([7-9]|[1-9][0-9])/.test(navigator.oscpu));

Expand Down
8 changes: 4 additions & 4 deletions editor/libeditor/tests/test_bug1053048.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
var selectionListener = {
count: 0,
notifySelectionChanged(aDocument, aSelection, aReason) {
ok(true, "selectionStart: " + textarea.selectionStart);
ok(true, "selectionEnd: " + textarea.selectionEnd);
this.count++;
},
ok(true, "selectionStart: " + textarea.selectionStart);
ok(true, "selectionEnd: " + textarea.selectionEnd);
this.count++;
},
};

// Move caret to the end of the textarea
Expand Down
9 changes: 4 additions & 5 deletions editor/libeditor/tests/test_bug1100966.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

getSpellChecker().UpdateCurrentDictionary(() => {
sendString(" ");
setTimeout(function() {
SimpleTest.executeSoon(function() {
sendString("a");
setTimeout(function() {
SimpleTest.executeSoon(function() {
synthesizeKey("KEY_Backspace");

onSpellCheck(div, function() {
Expand All @@ -47,13 +47,12 @@

SimpleTest.finish();
});
}, 0);
}, 0);
});
});
});
});

function getEditor() {
var Ci = SpecialPowers.Ci;
var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
return editingSession.getEditorForWindow(window);
}
Expand Down
2 changes: 1 addition & 1 deletion editor/libeditor/tests/test_bug1102906.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SimpleTest.waitForFocus( () => {
let content = document.getElementById("content");
let drag = document.getElementById("drag");
let selection = window.getSelection();
let selection = window.getSelection();

/* Perform drag-and-drop for an arbitrary content. The caret should be at
the end of the contenteditable. */
Expand Down
9 changes: 4 additions & 5 deletions editor/libeditor/tests/test_bug1154791.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
synthesizeKey("KEY_ArrowLeft");
synthesizeKey("KEY_ArrowLeft");

setTimeout(function() {
SimpleTest.executeSoon(function() {
synthesizeKey("KEY_Backspace");
setTimeout(function() {
SimpleTest.executeSoon(function() {
sendString(" ");

onSpellCheck(div, function() {
Expand All @@ -47,13 +47,12 @@

SimpleTest.finish();
});
}, 0);
}, 0);
});
});
});
});

function getEditor() {
var Ci = SpecialPowers.Ci;
var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
return editingSession.getEditorForWindow(window);
}
Expand Down
12 changes: 6 additions & 6 deletions editor/libeditor/tests/test_bug1230473.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
}
function isComposing() {
return isNSEditableElement() ? SpecialPowers.wrap(aEditor)
.editor
.composing :
SpecialPowers.wrap(window)
.docShell
.editor
.composing;
.editor
.composing :
SpecialPowers.wrap(window)
.docShell
.editor
.composing;
}
function clear() {
if (isNSEditableElement()) {
Expand Down
8 changes: 4 additions & 4 deletions editor/libeditor/tests/test_bug1257363.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
div.focus();
synthesizeMouse(div, 100, 2, {}); /* click behind and down */

var sel = window.getSelection();
var selRange = sel.getRangeAt(0);
sel = window.getSelection();
selRange = sel.getRangeAt(0);
is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node");
is(selRange.endOffset, 1, "offset should be 1");

Expand Down Expand Up @@ -136,8 +136,8 @@
div.focus();
synthesizeMouse(div, 100, 2, {}); /* click behind and down */

var sel = window.getSelection();
var selRange = sel.getRangeAt(0);
sel = window.getSelection();
selRange = sel.getRangeAt(0);
is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node");
is(selRange.endOffset, 1, "offset should be 1");

Expand Down
2 changes: 1 addition & 1 deletion editor/libeditor/tests/test_bug1258085.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
synthesizeKey("KEY_ArrowRight");
synthesizeKey("KEY_ArrowRight");
synthesizeKey("KEY_Backspace");
if (div.innerHTML, "x<br> ", "pre-wrap: Don't delete uncollapsed space");
is(div.innerHTML, "x<br> ", "pre-wrap: Don't delete uncollapsed space");
ok(getSelection().isCollapsed, "pre-wrap: Selection must be collapsed");
is(getSelection().focusNode, div.lastChild,
"pre-wrap: Focus must be in final text node");
Expand Down
2 changes: 1 addition & 1 deletion editor/libeditor/tests/test_bug1270235.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
element.focus();
let textNode = element.firstChild.firstChild;
let node = textNode.splitText(0);
node.parentNode.removeChild(node);
node.remove();

ok(!node.parentNode, "parent must be null");

Expand Down
4 changes: 4 additions & 0 deletions editor/libeditor/tests/test_bug1306532.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<script class="testbody" type="application/javascript">

function runTest() {
const headingone = document.getElementById("headingone");
const celltwo = document.getElementById("celltwo");
const pasteframe = document.getElementById("pasteframe");

// Copy content from table.
var selection = getSelection();
var startRange = document.createRange();
Expand Down
6 changes: 3 additions & 3 deletions editor/libeditor/tests/test_bug1315065.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
}
}

for (var i = 0; i < 4; i++) {
for (let i = 0; i < 4; i++) {
const kDescription = i == 0 ? "Backspace from immediately after the last character" :
"Backspace from " + i + "th empty text node";
editor.focus();
initForBackspace(i);
synthesizeKey("KEY_Backspace");
var p = document.getElementById("p");
let p = document.getElementById("p");
ok(p, kDescription + ": <p> element shouldn't be removed by Backspace key press");
is(p.tagName.toLowerCase(), "p", kDescription + ": <p> element shouldn't be removed by Backspace key press");
// When Backspace key is pressed even in empty text nodes, Gecko should not remove empty text nodes for now
Expand Down Expand Up @@ -112,7 +112,7 @@
}
}

for (var i = 0; i < 4; i++) {
for (let i = 0; i < 4; i++) {
const kDescription = i == 0 ? "Delete from immediately before the first character" :
"Delete from " + i + "th empty text node";
editor.focus();
Expand Down
1 change: 1 addition & 0 deletions editor/libeditor/tests/test_bug1318312.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<script class="testbody" type="text/javascript">

var outerEditor = document.getElementById("outerEditor");
var innerEditor = document.getElementById("innerEditor");

function runTests() {
outerEditor.focus();
Expand Down
2 changes: 1 addition & 1 deletion editor/libeditor/tests/test_bug1330796.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
var theEdit = document.getElementById("editable");
makeMailEditor();

for (i = 0; i < tests.length; i++) {
for (let i = 0; i < tests.length; i++) {
theEdit.innerHTML = tests[i][0];
theEdit.focus();
var theText = theEdit.firstChild.firstChild;
Expand Down
Loading

0 comments on commit 475e2a9

Please sign in to comment.