Skip to content

Commit

Permalink
Update: Create Linter.version API (fixes #9271) (#11010)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Oct 24, 2018
1 parent a940cf4 commit 3943635
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs/developer-guide/nodejs-api.md
Expand Up @@ -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.

Expand All @@ -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`.
Expand Down
9 changes: 9 additions & 0 deletions lib/linter.js
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/linter.js
Expand Up @@ -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;

Expand Down

0 comments on commit 3943635

Please sign in to comment.