diff --git a/lib/cli.js b/lib/cli.js index 593c354bc08b..487b03a8b256 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -137,6 +137,18 @@ const cli = { log.info("v" + require("../package.json").version); + } else if (currentOptions.printConfig) { + if (text) { + log.error("The --print-config option is not available for piped-in code."); + return 1; + } + + const engine = new CLIEngine(translateOptions(currentOptions)); + + const fileConfig = engine.getConfigForFile(currentOptions.printConfig); + + log.info(JSON.stringify(fileConfig, null, " ")); + return 0; } else if (currentOptions.help || (!files.length && !text)) { log.info(options.generateHelp()); @@ -153,24 +165,6 @@ const cli = { const engine = new CLIEngine(translateOptions(currentOptions)); - if (currentOptions.printConfig) { - if (files.length !== 1) { - log.error("The --print-config option requires a " + - "single file as positional argument."); - return 1; - } - - if (text) { - log.error("The --print-config option is not available for piped-in code."); - return 1; - } - - const fileConfig = engine.getConfigForFile(files[0]); - - log.info(JSON.stringify(fileConfig, null, " ")); - return 0; - } - const report = text ? engine.executeOnText(text, currentOptions.stdinFilename, true) : engine.executeOnFiles(files); if (currentOptions.fix) { diff --git a/lib/options.js b/lib/options.js index bbb2456a9804..f9f3f7d071cb 100644 --- a/lib/options.js +++ b/lib/options.js @@ -216,8 +216,8 @@ module.exports = optionator({ }, { option: "print-config", - type: "Boolean", - description: "Print the configuration to be used" + type: "path::String", + description: "Print the configuration which would be used for linting a given file (linting will not occur)" } ] }); diff --git a/package.json b/package.json index 6f818ac9ac0b..f23b017cea84 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "lodash": "^4.0.0", "mkdirp": "^0.5.0", "natural-compare": "^1.4.0", - "optionator": "^0.8.1", + "optionator": "^0.8.2", "path-is-inside": "^1.0.1", "pluralize": "^1.2.1", "progress": "^1.1.8", diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 648863a78ae6..c2e43d9b9119 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -880,17 +880,6 @@ describe("cli", function() { assert.equal(exitCode, 0); }); - it("should require a single positional file argument", function() { - const filePath1 = getFixturePath("files", "bar.js"); - const filePath2 = getFixturePath("files", "foo.js"); - - const exitCode = cli.execute("--print-config " + filePath1 + " " + filePath2); - - assert.isTrue(log.info.notCalled); - assert.isTrue(log.error.calledOnce); - assert.equal(exitCode, 1); - }); - it("should error out when executing on text", function() { const exitCode = cli.execute("--print-config", "foo = bar;"); diff --git a/tests/lib/options.js b/tests/lib/options.js index 6c1cd4ba2754..3bf7121d8621 100644 --- a/tests/lib/options.js +++ b/tests/lib/options.js @@ -359,10 +359,10 @@ describe("options", function() { }); describe("--print-config", function() { - it("should return true when passed --print-config", function() { - const currentOptions = options.parse("--print-config"); + it("should return file path when passed --print-config", function() { + const currentOptions = options.parse("--print-config file.js"); - assert.isTrue(currentOptions.printConfig); + assert.strictEqual(currentOptions.printConfig, "file.js"); }); }); });