Attachment #8833634: Self-hosting eslint plugin for bug #1330006

View | Details | Raw Unified | Return to bug 1330006
Collapse All | Expand All

(-)a/.eslintignore (-1 / +9 lines)
Line     Link Here 
 Lines 19-35   editor/** Link Here 
19
embedding/**
19
embedding/**
20
extensions/**
20
extensions/**
21
gfx/**
21
gfx/**
22
gradle/**
22
gradle/**
23
hal/**
23
hal/**
24
image/**
24
image/**
25
intl/**
25
intl/**
26
ipc/**
26
ipc/**
27
js/**
28
layout/**
27
layout/**
29
media/**
28
media/**
30
memory/**
29
memory/**
31
mfbt/**
30
mfbt/**
32
modules/**
31
modules/**
33
mozglue/**
32
mozglue/**
34
netwerk/**
33
netwerk/**
35
nsprpub/**
34
nsprpub/**
 Lines 150-165   devtools/client/debugger/test/mochitest/ Link Here 
150
devtools/client/debugger/test/mochitest/code_math.min.js
149
devtools/client/debugger/test/mochitest/code_math.min.js
151
devtools/client/debugger/test/mochitest/code_math_bogus_map.js
150
devtools/client/debugger/test/mochitest/code_math_bogus_map.js
152
devtools/client/debugger/test/mochitest/code_ugly*
151
devtools/client/debugger/test/mochitest/code_ugly*
153
devtools/client/debugger/test/mochitest/code_worker-source-map.js
152
devtools/client/debugger/test/mochitest/code_worker-source-map.js
154
devtools/client/framework/test/code_ugly*
153
devtools/client/framework/test/code_ugly*
155
devtools/server/tests/unit/babel_and_browserify_script_with_source_map.js
154
devtools/server/tests/unit/babel_and_browserify_script_with_source_map.js
156
devtools/server/tests/unit/setBreakpoint*
155
devtools/server/tests/unit/setBreakpoint*
157
156
157
# Exclude everything but selfhosted JS
158
js/ductwork/**
159
js/examples/**
160
js/ipc/**
161
js/public/**
162
js/xpconnect/**
163
js/src/jit-tests/**
164
js/src/tests/**
165
158
# mobile/android/ exclusions
166
# mobile/android/ exclusions
159
mobile/android/tests/
167
mobile/android/tests/
160
168
161
# Uses `#filter substitution`
169
# Uses `#filter substitution`
162
mobile/android/b2gdroid/app/b2gdroid.js
170
mobile/android/b2gdroid/app/b2gdroid.js
163
mobile/android/app/mobile.js
171
mobile/android/app/mobile.js
164
mobile/android/chrome/content/healthreport-prefs.js
172
mobile/android/chrome/content/healthreport-prefs.js
165
173
(-)a/js/src/builtin/.eslintrc.js (+21 lines)
Line     Link Here 
Line 0    Link Here 
1
"use strict";
2
3
module.exports = {
4
  "extends": [
5
    "../../../toolkit/.eslintrc.js"
6
  ],
7
8
  "rules": {
9
    // We should fix those at some point, but we use this to detect NaNs.
10
    "no-self-compare": "off",
11
    // Disabling these two make it easier to implement the spec.
12
    "spaced-comment": "off",
13
    "no-lonely-if": "off",
14
    // SpiderMonkey's style doesn't match any of the possible options.
15
    "brace-style": "off",
16
    // Manually defining all the selfhosted methods is a slog.
17
    "no-undef": "off",
18
    // Disabled until we can use let/const to fix those erorrs.
19
    "no-redeclare": "off",
20
  }
21
};
(-)a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js (+1 lines)
Line     Link Here 
 Lines 10-25    Link Here 
10
10
11
//------------------------------------------------------------------------------
11
//------------------------------------------------------------------------------
12
// Plugin Definition
12
// Plugin Definition
13
//------------------------------------------------------------------------------
13
//------------------------------------------------------------------------------
14
14
15
module.exports = {
15
module.exports = {
16
  processors: {
16
  processors: {
17
    ".xml": require("../lib/processors/xbl-bindings"),
17
    ".xml": require("../lib/processors/xbl-bindings"),
18
    ".js": require("../lib/processors/self-hosted"),
18
  },
19
  },
19
  rules: {
20
  rules: {
20
    "avoid-removeChild": require("../lib/rules/avoid-removeChild"),
21
    "avoid-removeChild": require("../lib/rules/avoid-removeChild"),
21
    "balanced-listeners": require("../lib/rules/balanced-listeners"),
22
    "balanced-listeners": require("../lib/rules/balanced-listeners"),
22
    "import-browserjs-globals": require("../lib/rules/import-browserjs-globals"),
23
    "import-browserjs-globals": require("../lib/rules/import-browserjs-globals"),
23
    "import-globals": require("../lib/rules/import-globals"),
24
    "import-globals": require("../lib/rules/import-globals"),
24
    "import-headjs-globals": require("../lib/rules/import-headjs-globals"),
25
    "import-headjs-globals": require("../lib/rules/import-headjs-globals"),
25
    "import-test-globals": require("../lib/rules/import-test-globals"),
26
    "import-test-globals": require("../lib/rules/import-test-globals"),
(-)a/tools/lint/eslint/eslint-plugin-mozilla/lib/processors/self-hosted.js (+50 lines)
Line     Link Here 
Line 0    Link Here 
1
/**
2
 * @fileoverview Remove macros from SpiderMonkey's self-hosted JS.
3
 *
4
 * This Source Code Form is subject to the terms of the Mozilla Public
5
 * License, v. 2.0. If a copy of the MPL was not distributed with this
6
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
 */
8
9
"use strict";
10
11
const selfHostedRegex = /js\/src\/builtin\/.*?\.js$/;
12
const macroRegex = /\s*\#(if|ifdef|else|elif|endif|include|define|undef).*/;
13
14
module.exports = {
15
  preprocess: function(text, filename) {
16
    if (!selfHostedRegex.test(filename)) {
17
      return [text];
18
    }
19
20
    let lines = text.split(/\n/);
21
    for (let i = 0; i < lines.length; i++) {
22
      if (!macroRegex.test(lines[i])) {
23
        // No macro here, nothing to do.
24
        continue;
25
      }
26
27
      for (; i < lines.length; i++) {
28
        lines[i] = "// " + lines[i];
29
30
        // If the line ends with a backslash (\), the next line
31
        // is also part of part of the macro.
32
        if (!lines[i].endsWith("\\")) {
33
          break;
34
        }
35
      }
36
    }
37
38
    return [lines.join("\n")];
39
  },
40
41
  postprocess: function(messages, filename) {
42
    let errors = [];
43
    for (let i = 0; i < messages.length; i++) {
44
      for (let message of messages[i]) {
45
        errors.push(message);
46
      }
47
    }
48
    return errors;
49
  }
50
}
(-)a/tools/lint/eslint/eslint-plugin-mozilla/package.json (-1 / +1 lines)
Line     Link Here 
 Lines 1-11    Link Here 
1
{
1
{
2
  "name": "eslint-plugin-mozilla",
2
  "name": "eslint-plugin-mozilla",
3
  "version": "0.2.17",
3
  "version": "0.2.18",
4
  "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
4
  "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
5
  "keywords": [
5
  "keywords": [
6
    "eslint",
6
    "eslint",
7
    "eslintplugin",
7
    "eslintplugin",
8
    "eslint-plugin",
8
    "eslint-plugin",
9
    "mozilla",
9
    "mozilla",
10
    "firefox"
10
    "firefox"
11
  ],
11
  ],

Return to bug 1330006