Skip to content

Commit

Permalink
Breaking: Improving optionator configuration for --print-config
Browse files Browse the repository at this point in the history
  • Loading branch information
platinumazure committed Sep 21, 2016
1 parent 0a36138 commit b242031
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 35 deletions.
30 changes: 12 additions & 18 deletions lib/cli.js
Expand Up @@ -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());
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/options.js
Expand Up @@ -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)"
}
]
});
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
11 changes: 0 additions & 11 deletions tests/lib/cli.js
Expand Up @@ -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;");

Expand Down
6 changes: 3 additions & 3 deletions tests/lib/options.js
Expand Up @@ -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");
});
});
});

0 comments on commit b242031

Please sign in to comment.