Skip to content

Commit

Permalink
New: CLIEngine#getRules() (refs eslint#6582)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Dec 28, 2017
1 parent c8bf687 commit 1d7a289
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
20 changes: 20 additions & 0 deletions docs/developer-guide/nodejs-api.md
Expand Up @@ -678,12 +678,32 @@ var cli = new CLIEngine({
}
});


// lint myfile.js and all files in lib/
var report = cli.executeOnFiles(["myfile.js", "lib/"]);

// output fixes to disk
CLIEngine.outputFixes(report);
```
### 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

Expand Down
5 changes: 5 additions & 0 deletions lib/cli-engine.js
Expand Up @@ -428,6 +428,11 @@ 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
11 changes: 10 additions & 1 deletion tests/lib/cli-engine.js
Expand Up @@ -138,7 +138,7 @@ describe("CLIEngine", () => {
assert.equal(report.results[0].fixableWarningCount, 0);
});

it("should report the toatl and per file warnings when using local cwd .eslintrc", () => {
it("should report the total and per file warnings when using local cwd .eslintrc", () => {

engine = new CLIEngine({
rules: {
Expand Down Expand Up @@ -2811,6 +2811,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 1d7a289

Please sign in to comment.