Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Create Linter.version API (fixes #9271) #11010

Merged
merged 1 commit into from Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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