From e824d800fb547242e168c8f12be8c5fa5cfc120d Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Thu, 13 Sep 2018 07:59:47 +0000 Subject: [PATCH] Bug 1489980 - Enable ESLint for editor/ - Manual fixes. r=masayuki 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 --HG-- extra : moz-landing-system : lando --- .eslintignore | 5 +- editor/AsyncSpellCheckTestHelper.jsm | 1 + editor/composer/test/test_bug519928.html | 8 +- editor/libeditor/tests/.eslintrc.js | 10 ++- editor/libeditor/tests/browser_bug629172.js | 16 ++-- .../tests/file_select_all_without_body.html | 2 +- .../tests/test_CF_HTML_clipboard.html | 9 +- editor/libeditor/tests/test_backspace_vs.html | 4 +- editor/libeditor/tests/test_bug1053048.html | 8 +- editor/libeditor/tests/test_bug1100966.html | 9 +- editor/libeditor/tests/test_bug1102906.html | 2 +- editor/libeditor/tests/test_bug1154791.html | 9 +- editor/libeditor/tests/test_bug1230473.html | 12 +-- editor/libeditor/tests/test_bug1257363.html | 8 +- editor/libeditor/tests/test_bug1258085.html | 2 +- editor/libeditor/tests/test_bug1270235.html | 2 +- editor/libeditor/tests/test_bug1306532.html | 4 + editor/libeditor/tests/test_bug1315065.html | 6 +- editor/libeditor/tests/test_bug1318312.html | 1 + editor/libeditor/tests/test_bug1330796.html | 2 +- editor/libeditor/tests/test_bug1425997.html | 1 - editor/libeditor/tests/test_bug366682.html | 1 - editor/libeditor/tests/test_bug372345.html | 1 - editor/libeditor/tests/test_bug404320.html | 1 - editor/libeditor/tests/test_bug408231.html | 21 +++-- editor/libeditor/tests/test_bug410986.html | 6 +- editor/libeditor/tests/test_bug414526.html | 2 +- editor/libeditor/tests/test_bug432225.html | 5 +- editor/libeditor/tests/test_bug471319.html | 5 +- editor/libeditor/tests/test_bug478725.html | 1 - editor/libeditor/tests/test_bug480972.html | 1 - editor/libeditor/tests/test_bug484181.html | 5 +- editor/libeditor/tests/test_bug502673.html | 18 ++-- editor/libeditor/tests/test_bug520189.html | 8 +- editor/libeditor/tests/test_bug525389.html | 87 ++++++++++--------- editor/libeditor/tests/test_bug537046.html | 2 +- editor/libeditor/tests/test_bug551704.html | 5 +- editor/libeditor/tests/test_bug569988.html | 16 ++-- editor/libeditor/tests/test_bug596333.html | 9 +- editor/libeditor/tests/test_bug612128.html | 3 +- editor/libeditor/tests/test_bug636465.html | 5 +- editor/libeditor/tests/test_bug645914.html | 2 +- editor/libeditor/tests/test_bug674770-2.html | 3 +- editor/libeditor/tests/test_bug772796.html | 2 +- editor/libeditor/tests/test_bug790475.html | 1 - editor/libeditor/tests/test_bug795418-2.html | 1 - editor/libeditor/tests/test_bug795418-3.html | 1 - editor/libeditor/tests/test_bug795785.html | 3 +- editor/libeditor/tests/test_bug830600.html | 1 - editor/libeditor/tests/test_bug850043.html | 3 +- editor/libeditor/tests/test_bug966155.html | 6 +- editor/libeditor/tests/test_bug966552.html | 6 +- .../tests/test_contenteditable_focus.html | 23 ++--- ...t_contenteditable_text_input_handling.html | 13 ++- .../tests/test_documentCharacterSet.html | 1 - .../test_dom_input_event_on_htmleditor.html | 6 +- .../test_dom_input_event_on_texteditor.html | 6 +- editor/libeditor/tests/test_dragdrop.html | 2 + .../tests/test_execCommandPaste_noTarget.html | 6 +- .../test_htmleditor_keyevent_handling.html | 8 +- .../tests/test_inlineTableEditing.html | 3 +- .../tests/test_nsITableEditor_getCellAt.html | 4 +- .../test_nsITableEditor_getCellIndexes.html | 2 +- .../test_nsITableEditor_getFirstRow.html | 8 +- ...st_nsITableEditor_getNextSelectedCell.html | 2 +- .../test_nsITableEditor_getTableSize.html | 2 +- .../tests/test_selection_move_commands.html | 4 +- .../test_texteditor_keyevent_handling.html | 5 +- .../spellchecker/tests/test_bug1200533.html | 2 + .../spellchecker/tests/test_bug1204147.html | 4 +- .../spellchecker/tests/test_bug1205983.html | 9 +- .../spellchecker/tests/test_bug1209414.html | 8 +- .../spellchecker/tests/test_bug1219928.html | 5 +- editor/spellchecker/tests/test_bug678842.html | 6 +- editor/spellchecker/tests/test_bug697981.html | 4 + editor/spellchecker/tests/test_bug717433.html | 2 + 76 files changed, 249 insertions(+), 238 deletions(-) diff --git a/.eslintignore b/.eslintignore index d70943eafaff..fbacac2f0af2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,6 +6,7 @@ **/crashtests/** # Also ignore reftest - specially crafted to produce expected output. **/reftest/** +**/reftests/** # Exclude expected objdirs. obj*/** @@ -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/** @@ -258,6 +258,9 @@ dom/xul/** # Third-party dom/media/webvtt/** +# Third-party +editor/libeditor/tests/browserscope/** + # Third-party gfx/ots/** gfx/skia/** diff --git a/editor/AsyncSpellCheckTestHelper.jsm b/editor/AsyncSpellCheckTestHelper.jsm index 0afba15c11f6..09af73311c55 100644 --- a/editor/AsyncSpellCheckTestHelper.jsm +++ b/editor/AsyncSpellCheckTestHelper.jsm @@ -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); diff --git a/editor/composer/test/test_bug519928.html b/editor/composer/test/test_bug519928.html index df6a1c1b5fb4..86ebf61417c9 100644 --- a/editor/composer/test/test_bug519928.html +++ b/editor/composer/test/test_bug519928.html @@ -5,14 +5,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=519928 --> Test for Bug 519928 - + Mozilla Bug 519928

- +
 
   
-    
+  
   
 
 
 Mozilla Bug 432225
 

 
   
-    
+  
 
 
 
@@ -33,17 +33,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=502673
       listener.prototype =
       {
         NotifyDocumentWillBeDestroyed() {
-    var editor = SpecialPowers.wrap(this.input).editor;
-    editor.removeDocumentStateListener(this);
-  },
+          var editor = SpecialPowers.wrap(this.input).editor;
+          editor.removeDocumentStateListener(this);
+        },
 
         NotifyDocumentCreated() {
-  },
+        },
 
         NotifyDocumentStateChanged(aNowDirty) {
-    var editor = SpecialPowers.wrap(this.input).editor;
-    editor.removeDocumentStateListener(this);
-  },
+          var editor = SpecialPowers.wrap(this.input).editor;
+          editor.removeDocumentStateListener(this);
+        },
 
         QueryInterface: SpecialPowers.wrapCallback(function(iid) {
           if (iid.equals(SpecialPowers.Ci.nsIDocumentStateListener) ||
@@ -81,7 +81,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=502673
         editor.addDocumentStateListener(listener1);
         editor.addDocumentStateListener(listener2);
         editor.addDocumentStateListener(listener3);
-      
+
         // Test 2. Fire NotifyDocumentWillBeDestroyed notifications where the
         // listeners remove themselves (though in the real world, listeners
         // shouldn't do this as nsEditor::PreDestroy removes them as
diff --git a/editor/libeditor/tests/test_bug520189.html b/editor/libeditor/tests/test_bug520189.html
index 1ef942f215a2..cd38234c8f16 100644
--- a/editor/libeditor/tests/test_bug520189.html
+++ b/editor/libeditor/tests/test_bug520189.html
@@ -7,7 +7,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=520182
   Test for Bug 520182
   
   
-    
+  
 
 
 Mozilla Bug 520182
@@ -79,6 +79,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=520182
 
 
   
-    
+  
 
 
 Mozilla Bug 537046
diff --git a/editor/libeditor/tests/test_bug551704.html b/editor/libeditor/tests/test_bug551704.html
index a4f17e54e816..1608d86b6529 100644
--- a/editor/libeditor/tests/test_bug551704.html
+++ b/editor/libeditor/tests/test_bug551704.html
@@ -106,10 +106,11 @@ function continueTest() {
       return;
     }
     var div = divs[current++];
+    let type;
     if (div.textContent == "a") {
-      var type = typeBCDEF;
+      type = typeBCDEF;
     } else {
-      var type = typeABCDEF;
+      type = typeABCDEF;
     }
     var expectedHTML = "
abc
def
"; var expectedText = "abc\ndef"; diff --git a/editor/libeditor/tests/test_bug569988.html b/editor/libeditor/tests/test_bug569988.html index 03cd50994ab3..a9d7be842ade 100644 --- a/editor/libeditor/tests/test_bug569988.html +++ b/editor/libeditor/tests/test_bug569988.html @@ -13,7 +13,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=569988 Mozilla Bug 569988

 
diff --git a/editor/libeditor/tests/test_bug612128.html b/editor/libeditor/tests/test_bug612128.html
index dbd794ba25a0..b44b220bb3a3 100644
--- a/editor/libeditor/tests/test_bug612128.html
+++ b/editor/libeditor/tests/test_bug612128.html
@@ -19,11 +19,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=612128
 
 ">
 
 
 
 
@@ -66,14 +66,14 @@ function runTests() { ok(!aEvent.cancelable, "input event must not be cancelable"); ok(aEvent.bubbles, "input event must be bubbles"); if (SpecialPowers.getBoolPref("dom.event.highrestimestamp.enabled")) { - var duration = Math.abs(window.performance.now() - aEvent.timeStamp); + let duration = Math.abs(window.performance.now() - aEvent.timeStamp); ok(duration < 30 * 1000, "perhaps, timestamp wasn't set correctly :" + aEvent.timeStamp + " (expected it to be within 30s of the current time but it " + "differed by " + duration + "ms)"); } else { var eventTime = new Date(aEvent.timeStamp); - var duration = Math.abs(Date.now() - aEvent.timeStamp); + let duration = Math.abs(Date.now() - aEvent.timeStamp); ok(duration < 30 * 1000, "perhaps, timestamp wasn't set correctly :" + eventTime.toLocaleString() + diff --git a/editor/libeditor/tests/test_dom_input_event_on_texteditor.html b/editor/libeditor/tests/test_dom_input_event_on_texteditor.html index 667afbda3eb8..4035ab3f415d 100644 --- a/editor/libeditor/tests/test_dom_input_event_on_texteditor.html +++ b/editor/libeditor/tests/test_dom_input_event_on_texteditor.html @@ -14,7 +14,7 @@
 
@@ -40,14 +40,14 @@ function runTests() { ok(!aEvent.cancelable, "input event must not be cancelable"); ok(aEvent.bubbles, "input event must be bubbles"); if (SpecialPowers.getBoolPref("dom.event.highrestimestamp.enabled")) { - var duration = Math.abs(window.performance.now() - aEvent.timeStamp); + let duration = Math.abs(window.performance.now() - aEvent.timeStamp); ok(duration < 30 * 1000, "perhaps, timestamp wasn't set correctly :" + aEvent.timeStamp + " (expected it to be within 30s of the current time but it " + "differed by " + duration + "ms)"); } else { var eventTime = new Date(aEvent.timeStamp); - var duration = Math.abs(Date.now() - aEvent.timeStamp); + let duration = Math.abs(Date.now() - aEvent.timeStamp); ok(duration < 30 * 1000, "perhaps, timestamp wasn't set correctly :" + eventTime.toLocaleString() + diff --git a/editor/libeditor/tests/test_dragdrop.html b/editor/libeditor/tests/test_dragdrop.html index 8b23c2f0f8d3..8cdf5e59363b 100644 --- a/editor/libeditor/tests/test_dragdrop.html +++ b/editor/libeditor/tests/test_dragdrop.html @@ -34,6 +34,8 @@ function doTest() { data: '

' }; var text = document.getElementById("text"); + var textarea = document.getElementById("textarea"); + var bold = document.getElementById("bold"); var input = document.getElementById("input"); var contenteditable = document.getElementById("contenteditable"); diff --git a/editor/libeditor/tests/test_execCommandPaste_noTarget.html b/editor/libeditor/tests/test_execCommandPaste_noTarget.html index 1a8606b4dc2e..65c5aa061cb9 100644 --- a/editor/libeditor/tests/test_execCommandPaste_noTarget.html +++ b/editor/libeditor/tests/test_execCommandPaste_noTarget.html @@ -13,18 +13,16 @@ let seenPaste = false; let seenCopy = false; document.addEventListener("copy", function oncpy(e) { - document.removeEventListener("copy", oncpy); e.clipboardData.setData("text/plain", "my text"); e.preventDefault(); seenCopy = true; - }); + }, {once: true}); document.addEventListener("paste", function onpst(e) { - document.removeEventListener("paste", onpst); is(e.clipboardData.getData("text/plain"), "my text", "The correct text was read from the clipboard"); e.preventDefault(); seenPaste = true; - }); + }, {once: true}); ok(SpecialPowers.wrap(document).execCommand("copy"), "Call should succeed"); diff --git a/editor/libeditor/tests/test_htmleditor_keyevent_handling.html b/editor/libeditor/tests/test_htmleditor_keyevent_handling.html index f56c22210ef6..a23a0887da54 100644 --- a/editor/libeditor/tests/test_htmleditor_keyevent_handling.html +++ b/editor/libeditor/tests/test_htmleditor_keyevent_handling.html @@ -13,13 +13,15 @@