diff --git a/lib/cli-engine.js b/lib/cli-engine.js index f68cda7cd..22237afba 100644 --- a/lib/cli-engine.js +++ b/lib/cli-engine.js @@ -11,11 +11,15 @@ var debug = require("debug")("text:cli-engine"); * Process files are wanted to lint. * CLIEngine is wrapper of textlint.js. * Aim to be called from cli with cli options. - * @param {object} options - cli option object + * @param {object|Config} options the options is command line options or Config object. * @constructor */ function CLIEngine(options) { - this.config = new Config(options); + if (options instanceof Config) { + this.config = options; + } else { + this.config = new Config(options); + } } /** * filter files by config diff --git a/lib/config/config.js b/lib/config/config.js index 085a1cbe1..45ee01726 100644 --- a/lib/config/config.js +++ b/lib/config/config.js @@ -16,10 +16,13 @@ var defaultOptions = { /** * Create config object form command line options * See options.js - * @param options the options is command line option object. @see options.js + * @param {object} options the options is command line option object. @see options.js * @constructor */ function Config(options) { + if (typeof options !== "object") { + return this; + } this.extensions = options.ext ? options.ext : defaultOptions.extensions; this.rulePaths = options.rulesdir ? options.rulesdir : defaultOptions.rulePaths; this.formatName = options.format ? options.format : defaultOptions.formatName; diff --git a/test/cli-engine-test.js b/test/cli-engine-test.js index dbd89ef84..62fa8055f 100644 --- a/test/cli-engine-test.js +++ b/test/cli-engine-test.js @@ -6,6 +6,26 @@ var rulesDir = __dirname + "/fixtures/rules"; var path = require("path"); describe("cli-engine-test", function () { var cliEngine; + describe("Constructor", function () { + context("when args is object", function () { + it("should convert the object and set config", function () { + cliEngine = new CLIEngine({ + rulesdir: [rulesDir] + }); + assert.deepEqual(cliEngine.config.rulePaths, [rulesDir]); + }); + }); + context("when args is Config object", function () { + it("should set directory to config", function () { + // Issue : when use Config as argus, have to export `../lib/config/config` + var Config = require("../lib/config/config"); + var config = new Config(); + config.rulePaths = [rulesDir]; + cliEngine = new CLIEngine(config); + assert.deepEqual(cliEngine.config.rulePaths, [rulesDir]); + }); + }); + }); describe("executeOnFiles", function () { beforeEach(function () { cliEngine = new CLIEngine({