Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
New: CLIEngine#getRules() (refs #6582) (#9782)
  • Loading branch information
Patrick McElhaney authored and ilyavolodin committed Jan 4, 2018
1 parent c64195f commit 65f0176
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
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

0 comments on commit 65f0176

Please sign in to comment.