Bug 1330006 - Land and enable self-hosted JS eslint plugin. r=till,mossop
authorTom Schuster <evilpies@gmail.com>
Tue, 07 Feb 2017 21:58:21 +0100
changeset 387938 4d103004bfc61b821b089d0119927f5914fca407
parent 387937 9b5f5d8b490679a00ab3042ef0d3bfb5eaf14b7a
child 387939 406d351b9dc84e31faab5384a4683d9b1f3ba0f6
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill, mossop
bugs1330006
milestone54.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 1330006 - Land and enable self-hosted JS eslint plugin. r=till,mossop
.eslintignore
js/src/builtin/.eslintrc.js
tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
tools/lint/eslint/eslint-plugin-mozilla/lib/processors/self-hosted.js
tools/lint/eslint/eslint-plugin-mozilla/package.json
--- a/.eslintignore
+++ b/.eslintignore
@@ -19,17 +19,16 @@ editor/**
 embedding/**
 extensions/**
 gfx/**
 gradle/**
 hal/**
 image/**
 intl/**
 ipc/**
-js/**
 layout/**
 media/**
 memory/**
 mfbt/**
 modules/**
 mozglue/**
 netwerk/**
 nsprpub/**
@@ -149,16 +148,27 @@ devtools/client/debugger/test/mochitest/
 devtools/client/debugger/test/mochitest/code_math.min.js
 devtools/client/debugger/test/mochitest/code_math_bogus_map.js
 devtools/client/debugger/test/mochitest/code_ugly*
 devtools/client/debugger/test/mochitest/code_worker-source-map.js
 devtools/client/framework/test/code_ugly*
 devtools/server/tests/unit/babel_and_browserify_script_with_source_map.js
 devtools/server/tests/unit/setBreakpoint*
 
+# Exclude everything but self-hosted JS
+js/ductwork/**
+js/examples/**
+js/ipc/**
+js/public/**
+js/xpconnect/**
+js/src/devtools/**
+js/src/octane/**
+js/src/jit-test/**
+js/src/tests/**
+
 # mobile/android/ exclusions
 mobile/android/tests/
 
 # Uses `#filter substitution`
 mobile/android/b2gdroid/app/b2gdroid.js
 mobile/android/app/mobile.js
 mobile/android/chrome/content/healthreport-prefs.js
 
new file mode 100644
--- /dev/null
+++ b/js/src/builtin/.eslintrc.js
@@ -0,0 +1,22 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "../../../toolkit/.eslintrc.js"
+  ],
+
+  "rules": {
+    // We should fix those at some point, but we use this to detect NaNs.
+    "no-self-compare": "off",
+    // Disabling these two make it easier to implement the spec.
+    "spaced-comment": "off",
+    "no-lonely-if": "off",
+    // SpiderMonkey's style doesn't match any of the possible options.
+    "brace-style": "off",
+    // Manually defining all the selfhosted methods is a slog.
+    "no-undef": "off",
+    // Disabled until we can use let/const to fix those erorrs,
+    // and undefined names cause an exception and abort during runtime initialization.
+    "no-redeclare": "off",
+  }
+};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
@@ -10,16 +10,17 @@
 
 //------------------------------------------------------------------------------
 // Plugin Definition
 //------------------------------------------------------------------------------
 
 module.exports = {
   processors: {
     ".xml": require("../lib/processors/xbl-bindings"),
+    ".js": require("../lib/processors/self-hosted"),
   },
   rules: {
     "avoid-removeChild": require("../lib/rules/avoid-removeChild"),
     "balanced-listeners": require("../lib/rules/balanced-listeners"),
     "import-browserjs-globals": require("../lib/rules/import-browserjs-globals"),
     "import-globals": require("../lib/rules/import-globals"),
     "import-headjs-globals": require("../lib/rules/import-headjs-globals"),
     "import-test-globals": require("../lib/rules/import-test-globals"),
new file mode 100644
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/processors/self-hosted.js
@@ -0,0 +1,44 @@
+/**
+ * @fileoverview Remove macros from SpiderMonkey's self-hosted JS.
+ *
+ * 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 selfHostedRegex = /js\/src\/builtin\/.*?\.js$/;
+const macroRegex = /\s*\#(if|ifdef|else|elif|endif|include|define|undef).*/;
+
+module.exports = {
+  preprocess: function(text, filename) {
+    if (!selfHostedRegex.test(filename)) {
+      return [text];
+    }
+
+    let lines = text.split(/\n/);
+    for (let i = 0; i < lines.length; i++) {
+      if (!macroRegex.test(lines[i])) {
+        // No macro here, nothing to do.
+        continue;
+      }
+
+      for (; i < lines.length; i++) {
+        lines[i] = "// " + lines[i];
+
+        // If the line ends with a backslash (\), the next line
+        // is also part of part of the macro.
+        if (!lines[i].endsWith("\\")) {
+          break;
+        }
+      }
+    }
+
+    return [lines.join("\n")];
+  },
+
+  postprocess: function(messages, filename) {
+    return Array.prototype.concat.apply([], messages);
+  }
+}
--- 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": "0.2.18",
+  "version": "0.2.19",
   "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
   "keywords": [
     "eslint",
     "eslintplugin",
     "eslint-plugin",
     "mozilla",
     "firefox"
   ],