Repository: eslint/eslint (js)

Issue:
Location of `version` property is inconsistent between core APIs
In ESLint 4.6.1, we have a `version` property on `CLIEngine` and `Linter` indicating the version of ESLint being used. However, the `version` property appears in different places; it's placed on `CLIEngine` directly, but it's placed on *instances* of `Linter`.

```js
const eslint = require("eslint");

eslint.CLIEngine.version // 4.6.1
eslint.Linter.version // undefined

new eslint.CLIEngine().version // undefined
new eslint.Linter().version // 4.6.1
```

This happened because the `version` property was added when `Linter` was a singleton rather than a constructor, so users were previously expected to access `eslint.linter.version`.

This could be mildly annoying; for example, an integration that only has access to `Linter` (like https://eslint.org/demo) would need to create a throwaway instance of `Linter` to get the version.

I propose that we add `version` as a static property of `Linter`. We could also copy it to `Linter.prototype` to prevent integrations from breaking if they were checking for the `version` property on instances.

Pull request:
Update: Create Linter.version API (fixes #9271)
<!--
    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)**

[ ] Documentation update
[ ] Bug fix ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/bug-report.md))
[ ] New rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-proposal.md))
[ ] Changes an existing rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-change-proposal.md))
[ ] Add autofixing to a rule
[ ] Add a CLI option
[x] Add something to the core
[ ] Other, please explain:

<!--
    If the item you've checked above has a template, please paste the template questions below and answer them. (If this pull request is addressing an issue, you can just paste a link to the issue here instead.)
-->

<!--
    Please ensure your pull request is ready:

    - Read the pull request guide (https://eslint.org/docs/developer-guide/contributing/pull-requests)
    - Include tests for this change
    - Update documentation for this change (if appropriate)
-->

<!--
    The following is required for all pull requests:
-->

**What changes did you make? (Give an overview)**

Added `Linter.version`. I used a getter because JavaScript doesn't yet have static class properties, and otherwise, I'd need to do some hacky thing to add a property to the `Linter` constructor. I think this makes sense since `Linter.version` should not be overwritten.


**Is there anything you'd like reviewers to focus on?**

Is this what was expected?



Patch:
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


Test patch:
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;