diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md index bfd16e8d2e1..b72425262bd 100644 --- a/docs/developer-guide/nodejs-api.md +++ b/docs/developer-guide/nodejs-api.md @@ -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) @@ -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. diff --git a/lib/cli-engine.js b/lib/cli-engine.js index 55450fd633e..0c1afcbcebd 100644 --- a/lib/cli-engine.js +++ b/lib/cli-engine.js @@ -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. diff --git a/tests/lib/cli-engine.js b/tests/lib/cli-engine.js index ec5af55e7de..48bc82f10b8 100644 --- a/tests/lib/cli-engine.js +++ b/tests/lib/cli-engine.js @@ -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([