Repository: eslint/eslint
Pull request #11009 (2018-10-23 20:39:31)

Fix: deprecation warning in RuleTester using Node v11
<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
-->

**What is the purpose of this pull request? (put an "X" next to item)**

[x] Bug fix

**Tell us about your environment**

* **ESLint Version:**
* **Node Version:**
* **npm Version:**

**What parser (default, Babel-ESLint, etc.) are you using?**

**Please show your full configuration:**

<details>
<summary>Configuration</summary>

<!-- Paste your configuration below: -->
```js

```

</details>

**What did you do? Please include the actual source code causing the issue.**

```js
"use strict";
const RuleTester = require("eslint").RuleTester;
try {
    new RuleTester().run(
        "foo",
        context => (context.report(context.getSourceCode().ast, "message"), {}),
        { valid: [], invalid: [{ code: "", errors: [5] }] }
    );
} catch (err) {
    // ignore
}
```

**What did you expect to happen?**

I expected `RuleTester` to produce no output because the error was caught.

**What actually happened? Please include the actual, raw output from ESLint.**

`RuleTester` printed a deprecation warning:

> (node:49648) [DEP0094] DeprecationWarning: assert.fail() with more than one argument is deprecated. Please use assert.strictEqual() instead or only pass a message.

**What changes did you make? (Give an overview)**

This updates `RuleTester` to avoid using the deprecated multi-argument `assert.fail` API in favor of the single-argument version. The single-argument version was introduced in Node v6.12.0, so we can use it since our support only covers Node `^6.14.0`.

**Is there anything you'd like reviewers to focus on?**

Nothing in particular



Patch:
diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md
index 47c0c84c3..a614d6b2f 100644
--- a/.github/ISSUE_TEMPLATE/BUG_REPORT.md
+++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.md
@@ -51,4 +51,10 @@ about: Report an issue with ESLint or rules bundled with ESLint
 
 **What did you expect to happen?**
 
+
 **What actually happened? Please include the actual, raw output from ESLint.**
+
+
+**Are you willing to submit a pull request to fix this bug?**
+
+
diff --git a/.github/ISSUE_TEMPLATE/CHANGE.md b/.github/ISSUE_TEMPLATE/CHANGE.md
index b5ae2ae83..3fe2fe241 100644
--- a/.github/ISSUE_TEMPLATE/CHANGE.md
+++ b/.github/ISSUE_TEMPLATE/CHANGE.md
@@ -19,6 +19,12 @@ about: Request a change that is not a bug fix, rule change, or new rule
 
 **The version of ESLint you are using.**
 
+
 **The problem you want to solve.**
 
+
 **Your take on the correct solution to problem.**
+
+
+**Are you willing to submit a pull request to implement this change?**
+
diff --git a/.github/ISSUE_TEMPLATE/NEW_RULE.md b/.github/ISSUE_TEMPLATE/NEW_RULE.md
index 3a04dc58a..8dfb93ba2 100644
--- a/.github/ISSUE_TEMPLATE/NEW_RULE.md
+++ b/.github/ISSUE_TEMPLATE/NEW_RULE.md
@@ -34,3 +34,7 @@ about: Propose a new rule to be added to ESLint
 ```
 
 **Why should this rule be included in ESLint (instead of a plugin)?**
+
+
+**Are you willing to submit a pull request to implement this rule?**
+
diff --git a/.github/ISSUE_TEMPLATE/RULE_CHANGE.md b/.github/ISSUE_TEMPLATE/RULE_CHANGE.md
index cc57bf532..9ecb2d002 100644
--- a/.github/ISSUE_TEMPLATE/RULE_CHANGE.md
+++ b/.github/ISSUE_TEMPLATE/RULE_CHANGE.md
@@ -33,3 +33,5 @@ about: Request a change to an existing rule
 **What does the rule currently do for this code?**
 
 **What will the rule do after it's changed?**
+
+**Are you willing to submit a pull request to implement this change?**
\ No newline at end of file
diff --git a/Makefile.js b/Makefile.js
index 896be6a5b..473ffdf58 100644
--- a/Makefile.js
+++ b/Makefile.js
@@ -849,7 +849,7 @@ target.browserify = function() {
     exec(`${getBinFile("browserify")} -x espree ${TEMP_DIR}linter.js -o ${BUILD_DIR}eslint.js -s eslint --global-transform [ babelify --presets [ es2015 ] ]`);
 
     // 6. Browserify espree
-    exec(`${getBinFile("browserify")} -r espree -o ${TEMP_DIR}espree.js`);
+    exec(`${getBinFile("browserify")} -r espree -o ${TEMP_DIR}espree.js --global-transform [ babelify --presets [ es2015 ] ]`);
 
     // 7. Concatenate Babel polyfill, Espree, and ESLint files together
     cat("./node_modules/babel-polyfill/dist/polyfill.js", `${TEMP_DIR}espree.js`, `${BUILD_DIR}eslint.js`).to(`${BUILD_DIR}eslint.js`);
diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md
index a2959d8e9..8dbccc7af 100644
--- a/docs/developer-guide/nodejs-api.md
+++ b/docs/developer-guide/nodejs-api.md
@@ -291,7 +291,7 @@ linter.defineParser("my-custom-parser", {
 const results = linter.verify("// some source text", { parser: "my-custom-parser" });
 ```
 
-### Linter#version
+### Linter#version/Linter.version
 
 Each instance of `Linter` has a `version` property containing the semantic version number of ESLint that the `Linter` instance is from.
 
@@ -302,6 +302,14 @@ const linter = new Linter();
 linter.version; // => '4.5.0'
 ```
 
+There is also a `Linter.version` property that you can read without instantiating `Linter`:
+
+```js
+const Linter = require("eslint").Linter;
+
+Linter.version; // => '4.5.0'
+```
+
 ## linter
 
 The `eslint.linter` object (deprecated) is an instance of the `Linter` class as defined [above](#linter). `eslint.linter` exists for backwards compatibility, but we do not recommend using it because any mutations to it are shared among every module that uses `eslint`. Instead, please create your own instance of `eslint.Linter`.
diff --git a/lib/linter.js b/lib/linter.js
index 8f7bdf9e4..b47e6eb1f 100644
--- a/lib/linter.js
+++ b/lib/linter.js
@@ -888,6 +888,15 @@ module.exports = class Linter {
         this.environments = new Environments();
     }
 
+    /**
+     * Getter for package version.
+     * @static
+     * @returns {string} The version from package.json.
+     */
+    static get version() {
+        return pkg.version;
+    }
+
     /**
      * Configuration object for the `verify` API. A JS representation of the eslintrc files.
      * @typedef {Object} ESLintConfig
diff --git a/lib/rules/no-irregular-whitespace.js b/lib/rules/no-irregular-whitespace.js
index 729f829a1..de6934c63 100644
--- a/lib/rules/no-irregular-whitespace.js
+++ b/lib/rules/no-irregular-whitespace.js
@@ -81,9 +81,7 @@ module.exports = {
             const locStart = node.loc.start;
             const locEnd = node.loc.end;
 
-            errors = errors.filter(error => {
-                const errorLoc = error[1];
-
+            errors = errors.filter(({ loc: errorLoc }) => {
                 if (errorLoc.line >= locStart.line && errorLoc.line <= locEnd.line) {
                     if (errorLoc.column >= locStart.column && (errorLoc.column <= locEnd.column || errorLoc.line < locEnd.line)) {
                         return false;
@@ -157,7 +155,7 @@ module.exports = {
                         column: match.index
                     };
 
-                    errors.push([node, location, "Irregular whitespace not allowed."]);
+                    errors.push({ node, message: "Irregular whitespace not allowed.", loc: location });
                 }
             });
         }
@@ -182,7 +180,7 @@ module.exports = {
                     column: sourceLines[lineIndex].length
                 };
 
-                errors.push([node, location, "Irregular whitespace not allowed."]);
+                errors.push({ node, message: "Irregular whitespace not allowed.", loc: location });
                 lastLineIndex = lineIndex;
             }
         }
@@ -224,9 +222,7 @@ module.exports = {
                 }
 
                 // If we have any errors remaining report on them
-                errors.forEach(error => {
-                    context.report(...error);
-                });
+                errors.forEach(error => context.report(error));
             };
         } else {
             nodes.Program = noop;


Test patch:
diff --git a/lib/testers/rule-tester.js b/lib/testers/rule-tester.js
index 9fbca945b..6d1bba989 100644
--- a/lib/testers/rule-tester.js
+++ b/lib/testers/rule-tester.js
@@ -397,7 +397,7 @@ class RuleTester {
          */
         function assertASTDidntChange(beforeAST, afterAST) {
             if (!lodash.isEqual(beforeAST, afterAST)) {
-                assert.fail(null, null, "Rule should not modify AST.");
+                assert.fail("Rule should not modify AST.");
             }
         }
 
@@ -551,7 +551,7 @@ class RuleTester {
                     } else {
 
                         // Message was an unexpected type
-                        assert.fail(message, null, "Error should be a string, object, or RegExp.");
+                        assert.fail(`Error should be a string, object, or RegExp, but found (${util.inspect(message)})`);
                     }
                 }
             }
diff --git a/tests/lib/linter.js b/tests/lib/linter.js
index dd8e10b95..5b2f2c31a 100644
--- a/tests/lib/linter.js
+++ b/tests/lib/linter.js
@@ -76,6 +76,14 @@ describe("Linter", () => {
         sandbox.verifyAndRestore();
     });
 
+    describe("Static Members", () => {
+        describe("version", () => {
+            it("should return same version as instance property", () => {
+                assert.strictEqual(Linter.version, linter.version);
+            });
+        });
+    });
+
     describe("when using events", () => {
         const code = TEST_CODE;