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

New: CLIEngine#getRules() (refs #6582) #9782

Merged
merged 1 commit into from Jan 4, 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
21 changes: 21 additions & 0 deletions docs/developer-guide/nodejs-api.md
Expand Up @@ -27,6 +27,7 @@ While ESLint is designed to be run on the command line, it's possible to use ESL
* [getFormatter()](#clienginegetformatter)
* [getErrorResults()](#clienginegeterrorresults)
* [outputFixes()](#cliengineoutputfixes)
* [getRules()](#clienginegetrules)
* [version](#cliengineversion)
* [RuleTester](#ruletester)
* [Customizing RuleTester](#customizing-ruletester)
Expand Down Expand Up @@ -732,6 +733,26 @@ var report = cli.executeOnFiles(["myfile.js", "lib/"]);
CLIEngine.outputFixes(report);
```

### CLIEngine#getRules()

This method returns a map of all loaded rules. Under the hood, it calls [Linter#getRules](#lintergetrules).

```js
const CLIEngine = require("eslint").CLIEngine;
const cli = new CLIEngine();

cli.getRules();

/*
Map {
'accessor-pairs' => { meta: { docs: [Object], schema: [Array] }, create: [Function: create] },
'array-bracket-newline' => { meta: { docs: [Object], schema: [Array] }, create: [Function: create] },
...
}
*/
```


### CLIEngine.version

`CLIEngine` has a static `version` property containing the semantic version number of ESLint that it comes from.
Expand Down
4 changes: 4 additions & 0 deletions lib/cli-engine.js
Expand Up @@ -420,6 +420,10 @@ class CLIEngine {
this.config = new Config(this.options, this.linter);
}

getRules() {
return this.linter.getRules();
}

/**
* Returns results that only contains errors.
* @param {LintResult[]} results The results to filter.
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/cli-engine.js
Expand Up @@ -2935,6 +2935,15 @@ describe("CLIEngine", () => {

});

describe("getRules()", () => {
it("should expose the list of rules", () => {
const engine = new CLIEngine();

assert.isTrue(engine.getRules().has("no-eval"), "no-eval is present");

});
});

describe("resolveFileGlobPatterns", () => {

leche.withData([
Expand Down