Bug 1593058 - Remove support for xbl in ESLint since xbl is almost removed now. r=mossop
authorMark Banner <standard8@mozilla.com>
Wed, 13 Nov 2019 15:53:55 +0000
changeset 501763 bb6776d41b9eae7155e49f0674c00c99ee8dbebf
parent 501762 27f06b7cc987734c9f55742f18351b5e40ea3aed
child 501764 97a383ec65b7791c289a1ae523cd7181d3ec6093
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1593058
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1593058 - Remove support for xbl in ESLint since xbl is almost removed now. r=mossop Differential Revision: https://phabricator.services.mozilla.com/D52852
tools/lint/eslint.yml
tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
tools/lint/eslint/eslint-plugin-mozilla/lib/processors/xbl-bindings.js
tools/lint/eslint/eslint-plugin-mozilla/lib/processors/xul.js
tools/lint/eslint/eslint-plugin-mozilla/package-lock.json
tools/lint/eslint/eslint-plugin-mozilla/package.json
--- a/tools/lint/eslint.yml
+++ b/tools/lint/eslint.yml
@@ -1,15 +1,15 @@
 ---
 eslint:
     description: JavaScript linter
     # ESLint infra handles its own path filtering, so just include cwd
     include: ['.']
     exclude: []
-    extensions: ['js', 'jsm', 'jsx', 'xml', 'xul', 'html', 'xhtml']
+    extensions: ['js', 'jsm', 'jsx', 'xul', 'html', 'xhtml']
     support-files:
         - '**/.eslintrc.js'
         - '.eslintignore'
         - 'tools/lint/eslint/**'
         # Files that can influence global variables
         - 'browser/base/content/nsContextMenu.js'
         - 'browser/base/content/utilityOverlay.js'
         - 'browser/components/customizableui/content/panelUI.js'
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
@@ -46,24 +46,16 @@ module.exports = {
     sizeToContent: false,
     // Specific to Firefox
     // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/uneval
     uneval: false,
   },
 
   overrides: [
     {
-      // Turn off use-services for xml files. XBL bindings are going away, and
-      // working out the valid globals for those is difficult.
-      files: "**/*.xml",
-      rules: {
-        "mozilla/use-services": "off",
-      },
-    },
-    {
       // We don't have the general browser environment for jsm files, but we do
       // have our own special environments for them.
       env: {
         browser: false,
         "mozilla/jsm": true,
       },
       files: ["**/*.jsm", "**/*.jsm.js"],
       rules: {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
@@ -23,17 +23,16 @@ module.exports = {
     "browser-window": require("../lib/environments/browser-window.js"),
     "chrome-worker": require("../lib/environments/chrome-worker.js"),
     "frame-script": require("../lib/environments/frame-script.js"),
     jsm: require("../lib/environments/jsm.js"),
     simpletest: require("../lib/environments/simpletest.js"),
     privileged: require("../lib/environments/privileged.js"),
   },
   processors: {
-    ".xml": require("../lib/processors/xbl-bindings"),
     ".xul": require("../lib/processors/xul"),
   },
   rules: {
     "avoid-Date-timing": require("../lib/rules/avoid-Date-timing"),
     "avoid-removeChild": require("../lib/rules/avoid-removeChild"),
     "balanced-listeners": require("../lib/rules/balanced-listeners"),
     "consistent-if-bracing": require("../lib/rules/consistent-if-bracing"),
     "import-browser-window-globals": require("../lib/rules/import-browser-window-globals"),
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/processors/xbl-bindings.js
+++ /dev/null
@@ -1,301 +0,0 @@
-/**
- * @fileoverview Converts functions and handlers from XBL bindings into JS
- * functions
- *
- * 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
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-"use strict";
-
-const NS_XBL = "http://www.mozilla.org/xbl";
-
-let XMLParser = require("./processor-helpers").XMLParser;
-
-// -----------------------------------------------------------------------------
-// Processor Definition
-// -----------------------------------------------------------------------------
-
-// Stores any XML parse error
-let xmlParseError = null;
-
-// Stores the lines of JS code generated from the XBL
-let scriptLines = [];
-// Stores a map from the synthetic line number to the real line number
-// and column offset.
-let lineMap = [];
-
-function addSyntheticLine(line, linePos, addDisableLine) {
-  lineMap[scriptLines.length] = { line: linePos, offset: null };
-  scriptLines.push(line + (addDisableLine ? "" : " // eslint-disable-line"));
-}
-
-/**
- * Adds generated lines from an XBL node to the script to be passed back to
- * eslint.
- */
-function addNodeLines(node, reindent) {
-  let lines = node.textContent.split("\n");
-  let startLine = node.textLine;
-  let startColumn = node.textColumn;
-
-  // The case where there are no whitespace lines before the first text is
-  // treated differently for indentation
-  let indentFirst = false;
-
-  // Strip off any preceding whitespace only lines. These are often used to
-  // format the XML and CDATA blocks.
-  while (lines.length && lines[0].trim() == "") {
-    indentFirst = true;
-    startLine++;
-    lines.shift();
-  }
-
-  // Remember the indent of the last blank line, which is the closing part of
-  // the CDATA block.
-  let lastIndent = 0;
-  if (lines.length && lines[lines.length - 1].trim() == "") {
-    lastIndent = lines[lines.length - 1].length;
-  }
-
-  // If the second to last line is also blank and has a higher indent than the
-  // last one, then the CDATA block doesn't close with the closing tag.
-  if (
-    lines.length > 2 &&
-    lines[lines.length - 2].trim() == "" &&
-    lines[lines.length - 2].length > lastIndent
-  ) {
-    lastIndent = lines[lines.length - 2].length;
-  }
-
-  // Strip off any whitespace lines at the end. These are often used to line
-  // up the closing tags
-  while (lines.length && lines[lines.length - 1].trim() == "") {
-    lines.pop();
-  }
-
-  if (!indentFirst) {
-    let firstLine = lines.shift();
-    // ESLint counts columns starting at 1 rather than 0
-    lineMap[scriptLines.length] = { line: startLine, offset: startColumn - 1 };
-    scriptLines.push(firstLine);
-    startLine++;
-  }
-
-  // Find the preceding whitespace for all lines that aren't entirely
-  // whitespace.
-  let indents = lines
-    .filter(s => s.trim().length > 0)
-    .map(s => s.length - s.trimLeft().length);
-  // Find the smallest indent level in use
-  let minIndent = Math.min.apply(null, indents);
-  let indent = Math.max(2, minIndent - lastIndent);
-
-  for (let line of lines) {
-    if (line.trim().length == 0) {
-      // Don't offset lines that are only whitespace, the only possible JS error
-      // is trailing whitespace and we want it to point at the right place
-      lineMap[scriptLines.length] = { line: startLine, offset: 0 };
-    } else {
-      line = " ".repeat(indent) + line.substring(minIndent);
-      lineMap[scriptLines.length] = {
-        line: startLine,
-        offset: 1 + indent - minIndent,
-      };
-    }
-
-    scriptLines.push(line);
-    startLine++;
-  }
-}
-
-module.exports = {
-  preprocess(text, filename) {
-    xmlParseError = null;
-    scriptLines = [];
-    lineMap = [];
-
-    let xp = new XMLParser(text);
-    if (xp.lastError) {
-      xmlParseError = xp.lastError;
-    }
-
-    // Sanity checks to make sure we're dealing with an XBL document
-    let document = xp.document;
-    if (document.children.length != 1) {
-      return [];
-    }
-
-    let bindings = document.children[0];
-    if (bindings.local != "bindings" || bindings.namespace != NS_XBL) {
-      return [];
-    }
-
-    for (let comment of document.comments) {
-      addSyntheticLine(`/*`, 0, true);
-      for (let line of comment.split("\n")) {
-        addSyntheticLine(`${line.trim()}`, 0, true);
-      }
-      addSyntheticLine(`*/`, 0, true);
-    }
-
-    addSyntheticLine(`this.bindings = {`, bindings.textLine);
-
-    for (let binding of bindings.children) {
-      if (binding.local != "binding" || binding.namespace != NS_XBL) {
-        continue;
-      }
-
-      addSyntheticLine(`"${binding.attributes.id}": {`, binding.textLine);
-
-      for (let part of binding.children) {
-        if (part.namespace != NS_XBL) {
-          continue;
-        }
-
-        if (part.local == "implementation") {
-          addSyntheticLine(`implementation: {`, part.textLine);
-        } else if (part.local == "handlers") {
-          addSyntheticLine(`handlers: [`, part.textLine);
-        } else {
-          continue;
-        }
-
-        for (let item of part.children) {
-          if (item.namespace != NS_XBL) {
-            continue;
-          }
-
-          switch (item.local) {
-            case "field": {
-              // Fields are something like lazy getter functions
-
-              // Ignore empty fields
-              if (item.textContent.trim().length == 0) {
-                continue;
-              }
-
-              addSyntheticLine(
-                `get ${item.attributes.name}() {`,
-                item.textLine
-              );
-              addSyntheticLine(`return (`, item.textLine);
-
-              // Remove trailing semicolons, as we are adding our own
-              item.textContent = item.textContent.replace(/;(?=\s*$)/, "");
-              addNodeLines(item, 5);
-
-              addSyntheticLine(`);`, item.textLine);
-              addSyntheticLine(`},`, item.textEndLine);
-              break;
-            }
-            case "constructor":
-            case "destructor": {
-              // Constructors and destructors become function declarations
-              addSyntheticLine(`${item.local}() {`, item.textLine);
-              addNodeLines(item, 4);
-              addSyntheticLine(`},`, item.textEndLine);
-              break;
-            }
-            case "method": {
-              // Methods become function declarations with the appropriate
-              // params.
-
-              let params = item.children
-                .filter(n => {
-                  return n.local == "parameter" && n.namespace == NS_XBL;
-                })
-                .map(n => n.attributes.name)
-                .join(", ");
-              let body = item.children.filter(n => {
-                return n.local == "body" && n.namespace == NS_XBL;
-              })[0];
-
-              addSyntheticLine(
-                `${item.attributes.name}(${params}) {`,
-                item.textLine
-              );
-              addNodeLines(body, 4);
-              addSyntheticLine(`},`, item.textEndLine);
-              break;
-            }
-            case "property": {
-              // Properties become one or two function declarations
-              for (let propdef of item.children) {
-                if (propdef.namespace != NS_XBL) {
-                  continue;
-                }
-
-                if (propdef.local == "setter") {
-                  addSyntheticLine(
-                    `set ${item.attributes.name}(val) {`,
-                    propdef.textLine
-                  );
-                } else if (propdef.local == "getter") {
-                  addSyntheticLine(
-                    `get ${item.attributes.name}() {`,
-                    propdef.textLine
-                  );
-                } else {
-                  continue;
-                }
-                addNodeLines(propdef, 4);
-                addSyntheticLine(`},`, propdef.textEndLine);
-              }
-              break;
-            }
-            case "handler": {
-              // Handlers become a function declaration with an `event`
-              // parameter.
-              addSyntheticLine(`function(event) {`, item.textLine);
-              addNodeLines(item, 4);
-              addSyntheticLine(`},`, item.textEndLine);
-              break;
-            }
-            default:
-              continue;
-          }
-        }
-
-        addSyntheticLine(
-          part.local == "implementation" ? `},` : `],`,
-          part.textEndLine
-        );
-      }
-      addSyntheticLine(`},`, binding.textEndLine);
-    }
-    addSyntheticLine(`};`, bindings.textEndLine);
-
-    let script = scriptLines.join("\n") + "\n";
-    return [script];
-  },
-
-  postprocess(messages, filename) {
-    // If there was an XML parse error then just return that
-    if (xmlParseError) {
-      return [xmlParseError];
-    }
-
-    // For every message from every script block update the line to point to the
-    // correct place.
-    let errors = [];
-    for (let i = 0; i < messages.length; i++) {
-      for (let message of messages[i]) {
-        // ESLint indexes lines starting at 1 but our arrays start at 0
-        let mapped = lineMap[message.line - 1];
-
-        message.line = mapped.line + 1;
-        if (mapped.offset) {
-          message.column -= mapped.offset;
-        } else {
-          message.column = NaN;
-        }
-
-        errors.push(message);
-      }
-    }
-
-    return errors;
-  },
-};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/processors/xul.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/processors/xul.js
@@ -12,17 +12,17 @@
 let path = require("path");
 let fs = require("fs");
 
 let XMLParser = require("./processor-helpers").XMLParser;
 
 // Stores any XML parse error
 let xmlParseError = null;
 
-// Stores the lines of JS code generated from the XBL
+// Stores the lines of JS code generated from the XUL.
 let scriptLines = [];
 // Stores a map from the synthetic line number to the real line number
 // and column offset.
 let lineMap = [];
 
 let includedRanges = [];
 
 // Deal with ifdefs. This is the state we pretend to have:
--- a/tools/lint/eslint/eslint-plugin-mozilla/package-lock.json
+++ b/tools/lint/eslint/eslint-plugin-mozilla/package-lock.json
@@ -1,11 +1,11 @@
 {
   "name": "eslint-plugin-mozilla",
-  "version": "2.2.0",
+  "version": "2.3.0",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
     "@babel/code-frame": {
       "version": "7.5.5",
       "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz",
       "integrity": "sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==",
       "dev": true,
--- a/tools/lint/eslint/eslint-plugin-mozilla/package.json
+++ b/tools/lint/eslint/eslint-plugin-mozilla/package.json
@@ -1,11 +1,11 @@
 {
   "name": "eslint-plugin-mozilla",
-  "version": "2.2.0",
+  "version": "2.3.0",
   "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
   "keywords": [
     "eslint",
     "eslintplugin",
     "eslint-plugin",
     "mozilla",
     "firefox"
   ],